message: 403: {"code":"ENTITLEMENT_ERROR","message":"Error 403: the user is not subscribed to required model plan"}

stop_reason: error


error_message: 403: {"code":"ENTITLEMENT_ERROR","message":"Error 403: the user is not subscribed to required model plan"}


<analysis>
**Literal Request**: Survey the codebase to find the smallest default-OFF implementation seam for Telegram Channel Direct Messages in NutriCoach, compare v1.4 worktree with frozen v1.1, and report exact files, symbols, and line references without editing.
**Actual Need**: Identify where Telegram updates are parsed, routed, dispatched, configured, and tested so a new capability can be added with minimal blast radius and clear compatibility boundaries.
**Success Looks Like**: A precise integration path with absolute file paths, symbol/line pointers, dependency graph, risk notes, and test seams for an isolated adapter/module hook.
</analysis>


<results>
<files>
- /home/cube/projects/richard/.worktrees/nutricoach-v140-impl/gateway/platforms/telegram.py - main seam for Telegram update parsing, send/edit transport, DM-topic routing, and callback/text dispatch.
- /home/cube/projects/richard/.worktrees/nutricoach-v111-impl/gateway/platforms/telegram.py - frozen comparison; same DM-topic metadata/routing shape.
- /home/cube/projects/richard/.worktrees/nutricoach-v140-impl/gateway/platforms/base.py - metadata/reply-anchor builders that seed Telegram fallback routing.
- /home/cube/projects/richard/.worktrees/nutricoach-v140-impl/gateway/delivery.py - delivery router that preserves explicit `direct_messages_topic_id` and creates named private DM topics.
- /home/cube/projects/richard/.worktrees/nutricoach-v140-impl/gateway/config.py - Telegram config/env bridge; no DM-topic feature flag present.
- /home/cube/projects/richard/.worktrees/nutricoach-v140-impl/tests/gateway/test_dm_topics.py - inbound DM-topic parsing and routing tests.
- /home/cube/projects/richard/.worktrees/nutricoach-v140-impl/tests/gateway/test_telegram_thread_fallback.py - send/typing fallback behavior for forum and private DM topics.
- /home/cube/projects/richard/.worktrees/nutricoach-v140-impl/tests/gateway/test_telegram_reply_mode.py - `reply_to_mode` contract for DM-topic fallback.
- /home/cube/projects/richard/.worktrees/nutricoach-v140-impl/tests/gateway/test_delivery.py - explicit `direct_messages_topic_id` propagation through delivery routing.
- /home/cube/projects/richard/.worktrees/nutricoach-v140-impl/tests/gateway/test_telegram_rich_messages.py - rich-send routing drops `message_thread_id` when direct DM topic metadata is present.
</files>

<answer>
Bot API 10.2 DM-topic fields are already represented in both worktrees on the outbound side.

Evidence:
- `gateway/platforms/telegram.py:877-982` has `_metadata_direct_messages_topic_id()` and `_thread_kwargs_for_send()` emitting `direct_messages_topic_id`.
- `gateway/platforms/telegram.py:1018-1094` retries DM-topic sends and strips routing correctly on failure.
- `gateway/platforms/base.py:47-94` seeds `telegram_dm_topic_reply_fallback` and `direct_messages_topic_id` from Telegram DM sources.
- `gateway/delivery.py:353-357` preserves explicit `direct_messages_topic_id` metadata.
- `gateway/config.py:1328-1417` has Telegram config parsing, but no DM-topic enable flag.
- `gateway/platforms/telegram.py:15349-15490` still parses inbound messages only from `message_thread_id` + `is_topic_message`; there is no separate Bot API direct-messages-topic update field handling.

Smallest default-OFF seam:
- Extract Telegram DM-topic routing into a dedicated helper module like `/home/cube/projects/richard/.worktrees/nutricoach-v140-impl/gateway/platforms/telegram_dm_topics.py`.
- Keep `TelegramAdapter` thin and hook only:
  - `_build_message_event`
  - `_thread_kwargs_for_send`
  - `_compute_single_send_routing`
  - the callback path that re-sends into the prompt topic
- Leave `base.py` and `delivery.py` as metadata producers/consumers.

Compatibility risks:
- preserve `reply_to_mode="off"` on `telegram_dm_topic_reply_fallback`
- preserve named-topic creation via `telegram_dm_topic_created_for_send`
- never send `message_thread_id` together with `direct_messages_topic_id`
- keep inbound DM-topic parsing gated by `is_topic_message` so ordinary reply anchors do not become durable threads

Worktree strategy:
- Use a new sibling isolated worktree off the sealed v1.4 tree.
- Keep the frozen v1.1 tree read-only as comparison baseline.
- Do not touch the sealed v1.4 worktree for the extraction; that keeps the delta small and reviewable.
</answer>

<next_steps>
Use the sibling worktree and pin the seam with tests in `test_dm_topics.py`, `test_telegram_thread_fallback.py`, `test_telegram_reply_mode.py`, `test_delivery.py`, and `test_telegram_rich_messages.py` before any refactor.
</next_steps>
</results>