Repository navigation
feat(desktop): add a CodeMode preference - #3850
nitishagar wants to merge 3 commits into
Conversation
Astro-Han
left a comment
There was a problem hiding this comment.
I reviewed this head and found no blocking issues.
Adds CodeMode preference correctly scoped (auto as omission, strict toolMode validation, backend unavailable on unsupported); no second path.
No P0-P3. Note: exact head currently has no hosted checks — needs CI green before merge.
简体中文
该头无阻断,待 CI。Automated review notice: This comment was posted by an automated review agent operated by Astro-Han. It is not an independent human review and does not replace one.
|
I think we need a rebase before proceeding. |
0e6d2aa to
064d699
Compare
There was a problem hiding this comment.
This PR is the producer that makes Code Mode reachable in production. Nothing in production assigns toolMode = 'code_mode' today (#3213). That makes this an execution-model change rather than a preference, and the body should carry the weight of one — right now it reads as "add a setting".
I posted the surrounding context as a status revision on #1383, including the #2466 gate outcome. The short version: same verifier pass rate at roughly 1.7x provider steps, 3.7x tool calls, and 2x tokens, and a decision to keep Code Mode default-off with no automatic enablement for any model.
To be precise about scope, since it matters below: selecting Code Mode adds exec alongside the existing direct tools (projectToolModePlan, ai-sdk-backend.ts:519-530). It is not CodeModeOnly, and #2466's 3.7x tool-call figure was measured on exactly this configuration.
P1 — selecting Auto after Code Mode is a silent no-op
runtime-host-settings-ipc-main.ts:416 drops auto from the patch:
...(patch.toolModePreference === "direct" || patch.toolModePreference === "code_mode"
? { toolModePreference: patch.toolModePreference }
: {}),and the commit is a spread merge, so a stored code_mode survives. The user selects Auto, the UI accepts it, and nothing changes — the only way back is editing settings.json. Three lines above, the same function uses Object.hasOwn(patch, "thinkingLevel"), which is the clearing idiom this needs.
Combined with the cost profile, the practical effect is: turning it on doubles the token bill, drops the cache, and cannot be turned off from the UI.
P2 — per-send resolution rebuilds the provider prompt cache for every live session
runtime-host-session-execution-ipc-main.ts:275 resolves the preference on every send. Tool definitions sit at the front of the request prefix, ahead of the whole conversation, so adding exec invalidates the cache for everything after it.
The repository already treats this as user-visible for the model switcher:
switchWarning: 'Switching may rebuild the provider prompt cache, making the next request slower or more expensive.'
shown at the point of action in chat-model-switcher.tsx:241 and announced via its live region. Tool mode has no equivalent, and its blast radius is larger: model switching is per-session and user-initiated inside that session, while this is a global setting whose change lands on every open session at its next send. One click in Settings can rebuild the cache of every long conversation at once, from a screen where none of them are visible.
The PR's own copy already describes the safer behavior — "only tasks created after the change are affected" / "仅影响更改设置后新建的任务" — and #2578's acceptance says "applies to new runs". Two of the three say new tasks; only the implementation says per send. Resolving once at session creation and pinning it to the session satisfies the copy, satisfies the acceptance, and removes this whole class of problem.
P2 — the advertised unavailable state is compiled out
tool-mode-preference.ts:41 is export const DESKTOP_CODE_MODE_AVAILABLE = true;, so the "Unavailable on this backend" / 「当前后端不可用」 path and both locale strings are unreachable in every shipping build. #2578 asks for "a clear unavailable state if the selected backend cannot execute CodeMode" and "unsupported backends do not silently ignore an explicit CodeMode selection". Given that current evidence points to one model family using Code Mode effectively, this is the single most load-bearing signal in the feature, and it is the one that does not work.
The UI/UX change needs a before/after
This changes what the model can do, and three things are invisible in the diff:
- No in-product indication of which mode a task is running. After enabling Code Mode there is nowhere a user can see that a given task is using it.
- No cost signal. The four user-facing strings are
Auto (currently direct),Direct tool calls,Code Mode,Unavailable on this backend. None mentions that the measured cost is roughly double. - The unavailable state cannot be photographed, per the point above.
Screenshots of the Settings selector in both locales, plus a short impact statement covering the above, would let a reviewer judge the change that is actually shipping.
Question — exec name collision
ai-sdk-backend.ts:1731 throws Tool name "exec" is reserved for Code Mode. when the surface already contains a tool named exec. If a user's MCP server exposes one, does enabling this preference fail that session's turns? If so it is worth stating how it surfaces.
CI
test is failing. The protocol compatibility epoch guard flags packages/runtime-host/src/protocol/turn.ts; the epoch is unchanged and there is no declaration under packages/runtime-host/protocol-compatible-changes/.
The product boundary the PR chose is right — auto resolves at the boundary and never enters Runtime, which is what #2578 asked for. The concerns above are about exposure and binding, not about the shape.
AI use: Claude Code assisted with source and issue investigation; the analysis and conclusions are my own.
e86a52e to
41c1149
Compare
Add the closed 'auto' | 'direct' | 'code_mode' preference beside the existing chat defaults: an optional ChatDefaultsSettings.toolModePreference whose normalization is total (missing legacy values and garbage both land on 'auto', never failing validation), and the matching RuntimePolicy field whose codec persists explicit overrides only — 'auto' is stored as field omission so policy documents written before this preference stay canonical without a schema bump. Runtime never observes the preference itself, only the resolved concrete mode. Generated-by: pi
Let a trusted host resolve the user's chat-defaults tool-mode preference into the existing per-run plumbing: turn.start accepts an optional concrete toolMode (validated at the protocol boundary — 'auto' cannot cross), the interactive coordinator places it on the external-message execution descriptor beside maxSteps, and the durable admission carries it so retried and recovered Turns keep their start-time protocol. drainTurn spreads the descriptor value into the UserMessageInput that lands on the AgentRun record, and recovery now asserts a run's persisted toolMode matches its admission. Generated-by: pi
41c1149 to
33f954d
Compare
Resolve the stored preference exactly once per send, in main: an explicit 'direct' | 'code_mode' rides the turn into its persisted AgentRun, while 'auto', a missing value, and anything unrecognized all resolve to field omission — turn payloads stay byte-identical to before the preference existed (pinned by the existing startTurn deep-equal test). The Settings → General chat defaults card gains a three-option selector with locale copy in English and zh-CN; if the active host composition cannot execute CodeMode, that option renders disabled-with-reason rather than silently downgrading a selection. Generated-by: pi Review follow-ups (apache#3850): - Selecting Auto after Code Mode actually clears the stored override: the settings projection now uses the same Object.hasOwn clearing idiom as thinkingLevel — a present key carries the concrete override or undefined, and the host-side codec normalizes the non-override spellings away. Previously 'auto' was dropped from the patch, so the spread merge kept the stored 'code_mode' and the selector was a silent no-op. - The resolved mode is pinned per session at its first send instead of re-resolved on every send: tool definitions sit ahead of the conversation in the request prefix, so a global settings change would otherwise rebuild the provider prompt cache of every live session on its next send. Pinning matches the advertised behavior — only sessions that start after the change pick up the new mode. Pins are FIFO-capped; session ids are never reused, so the cap is purely a memory bound.
33f954d to
8248ba9
Compare
|
Closing this pull request. #2578 is assigned to me and was not open for pickup; a "picking this up" comment on an issue that already has an assignee is not a claim, and the design here needs discussion before implementation. The review on this head stands: it is a production-reachable execution-model change, not a preference, and the shape of that change has not been agreed. If you want to work on Code Mode, start on #2578 with a proposal and wait for the assignee to hand it off, or pick an issue that is unassigned or labelled help-wanted. Thanks for the effort here regardless. |
Summary
Adds a user-facing CodeMode preference to Desktop's chat-defaults settings, resolving once at the product boundary into the existing Runtime
ToolMode(auto | direct | code_mode).autois the default and preserves today's Direct behavior exactly; explicit selections are validated at the IPC boundary, persisted on the AgentRun record via the existingtoolModefield, and never expose a second CodeMode path. Backends that cannot execute CodeMode surface an explicit unavailable state instead of silently downgrading.feat(core): closed tool-mode preference on chat defaults with back-compat normalization (missing/garbage →auto)feat(runtime-host): carries an explicit tool mode on interactive root runsfeat(desktop): resolves the preference at the send boundary; selector UI + locale copy (en/zh-CN)Legacy settings files keep working: an absent preference normalizes to
auto, and no payload changes for existing users.Fixes #2578
Generated content
Material parts of this change were generated with AI coding assistance (
Generated-by: pitrailers on each commit).