Skip to content

fix(desktop): declare a mode for Bot sessions - #4213

Open
orangeCatDeveloper wants to merge 3 commits into
apache:mainfrom
orangeCatDeveloper:fix/bot-session-declared-mode
Open

fix(desktop): declare a mode for Bot sessions#4213
orangeCatDeveloper wants to merge 3 commits into
apache:mainfrom
orangeCatDeveloper:fix/bot-session-declared-mode

Conversation

@orangeCatDeveloper

@orangeCatDeveloper orangeCatDeveloper commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Fixes #4193

Every Bot conversation (Feishu, Telegram, WeCom) answers Maka 暂时无法处理这条消息:机器人对话处理失败 and no session is ever created, while the platform connection itself stays healthy.

Root cause: explore is a boundary a product mode confers, not one a caller may request directly (create-session-input.ts), but the Bot adapter requested it directly — permissionMode: 'explore' with no mode. prepareCreate rejects that, and the rejection matches no category in generalizedErrorMessage, so the Bot shows the generic fallback and the failure reads like a platform or credentials problem. Desktop chat is unaffected: it starts at ask.

A Bot session is exactly such a product intent, so bot joins SESSION_START_MODE_SPECS and the adapter names it instead of asking for explore. Unlike Deep Research it carries no name of its own — prepareCreate resolves mode?.name ?? input.name, and a fixed spec name would flatten 飞书 任务 / Telegram 任务 into one label — so SessionStartModeSpec.name becomes optional. Its mode:bot label is reserved for free, since prepareCreate already refuses caller-supplied mode labels.

The registry itself moves from deep-research.ts to session-start-mode.ts. It was born there when Deep Research was its only member; bot is a sibling, not a Deep Research detail, and nobody looks for Bot permissions in a file named for Deep Research. Pure move — the importers that only wanted the generic symbols follow the new path.

A mode without a name of its own also exposed a sibling defect: sessions:create dropped the requested name whenever a mode was present, which held only while every mode carried one. It now forwards the name either way and leaves the precedence to the Host. The Bot adapter talks to the Host directly and never took that path, so this is a contract repair, not a second user-visible bug.

Deliberately not covered: bot-incoming-main.ts still swallows invalid_request into 机器人对话处理失败, which is what made this take a packaged-app patch to diagnose. updateSessionConfiguration still admits explore with no mode — the path prepareSession uses to re-arm a bound Bot session.

Before / after, session creation with the input the Feishu Bot actually sends:

BEFORE session.create => {"ok":false,"error":{"code":"invalid_request","message":"Session creation requires a declared mode for explore permission"}}

AFTER  session.create => ok: true persisted: {"name":"飞书 任务","labels":["bot","feishu","mode:bot"],"permissionMode":"explore"}

Both regressions are guarded where they were rejected — at the coordinator and at the IPC handler. The Bot adapter's own test never reached either: its fake client returns a session without entering prepareCreate, which is why this shipped.

Generative tooling: Claude Code (Opus 5) wrote this change; commits carry a Generated-by trailer.

@github-actions github-actions Bot added the effort/S Under 100 readable lines label Aug 29, 2026
@orangeCatDeveloper
orangeCatDeveloper force-pushed the fix/bot-session-declared-mode branch 3 times, most recently from f013205 to 45a2eba Compare August 29, 2026 20:07
Explore is a boundary a product mode confers, not one a caller may request
directly, so the Bot adapter's bare `permissionMode: 'explore'` was rejected
and no Bot conversation could open a session. Bot is such a mode, and it
carries no name of its own so a Session still reads as the platform that
opened it.

`session.create.mode` accepts a value it did not before, and a Host that
predates it answers `Invalid Session start mode`, so the compatibility epoch
moves with it.

Generated-by: Claude Code
`sessions:create` dropped the requested name whenever a mode was present,
which held only while every mode carried a name of its own. The Host already
resolves that precedence, so the name goes to it either way.

Generated-by: Claude Code
The registry was born with Deep Research as its only member, so it lived in
that module. `bot` is a sibling, not a Deep Research detail, and nobody looks
for Bot permissions in a file named for Deep Research.

Generated-by: Claude Code
@orangeCatDeveloper
orangeCatDeveloper force-pushed the fix/bot-session-declared-mode branch from 45a2eba to a6a5147 Compare August 29, 2026 20:11
@orangeCatDeveloper
orangeCatDeveloper marked this pull request as ready for review August 29, 2026 20:34
@github-actions github-actions Bot added effort/M Under 500 readable lines and removed effort/S Under 100 readable lines labels Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/M Under 500 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Bot (Feishu/Telegram/WeCom) sessions fail with 机器人对话处理失败: runtime host rejects explore sessions without a declared mode

1 participant