Skip to content

fix(native-chat): show the Codex and Claude model picker the moment a chat opens - #22756

Merged
brennanb2025 merged 27 commits into
mainfrom
brennanb2025/fix-codex-chat-model
Sep 25, 2026
Merged

brennanb2025 merged 27 commits into
mainfrom
brennanb2025/fix-codex-chat-model

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 29 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2915 $\color{#cf222e}{\Huge{\mathbf{−}}}$​19 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2896
Prod 67 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2684 $\color{#cf222e}{\Huge{\mathbf{−}}}$​329 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2355

ELI5

Before this PR, the only way the app could learn which models a chat can use was to ask the running chat itself. So the model picker stayed empty until the chat had fully started, which often took half a second to two seconds. This PR gives the app its own saved copy of each account's model list, so the picker can appear the moment a chat opens. It also makes sure the name the picker shows is the model the chat will really run, and that a model you pick while the chat is still starting is the one your first message uses.

What Changed

User-visible before and after

Before (main) After
New Codex chat No picker for 0.5-2 s Picker appears with the composer (~0.23 s), naming the model and effort from your Codex config
New Claude chat Picker late, then shows "Sonnet" until the first reply, even when your Claude settings pick another model Picker appears at once; after Claude starts (~1 s) it names the model Claude will actually run
Picking a model while the chat is starting Not possible (no picker yet) The pick is used by the first message
Reopened chat Picker late List shows at once; no model name until the chat reports what it runs

The architecture change

Before: the model list had no owner. It only existed as the answer to a question asked of a live chat session (agentSession.options), and that session only exists after it has spawned, finished its handshake, and listed models from the provider (often over the network). Every reader paid that cost, the answer was thrown away between readers, and the renderer also hid the picker until the session's create call returned.

picker ──▶ agentSession.options ──▶ live session (must be running) ──▶ provider model/list

After: three pieces, each with one clear owner.

MAIN PROCESS (host)
  model catalog store ........ one list per agent + account home, saved to disk
    ▲ written by: every listing a live session already does
    ▲ written by: one background listing when nothing is stored or it is stale
    ▼ read by:    agentSession.modelCatalog  (new; no live session, no queue)
    ▼ read by:    agentSession.options       (live session; now also says what will run)

RENDERER
  picker ........ reads modelCatalog from the first frame, then options once the chat runs
  launch ........ owns picks made before the chat exists; applies them, then counts as started
  every sender .. (composer, launch prompts, retries) already waits for "started"

1. A model catalog the host owns (src/main/native-chat/agent-model-catalog/)

  • One saved model list per agent and account home (the account a session launches under). A list is never shown for, or written by, a different account.
  • Filled by the listings live sessions already do, so it costs nothing extra while you are chatting. When nothing is stored yet, or the list is over 10 minutes old, it runs one short background listing, resolved exactly like a real launch: a read-only Codex app-server with plugins off, or Claude's one-shot CLI listing.
  • Saved to disk (successful lists only, atomic write, rewritten only when the list changes, written out at quit), so the first chat after a restart already has a list. Failures are held for 30 seconds and never saved.
  • Read through a new request, agentSession.modelCatalog. It answers without a live session and without waiting in the session's command queue, which is what lets the picker show while the chat is still starting. A chat's picker only asks while the chat is visible, so hidden tabs restored at startup start nothing.
  • Working out the account for a chat that doesn't exist yet uses a read-only twin of launch preparation: the same routing decisions, but it creates, syncs, starts, and changes nothing. A parity test keeps the two in step.
  • agentSession.options now serves its model list from this store too, so a session lists models at most once at start (zero times when the store is warm) instead of on every read.

2. The launch owns picks made before the chat exists (src/renderer/src/lib/structured-agent-session-launch*.ts)

  • Opening a chat starts it right away. A model or effort picked before the create call returns is stored on the launch itself, not in the picker component.
  • When create returns, the launch applies those picks to the new session and only then counts as started. Everything that sends a first message (the composer, launch prompts such as Fix checks, quick launch, folder auto-submit, and retries) already waits for the launch to finish starting, so every one of them sends after the pick with no extra checks.
  • A refused pick shows the same error as a refused mid-chat pick. Retrying a failed start keeps the pick; closing the tab drops it. For Claude, a pick made while Claude is still starting now waits for it to be ready (at most 30 s) instead of being refused.

3. The name shown is what will run (host)

Orca sends no model when you haven't chosen one, so your agent's own config decides. The picker therefore shows what the agent reports it will run, never a guess:

  • Codex: the listing also asks Codex for its configured model and effort (config/read) and marks those as the default. If the repo has its own .codex/config.toml between its root and the chat folder (which could change the model), or the configured model isn't in the list, the picker names nothing until the chat reports.
  • Claude: after startup, the session reports the model and effort from Claude's own settings readback (get_settings → applied), which already applies ANTHROPIC_MODEL and your Claude settings. Claude never uses the list's "default" row as a name.
  • Every early name is unconfirmed; the chat's first report confirms or corrects it. Reopened and resumed chats name nothing until they report.

Unchanged: panes on SSH, WSL, or a paired remote runtime keep their own per-host listing, since a local store can't speak for another machine. Terminal-based (PTY) chat panes on this machine read the new store instead of running their own CLI listing.

Why

The root cause was structural: the model list existed only as a side effect of a running session, so the picker could never be faster than session startup plus a provider fetch. Alternatives considered:

  • Cache in the renderer: every window and client would keep its own copy, and none would survive a restart, which is when users notice the gap most.
  • Push list updates to clients: a new push channel has to be negotiated across mixed client and host versions. Reading on demand at the moments the picker already re-reads (open, option change, turn end, startup finished) closes the gap without that.
  • Hold early picks in the picker and send them after start: an earlier version of this PR did this. Each separate way of sending a first message then needed its own ordering check, and review kept finding ones it missed. Making the pick part of the launch removes that whole class.
  • Have Orca choose and send a model at start: that would override your Codex and Claude config, which Orca deliberately respects. So the picker's value before the first turn is what the provider reports it will run, not a selection Orca chooses and sends, and it names nothing when it can't be sure.

Compatibility and known limits

  • Mixed versions: agentSession.modelCatalog (with an optional worktree field) is new and additive. A new client on an old host gets method_not_found, or forbidden through the mobile allowlist, and falls back to today's behaviour. Old clients keep calling agentSession.options, which still returns models (now possibly up to 10 minutes old, refreshed behind it).
  • Project config check: the host only checks that a project .codex/config.toml exists; it doesn't read it, honour custom project_root_markers, or check folder trust. Each gap errs toward naming nothing, including repos whose config only sets hooks or MCP servers.
  • Mobile: a phone or paired web client could send a message in the short gap between the host starting a chat and the desktop applying a pick made during launch; closing that would need the pick to travel with the create request. Mobile also doesn't re-read when Claude finishes starting, so a Claude chat opened on a phone mid-startup can show the old fallback name until reopened, as on main.

Linked Issue

None.

Visual Proof

Opening a new Codex chat. The clock counts from the click on New tab → Codex.

Before (main): the picker appears only after the session has started and listed models.

codex-picker-before.webm

After (this PR): the picker appears with the composer, already showing the configured model and effort.

codex-picker-after.webm

Same moment (349 ms after the click), hidden dev builds:

main this PR
main: composer, no picker PR: picker names GPT-6-Astra / High

New Claude chat whose settings choose Opus, after start:

main (wrong) this PR
main shows Sonnet PR shows Opus

Time from clicking New tab → Codex until the picker names the model, 3 runs each:

Warm (list saved) First chat, nothing saved
main 0.53-0.56 s (no picker until then) 1.32 s
this PR 0.23-0.24 s, with the composer picker at 0.32 s, named at 1.62 s

Testing

  • Unit tests cover each piece and were each proven by deleting the fix and watching the test fail:
    • store: freshness, the failure hold, saving across restart, account isolation, write on change, flush at quit;
    • background listings: plugins off, Claude's config-folder rule, a stalled config/read keeps the list;
    • read-only account resolution: matches launch preparation and writes nothing;
    • launch-owned picks: applied before start and before launch prompts, kept on retry, dropped on close, errors shown;
    • the "what will run" rules for Codex and Claude, and reopened and resumed chats.
  • Real CLIs: Claude 2.1.258-2.1.280 with a scratch config folder (get_settings.applied.model follows ANTHROPIC_MODEL > settings > default; the list's default row ignores both). Codex 0.156.1: config/read returns the configured model and effort.
  • Live, hidden dev builds of main and this PR on macOS:
    • new Codex chat;
    • model and effort picked during launch, then a real turn (Codex's log shows the picked model ran);
    • new Claude chat with and without a saved choice (transcripts confirm the model);
    • a pick during Claude startup;
    • a reopened chat after restart (never showed a wrong name);
    • a repo with its own .codex/config.toml;
    • no leftover background processes.
  • Cross-version: the new request is in the wire surface manifest, host stub fixture, gate fixture, and mobile allowlist; those suites pass.
  • Gates: pnpm tc, affected suites, every audit and ratchet test, the changed-lines quality gate, oxlint, React Doctor. CI green.
  • Platforms: macOS live. Structured sessions run on the local machine only by design; Windows paths go through path utilities and processes through the shared runner, but I didn't run it on Windows.
  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

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

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance.

  • Size: about half the diff is tests. The production change is the three pieces above; they ship together because showing the picker early is only safe once the name it shows is right.
  • Follow-ups (out of scope): an Orca "default model" setting (with "use my agent's config" as a choice); letting Grok, OMP, and Cursor feed the same store; sending launch-time picks with the create request to close the mobile gap.

Checklist

  • This PR is small and focused (one problem, but it spans the host catalog, the launch, and the picker)
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • 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)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred) — typecheck, oxlint, the changed-code gate, audits, and the affected suites pass locally; CI is green

… chat opens

A new structured chat showed no model picker until its session had been
created, spawned, initialized and had answered a model listing — and the
picker then listed the models a second time. Codex's listing often goes to
the network, so the picker took 0.6-2 s to appear.

- Keep a host-owned model catalog per agent and account home, persisted on
  success only and refreshed in the background once it ages out. A new
  read-only agentSession.modelCatalog RPC answers from it without a live
  session; sessions reuse it instead of listing again.
- Render the picker while the launch is still provisional, showing the saved
  default. A pick made before the session exists is held and applied once it
  publishes; only the host's acceptance saves it as the default.
- Mark the model and effort set in the user's Codex config as the listing's
  default (config/read), so the first frame names what the chat will run.
- Resolve the account a record-less read would use without running launch
  preparation, which writes and syncs account state.
A pick made while a chat launches had no fence to go to, so the pane held it
and flushed it after publish; every other sender (the outbox, the launch
prompt) then needed its own gate to wait for that flush. The launch now keeps
those picks in its own state, applies them against the create receipt's fence
before it counts as published, and every sender follows publish by
construction. The pane flush, the outbox gate and the module-wide held-pick
registry are gone.

The launch also snapshots the saved selection its create seeds when the intent
is built, so a pick in another chat no longer relabels one still launching, and
a pick the host refuses is reported the way a refused mid-session pick is.
…replace

The catalog's default is the account's, read without a working directory, but
a chat runs in its worktree, where a project config (Codex's .codex/config.toml
between the project root and the worktree, or a Claude .claude settings file
that sets a model) picks the model instead. The picker named the account
default there while the chat ran the project's model.

A new chat's catalog read now names its worktree. The host checks that
workspace for such config (existence only for Codex, the model key for
Claude) and, when any is present or the workspace is not a local directory,
serves the listing with no default, so the picker names nothing until the chat
reports its model.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status: ready for review at 1bfece2

Seven review loops ran on this PR. The last one came back clean. Live Electron QA passed on the final head. CI is running.

What the review changed (all pushed)

  • Architecture: a model picked while a chat is starting is now owned by the launch and applied before the launch counts as started. An earlier version held the pick in the picker component and needed a separate ordering check for each way a first message can be sent. With the launch owning the pick, the first message, launch prompts (Fix checks, quick launch, folder auto-submit) and retries all come after it.
  • Claude label: a new Claude chat no longer shows "Sonnet" (the built-in fallback) while running another model. After startup, the picker shows Claude's own get_settings → applied model and effort, so it follows ANTHROPIC_MODEL and the user's Claude settings. The same bug exists on main.
  • Honest early names:
    • Only Codex names a configured default before the first report.
    • A Codex chat names nothing when the repo has its own .codex/config.toml, or when the configured model isn't in the list.
    • Reopened and resumed chats name nothing until the session reports its model.
  • Picks during startup:
    • A Claude pick made while Claude is starting now waits for it, up to 30 s, instead of being refused.
    • When both a model and an effort are picked, both apply before the first message.
    • A refused pick shows an error.
    • The picker no longer looks clickable before a reopened chat reconnects.
  • Probes: the background Codex listing runs with plugins disabled. The Claude listing uses the same config-folder rule as a real launch. A stalled config/read no longer throws away the listing.
  • Perf: a hidden chat tab no longer asks for the catalog. The catalog file is rewritten only when the list changes and is written out at quit. Panes on SSH, WSL or a paired remote runtime keep their per-host listing.
  • CI: renamed a parameter the global-fetch audit flagged.

Live QA (hidden dev builds, macOS, main 7a71e20 vs this branch)

Scenario Result
New Codex chat PASS. The picker appears with the composer and names the configured model and effort (0.23 s vs 0.55 s on main). The live report matches.
Model and effort picked during launch, then a real turn PASS. Codex's own rollout shows the picked model and effort ran.
New Claude chat, no saved choice PASS. No name for about 1 s while Claude starts, then "Opus (1M context)" (from the user's settings), confirmed by the turn. Never shows "Sonnet".
New Claude chat, saved choice PASS. The saved model shows from the first frame.
Pick during Claude startup PASS. Applied, with no error.
Reopened chat after restart PASS. It never showed a wrong model. The saved default was deliberately set to a different model to catch this.
Repo with its own .codex/config.toml PASS. No name before the report, then the project's model.
Leftover processes / console errors PASS. None.

New Claude chat, whose settings choose Opus:

main this branch
main shows Sonnet branch shows Opus

Codex model and effort picked during launch, after the turn:

GPT-6-Sol / Low after the turn

Reopened chat: no name while it reconnects, then its real model.

reconnecting reconnected
no name Haiku

Repo with its own Codex config:

before the report after
no name GPT-5.5 / Low

Gates

  • pnpm tc.
  • The affected suites, by explicit file list: 2185 tests in the final loop.
  • Every audit and ratchet test under src/main, src/shared, src/cli and src/relay.
  • Changed-lines quality gate, full oxlint on touched files, and React Doctor.
  • Every fix has a test shown to fail when the fix is removed.
  • The PR adds no lockfile change and no docs.

Known and accepted

  • In a repo whose .codex/config.toml only sets hooks or MCP, a new Codex chat still names nothing before the first report, because the check looks only for the file.
  • A mobile or paired-web client can send in the short gap between the host starting the chat and the desktop applying a pick made during launch. The pick would need to travel with the create request to close this; that's a possible follow-up.
  • Mobile doesn't re-read options when Claude finishes starting. This is the same as main.
  • Not run on Windows or Linux. Structured sessions only run on the local machine by design, and paths and child processes go through the shared helpers.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

CI update: all 21 checks pass on 1bfece2 (10 skipped by path filter). The PR is ready for review.

@brennanb2025
brennanb2025 marked this pull request as ready for review September 25, 2026 05:26
@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

📝 Walkthrough

Walkthrough

The change adds host-side Claude and Codex model-catalog discovery, caching, persistence, and RPC access. Renderer model pickers can use host catalogs and apply launch-seeded defaults. Structured-session launches now hold option picks made before publication and apply them against the launch receipt. Provider option reads and writes also account for reported Claude settings and startup state.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to 1bfec

The faster model picker introduces several issues that should be fixed before merging.

  • First prompt can use the wrong model: if the app reloads mid-launch, the first message can run with the original model instead of the one picked.
  • Claude effort gets stuck: a Claude effort taken only from settings can be saved to the chat and persist after the user changes Claude settings.
  • Picks can hang or be refused: a pick made just before closing a tab can hang, and re-picking the same value can report a refusal without sending it.
  • Codex sign-in can break: the background Codex catalog probe runs without the per-account lock, so it can race other Codex processes and invalidate the stored Codex login.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to 1bfec

The change affects account-specific choices at chat startup and adds a way to read them from another client. It is not yet clear that every read is restricted to the intended account.

Retained concerns

  • Medium · security · inferred: A capable mobile client can request a catalog using a supplied session ID. The visible read path uses a matching session record to select its account catalog without checking that the caller owns that session; whether an upstream authorization layer supplies that check is unresolved.
Security review details

Security Blast Radius

  • inferred — The relevant independently reachable scope is a capable client of one host and catalogs associated with session IDs or account homes available there. Evidence does not establish exposure across hosts or tenants.

Security Findings and Attack Paths

  • inferred — A capable client can supply a session ID that selects a matching record’s account-specific catalog. Whether that client can name a session outside its authorized account, and thus read its catalog, depends on authorization not established by the inspected path.

Trust Boundaries and Controls

  • observed — Capability admission, provider matching, account-home-derived fingerprints, and host-side worktree resolution constrain reads. None of those inspected checks establishes caller ownership of a supplied session record.

Resilience and Maintainability Implications

  • observed — Catalog persistence loads only schema-versioned, parsed entries and serializes writes through a temporary file and rename. Write failure leaves the in-memory store authoritative for that run.

Hardening Proposals

  • proposed — Confirm that RPC authorization binds a supplied session ID to the requesting client before using its account-home catalog; if that binding is not guaranteed, enforce it at the read boundary.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The description does not link an issue and states "None", which violates the repository requirement that every pull request include a linked issue. Add the issue reference that this pull request fixes or addresses.
Docstring Coverage ❓ Inconclusive Docstring coverage is 36.54% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 104 functions across 50 files. (45 skippe… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Out of Scope Changes check ✅ Passed The changes span host catalog storage, launch handling, RPC wiring, renderer state, and tests, but these areas directly support the stated goal of showing Codex and Claude model pickers earlier.
Title check ✅ Passed The title clearly and concisely describes the primary user-facing change: showing the Codex and Claude model picker when a chat opens.
Description check ✅ Passed The description is comprehensive and covers the user-visible behavior, architecture, rationale, compatibility, testing, visual proof, and known limitations. The Linked Issue section says "None" even t…
Full details: Docstring Coverage

Explanation

Docstring coverage is 36.54% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 104 functions across 50 files. (45 skipped: 45 over the file limit.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

@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: 5


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 7c23524b-db91-475a-81c0-2794981ce892

📥 Commits

Reviewing files that changed from the base of the PR and between 7a71e20 and 1bfece2.

⛔ Files ignored due to path filters (1)
  • src/shared/rpc-contract/rpc-params-catalog.generated.ts is excluded by !**/*.generated.*
📒 Files selected for processing (95)
  • src/main/claude/claude-model-catalog-probe.test.ts
  • src/main/claude/claude-model-catalog-probe.ts
  • src/main/claude/claude-structured-applied-options.test.ts
  • src/main/claude/claude-structured-launch-resolution.ts
  • src/main/claude/claude-structured-options.ts
  • src/main/claude/claude-structured-session-acquisition.ts
  • src/main/claude/claude-structured-session-adapter.ts
  • src/main/claude/claude-structured-session-options.ts
  • src/main/claude/claude-structured-session-startup-gate.ts
  • src/main/claude/claude-structured-session-startup.test.ts
  • src/main/claude/claude-structured-session-startup.ts
  • src/main/claude/claude-structured-session-state.ts
  • src/main/claude/claude-structured-session-test-support.ts
  • src/main/codex-accounts/runtime-home-read-only-launch-resolution.test.ts
  • src/main/codex-accounts/runtime-home-service-home-routing.ts
  • src/main/codex-accounts/runtime-home-service-launch.ts
  • src/main/codex-cli/codex-read-only-app-server-args.ts
  • src/main/codex/codex-app-server-session.ts
  • src/main/codex/codex-configured-launch-defaults.test.ts
  • src/main/codex/codex-configured-launch-defaults.ts
  • src/main/codex/codex-model-catalog-probe.test.ts
  • src/main/codex/codex-model-catalog-probe.ts
  • src/main/codex/codex-structured-acquire-catalog.ts
  • src/main/codex/codex-structured-launch-resolution.ts
  • src/main/codex/codex-structured-model-catalog.ts
  • src/main/codex/codex-structured-session-acquire.ts
  • src/main/codex/codex-structured-session-options-catalog.test.ts
  • src/main/codex/codex-structured-session-options.ts
  • src/main/codex/codex-structured-session-state.ts
  • src/main/native-chat/agent-model-catalog/agent-model-catalog-fingerprint.ts
  • src/main/native-chat/agent-model-catalog/agent-model-catalog-persistence.ts
  • src/main/native-chat/agent-model-catalog/agent-model-catalog-service.test.ts
  • src/main/native-chat/agent-model-catalog/agent-model-catalog-service.ts
  • src/main/native-chat/agent-model-catalog/agent-model-catalog-store.test.ts
  • src/main/native-chat/agent-model-catalog/agent-model-catalog-store.ts
  • src/main/native-chat/agent-model-catalog/agent-project-model-override.test.ts
  • src/main/native-chat/agent-model-catalog/agent-project-model-override.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-adapter-router.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-adapter.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-claude-options-round-trip.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-host-mutations.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-host-types.ts
  • src/main/rate-limits/codex-fetcher.test.ts
  • src/main/rate-limits/codex-fetcher.ts
  • src/main/runtime/mobile-rpc-allowlist.test.ts
  • src/main/runtime/orca-runtime-get-worktree-ps.ts
  • src/main/runtime/orca-runtime-preserved-branch-cleanup.ts
  • src/main/runtime/orca-runtime-resolve-recovered-structured-tui-transcript.ts
  • src/main/runtime/orca-runtime-state-fields.ts
  • src/main/runtime/orca-runtime-structured-agent-session-create-intent.test.ts
  • src/main/runtime/rpc/methods/structured-agent-session-gate-classification.test-fixture.ts
  • src/main/runtime/rpc/methods/structured-agent-session-options-read.test.ts
  • src/main/runtime/rpc/methods/structured-agent-session-options-read.ts
  • src/main/runtime/rpc/methods/structured-agent-session-schemas.ts
  • src/main/runtime/rpc/methods/structured-agent-session.test.ts
  • src/main/runtime/rpc/methods/structured-agent-session.ts
  • src/main/runtime/runtime-rpc/runtime-rpc-mobile-method-allowlist.ts
  • src/main/runtime/structured-agent-account-home.ts
  • src/main/runtime/structured-agent-model-catalog-wiring.ts
  • src/main/runtime/structured-agent-session-runtime.test.ts
  • src/main/runtime/structured-agent-session-runtime.ts
  • src/main/runtime/structured-claude-runtime-adapter.ts
  • src/main/startup/main-process-runtime-service.ts
  • src/renderer/src/components/native-chat/NativeChatStructuredSession.launch-lifecycle.test.tsx
  • src/renderer/src/components/native-chat/NativeChatStructuredSession.test-harness.tsx
  • src/renderer/src/components/native-chat/NativeChatStructuredSession.tsx
  • src/renderer/src/components/native-chat/native-chat-session-option-discovery.ts
  • src/renderer/src/components/native-chat/native-chat-session-option-enrichment.test.ts
  • src/renderer/src/components/native-chat/use-host-model-catalog-upgrade.ts
  • src/renderer/src/components/native-chat/use-native-chat-provisional-launch.test.tsx
  • src/renderer/src/components/native-chat/use-native-chat-provisional-launch.ts
  • src/renderer/src/components/native-chat/use-native-chat-session-options.ts
  • src/renderer/src/components/native-chat/use-structured-agent-session-mutate.ts
  • src/renderer/src/components/native-chat/use-structured-agent-session-option-state.ts
  • src/renderer/src/components/native-chat/use-structured-agent-session-options.test.tsx
  • src/renderer/src/components/native-chat/use-structured-agent-session-options.ts
  • src/renderer/src/components/native-chat/use-structured-agent-session-provisional.test.tsx
  • src/renderer/src/components/native-chat/use-structured-agent-session.ts
  • src/renderer/src/lib/launch-structured-agent-session.ts
  • src/renderer/src/lib/structured-agent-session-launch-cancellation.test.ts
  • src/renderer/src/lib/structured-agent-session-launch-options.test.ts
  • src/renderer/src/lib/structured-agent-session-launch-options.ts
  • src/renderer/src/lib/structured-agent-session-launch-registry.ts
  • src/renderer/src/lib/structured-agent-session-launch-reload.ts
  • src/renderer/src/lib/structured-agent-session-launch-resume-identity.test.ts
  • src/renderer/src/lib/structured-agent-session-launch.ts
  • src/shared/agent-session-option-catalog-types.ts
  • src/shared/agent-session-wire.ts
  • src/shared/native-chat-session-option-snapshot.ts
  • src/shared/rpc-contract/structured-agent-session-params.ts
  • src/shared/structured-agent-session-model-catalog-application.test.ts
  • src/shared/structured-agent-session-options.test.ts
  • src/shared/structured-agent-session-options.ts
  • tests/e2e/cross-version-wire/structured-agent-session-host-fixture.ts
  • tests/e2e/cross-version-wire/structured-agent-session-surface-manifest.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.

catalog: unknown[]
): StructuredAgentSessionStartedOptions['reportedOptions'] {
const { current } = claudeStructuredSessionOptionsFrom(session, catalog)
if (session.options.has('effort') || session.reportedOptions.effort !== undefined) {

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

Do not persist an effort that only came from settings.

When get_settings supplies an effort, applyClaudeStartupFacts copies it into session.reportedOptions.effort. This condition then returns current even if nobody selected an effort for the session. Startup persists that settings-derived effort as a session option, so a reopened chat can retain it after the user changes Claude settings. Distinguish an explicit or provider-reported session effort from the settings-derived value. Keep the latter in appliedOptions for display only.

Comment on lines +50 to +60
const run = deps.runSession ?? runCodexAppServerSession
const listing = await run(
{
command: spawnCmd,
args: spawnArgs,
cliPath: command,
env: { ...definedEnv(environment), CODEX_HOME: accountHomePath },
timeoutMs: CODEX_MODEL_CATALOG_PROBE_TIMEOUT_MS
},
(rpc) => fetchCodexModelCatalogListing({ connection: rpc })
)

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.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
rg -nP -C4 '\brunCodexProcessWithHomeLock\s*\(' --type=ts
rg -nP -C4 '\bresolveCodexHomeProcessLockKeyForSpawnEnv\b' --type=ts
rg -nP -C3 'readCodexRateLimitsViaRpc|HomeLock' src/main/rate-limits

Repository: stablyai/orca

Length of output: 13279


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- probe ---'
cat -n src/main/codex/codex-model-catalog-probe.ts
printf '%s\n' '--- lock implementation ---'
cat -n src/main/codex-cli/codex-home-process-lock.ts
printf '%s\n' '--- app-server session definition and callers ---'
rg -n -C6 'runCodexAppServerSession|discoverModelsLocal|runCodexProcessWithHomeLock' src/main --type=ts
printf '%s\n' '--- rate-limit fetcher and RPC probe ---'
sed -n '1,190p' src/main/rate-limits/codex-fetcher.ts
sed -n '1,180p' src/main/rate-limits/codex-rpc-rate-limit-probe.ts
printf '%s\n' '--- OAuth conflict references ---'
rg -n -i -C5 '5370|refresh token|oauth|auth\.json|process lock|home lock' src/main --type=ts

Repository: stablyai/orca

Length of output: 45650


🏁 Script executed:

#!/bin/bash
set -e
cat -n src/main/codex/codex-model-catalog-probe.ts
cat -n src/main/codex-cli/codex-home-process-lock.ts
rg -n -C8 'runCodexAppServerSession|discoverModelsLocal|runCodexProcessWithHomeLock' src/main --type=ts
sed -n '1,190p' src/main/rate-limits/codex-fetcher.ts
sed -n '1,180p' src/main/rate-limits/codex-rpc-rate-limit-probe.ts
rg -n -i -C5 '5370|refresh token|oauth|auth\.json|process lock|home lock' src/main --type=ts

Repository: stablyai/orca

Length of output: 45660


Serialize the model-catalog probe per Codex home.

The probe starts an Orca-managed Codex process with CODEX_HOME=accountHomePath, but it calls runCodexAppServerSession without the home lock. The lock exists because concurrent Orca-spawned processes can consume the same rotating OAuth refresh token twice and invalidate the stored credential.

Suggested fix
 import { runCodexAppServerSession } from './codex-app-server-session'
+import {
+  resolveCodexHomeProcessLockKeyForSpawnEnv,
+  withCodexHomeProcessLock
+} from '../codex-cli/codex-home-process-lock'
...
-    const listing = await run(
-      {
+    const invocation = {
         command: spawnCmd,
         args: spawnArgs,
         cliPath: command,
         env: { ...definedEnv(environment), CODEX_HOME: accountHomePath },
         timeoutMs: CODEX_MODEL_CATALOG_PROBE_TIMEOUT_MS
-      },
-      (rpc) => fetchCodexModelCatalogListing({ connection: rpc })
+    }
+    const listing = await withCodexHomeProcessLock(
+      resolveCodexHomeProcessLockKeyForSpawnEnv(invocation.env),
+      () => run(invocation, (rpc) => fetchCodexModelCatalogListing({ connection: rpc }))
     )

held: id === 'model' ? { model: encoded } : { ...held, [id]: encoded }
}
notifyStructuredLaunchListeners()
return new Promise((resolve) => replies.set(id, resolve))

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.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Settle held picks when the launch is cancelled.

If a user closes the tab while creation is pending, cancelStructuredAgentLaunch cancels the launch before it receives a receipt. The application loop never runs, so the promise returned at Line 74 never settles. Resolve the outstanding replies when the launch is cancelled.

seed
} = state.selection
// A pick made while this one was in flight superseded it and stays held for the next pass.
const settled = current === encoded

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Match an option reply to the pick that started its write.

If a user picks the same encoded value again while its first write is in flight, the new pick replaces the reply but leaves an identical value in held. Line 119 treats the first write as settlement of the new pick. If that write fails transiently, the new pick receives its refusal and is never sent. Track a pick identity or generation instead of comparing only encoded.

onVisibilityChanged: undefined,
callers
callers,
selection: { seed: intent.seedOptions, held: {} }

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

🔎 Supported by static analysis

🏁 Script executed:

cat src/renderer/src/lib/structured-agent-session-launch-reload.ts
rg -n 'held|seedOptions|restore' src/renderer/src/lib/structured-agent-session-launch.ts src/renderer/src/lib/structured-agent-session-launch-registry.ts src/renderer/src/lib/launch-structured-agent-session.ts

Repository: stablyai/orca

Length of output: 3390


🏁 Script executed:

set -e
printf '%s\n' '--- reload and launch definitions ---'
sed -n '1,360p' src/renderer/src/lib/structured-agent-session-launch.ts
printf '%s\n' '--- registry definitions and persistence ---'
sed -n '1,340p' src/renderer/src/lib/structured-agent-session-launch-registry.ts
printf '%s\n' '--- intent and seed resolution ---'
sed -n '1,230p' src/renderer/src/lib/launch-structured-agent-session.ts
printf '%s\n' '--- focused references ---'
rg -n -C 4 'persistStructured|PersistedStructured|selection\.held|selection|publish|promptDelivery|lifecycle|restorePersistedStructuredLaunchState|settle|reconcil' src/renderer/src/lib

Repository: stablyai/orca

Length of output: 45666


🏁 Script executed:

set -e
sed -n '1,360p' src/renderer/src/lib/structured-agent-session-launch.ts
sed -n '1,340p' src/renderer/src/lib/structured-agent-session-launch-registry.ts
sed -n '1,230p' src/renderer/src/lib/launch-structured-agent-session.ts
rg -n -C 4 'persistStructured|PersistedStructured|selection\.held|selection|publish|promptDelivery|lifecycle|restorePersistedStructuredLaunchState|settle|reconcil' src/renderer/src/lib

Repository: stablyai/orca

Length of output: 45664


🏁 Script executed:

rg -n -C 8 'type Persisted|interface Persisted|persistStructuredLaunchState|getPersistedStructuredAgentLaunchRecord|restorePersistedStructuredLaunchState|selection|publish|promptDelivery' src/renderer/src/lib/structured-agent-session-launch-registry.ts src/renderer/src/lib/structured-agent-session-launch.ts src/renderer/src/lib/structured-agent-session-launch-reload.ts src/renderer/src/lib/launch-structured-agent-session.ts

Repository: stablyai/orca

Length of output: 43880


🏁 Script executed:

set -e
printf '%s\n' '--- recovery ---'
sed -n '1,360p' src/renderer/src/lib/structured-agent-session-launch-recovery.ts
printf '%s\n' '--- callers and prompt delivery ---'
sed -n '1,380p' src/renderer/src/lib/structured-agent-session-launch-callers.ts
sed -n '1,360p' src/renderer/src/lib/structured-agent-session-launch-prompt.ts
printf '%s\n' '--- restore and recovery call sites ---'
rg -n -C 6 'restorePersistedStructuredLaunchState|retryStructuredAgentSessionLaunch|launchAndReconcile|reconcileUnknownLaunch|markStructuredAgentSessionLaunchPublished|promptDeliveryResult|structuredLaunchStates' src/renderer/src

Repository: stablyai/orca

Length of output: 42261


🏁 Script executed:

set -e
printf '%s\n' '--- persisted record type ---'
rg -n -C 8 'StructuredAgentLaunchPersistedRecord|writeStructuredAgentLaunchRecord|readStructuredAgentLaunchRecord' src/renderer/src/lib/structured-agent-session-launch-persistence.ts
printf '%s\n' '--- outbox consumers ---'
rg -n -C 8 'structured-agent-session-outbox|readStructuredAgentSession|dispatchStructured|agentSession.send|mutateStructuredAgentSessionLaunchPrompt' src/renderer/src/components src/renderer/src/lib src/renderer/src/runtime
printf '%s\n' '--- publication marker ---'
rg -n -C 12 'markStructuredAgentSessionLaunchPublished' src/renderer/src

Repository: stablyai/orca

Length of output: 41863


🏁 Script executed:

set -e
sed -n '1,280p' src/renderer/src/components/native-chat/structured-agent-session-outbox-dispatch.ts
sed -n '1,190p' src/renderer/src/components/native-chat/structured-agent-session-outbox-storage.ts
rg -n -C 8 'useStructuredAgentSession|outbox-dispatch|drainStructured|dispatchStructuredAgent|readStructuredAgentSessionLaunchOutbox|fence' src/renderer/src/components/native-chat src/renderer/src

Repository: stablyai/orca

Length of output: 45668


🏁 Script executed:

set -e
rg -l 'dispatchStructuredAgentSessionOutboxEntry|readMountedStructuredAgentSessionOutbox' src/renderer/src
for f in $(rg -l 'dispatchStructuredAgentSessionOutboxEntry|readMountedStructuredAgentSessionOutbox' src/renderer/src | grep -v 'test'); do
  echo "--- $f ---"
  rg -n -C 12 'dispatchStructuredAgentSessionOutboxEntry|readMountedStructuredAgentSessionOutbox|useStructuredAgentSessionOutbox|fence|outbox' "$f"
done

Repository: stablyai/orca

Length of output: 21032


Preserve held selections before dispatching the launch prompt.

The launch record does not persist held selections. A reload therefore restores no model pick.

The launch can publish the host session before applyStructuredLaunchHeldOptions completes. The prompt remains in the persisted outbox. After reload, useStructuredAgentSessionOutbox reads that entry and can call agentSession.send as soon as a session fence is available. It does not wait for the held selections to be restored or applied.

Persist and restore held selections, or block launch outbox dispatch until selection reconciliation completes. Otherwise, the first prompt can run with the original model instead of the model selected before reload.

@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.

Important

The new Codex model-catalog probe spawns a Codex app-server under the account home without the per-home process lock every other Orca Codex spawn already takes, so it can race a token rotation and permanently invalidate the stored OAuth credential. One inline comment with the suggested fix; everything else reviewed cleanly.

Reviewed changes

  • Host model catalog. New agent-model-catalog/ store + service + file persistence: per (agent, account-home, wslDistro) fingerprint, 10 min freshness, 30 s failure hold, success-only, coalesced save flushed at quit.
  • Session-less probes. createCodexModelCatalogProbe (short-lived read-only app-server, plugins disabled) and createClaudeModelCatalogProbe (one-shot CLI listing), both built on the launch invocation resolvers so a probe lists under the same binary/env as a real session.
  • agentSession.modelCatalog. Additive read RPC answered from the host store without a session queue, wired through the capability gate, cross-version manifest/fixtures, and the mobile allowlist.
  • Configured defaults. Codex config/read re-points the listing default at the user's configured model/effort, and a project .codex/config.toml withholds the default; Claude names get_settings.applied.model before the first turn with applied effort kept display-only.
  • Launch-owned early picks. structured-agent-session-launch-options.ts holds pre-publish picks and publishWithHeldOptions applies them against the create receipt fence before any send; markStructuredAgentSessionLaunchPublished now defers to that settlement while pending.
  • Renderer. Seed catalog from the first frame, host-catalog upgrade while starting, latched launch view, picker locked between publish and attach, Claude re-read once it starts; live listings write through to the store pinned to the spawn account.

ℹ️ Picker open can now spawn a provider CLI and write a new state file

Part of the latency win is operational: a cold picker read starts a short-lived Codex app-server (or a Claude CLI listing) from the main process, and the store persists to a new agent-model-catalog.json under the profile state directory. The visible-only guard, the in-flight join, and the 30 s failure TTL keep this bounded, so this is a release-notes/ops note rather than a defect — but the trigger is as ordinary as opening a chat, so it is worth calling out.

Technical details
# New process spawns and on-disk state introduced by a picker render

## Affected sites
- `src/main/native-chat/agent-model-catalog/agent-model-catalog-service.ts` — a record-less `read` kicks a probe when the key is cold/stale.
- `src/main/codex/codex-model-catalog-probe.ts` — spawns a Codex app-server.
- `src/main/claude/claude-model-catalog-probe.ts` — runs a one-shot Claude CLI listing.
- `src/main/native-chat/agent-model-catalog/agent-model-catalog-persistence.ts` — writes `agent-model-catalog.json` under the profile state dir.

## Required outcome
- Release notes mention the new background listing on first picker open and the new state file.
- Confirm the privacy/data-retention posture for a new persisted file (model ids and account-home fingerprints only; no credentials) is acceptable.

## Open questions for the human
- Should the probe be gated behind an explicit setting for users running metered provider billing?

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

...CODEX_SHORT_LIVED_PROBE_APP_SERVER_ARGS
])
const run = deps.runSession ?? runCodexAppServerSession
const listing = await run(

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.

This probe spawns a Codex app-server with CODEX_HOME set but does not take the per-home process lock. Every other Orca-spawned Codex process serializes on the account home precisely because concurrent spawns can consume one OAuth refresh-token rotation twice and permanently invalidate the stored credential — see codex-fetcher.ts:240, source-control-local-generation.ts:71, and commit-message-model-discovery.ts:175. Because a picker open is what triggers this spawn, it can land alongside a rate-limit refresh or a commit-message run on the same home.

Technical details
# Serialize the model-catalog probe per Codex home

## Affected sites
- `src/main/codex/codex-model-catalog-probe.ts:51-60` — `runCodexAppServerSession` is invoked directly, outside `withCodexHomeProcessLock`.
- `src/main/codex-cli/codex-home-process-lock.ts:5-9` — states the invariant: two Orca spawns refreshing the same home can invalidate the credential.
- `src/main/rate-limits/codex-fetcher.ts:238-240` — the existing pattern for a short-lived probe.

## Required outcome
- The probe's app-server run serializes on the same key the rate-limit and commit-message spawns use, so a model listing cannot race a token rotation on that home.

## Suggested approach (optional)
- Import `resolveCodexHomeProcessLockKeyForSpawnEnv` and `withCodexHomeProcessLock` from `../codex-cli/codex-home-process-lock`.
- Build the invocation object, then `withCodexHomeProcessLock(resolveCodexHomeProcessLockKeyForSpawnEnv(invocation.env), () => run(invocation, (rpc) => fetchCodexModelCatalogListing({ connection: rpc })))`.
- Note the lock only serializes Orca's own background spawns (live session panes do not take it), which matches the existing rate-limit/commit-message behavior.

## Open questions for the human (optional)
- Is holding the home lock for up to the 15 s probe deadline acceptable, or should the probe yield to a waiting user-triggered spawn?

seed
} = state.selection
// A pick made while this one was in flight superseded it and stays held for the next pass.
const settled = current === encoded

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.

settled compares only the encoded value, so re-picking the same value while its first write is in flight makes that first write's outcome resolve the newer reply and remove it from held without a second attempt. If the first write fails transiently, the re-pick is silently dropped. Tracking a per-pick identity (or generation) alongside the value would separate the two. Narrow, but cheap to make exact.

@brennanb2025
brennanb2025 merged commit e0144a9 into main Sep 25, 2026
64 checks passed
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