Skip to content

fix(native-chat): honor structured routing with saved options - #19040

Merged
brennanb2025 merged 7 commits into
mainfrom
brennanb2025/fix-codex-chat-native
Sep 6, 2026
Merged

brennanb2025 merged 7 commits into
mainfrom
brennanb2025/fix-codex-chat-native

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​182 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​177
Prod 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​53 $\color{#cf222e}{\Huge{\mathbf{−}}}$​15 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​38

ELI5

Turning on structured chat now reliably opens structured Codex/Claude chats even when a model or effort was previously selected, and that selection is applied to the new chat.

What Changed

  • removed saved session options from the legacy-routing conditions
  • resolved persisted model/effort on the execution host and persisted them atomically with a new structured session reservation
  • passed the persisted values to provider acquisition before a first prompt can be sent
  • kept boolean and unsupported legacy-only options out of the structured provider contract
  • added routing, create-intent, RPC, and acquisition regression coverage

Why

A recent routing guard treated any saved model/effort as a reason to fall back to legacy native chat. Removing that guard exposed a second gap: the structured path did not seed those saved values. Persisting them during reservation preserves the selected behavior without a post-create race.

Regression Point

Introduced by #18248 — feat(native-chat): unify local agent entrypoint routing, commit c4f335b49d.

Linked Issue

Reported directly; no linked tracker issue.

Visual Proof

Before: New tab → Codex opened a terminal-backed legacy chat when saved options existed.

After: the same flow renders a structured Codex Chat with the saved Medium / GPT-5.6-Sol selection.

Structured Codex chat with saved model and effort

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Local macOS verification:

  • 5 focused test files, 87 tests
  • node and web TypeScript checks
  • changed-code quality gate
  • Electron build
  • background Electron CDP: verified the rendered structured chat, agent-session tab state, no terminal-backed tab, and durable { model: "gpt-5.6-sol", effort: "medium" } session record

CI covers the full test matrix and macOS/Windows packaging.

AI Disclosure

Review

Please focus on structured create idempotency and ensuring initial options are durable before provider acquisition.

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

The option seeding is host-side and does not change the remote RPC schema. Location resolution remains shared across local, SSH, WSL, git worktree, and folder workspace flows.

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)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 490dc6d6-c5b7-4b52-af51-7c5f5d993b1d

📥 Commits

Reviewing files that changed from the base of the PR and between eb33ee6 and b1b9256.

📒 Files selected for processing (2)
  • src/renderer/src/lib/launch-agent-structured-chat-guard.test.ts
  • src/shared/native-chat-session-option-defaults.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/lib/launch-agent-structured-chat-guard.test.ts

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


📝 Walkthrough

Walkthrough

Structured native-chat routing no longer falls back to legacy routing when initialSessionOptions contains a model. Structured session creation resolves model and effort defaults, forwards them through attach and reservation, validates them, and persists them before provider acquisition. Tests cover routing, intent creation, option forwarding, retry replay, and session persistence.

Merge Risk: ⚪ Minimal · up to b1b92

Structured Codex and Claude chats now retain supported saved model and effort preferences through session creation without falling back to terminal-backed routing. The covered routing, persistence, acquisition, and retry paths show no remaining merge-blocking risk.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change, motivation, testing, scope, and regression coverage. However, it does not provide the required linked issue and includes only one visual attachment despite the tem… Add a valid linked issue using the required “Fixes #...” format. Attach both before and after visual evidence, or use “N/A” with a reason if the change has no visual or interaction impact.
Docstring Coverage ⚠️ Warning Docstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 12 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: preserving structured native-chat routing when saved options exist.
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.
Full details: Description check

Explanation

The description explains the change, motivation, testing, scope, and regression coverage. However, it does not provide the required linked issue and includes only one visual attachment despite the template requiring before-and-after proof for UI or behavior changes.

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

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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: bc1df21d-2072-424f-84b7-61f310b241fd

📥 Commits

Reviewing files that changed from the base of the PR and between b51bbf3 and 16fb66a.

📒 Files selected for processing (3)
  • src/renderer/src/lib/agent-launch-routing.test.ts
  • src/renderer/src/lib/agent-launch-routing.ts
  • src/renderer/src/lib/launch-agent-structured-chat-guard.test.ts
💤 Files with no reviewable changes (1)
  • src/renderer/src/lib/agent-launch-routing.ts

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

@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

Removing the hasInitialSessionOptions guard routes launches with a saved model/effort to the structured path, but the structured path never reads nativeChatSessionOptions — the saved preference is silently dropped instead of applied.

Reviewed changes

  • Routing guard removal — resolveAgentLaunchRoute stops forcing legacy-native-chat when initialSessionOptions is present, so Codex/Claude launches with a saved model or effort keep the structured route.
  • Routing unit test — agent-launch-routing.test.ts now asserts a saved model still resolves to structured-native-chat and drops the old legacy-routing assertion.
  • Launch-path guard test — launch-agent-structured-chat-guard.test.ts adds an end-to-end case that saved Codex options keep the launch on the structured path.

⚠️ Saved model and effort are not applied on the structured path

The guard this PR removes was the only thing routing a launch with nativeChatSessionOptions to the legacy TUI path, where resolveAgentLaunchCommand emits the saved model/effort as -m / --effort / -c model_reasoning_effort= flags. On the structured path nothing reads that setting: startStructuredAgentLaunch(worktreeId, agent, { prompt, promptDelivery, onPromptDelivered }) drops startupPlan.sessionOptions, and the host resolves the provider model from agentDefaultArgs (resolveConfiguredCodexStructuredArgs / resolveConfiguredClaudeStructuredArgs), not nativeChatSessionOptions. A user who saved gpt-5.6-sol with medium effort now opens a structured chat on the default model with no effort override, silently. The new test asserts only routing (focusAfterMenuClose: 'structured-session', mockCreateTab not called), so it passes whether or not the model/effort is applied.

Technical details
# Saved model/effort dropped on the structured route

## Affected sites
- src/renderer/src/lib/launch-agent-in-new-tab.ts:231 — `startStructuredAgentLaunch` carries no `sessionOptions`; `StructuredAgentLaunchOptions` is only `{ prompt, promptDelivery, onPromptDelivered }`.
- src/renderer/src/lib/structured-agent-session-launch-callers.ts:13 — `StructuredAgentLaunchOptions` has no option fields.
- src/renderer/src/lib/launch-structured-agent-session.ts:95 — the `agentSession.create` intent sends only `{ worktree, agent }`.
- src/main/runtime/orca-runtime-get-worktree-ps.ts:191-201 — the structured provider launch args come from `agentDefaultArgs`, not `nativeChatSessionOptions`.
- src/renderer/src/components/native-chat/native-chat-launch-session-options.ts — `resolveInitialNativeChatSessionOptions` (the source of `startupPlan.sessionOptions`) is only consumed by the legacy TUI branch.

## Required outcome
- The saved model/effort reaches the structured session (apply it to the structured launch args or an initial `agentSession.setOption`), or the guard is retained.
- The new test asserts the model/effort actually reaches the structured session, not only that routing changed.

## Open questions for the human
- Is the structured chat meant to seed its initial model from `nativeChatSessionOptions`, or is that setting intentionally legacy-only?

ℹ️ Nitpicks

  • initialSessionOptions is no longer read anywhere in resolveAgentLaunchRoute — it is now dead input that every caller still computes and passes. Consider removing it from AgentLaunchRoutingInput (and the launch-agent-in-new-tab.ts call site) or documenting why it is retained.

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

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

Reviewed changes

This run reviewed the follow-up commit (94d402b) on top of the previously reviewed guard removal. It closes the gap the prior review flagged: the saved model/effort now reaches the structured session instead of being silently dropped.

  • options threaded through the attach/reservation path — AgentSessionAttachParams, AgentSessionReserveRequest, and createAgentSessionRecord now carry a host-resolved options map, validated by the exported isAgentSessionOptions.
  • Seed resolved on the executing host — resolveStructuredAgentSessionIntent derives { model, effort } from resolveNativeChatSessionOptionDefaults(settings.nativeChatSessionOptions, agent), mirroring the -m / --effort / -c model_reasoning_effort= flags the legacy TUI path used to emit.
  • Fingerprint computation unified — agentSession.create reuses attachFingerprintFields instead of a hand-rolled field list, so the attach fingerprint includes options and stays consistent with admitAttachOrRefuse. Canonicalization drops undefined keys, so this is wire-neutral.
  • Coverage added — new tests assert the create intent carries { model, effort }, the reservation persists options before the first acquisition, and the RPC forwards them to host.attach.

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

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

Reviewed changes

One follow-up commit landed mid-review, tightening the create-path fingerprint so it provably matches the attach-time recomputation.

  • Fingerprint now hashes the client envelope — agentSession.create computes the attach fingerprint from attachFingerprintFields({ ...resolved, envelope: params.envelope }) rather than attachFingerprintFields(resolved), so the hashed expectedRuntimeFence is params.envelope.expectedRuntimeFence (validated null for create) instead of the resolver's hardcoded-null envelope. The two values are equal today, so this is behavior-preserving, but it removes the one place the create-time and admitAttachOrRefuse recomputations could drift apart.

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

Merge Sim added 2 commits September 6, 2026 01:38
Seeding host-resolved options into the attach fingerprint put a mutable
value into the durable operation identity. A create whose outcome was
unknown, retried under the same operation id after the user reselected a
model, re-resolved different options and hashed to a different
fingerprint — so the ledger refused it as a conflict instead of
replaying. That refusal is not definitive, so no legacy fallback fires
and the launch has no recovery.

Options are the session's initial state, not its identity, and the
reservation still carries them to the record. Excluding them also makes
the digest byte-identical to the pre-change one in every case, not just
when no options resolve.
The create-intent resolver narrowed saved options to model/effort with an
inline key literal, inside a file carrying @ts-nocheck — so neither the
key list nor the string narrowing had a typechecked or testable home, and
the repo already expresses this concept as a named shared shape.

Move it to resolveStructuredLaunchSeedOptions beside the persisted
settings it reads, where it is typechecked and unit-tested, and document
why the seed is exactly model and effort: they are the only ids the
picker persists that both providers also accept as strings.

No behavior change. Adds coverage for a non-string persisted effort,
which settings.json can hold and the durable record must not carry.

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

Reviewed changes

This run reviewed the follow-up commit (52c78c30) on top of the previously approved 94d402b and 5d72c80. It removes options from the attach fingerprint so a create retried after the host re-resolves different options replays instead of conflicting.

  • options excluded from the attach fingerprint — attachFingerprintFields now hashes only session identity (location, provider, agent, accountHome, runtimeKind, providerHandle, expectedRuntimeFence), treating options as initial state rather than identity. A create retried after the user reselects a model/effort computes the same fingerprint and replays the original record instead of being refused with agent_session_operation_conflict.
  • Replay regression test — structured-agent-session-acquisition-options.test.ts asserts a retry with different options still replays and preserves the first attempt's options.

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

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

Reviewed changes

This run reviewed the follow-up commit (eb33ee6) on top of the previously approved 52c78c30. It extracts the inline ['model','effort'] filter into a named, documented helper and adds dedicated tests.

  • resolveStructuredLaunchSeedOptions extracted — the host-side seed narrowing moves from an inline Object.fromEntries in the create-intent resolver into src/shared/native-chat-session-option-defaults.ts, with a doc comment explaining why only model/effort are seedable.
  • Whitespace hardening — the helper drops blank values via .trim(), so a user-writable non-string or blank effort cannot reach the durable Record<string, string> record.
  • Coverage added — native-chat-session-option-defaults.test.ts asserts seeding, mid-session-only id exclusion, and blank/non-string value exclusion.

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

Merge Sim added 2 commits September 6, 2026 01:49
The case drives a saved Codex model and effort through the launch path,
but the structured create intent it asserts on carries no options, so it
pins the route and not the preservation its name claimed. Preservation is
pinned host-side, where the seeding actually happens.
valuesByModel is merged over the resolved model, so a stored `model` key
can blank it — the seed then empties out and must resolve to undefined.
Nothing covered that branch, so returning the empty map unguarded stayed
green.

It matters because emitting `{ model: '' }` fails the record's
bounded-string guard, and agent_session_options_invalid is not a wire
refusal code: classifyStoreFailure rethrows it, the client reads the raw
error as an unknown outcome, and the launch strands with no fallback.

Corrects eb33ee6, whose message claimed no behavior change. That
extraction also stopped emitting empty and whitespace-only values, which
is a fix on six input shapes, not a pure move.

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

Reviewed changes

This run reviewed the final follow-up commit (b1b9256) on top of the previously reviewed seed-narrowing work. It is test-only, with no production change.

  • Empty-model edge case pinned — native-chat-session-option-defaults.test.ts adds a case asserting resolveStructuredLaunchSeedOptions returns undefined when a stored valuesByModel model: '' blanks the resolved model, rather than emitting { model: '' } that would fail the durable record's bounded-string guard.

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

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Independent Grok Electron validation — PR #19040

Validated remote head: b1b9256b2b5dd17e6257fcbdfa836ef00302976c
Local worktree HEAD matched this oid before and after the run.
App identity: Orca: brennanb2025/fix-codex-chat-native (eider @ brennanb2025/fix-codex-chat-native).

No code was modified. No merge was performed. No defect requiring a fix loop was found.

Scenarios

Isolated ORCA_DEV_USER_DATA_PATH profile, ORCA_BACKGROUND_LAUNCH=1, CDP on 127.0.0.1:9335. Seeded settings before launch:

  • experimentalNativeChat: true
  • experimentalStructuredNativeChat: true
  • openAgentTabsInChatByDefault: true
  • Codex saved options: { model: "gpt-5.6-sol", effort: "medium" }
  • Claude saved options: { model: "opus", effort: "high" }

Added a throwaway local git worktree, then exercised the visible New Tab menu.

  1. New Tab → Codex (no prompt sent)
  2. New Tab → Claude (no prompt sent)
  3. Switch back to the Codex Chat tab

Credentials: ~/.codex and ~/.claude were present; both routes launched.

Visible evidence

New Tab menu with Claude and Codex entries:

02-new-tab-menu.png

Codex: structured chat UI titled Codex Chat, empty-state copy “Start a chat with Codex”, composer showing Medium and GPT-5.6-Sol. Not a terminal-backed legacy session.

03-codex-structured-chat.png

Claude: structured chat UI titled Claude Chat, empty-state copy “Start a chat with Claude”, composer showing opus. Not a terminal-backed legacy session.

04-claude-structured-chat.png

After Claude launch, Codex Chat still shows structured Medium / GPT-5.6-Sol with both tabs present:

05-codex-after-claude-launch.png

Screenshots are uncropped full-window CDP captures (1728×1007). A Playwright inspector overlay is visible at the bottom of the window; it is not product UI.

Backing evidence

Renderer store after both launches:

  • activeTabType: "agent-session"
  • unifiedTabsByWorktree: two contentType: "agent-session" tabs (Codex Chat, Claude Chat)
  • tabsByWorktree: empty (no terminal tabs)
  • ptyIdsByTabId: empty
  • Settings still hold the seeded nativeChatSessionOptions

Durable agent-sessions.json records before any prompt:

session provider options lease runtimeKind
codex_3199f2a8_1838_4a06_9a24_e793aa788a18 codex { model: "gpt-5.6-sol", effort: "medium" } live native
claude_ed3b7627_9e57_4619_9024_443b1755ad5d claude { model: "opus", effort: "high" } live native

Both records are in visibleSessionIds.

Unverified gaps

  • Folder-workspace, SSH, WSL, and Windows hosts were not exercised.
  • No first prompt was sent (this check is pre-prompt persistence/routing).
  • Claude composer showed the saved opus model but did not render a visible Effort control; the durable record still carried effort: "high".
  • Native-focus / visible-window tests were not run (forbidden on the user’s desktop).

@brennanb2025

brennanb2025 commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Final review and validation status

All requested review and QA loops are complete at b1b9256b2b5dd17e6257fcbdfa836ef00302976c.

  • Regression point: PR feat(native-chat): unify local agent entrypoint routing #18248, commit c4f335b49d.
  • Claude review: repeated same-model review ended CLEAN. Review found and fixed a durable-create idempotency defect plus malformed saved-option edge cases; the final focused sweep passed 1,658 tests across 187 files, both node/web typechecks, and the native code-quality audit.
  • Readiness: opening and closing readiness reviews passed with no P0/P1 findings.
  • Precedent: aligned with the established structured-session boundary: the structured toggle selects the structured transport, while saved model/effort values seed initial durable session state before provider acquisition. The fix extends the existing reservation/acquisition path and adds no parallel session mechanism or wire-schema change.
  • Manual Electron validation: real New Tab → Codex and New Tab → Claude flows both rendered structured chat tabs. Backing state showed two agent-session tabs, zero terminal tabs/PTY mappings, and durable pre-prompt options of Codex gpt-5.6-sol / medium and Claude opus / high.
  • Visual proof: fix(native-chat): honor structured routing with saved options #19040 (comment)
  • CI: all final-head checks passed, including static analysis, typecheck, cross-version wire compatibility, macOS packaging, Windows packaging, and all eight test shards.

Remaining manual gaps: folder/SSH/WSL/Windows hosts and a first prompt were not exercised in the Electron run. CI covers Windows packaging and the automated suites cover the host-side path.

Merged: squash commit 39cbc68f169e4400e8c67494c85a0e96c914b92f after all final-head checks and manual validation passed.

@brennanb2025
brennanb2025 merged commit 39cbc68 into main Sep 6, 2026
27 checks passed
brennanb2025 pushed a commit that referenced this pull request Sep 6, 2026
Carries main's #19040 through this branch's two extractions, which would
otherwise have silently reverted it: both conflicts are the same shape,
where main fixed code this branch had already moved elsewhere.

- resolveStructuredNativeChatSupport no longer refuses a launch that has
  saved session options. Main removed that term from resolveAgentLaunchRoute
  directly; this branch had lifted the whole predicate into the shared
  module, so taking either conflict side kept the refusal alive. The blocker
  member, the unused input field, the orchestration blocker-to-reason entry
  and the case pinning it are removed with it. Main's own routing test failed
  on this merge before the port and passes after, which is what proves the
  port is load-bearing rather than cosmetic.

- The structured create fingerprint now goes through attachFingerprintFields.
  Same shape again: main replaced the inline field list in
  structured-agent-session.ts, but this branch had moved that computation
  into structured-agent-session-create.ts. Options stay out of the digest,
  which is main's point: they are the session's initial state, not its
  identity, so a retry after the user reselects a model replays instead of
  conflicting.
brennanb2025 added a commit that referenced this pull request Sep 9, 2026
…placement (#19431)

* fix(orchestration): let worker-start actually produce a structured chat

`orchestration.workerStart` reads the user's "open agent tabs in chat"
default, but two placement checks downgraded a structured-preferring
worker to a PTY terminal agent for the two flags a routine dispatch
always passes:

  --worktree new-child / new-top-level  -> worktree_creation
  --model / --effort                    -> launch_preferences

so in practice a structured worker never happened.

launch_preferences was stale. PR #19040 gave AgentSessionAttachParams
`options` and added resolveStructuredLaunchSeedOptions, which narrows a
saved selection to exactly `model` and `effort` — the two ids both
structured providers accept as strings. --model/--effort now go through
that same narrowing (extracted as narrowStructuredLaunchSeedOptions) and
seed the worker's session instead of forcing a terminal. An option set
that narrows to nothing resolves to undefined, never `{}`, which would
fail the record's bounded-string guard under a code that is not a wire
refusal and strand the launch with no fallback.

worktree_creation was a consequence of createWorkerWorktree creating
agent-first: its startup terminal WAS the worker, so the structured
branch below it was unreachable for any new worktree. A structured
worker now creates the worktree with no startup agent and creates its
session for the worktree afterwards — the order the renderer's own
structured worktree create already uses. Because the executing host can
only answer agentSession.createSupport for a workspace that exists, that
verdict moved after creation: a refusal (WSL, and the rest) becomes a
terminal agent in the worktree just created, never a failed start.

--on and --terminal still downgrade, with their reasons intact, and
every remaining downgrade still states itself in the mode receipt.

The wait-for-setup gate is preserved explicitly. A PTY worker got it for
free — agent-first creation sequences the agent's startup command behind
the setup runner, so tui-idle could not arrive until setup exited. A
structured session has no startup command to sequence, so the gate is
now awaited directly, bounded by the start's own timeout.

Split out worker-worktree-creation.ts and worker-start-agent-placement.ts
rather than growing two files that were both pinned at the max-lines cap.

* refactor(native-chat): make shared feasibility authoritative for launch routing

* Type the structured setup gate's absent blocked reason so the wait union stays property-typed

The type-aware audit rejected the blocked-reason template literal: narrowing the
wait union with an 'in' check left the field typed unknown. Declaring that a
structured setup gate never carries a blocked reason restores the direct read.

---------

Co-authored-by: Merge Sim <sim@local>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ai#19040)

* fix(native-chat): keep saved options on structured route

* fix(native-chat): seed structured session options

* fix(native-chat): preserve create wire compatibility

* fix(native-chat): keep create replayable across an option change

Seeding host-resolved options into the attach fingerprint put a mutable
value into the durable operation identity. A create whose outcome was
unknown, retried under the same operation id after the user reselected a
model, re-resolved different options and hashed to a different
fingerprint — so the ledger refused it as a conflict instead of
replaying. That refusal is not definitive, so no legacy fallback fires
and the launch has no recovery.

Options are the session's initial state, not its identity, and the
reservation still carries them to the record. Excluding them also makes
the digest byte-identical to the pre-change one in every case, not just
when no options resolve.

* refactor(native-chat): name the structured launch option seed

The create-intent resolver narrowed saved options to model/effort with an
inline key literal, inside a file carrying @ts-nocheck — so neither the
key list nor the string narrowing had a typechecked or testable home, and
the repo already expresses this concept as a named shared shape.

Move it to resolveStructuredLaunchSeedOptions beside the persisted
settings it reads, where it is typechecked and unit-tested, and document
why the seed is exactly model and effort: they are the only ids the
picker persists that both providers also accept as strings.

No behavior change. Adds coverage for a non-string persisted effort,
which settings.json can hold and the durable record must not carry.

* test(native-chat): name the structured routing pin for what it asserts

The case drives a saved Codex model and effort through the launch path,
but the structured create intent it asserts on carries no options, so it
pins the route and not the preservation its name claimed. Preservation is
pinned host-side, where the seeding actually happens.

* test(native-chat): pin the empty seed the record cannot carry

valuesByModel is merged over the resolved model, so a stored `model` key
can blank it — the seed then empties out and must resolve to undefined.
Nothing covered that branch, so returning the empty map unguarded stayed
green.

It matters because emitting `{ model: '' }` fails the record's
bounded-string guard, and agent_session_options_invalid is not a wire
refusal code: classifyStoreFailure rethrows it, the client reads the raw
error as an unknown outcome, and the launch strands with no fallback.

Corrects eb33ee6, whose message claimed no behavior change. That
extraction also stopped emitting empty and whitespace-only values, which
is a fix on six input shapes, not a pure move.

---------

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