Repository navigation
fix(native-chat): remember structured chat model and effort picks - #19147
Conversation
📝 WalkthroughWalkthroughThe change adds shared types and helpers for native chat option mutations and structured option-pick extraction. Runtime RPC handling validates and applies mutations to host settings. Renderer hooks persist selections and retire unavailable models through the RPC. Mobile hooks persist accepted Claude and Codex option updates through the host client. Tests cover validation, merging, concurrency, target routing, and rejected writes. Merge Risk: 🟡 Moderate · up to Rapid or overlapping option changes can save the wrong model/effort combination, causing later sessions to restore stale choices. These persistence races should be fixed before merge. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Structured Claude and Codex sessions already read the saved launch options at create, but nothing ever wrote them back. The only writer of `nativeChatSessionOptions` was the PTY picker, and the composer swaps in the structured surface for structured panes, so a structured pick went nowhere: it was forgotten when the session ended and every new session started at the CLI default. Persist a settled pick from both the desktop and mobile structured surfaces. Model and effort are stored as a pair, because a launch resolves a stored effort only under a stored model — so an effort-only pick adopts the model it was chosen against, otherwise the remembered effort never reaches a launch at all. Two things the persist path deliberately avoids: it writes what the provider committed rather than what was requested, since Codex reconciles an effort the newly selected model cannot run; and it never writes the provider readback, which is the CLI's own default and would pin a `-m` the user never chose.
There was a problem hiding this comment.
Caution
The mobile half of this PR is a silent no-op: it persists nativeChatSessionOptions through the client-settings RPC, but that field lives in the global settings record and is not exposed over that wire surface. The desktop half is correct; the mobile half never reads or writes anything.
Reviewed changes
- Pick planner —
structuredAgentSessionOptionPicksturns a settled mutation into the{model, effort}picks worth remembering, keyed off the exportedSTRUCTURED_LAUNCH_SEED_OPTION_IDS. - Record fold —
applyNativeChatSessionOptionPicksfolds a batch onto the durable record in one pass. - Desktop persistence —
use-structured-agent-sessionpersists throughenqueueSessionOptionSettingsWrite, now extracted intonative-chat-session-option-settings-write.tsso the PTY and structured panes share one serialized queue. - Mobile persistence —
persistMobileStructuredOptionPicksreads/writes the host record oversettings.get/settings.update, wired fromuse-mobile-structured-agent-optionson accepted results. - Tests — planner/fold unit tests, desktop hook end-to-end, and a mobile serialization test.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
| const modelId = | ||
| typeof committedModel === 'string' && committedModel.trim() | ||
| ? committedModel | ||
| : resolveEffectiveNativeChatModelId(state.catalog, state.catalog.models, state.record) |
There was a problem hiding this comment.
For an effort-only pick (no committed.model), this falls back to resolveEffectiveNativeChatModelId, which returns state.record.model — populated from the provider readback result.current.model, not from a user-chosen model. applyNativeChatSessionOptionPicks then writes it with adoptModelAsLaunchDefault defaulting to true, so a user who changes only the effort gets model: <cli-default> persisted and a -m <cli-default> flag on every later launch. This contradicts the resolveNativeChatSessionOptionDefaults comment ("only a model explicitly selected by the user authorizes launch flags") and the PR body's "never writes the provider readback" claim. If the pinning is intended (the alternative makes the effort dead weight), please reconcile the misleading comment/description; if not, gate the model adoption on the model actually being user-selected (e.g. record.model.source === 'dispatched').
d30cb44 to
77fb9d7
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: 85b0ba1d-11c6-49b5-9b42-f6be2a60dd77
📒 Files selected for processing (22)
mobile/src/session/mobile-native-chat-session-option-persistence.test.tsmobile/src/session/mobile-native-chat-session-option-persistence.tsmobile/src/session/use-mobile-structured-agent-options.tsmobile/src/session/use-mobile-structured-agent-session.test.tsxsrc/main/runtime/orca-runtime-pty-foreground-process-reads.tssrc/main/runtime/orca-runtime-tests/paired-settings.spec.tssrc/main/runtime/rpc/methods/client-native-chat-settings.test.tssrc/main/runtime/rpc/methods/client-settings-schemas.tssrc/main/runtime/rpc/methods/client-ui.tssrc/main/runtime/runtime-client-settings.tssrc/main/runtime/runtime-rpc-mobile-native-chat-settings.test.tssrc/main/runtime/runtime-rpc/runtime-rpc-mobile-method-allowlist.tssrc/main/runtime/runtime-store-contract.tssrc/renderer/src/components/native-chat/native-chat-retire-persisted-model.test.tssrc/renderer/src/components/native-chat/native-chat-session-option-settings-write.tssrc/renderer/src/components/native-chat/use-native-chat-session-options.tssrc/renderer/src/components/native-chat/use-structured-agent-session.test.tsxsrc/renderer/src/components/native-chat/use-structured-agent-session.tssrc/shared/native-chat-session-option-defaults.tssrc/shared/native-chat-session-options.tssrc/shared/structured-agent-session-option-picks.test.tssrc/shared/structured-agent-session-options.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review.
| void persistMobileStructuredOptionPicks({ | ||
| client, | ||
| agent, | ||
| picks: structuredAgentSessionOptionPicks(optionState, committed) |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Serialize same-session option mutations before persisting picks.
setStructuredOption captures optionState before awaiting mutate. Two calls from the same render can therefore overlap. If a model update and an effort update both succeed, the effort response can contain only effort. structuredAgentSessionOptionPicks then resolves modelId from the pre-mutation record and can persist the effort under the previous model. The next launch can select the new model without that effort. Serialize mutations per session and derive each persistence payload from the ordered current record after the accepted mutation commits. Updating activeOptionRecordRef alone does not prevent this race.
| target: RuntimeClientTarget, | ||
| mutation: NativeChatSessionOptionSettingsMutation | ||
| ): Promise<void> { | ||
| return callRuntimeRpc(target, 'settings.mutateNativeChatSessionOptions', mutation) |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Serialize native-chat session-option writes per RuntimeClientTarget.
enqueueSessionOptionSettingsWrite calls callRuntimeRpc without a shared tail. If consecutive RPCs complete out of invocation order, updateNativeChatSessionOptions applies the older delta to the current settings after the newer delta. Delta merging does not prevent this stale overwrite. Add a per-target promise tail around the complete RPC call, and recover rejected tails so later writes still execute.
There was a problem hiding this comment.
ℹ️ No new issues since the prior review — the critical mobile no-op is fixed cleanly. One prior minor thread (effort-only pick pinning) is still open, which is why this is not an approval; see below.
Reviewed changes
- Host-owned atomic mutation — a new
settings.mutateNativeChatSessionOptionsRPC (schema inclient-settings-schemas.ts, method inclient-ui.ts, mobile allowlist entry) appliesapply-picks/clear-model-if-missingdeltas to the runtime's latestnativeChatSessionOptions, replacing the renderer-side serialized read-modify-write chain. The host applies read-compute-write synchronously, so concurrent deltas no longer clobber each other. - Mobile persistence fixed —
persistMobileStructuredOptionPicksnow sends the mutation to the host runtime instead of the client-settingssettings.get/settings.updatepath that never carried the field. - Desktop routing by target — the structured pane persists to the session's runtime target (local or remote environment), while the PTY picker and model retirement stay on the local runtime.
- Retirement moved to host —
clear-model-if-missingcompares the persisted model against the authoritative list at mutation time on the host. - Tests — new dispatch/schema validation, host atomic-apply, mobile serialization, and desktop hook end-to-end coverage.
⚠️ Still-open prior concern: effort-only pick pins the CLI-default model
This was raised in the prior review and is unchanged in this delta. When a user changes only effort without ever selecting a model, structuredAgentSessionOptionPicks falls back to resolveEffectiveNativeChatModelId, which returns the provider-readback/CLI-default model, and applyNativeChatSessionOptionPicks then writes it as the launch default. The code documents this as deliberate (an effort without a model is dead weight), but it contradicts the PR body's "never writes the provider readback" claim. This is a design decision only the author can make — either gate model adoption on the model being user-selected (source === 'dispatched'), or update the body/comment to state plainly that an effort-only pick adopts the effective model. Left as an open thread, not re-raised inline.
ℹ️ PR description is stale
The body still states "No new wire surface, so it works against any host version" and "Mobile writes to the host record over the existing settings.get / settings.update methods". The implementation now uses a dedicated settings.mutateNativeChatSessionOptions method — a real wire addition. Degradation against older hosts is clean (unknown method → error → swallowed by the existing .catch), but the description and the "Backwards compatibility / no wire change" note should be updated.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
Electron QA — structured native-chat model/effort persistenceCommit: Scenario (real structured Claude chat, two sessions):
No relevant console/runtime errors on the persist path (renderer: 0 errors; unrelated tooltip / React Grab / xterm deadline warnings only). Session 1 — default pairSession 1 — selected Sonnet + LowSession 2 — retained Sonnet + Low |
Native mobile QA (PR 19147 @ 77fb9d7)Platform: iOS Simulator · iPhone 17 Pro · iOS 26.5 Flow
Host backing recordAfter the mobile picks, isolated Electron { "codex": { "model": "gpt-5.6-sol", "valuesByModel": { "gpt-5.6-sol": { "effort": "high" } } } }The second structured launch seeded that same pair. LogsMetro served ScreenshotsPaired home: Structured session default pair (GPT-6-Astra Medium): Native picker: After pick (GPT-5.6-Sol High): Second structured session restored the pair: |
Final review status — READYCommit: The review/fix loop found and fixed two persistence gaps: the mobile write was a silent no-op, and desktop remote sessions wrote the client-local settings record. Both now use the narrow, host-owned Verification
End-to-end QA
Verdict: ready to land. Non-blocking residual coverage: Android and Windows/WSL runtime UI were not manually exercised; Windows packaging passed, and native behavior was exercised on iOS. |
…ablyai#19147) * fix(native-chat): remember structured chat model and effort picks Structured Claude and Codex sessions already read the saved launch options at create, but nothing ever wrote them back. The only writer of `nativeChatSessionOptions` was the PTY picker, and the composer swaps in the structured surface for structured panes, so a structured pick went nowhere: it was forgotten when the session ended and every new session started at the CLI default. Persist a settled pick from both the desktop and mobile structured surfaces. Model and effort are stored as a pair, because a launch resolves a stored effort only under a stored model — so an effort-only pick adopts the model it was chosen against, otherwise the remembered effort never reaches a launch at all. Two things the persist path deliberately avoids: it writes what the provider committed rather than what was requested, since Codex reconciles an effort the newly selected model cannot run; and it never writes the provider readback, which is the CLI's own default and would pin a `-m` the user never chose. * fix(native-chat): persist session option picks atomically --------- Co-authored-by: Merge Sim <sim@local>










ELI5
Structured chat forgot which model and thinking level you explicitly picked. Change to Sonnet + Low, end the session, and the next one returned to the CLI default. Structured Claude and Codex chats now remember the provider-confirmed pair and seed it into the next session.
What Changed
Structured Claude and Codex panes now persist settled option picks into
nativeChatSessionOptions, the durable record every structured launch already reads.structuredAgentSessionOptionPicksconverts the provider's committed option result into the model/effort picks a later launch can actually seed. It never persists a provider readback that the user did not choose.settings.mutateNativeChatSessionOptionsRPC sends a narrow delta to the execution runtime. The host re-reads its latest record, applies the batch atomically, and preserves other agents and concurrent picks.RuntimeClientTarget. Mobile sends the same mutation to its paired host. PTY picker and stale-model retirement writes use the same host-owned mutation.Persistence is best-effort. A new client talking to an older host receives an unknown-method failure, swallows only that preference write, and leaves the live option change working; the next session simply starts from the previous/default saved selection. Old clients remain compatible with new hosts, and the persisted record shape is unchanged.
Why
The read half already existed: structured creation seeds
{ model, effort }from saved settings. The write half did not. The prior writer lived only in the terminal-backed picker, while structured panes replace that surface with the structured transport. As a result, structured picks were visible for the current session but were never stored.The fix writes only after the provider accepts a change and uses the provider-returned reconciled values. This matters when a model switch also changes the valid effort. Mobile deliberately does not persist an
unknowndelivery outcome because the provider may have refused it.Linked Issue
No issue — reported directly in conversation.
Visual Proof
Testing
pnpm tc— passedcd mobile && pnpm run typecheck— passedpnpm run check:code-quality:changed— 0 findings across 22 changed filesFinal focused desktop/shared review suite — 75 tests passed
Final focused mobile integration suite — 21 tests passed
Runtime atomicity/retirement focus — 2 tests passed
Broad mobile suite — 4,194 passed, 3 skipped across 515 files
Electron desktop QA — changed Claude from High + Opus to Low + Sonnet, opened a new session, and saw Low + Sonnet restored from the host record
Native iOS QA — changed Codex from GPT-6-Astra Medium to GPT-5.6-Sol High, opened a new session, and saw GPT-5.6-Sol High restored from the host record
Linux SSH smoke QA — real SSH connection, remote repository/file listing, and terminal-backed Codex launch passed; renderer had 0 errors
CI — green, including root/mobile tests, static analysis, typecheck, macOS packaging, and Windows packaging
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Final adversarial review-until-clean verdict: CLEAN. No in-scope correctness, compatibility, security, or performance issues remain.
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Checklist
N/Awith reason