Repository navigation
fix(codex): repair new Chat sends, identity and model display - #23792
JustTalDevelops wants to merge 3 commits into
Conversation
|
| onCancelUnsubmitted: () => { | ||
| if (!firstEnterSent) { | ||
| clearUnsubmittedAgentInput(settings, ptyId, options) | ||
| } | ||
| } |
There was a problem hiding this comment.
Cancellation can strand prompts
If Codex swallows the first Enter and the user cancels before the retry, cancellation stops the retry, but this guard also skips clearing the prompt. A Stop or model-switch action can leave that text in the live Codex composer, where a later Enter may submit it unexpectedly. The image-send path has the same guard. Sending the first Enter does not establish that Codex accepted it.
| const hookMatchesForegroundAgent = | ||
| pty?.connected === true && | ||
| pty.foregroundAgent !== null && | ||
| pty.foregroundAgent === hookRow.agentType && | ||
| pty.foregroundAgent === hookRow.providerSessionAgentType && | ||
| hookRow.providerSession !== null |
There was a problem hiding this comment.
Cached foreground keeps exited sessions
If Codex exits after showing a neutral conversation title and the shell sets another neutral title, foregroundAgent can still say codex: it is cached, and that title change does not start a new foreground check. This condition can then keep publishing the old provider session as done while the shell owns the pane, instead of suppressing it as intended, until the hook agent evidence expires.
There was a problem hiding this comment.
Important
The mobile/headless projection change is gated on pty.foregroundAgent, which Orca-launched panes never populate — so the branch may not fire for the fresh Codex Chat scenario the PR describes. Please confirm the target scope before merging.
Reviewed changes
- Codex submit retry —
sendNativeChatMessageand the image path now schedule a second Enter afterTUI_AGENT_CONFIG.codex.submitRetryDelayMs(1200ms) viascheduleNativeChatSubmit, deferringmarkSubmitted()so the per-PTY queue holds the line across both writes andsettleAfterMsincludes the retry. - Composer wiring —
use-native-chat-pty-composer-sendapplies the retry only whenagent === 'codex', throughpromptSendOptionsfor text, image, and command-classification sends. - Cancel semantics — a new
firstEnterSentguard stopsonCancelUnsubmittedfrom re-clearing the composer once the first Enter has fired. - Mobile projection —
buildRuntimeMobileAgentStatusaddshookMatchesForegroundAgenttohasLiveHookSignal, preserving a Codex provider session under a neutral conversation title while the pane is connected with a live matching foreground agent and hook row. - Tests — exact write-order assertions for the retry/queue-hold, cancel-after-Enter, and image retry; a projection test that fails if the new OR is removed, plus a shell/suppress case.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| const hookMatchesForegroundAgent = | ||
| pty?.connected === true && | ||
| pty.foregroundAgent !== null && | ||
| pty.foregroundAgent === hookRow.agentType && | ||
| pty.foregroundAgent === hookRow.providerSessionAgentType && | ||
| hookRow.providerSession !== null |
There was a problem hiding this comment.
This branch can only fire when pty.foregroundAgent is non-null, but Orca-launched panes never populate that field: RuntimePtyForegroundAgent.load returns early on pty.launchAgent (src/main/runtime/runtime-pty-foreground-agent.ts:123), and the only other writer is isTerminalRunningSettledPromptAgent (src/main/runtime/orca-runtime-get-pty-record-for-pane-key.ts:143), reached from a desktop terminal.send with agentPrompt: true — not from a native-chat send. A fresh Codex tab created through the launch funnel gets launchAgent === 'codex', so foregroundAgent stays null and this condition is false in exactly the scenario the PR targets.
Technical details
# `hookMatchesForegroundAgent` may be unreachable for Orca-launched Codex chat
## Affected sites
- `src/main/runtime/runtime-mobile-agent-status-builder.ts:70-75` — gate requires `pty.foregroundAgent !== null` and equal to the hook agent + provider-session agent.
- `src/main/runtime/runtime-mobile-agent-status-builder.test.ts:17-34` — the `codexPty` fixture sets both `launchAgent: 'codex'` and `foregroundAgent`, but the refresh path forbids that combination, so the test models a state the production refresh cannot reach for a launched pane.
## Evidence
- `src/renderer/src/lib/launch-agent-in-new-tab.ts:245-273` sets `launchAgent`/`launchConfig`; `src/renderer/src/store/terminals/terminal-startup-queues.ts:23-25` mints a launch token; `src/main/ipc/pty/pane/launch-authority.ts:16-31` admits it; `src/main/runtime/orca-runtime-register-pty.ts:112-114` sets `pty.launchAgent`.
- `src/main/runtime/runtime-pty-foreground-agent.ts:120-136`: `if (!controller || !pty?.connected || pty.launchAgent) return false` — so `foregroundAgent` is only written for panes with no `launchAgent`.
- The only unguarded writer is `orca-runtime-get-pty-record-for-pane-key.ts:143`, called solely from `rpc/methods/terminal/terminal-send-method.ts:197` behind `agentPrompt === true && client.type === 'desktop'` (CLI/orchestration), which the native-chat composer does not use.
## Required outcome
- Establish whether the reported fresh Codex Chat pane was Orca-launched. If so, the branch needs shared evidence that holds for a launched pane — e.g. also accept `pty.launchAgent === hookRow.agentType` (retired on agent exit via `retirePtyAgentLaunchAuthority`), or a foreground signal derived from the launch config.
- If the intended scope is manually-started Codex panes only, say so in the PR body and make the test fixture reflect it.| onCancelUnsubmitted: () => { | ||
| if (!firstEnterSent) { | ||
| clearUnsubmittedAgentInput(settings, ptyId, options) | ||
| } | ||
| } |
There was a problem hiding this comment.
In the retry window the first Enter is frequently the one Codex swallows, so firstEnterSent being true does not prove the prompt is running — cancelling here now leaves the pasted text stranded in the composer, the exact failure this PR fixes. Since a clear on an already-submitted (empty) composer is a harmless no-op, consider keeping the cancel clear, or skipping it only once the retry Enter itself has fired. The same guard is duplicated in native-chat-runtime-image-send.ts:83-87.
Technical details
# Cancel during the Codex retry window leaves an unsubmitted prompt behind
## Affected sites
- `src/renderer/src/components/native-chat/native-chat-runtime-send.ts:191-195` — `onCancelUnsubmitted` skips the clear whenever `firstEnterSent`.
- `src/renderer/src/components/native-chat/native-chat-runtime-image-send.ts:83-87` — same guard.
- `src/renderer/src/components/native-chat/native-chat-pty-send-queue.ts:171` — `shouldClear = bodyStarted && !submitted`; `markSubmitted()` is deferred until the retry, so a cancel in the window reaches `onCancelUnsubmitted`.
## Required outcome
- Decide the intended cancel semantics: after the first Enter, either always clear (Ctrl+U on an empty/running composer is a no-op) or distinguish "first Enter submitted" from "first Enter swallowed" so the stranded body is still cleaned up.
- Callers that can hit this window: `cancelPendingSends` on unmount/pane swap (`use-native-chat-send-lifecycle.ts:54`) and session-option dispatch.|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe mobile status builder recognizes a matching foreground agent as a live hook signal under the specified provider-session conditions. Native chat prompt sends support an optional second Enter. Codex prompt sends use the configured retry delay, and message and image-send paths include that delay in their queued duration. Cancellation clears input only if the first Enter has not been sent. The session-options hook reads Codex model and effort values from terminal footers and reports the model as a choice. Priority: ➖ Normal Merge Risk: 🔵 Low · up to Codex users whose status line omits the directory item may still see no current model in chat. This is a bounded display issue; chat sends remain available. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to Sending a message can now trigger a delayed second keystroke. The review could not establish that it always reaches the original message rather than a subsequent interactive prompt. Existing session checks limit the scope, but the transition warrants review. Retained concerns
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: ed715be1-a7e0-40b6-bf41-bfb8f7efaaa3
📒 Files selected for processing (4)
src/renderer/src/components/native-chat/codex-terminal-session-options.test.tssrc/renderer/src/components/native-chat/codex-terminal-session-options.tssrc/renderer/src/components/native-chat/use-native-chat-session-options.test.tssrc/renderer/src/components/native-chat/use-native-chat-session-options.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
| const CODEX_FOOTER = | ||
| /^([A-Za-z][\w.\-/]*(?:\s+[A-Za-z0-9][\w.\-/]*)*)\s+(default|minimal|low|medium|high|xhigh|max|ultra)\s*·\s*(?:~[/\\]|[/\\]|[A-Za-z]:[/\\])/i |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Accept Codex status lines without a directory item.
If a user configures tui.status_line = ["model-with-reasoning", "git-branch"], the model and effort can appear without a directory. CODEX_FOOTER then rejects the line, so the current model is not reported. Codex 0.158.0 permits users to select and order status-line items. Parse the model item without requiring current-dir, and test a configured layout. (raw.githubusercontent.com)
|
|
||
| useEffect(() => { | ||
| if (!surface || agent !== 'claude') { | ||
| if (!surface || (agent !== 'claude' && agent !== 'codex')) { |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
# Find the hook's callers and any screen-change reporting path.
rg -n -C 8 '\buseNativeChatSessionOptions\s*\(' src/renderer
rg -n -C 5 'readTerminalScreen|reportSessionOptions|onData|onRender' src/renderer/src/components/native-chatRepository: stablyai/orca
Length of output: 41497
🏁 Script executed:
#!/bin/bash
printf '%s\n' '--- hook ---'
sed -n '80,260p' src/renderer/src/components/native-chat/use-native-chat-session-options.ts
printf '%s\n' '--- caller reader references ---'
rg -n -C 12 'readTerminalScreen\s*=|readTerminalScreen:|useCallback.*readTerminalScreen|onRender|subscribe.*screen|screen.*subscribe' src/renderer/src/components/native-chat src/renderer/src | head -240
printf '%s\n' '--- resolved view surrounding reader construction ---'
rg -n -C 20 'readTerminalScreen' src/renderer/src/components/native-chat/NativeChatResolvedView.tsxRepository: stablyai/orca
Length of output: 37265
🏁 Script executed:
#!/bin/bash
sed -n '80,260p' src/renderer/src/components/native-chat/use-native-chat-session-options.ts
printf '%s\n' '--- reader definitions and uses ---'
rg -n -C 16 'readTerminalScreen|onRender|subscribe.*screen|screen.*subscribe' src/renderer/src/components/native-chat src/renderer/src | head -260Repository: stablyai/orca
Length of output: 38061
🏁 Script executed:
#!/bin/bash
printf '%s\n' '--- NativeChatView ---'
sed -n '1,90p' src/renderer/src/components/native-chat/NativeChatView.tsx
printf '%s\n' '--- NativeChatView callers and reader wiring ---'
rg -n -C 16 'NativeChatView|readTerminalScreen' src/renderer/src --glob '!**/*.test.*' | head -320Repository: stablyai/orca
Length of output: 36886
🏁 Script executed:
#!/bin/bash
sed -n '1,180p' src/renderer/src/components/terminal-pane/TerminalPaneNativeChatPortal.tsx
rg -n -C 18 'readTerminalScreen|screenReader|onRender|onData|subscribe' src/renderer/src/components/terminal-pane src/renderer/src/components/terminal --glob '!**/*.test.*' | head -320Repository: stablyai/orca
Length of output: 37158
🏁 Script executed:
#!/bin/bash
rg -n -C 30 'readNativeChatTerminalScreen' src/renderer/src/components/terminal-pane/use-terminal-pane-controller.ts
rg -n -C 20 'readNativeChatTerminalScreen' src/renderer/src/components/terminal-paneRepository: stablyai/orca
Length of output: 18151
Report Codex model changes from terminal updates.
readNativeChatTerminalScreen keeps the same identity while the chat leaf remains unchanged. A Codex footer update therefore does not rerun the reporting effect. The discovery callback also reuses the cached screen, so the session options can keep the previous model. Subscribe to terminal-screen changes and report the current Codex options when the footer changes.
There was a problem hiding this comment.
ℹ️ No critical issues — one design question on the new Codex model source.
Reviewed changes
Reviewed the second commit (1f93956, "show current Codex model from terminal footer") on top of the previously reviewed 25f9b47.
- New Codex footer parser —
readCodexSessionOptionsFromTerminalScreenstrips ANSI, scans the last eight non-empty screen lines bottom-up for aModel <effort> · <path>footer, rejects theloadingplaceholder, resolves the displayed label against the host catalog (falling back to the label), and returnsmodel/effort. - Wired into the session-option hook —
useNativeChatSessionOptionsnow reads the terminal screen forcodexin the same three places it already did forclaude: the initial snapshot, the scrape effect, and the post-discovery re-resolve. - Tests — a captured 0.157.1 transcript, a live 0.158 footer, catalog resolution, header-scrolled-off, and loading-placeholder cases, plus a hook-level test that names a Codex session from the footer. All 14 tests pass locally.
ℹ️ Codex now has two model reporters and the precedence is implicit
The new footer reader makes Codex a second source of its model, but the hook-reported-model effect still runs for Codex — it is excluded only for claude — and it is declared after the footer effect, so on mount it reports last (and re-runs whenever the hook value changes while the footer effect runs only once per surface). Codex hook payloads do carry a model, so this combination is reachable. Which source is authoritative after a mid-session switch, and is the current last-write-wins behavior intended?
Technical details
# Codex has two model reporters and the precedence is implicit
## Affected sites
- `src/renderer/src/components/native-chat/use-native-chat-session-options.ts:149-195` — new Codex footer read (`reportCurrentValues`); declared first, re-runs only when `surface` identity changes.
- `src/renderer/src/components/native-chat/use-native-chat-session-options.ts:203-226` — hook-reported-model effect; the guard excludes only `claude`, so it still runs for `codex`, is declared after the footer effect, and re-runs on every changed `reportedModel`.
- `src/main/agent-hooks/server-codex-normalization.test.ts:31-40` — Codex hook payloads carry `model` (`payload.model`), which reaches `agentStatusByPaneKey[paneKey].model` via `agent-status-live-entry-builder.ts:209`.
- `src/renderer/src/components/native-chat/use-native-chat-session-options.test.ts:196-213` — the existing "hook model is ignored for Claude" test has no Codex equivalent; every added Codex test omits `paneKey`, so the two-source path is untested.
## Required outcome
- State the intended precedence: when a Codex hook model and a terminal-footer model are both present, which one is authoritative?
- If the footer should be authoritative for the current model, exclude `codex` from the hook effect as `claude` is; if the hook is authoritative, document that the footer only seeds the initial value.
- Cover the combined case with a test that supplies a `paneKey` whose store entry has a hook model alongside a footer screen.
## Open questions for the human
- Does a Codex mid-session `/model` switch reach the picker through the hook path (next `UserPromptSubmit`) or should the footer be re-read?DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
In a new Codex Chat, a prompt could sit unsent in Terminal because Codex sometimes ignores the first Enter after pasted text. After Codex gave the terminal a conversation title, Orca could hide the session from Chat. The Chat model button also stayed at “Model” even while Terminal showed the running model. This change makes sends reliable, keeps the transcript addressable, and shows the model Codex actually reports.
What Changed
/modelpicker remains the way to change it.Why
The retry timing already exists for Codex launch drafts in
TUI_AGENT_CONFIG; Chat sends were the missing caller. The host already has process and hook evidence to distinguish a conversation title from a shell title. Codex prints its current model in the footer, including account-specific models that Orca's static catalog does not yet list, so Chat can report that value without guessing a default or adding a status store.This covers fresh Codex Chat sessions. #23739 covers explicit desktop resumes, and #23411 addresses the shared Codex daemon's pane identity.
Linked Issue
Related to #22873. Complements #23411 and #23739.
Visual Proof
The focused tests cover the swallowed first Enter, queued follow-up, cancellation, image send, a neutral conversation title, and model detection by replaying a captured Codex 0.157.1 PTY transcript through xterm serialization. A 0.158.0 footer sample also covers the newer layout. A user confirmed that a fresh prompt submitted and appeared in Chat on the previous local build; the updated model display awaits manual confirmation.
Testing
git diff --checkpassedThe live remote reproduction confirmed that a second Enter submits a stranded prompt and that a Codex conversation title can hide an otherwise valid provider session. A temporary server-side reconciliation was tested separately; it is not part of this PR. CI should run the full build and cross-platform suite.
AI Disclosure
OpenAI Codex (GPT-6) prepared the change and tests under user direction. I reviewed the diff and verification output.
Review
Please check the queue's cancellation behavior between the first and retry Enter, the foreground-agent evidence for preserving Chat identity, and the terminal-footer match against the captured Codex transcript.
Agent skill upstream boundary
Notes
Security: the title fallback requires a matching live foreground agent and a provider session from the hook server. Performance: one extra Enter for Codex Chat sends; model reading adds no polling. Backwards compatibility: no RPC or persistence changes. SSH/remote: the host projection also reaches paired mobile clients; send and model display changes are desktop-renderer scoped.
Checklist