Skip to content

fix(native-chat): remember structured chat model and effort picks - #19147

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/sculpin
Sep 7, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/sculpin

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​641 $\color{#cf222e}{\Huge{\mathbf{−}}}$​61 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​580
Prod 14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​249 $\color{#cf222e}{\Huge{\mathbf{−}}}$​58 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​191

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.

  • structuredAgentSessionOptionPicks converts 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.
  • Effort remains model-scoped. An explicit effort-only pick also adopts the model it was chosen against; otherwise launch resolution would have no model under which to restore that effort.
  • The additive settings.mutateNativeChatSessionOptions RPC 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.
  • Desktop routes the mutation through the structured session's RuntimeClientTarget. Mobile sends the same mutation to its paired host. PTY picker and stale-model retirement writes use the same host-owned mutation.
  • RPC input is strict and bounded to known agents, supported option value kinds, at most eight picks, and at most 256 catalog model ids for retirement.

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 unknown delivery outcome because the provider may have refused it.

Linked Issue

No issue — reported directly in conversation.

Visual Proof

Connected Linux SSH workspace

Testing

  • pnpm tc — passed

  • cd mobile && pnpm run typecheck — passed

  • pnpm run check:code-quality:changed — 0 findings across 22 changed files

  • Final 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

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Security: no secrets or new privilege boundaries; the new RPC is authenticated through the existing runtime dispatcher and strictly validates its bounded mutation payload.
  • Cross-platform: no path, shell, shortcut, or native-module behavior changed. macOS Electron, native iOS, Linux SSH compatibility, and Windows packaging were exercised.
  • Remote ownership: structured desktop calls target the execution runtime; mobile writes to its paired host. Direct SSH intentionally remains terminal-backed and does not expose the structured picker.
  • Backward compatibility: the RPC is additive and best-effort against older hosts; the persisted settings shape is unchanged.
  • Performance: one bounded mutation per accepted pick, with model + effort batched into one request; no polling, timers, listeners, subprocesses, or new hot-path scans.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • Typecheck, targeted tests, changed-file quality, and CI pass

@coderabbitai

coderabbitai Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The 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 77fb9

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 47.06% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 22 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: persisting structured chat model and effort picks.
Description check ✅ Passed The description is detailed and covers the required change summary, rationale, testing, visual proof, compatibility, security, performance, and checklist items. The Linked Issue section does not provi…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 — structuredAgentSessionOptionPicks turns a settled mutation into the {model, effort} picks worth remembering, keyed off the exported STRUCTURED_LAUNCH_SEED_OPTION_IDS.
  • Record fold — applyNativeChatSessionOptionPicks folds a batch onto the durable record in one pass.
  • Desktop persistence — use-structured-agent-session persists through enqueueSessionOptionSettingsWrite, now extracted into native-chat-session-option-settings-write.ts so the PTY and structured panes share one serialized queue.
  • Mobile persistence — persistMobileStructuredOptionPicks reads/writes the host record over settings.get/settings.update, wired from use-mobile-structured-agent-options on accepted results.
  • Tests — planner/fold unit tests, desktop hook end-to-end, and a mobile serialization test.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

const modelId =
typeof committedModel === 'string' && committedModel.trim()
? committedModel
: resolveEffectiveNativeChatModelId(state.catalog, state.catalog.models, state.record)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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').

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 85b0ba1d-11c6-49b5-9b42-f6be2a60dd77

📥 Commits

Reviewing files that changed from the base of the PR and between 6fd03a7 and 77fb9d7.

📒 Files selected for processing (22)
  • mobile/src/session/mobile-native-chat-session-option-persistence.test.ts
  • mobile/src/session/mobile-native-chat-session-option-persistence.ts
  • mobile/src/session/use-mobile-structured-agent-options.ts
  • mobile/src/session/use-mobile-structured-agent-session.test.tsx
  • src/main/runtime/orca-runtime-pty-foreground-process-reads.ts
  • src/main/runtime/orca-runtime-tests/paired-settings.spec.ts
  • src/main/runtime/rpc/methods/client-native-chat-settings.test.ts
  • src/main/runtime/rpc/methods/client-settings-schemas.ts
  • src/main/runtime/rpc/methods/client-ui.ts
  • src/main/runtime/runtime-client-settings.ts
  • src/main/runtime/runtime-rpc-mobile-native-chat-settings.test.ts
  • src/main/runtime/runtime-rpc/runtime-rpc-mobile-method-allowlist.ts
  • src/main/runtime/runtime-store-contract.ts
  • src/renderer/src/components/native-chat/native-chat-retire-persisted-model.test.ts
  • src/renderer/src/components/native-chat/native-chat-session-option-settings-write.ts
  • src/renderer/src/components/native-chat/use-native-chat-session-options.ts
  • src/renderer/src/components/native-chat/use-structured-agent-session.test.tsx
  • src/renderer/src/components/native-chat/use-structured-agent-session.ts
  • src/shared/native-chat-session-option-defaults.ts
  • src/shared/native-chat-session-options.ts
  • src/shared/structured-agent-session-option-picks.test.ts
  • src/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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ 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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ 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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ 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.mutateNativeChatSessionOptions RPC (schema in client-settings-schemas.ts, method in client-ui.ts, mobile allowlist entry) applies apply-picks/clear-model-if-missing deltas to the runtime's latest nativeChatSessionOptions, 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 — persistMobileStructuredOptionPicks now sends the mutation to the host runtime instead of the client-settings settings.get/settings.update path 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-missing compares 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.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Electron QA — structured native-chat model/effort persistence

Commit: 77fb9d7bf8fdc8764b353741095d5e0f424d16d6
Identity: Orca: brennanb2025/sculpin (isolated profile, ORCA_BACKGROUND_LAUNCH=1, CDP)

Scenario (real structured Claude chat, two sessions):

  1. Open structured Claude Chat. Visible pills started at High + Opus (1M context) (CLI default).
  2. Through the composer pills, select Sonnet then Low. Host settings wrote { claude: { model: "sonnet", valuesByModel: { sonnet: { effort: "low" } } } } (renderer store, settings.get, and profiles/local-default/orca-data.json).
  3. Close that session. Open a new structured Claude Chat. Visible pills started as Low + Sonnet, matching the saved pair — not the CLI default.

No relevant console/runtime errors on the persist path (renderer: 0 errors; unrelated tooltip / React Grab / xterm deadline warnings only).

Session 1 — default pair

01-session1-default-pills.png

Session 1 — selected Sonnet + Low

02-session1-selected-sonnet-low.png

Session 2 — retained Sonnet + Low

03-session2-retained-sonnet-low.png

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Native mobile QA (PR 19147 @ 77fb9d7)

Platform: iOS Simulator · iPhone 17 Pro · iOS 26.5
Host: isolated branch Electron (Orca: brennanb2025/sculpin, CDP 9333, ORCA_BACKGROUND_LAUNCH=1). Paired over LAN to that runtime only.

Flow

  1. Paired the native app to the isolated host (Host 1, worktree brennanb2025/sculpin / fix(native-chat): remember structured chat model and effort picks #19147).
  2. Opened a structured Codex Chat session. Native picker started at GPT-6-Astra Medium.
  3. Through the real native picker, selected GPT-5.6-Sol then High.
  4. Closed that session and started a new structured Codex session.
  5. The visible native picker restored GPT-5.6-Sol High.

Host backing record

After the mobile picks, isolated Electron settings.nativeChatSessionOptions was:

{ "codex": { "model": "gpt-5.6-sol", "valuesByModel": { "gpt-5.6-sol": { "effort": "high" } } } }

The second structured launch seeded that same pair.

Logs

Metro served exp+orca-mobile from this worktree with no redbox. Electron logs were clean aside from benign FileListingCancelledError / MaxListeners warnings. No pairing codes or tokens in this comment.

Screenshots

Paired home:

03-paired-home.png

Structured session default pair (GPT-6-Astra Medium):

06-structured-codex-default-pair.png

Native picker:

07-structured-picker-open.png

After pick (GPT-5.6-Sol High):

08-structured-sol-high.png

Second structured session restored the pair:

09-second-session-restored-pair.png

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Final review status — READY

Commit: 77fb9d7bf8fdc8764b353741095d5e0f424d16d6

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 settings.mutateNativeChatSessionOptions RPC, which atomically applies bounded deltas to the latest host record. The final same-model adversarial re-review returned CLEAN, the closing readiness checklist found no P0/P1/P2 issues, and the performance audit is clean.

Verification

  • Root and mobile typechecks passed.
  • Final focused suites: 75 desktop/shared tests, 21 mobile integration tests, and 2 runtime atomicity/retirement tests passed.
  • Broad mobile suite: 4,194 passed, 3 skipped across 515 files.
  • Changed-file quality: 0 findings across 22 files.
  • CI is green, including Mobile Checks, static analysis, typecheck, macOS package, Windows package, and all 8 test shards.
  • Branch, PR head, and remote are identical; the worktree is clean.

End-to-end QA

  • Desktop Electron: real structured Claude session changed Opus/High → Sonnet/Low; a fresh session visibly restored Sonnet/Low and the host record matched.
  • Native iOS: real structured Codex session changed GPT-6-Astra/Medium → GPT-5.6-Sol/High; a fresh native session visibly restored the pair and the host record matched.
  • Linux direct SSH: connected a real throwaway SSH host, loaded the remote repository/files, and launched terminal-backed Codex with 0 renderer errors. Direct SSH intentionally uses terminal chat and does not expose the structured picker, so this is a compatibility smoke check—not a claim of structured-picker persistence over direct SSH.

Connected Linux SSH workspace

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.

@brennanb2025
brennanb2025 merged commit 546fd9b into main Sep 7, 2026
29 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant