Repository navigation
Improve Codex startup prompt reliability - #5686
Conversation
Co-authored-by: Orca <[email protected]>
|
Ready to review this PR? Stage has broken it down into 13 individual chapters for you: Chapters generated by Stage for commit 6771091 on Jun 18, 2026 6:18pm UTC. |
📝 WalkthroughWalkthroughThis pull request introduces a 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/renderer/src/lib/launch-work-item-direct-agent.ts (1)
10-16:⚠️ Potential issue | 🟠 MajorAdd
startupCommandDeliverytobuildDirectWorkItemStartupOptsreturn type.The function emits
startupCommandDelivery(lines 28–30) but the declared return type omits it, breaking the type contract for callers.♻️ Suggested type update
export function buildDirectWorkItemStartupOpts( agent: TuiAgent | null, plan: AgentStartupPlan | null, launchSource: LaunchSource ): { - startup?: { command: string; env?: Record<string, string>; telemetry?: AgentStartedTelemetry } + startup?: { + command: string + env?: Record<string, string> + startupCommandDelivery?: StartupCommandDelivery + telemetry?: AgentStartedTelemetry + } } {src/renderer/src/lib/onboarding-folder-agent-startup.ts (1)
11-15:⚠️ Potential issue | 🟠 MajorAdd missing
startupCommandDeliveryfield toOnboardingFolderAgentStartuptype.The function returns an object that conditionally includes
startupCommandDeliveryfromstartupPlan, but the exported type definition omits it, breaking type safety.♻️ Suggested fix
Add the import:
+import type { StartupCommandDelivery } from '../../../shared/codex-startup-delivery' import type { AgentStartedTelemetry } from '`@/lib/worktree-activation`'Update the type:
export type OnboardingFolderAgentStartup = { command: string env?: Record<string, string> + startupCommandDelivery?: StartupCommandDelivery telemetry: AgentStartedTelemetry }
🧹 Nitpick comments (2)
src/relay/pty-shell-launch.ts (1)
272-273: ⚡ Quick winAdd a short
Whycomment for the zsh fast-path bypass condition.This branch encodes a non-obvious constraint (keep markerless fast path unless shell-ready is explicitly requested). A one-liner here would make future edits safer.
Suggested patch
- if (shellName === 'zsh' && !hasOverlayRestoreEnv(env) && !emitReadyMarker) { + // Why: preserve plain zsh startup fast path; only force wrappers when shell-ready is requested. + if (shellName === 'zsh' && !hasOverlayRestoreEnv(env) && !emitReadyMarker) { return { args: POSIX_LOGIN_ARGS, env: {} } }As per coding guidelines, "When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does."
Source: Coding guidelines
src/relay/pty-handler.ts (1)
437-443: ⚡ Quick winDocument why the startup delivery hint is normalized before helper evaluation.
The
'shell-ready' ? 'shell-ready' : undefinedcoercion is subtle; a short why-comment would prevent accidental behavior drift here.Suggested patch
const shellLaunch = getRelayShellLaunchConfig(shell, spawnEnv, process.platform, { + // Why: only explicit shell-ready hints are trusted; native codex --prefill + // detection still auto-enables via shouldUseShellReadyStartupDelivery. emitReadyMarker: shouldUseShellReadyStartupDelivery({ command, startupCommandDelivery: params.startupCommandDelivery === 'shell-ready' ? 'shell-ready' : undefined }) })As per coding guidelines, "When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does."
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: c173ef68-fd88-495e-8c3a-eb69d032025c
📒 Files selected for processing (63)
src/main/daemon/daemon-pty-adapter.test.tssrc/main/daemon/daemon-pty-adapter.tssrc/main/daemon/daemon-server.tssrc/main/daemon/pty-subprocess.test.tssrc/main/daemon/pty-subprocess.tssrc/main/daemon/terminal-host.tssrc/main/daemon/types.tssrc/main/ipc/pty.test.tssrc/main/ipc/pty.tssrc/main/ipc/worktree-remote.tssrc/main/providers/local-pty-provider.tssrc/main/providers/ssh-pty-provider.tssrc/main/providers/types.tssrc/main/runtime/orca-runtime.tssrc/main/runtime/rpc/methods/session-tabs.test.tssrc/main/runtime/rpc/methods/session-tabs.tssrc/main/runtime/rpc/methods/terminal.tssrc/main/runtime/rpc/methods/worktree-schemas.tssrc/main/runtime/rpc/methods/worktree.test.tssrc/main/runtime/rpc/methods/worktree.tssrc/preload/api-types.tssrc/preload/index.tssrc/relay/pty-handler.test.tssrc/relay/pty-handler.tssrc/relay/pty-shell-launch.test.tssrc/relay/pty-shell-launch.tssrc/renderer/src/components/floating-terminal/FloatingTerminalWindowControls.tsxsrc/renderer/src/components/settings/general-search.tssrc/renderer/src/components/settings/general-support-search.tssrc/renderer/src/components/sidebar/folder-workspace-composer-submit.tssrc/renderer/src/components/terminal-pane/pty-connection-types.tssrc/renderer/src/components/terminal-pane/pty-connection.test.tssrc/renderer/src/components/terminal-pane/pty-connection.tssrc/renderer/src/components/terminal-pane/pty-dispatcher.tssrc/renderer/src/components/terminal-pane/pty-transport.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport.tssrc/renderer/src/components/terminal-pane/shell-ready-marker-scan.test.tssrc/renderer/src/components/terminal-pane/shell-ready-marker-scan.tssrc/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.tssrc/renderer/src/hooks/useComposerState.tssrc/renderer/src/hooks/useIpcEvents.tssrc/renderer/src/lib/launch-agent-background-session.test.tssrc/renderer/src/lib/launch-agent-background-session.tssrc/renderer/src/lib/launch-agent-in-new-tab.tssrc/renderer/src/lib/launch-work-item-direct-agent.test.tssrc/renderer/src/lib/launch-work-item-direct-agent.tssrc/renderer/src/lib/launch-work-item-direct.tssrc/renderer/src/lib/onboarding-folder-agent-startup.tssrc/renderer/src/lib/resume-sleeping-agent-session.tssrc/renderer/src/lib/source-control-agent-action-plan.tssrc/renderer/src/lib/ssh-background-startup-delivery.tssrc/renderer/src/lib/worktree-activation.tssrc/renderer/src/lib/worktree-creation-flow.tssrc/renderer/src/runtime/web-runtime-session.test.tssrc/renderer/src/runtime/web-runtime-session.tssrc/renderer/src/store/slices/terminals.tssrc/renderer/src/store/slices/worktrees.tssrc/shared/codex-startup-delivery.test.tssrc/shared/codex-startup-delivery.tssrc/shared/tui-agent-startup.test.tssrc/shared/tui-agent-startup.tssrc/shared/types.ts
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/main/providers/local-pty-shell-ready.ts (1)
77-85: ⚡ Quick winAdd a short why-comment for the marker recovery branch.
This full-prefix-but-no-BEL path is subtle: it must preserve marker-like user output while still allowing the current byte to start a real marker. A one-line comment would make that invariant harder to regress.
Proposed comment
} else { + // Why: a full marker prefix without BEL is user output; keep scanning if + // this byte could start a real marker immediately afterward. output += state.heldBytes state.heldBytes = '' state.matchPos = 0As per coding guidelines, “When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does.”
Source: Coding guidelines
src/main/providers/local-pty-shell-ready.test.ts (1)
135-148: ⚡ Quick winCover the restart-on-ESC branch.
The new test covers flushing when the non-BEL byte is ordinary text, but not the changed path where that byte is
\x1band should begin a new marker match. Add a focused case so the overlap/restart behavior stays protected.Suggested test case
describe('scanForShellReady', () => { it('flushes marker-like output when the full marker is not BEL-terminated', () => { const state = createShellReadyScanState() expect(scanForShellReady(state, 'before \x1b]777;orca-shell-readyx')).toEqual({ output: 'before \x1b]777;orca-shell-readyx', matched: false }) expect(scanForShellReady(state, ' after')).toEqual({ output: ' after', matched: false }) }) + + it('restarts matching when an unterminated marker is followed by another marker', () => { + const state = createShellReadyScanState() + + expect( + scanForShellReady( + state, + 'before \x1b]777;orca-shell-ready\x1b]777;orca-shell-ready\x07 after' + ) + ).toEqual({ + output: 'before \x1b]777;orca-shell-ready after', + matched: true + }) + }) })
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 54551611-9b6e-4b5f-a19c-4feb5a1a8e61
📒 Files selected for processing (14)
src/main/providers/local-pty-provider.test.tssrc/main/providers/local-pty-provider.tssrc/main/providers/local-pty-shell-ready.test.tssrc/main/providers/local-pty-shell-ready.tssrc/relay/pty-handler.tssrc/relay/pty-shell-launch.tssrc/renderer/src/components/terminal-pane/pty-connection.test.tssrc/renderer/src/components/terminal-pane/pty-connection.tssrc/renderer/src/components/terminal-pane/shell-ready-marker-scan.test.tssrc/renderer/src/components/terminal-pane/shell-ready-marker-scan.tssrc/renderer/src/lib/launch-agent-background-session.test.tssrc/renderer/src/lib/launch-work-item-direct-agent.tssrc/renderer/src/lib/onboarding-folder-agent-startup.tssrc/renderer/src/lib/ssh-background-startup-delivery.ts
🚧 Files skipped from review as they are similar to previous changes (8)
- src/relay/pty-handler.ts
- src/renderer/src/lib/launch-work-item-direct-agent.ts
- src/renderer/src/components/terminal-pane/shell-ready-marker-scan.test.ts
- src/renderer/src/components/terminal-pane/shell-ready-marker-scan.ts
- src/main/providers/local-pty-provider.ts
- src/renderer/src/lib/ssh-background-startup-delivery.ts
- src/relay/pty-shell-launch.ts
- src/renderer/src/components/terminal-pane/pty-connection.ts
* upstream/main: (220 commits) Show and Filter Automation-Created Workspaces (stablyai#5697) Fix premature project header truncation Send review notes to any running agent of a worktree (stablyai#5654) Fix workspace sidebar appearance setting (stablyai#5725) Highlight the open file in the Source Control sidebar (stablyai#5667) release: v1.4.80-rc.1 Fix premature Codex completion notifications (stablyai#5682) Improve Codex startup prompt reliability (stablyai#5686) Keep hibernated agent completions visible (stablyai#5689) Move Prompt Cache Timer setting to Agents pane, simplify expired state (stablyai#5691) release: v1.4.80-rc.0 Skip GitHub CLI preflight checks if no GitHub projects exist fix: restore font family keyboard navigation in settings Update README downloads badge fix(landing): make GitHub CLI setup nudge dismissible and provider-aware (stablyai#5688) Fix nested workspace card indentation (stablyai#5684) Fix flaky e2e tests (stablyai#5680) Replace plus icon with play button on quick command entry (stablyai#5674) Use managed Pi and OMP extensions (stablyai#5681) Narrow computer-use e2e trigger (stablyai#5685) ... # Conflicts: # mobile/src/terminal/TerminalWebView.tsx # mobile/src/terminal/terminal-webview-text-zoom.test.ts
* upstream/main: (78 commits) Show and Filter Automation-Created Workspaces (stablyai#5697) Fix premature project header truncation Send review notes to any running agent of a worktree (stablyai#5654) Fix workspace sidebar appearance setting (stablyai#5725) Highlight the open file in the Source Control sidebar (stablyai#5667) release: v1.4.80-rc.1 Fix premature Codex completion notifications (stablyai#5682) Improve Codex startup prompt reliability (stablyai#5686) Keep hibernated agent completions visible (stablyai#5689) Move Prompt Cache Timer setting to Agents pane, simplify expired state (stablyai#5691) release: v1.4.80-rc.0 Skip GitHub CLI preflight checks if no GitHub projects exist fix: restore font family keyboard navigation in settings Update README downloads badge fix(landing): make GitHub CLI setup nudge dismissible and provider-aware (stablyai#5688) Fix nested workspace card indentation (stablyai#5684) Fix flaky e2e tests (stablyai#5680) Replace plus icon with play button on quick command entry (stablyai#5674) Use managed Pi and OMP extensions (stablyai#5681) Narrow computer-use e2e trigger (stablyai#5685) ... # Conflicts: # mobile/app/h/[hostId]/session/[worktreeId].tsx # mobile/src/terminal/TerminalWebView.tsx # mobile/src/terminal/terminal-webview-html.ts
* upstream/main: (220 commits) Show and Filter Automation-Created Workspaces (stablyai#5697) Fix premature project header truncation Send review notes to any running agent of a worktree (stablyai#5654) Fix workspace sidebar appearance setting (stablyai#5725) Highlight the open file in the Source Control sidebar (stablyai#5667) release: v1.4.80-rc.1 Fix premature Codex completion notifications (stablyai#5682) Improve Codex startup prompt reliability (stablyai#5686) Keep hibernated agent completions visible (stablyai#5689) Move Prompt Cache Timer setting to Agents pane, simplify expired state (stablyai#5691) release: v1.4.80-rc.0 Skip GitHub CLI preflight checks if no GitHub projects exist fix: restore font family keyboard navigation in settings Update README downloads badge fix(landing): make GitHub CLI setup nudge dismissible and provider-aware (stablyai#5688) Fix nested workspace card indentation (stablyai#5684) Fix flaky e2e tests (stablyai#5680) Replace plus icon with play button on quick command entry (stablyai#5674) Use managed Pi and OMP extensions (stablyai#5681) Narrow computer-use e2e trigger (stablyai#5685) ... # Conflicts: # src/renderer/src/i18n/locales/en.json # src/renderer/src/i18n/locales/es.json # src/renderer/src/i18n/locales/ja.json # src/renderer/src/i18n/locales/ko.json # src/renderer/src/i18n/locales/zh.json
* upstream/main: (341 commits) Show and Filter Automation-Created Workspaces (stablyai#5697) Fix premature project header truncation Send review notes to any running agent of a worktree (stablyai#5654) Fix workspace sidebar appearance setting (stablyai#5725) Highlight the open file in the Source Control sidebar (stablyai#5667) release: v1.4.80-rc.1 Fix premature Codex completion notifications (stablyai#5682) Improve Codex startup prompt reliability (stablyai#5686) Keep hibernated agent completions visible (stablyai#5689) Move Prompt Cache Timer setting to Agents pane, simplify expired state (stablyai#5691) release: v1.4.80-rc.0 Skip GitHub CLI preflight checks if no GitHub projects exist fix: restore font family keyboard navigation in settings Update README downloads badge fix(landing): make GitHub CLI setup nudge dismissible and provider-aware (stablyai#5688) Fix nested workspace card indentation (stablyai#5684) Fix flaky e2e tests (stablyai#5680) Replace plus icon with play button on quick command entry (stablyai#5674) Use managed Pi and OMP extensions (stablyai#5681) Narrow computer-use e2e trigger (stablyai#5685) ... # Conflicts: # src/main/text-generation/commit-message-text-generation.test.ts # src/main/text-generation/commit-message-text-generation.ts
Co-authored-by: Orca <[email protected]>
Summary
Improves reliability for Codex sessions that start with prefilled issue/work-item context while preserving the recent fast path for plain Codex startup.
The design uses an explicit
startupCommandDeliveryhint for payload-bearing Codex launches, plus a narrow nativecodex --prefillparser fallback. Plaincodexstays on the markerless fast path. Payload-bearing Codex launches wait for shell readiness across local PTY, daemon, runtime/web/mobile propagation, visible SSH, and background SSH. SSH shells that cannot emit the marker fall back after a bounded timeout instead of dropping the command forever.Design Review
The scratch design doc was created and reviewed before implementation. Review feedback drove the final shape: explicit delivery metadata instead of broad command guessing, no runtime-home isolation in this PR, and no slowdown for the common plain-Codex path.
Implementation
shell-readylaunches and rawcodex --prefillcommands.startupCommandDeliverythrough startup planning, renderer pending startup state, preload/API types, runtime RPC, web/mobile terminal creation, daemon protocol, local PTY, and SSH metadata.No product-authored agent workflow instructions or external side-effect instructions were added; changed paths pass user/issue context as data.
Completeness Verification
Completeness pass found dropped metadata in runtime/web/mobile/remote paths; those were fixed. Later review rounds found and fixed daemon timeout behavior, a mobile session argument propagation bug, Windows oversized draft parity gaps, visible SSH shell-ready delivery, unsupported SSH-shell fallback, background SSH delivery, and raw
codex --prefillSSH parity.Code Review
Multiple two-reviewer rounds were run. The final pair both returned clean on the latest diff, including local/daemon fast path, visible/background SSH, raw
codex --prefill, Windows fallback, propagation boundaries, max-lines split, and agent-facing text boundaries.Brennan Test Changes
brennan-test-changesvalidated the local product surface in Electron from this worktree using a disposable profile and demo project. A fake absolutecodexshim confirmedstartupCommandDelivery: 'shell-ready'waits fororca-shell-readybefore command delivery, preserves payload text, uses the expected cwd, and pointsCODEX_HOMEat the disposable runtime home.After that validation, additional review-driven SSH parity fixes were made and covered with focused unit/integration tests. A live Codex provider/auth/network run was not completed; deterministic PTY plumbing was tested instead.
CodeRabbit follow-up fixed stale fallback shell readiness metadata, quiet SSH shell-ready fallback scheduling, invalid marker flush behavior, background SSH cleanup rearming, and two startupCommandDelivery type omissions.
Checks
pnpm run typecheckpnpm run lint(passes with existingSourceControl.tsxexhaustive-deps warning)git diff --checkpnpm vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/pty-connection.test.ts src/renderer/src/components/terminal-pane/shell-ready-marker-scan.test.ts src/renderer/src/lib/launch-agent-background-session.test.ts src/relay/pty-shell-launch.test.ts src/relay/pty-handler.test.ts src/shared/codex-startup-delivery.test.tspnpm vitest run --config config/vitest.config.ts src/renderer/src/lib/launch-agent-in-new-tab.test.ts src/renderer/src/lib/launch-work-item-direct-agent.test.ts src/renderer/src/lib/launch-work-item-direct.test.ts src/renderer/src/lib/source-control-agent-action-plan.test.ts src/shared/tui-agent-startup.test.tspnpm vitest run --config config/vitest.config.ts src/renderer/src/runtime/web-runtime-session.test.ts src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.ts src/renderer/src/components/terminal-pane/pty-transport.test.ts src/renderer/src/components/terminal-pane/pty-connection.test.ts -t "startup command|SSH connections|passes startup commands|startup command delivery|paired web terminals"pnpm vitest run src/main/ipc/pty.test.ts -t "native prefill|delivery-hinted Codex|no-marker wrapper"pnpm vitest run src/main/daemon/daemon-pty-adapter.test.ts -t "Codex startup|delivery-hinted Codex|short daemon shell-ready"pnpm vitest run src/main/daemon/pty-subprocess.test.ts --testTimeout=15000pnpm vitest run src/main/providers/local-pty-provider.test.ts src/main/providers/local-pty-shell-ready.test.ts src/relay/pty-shell-launch.test.ts src/relay/pty-handler.test.tsAssumptions and Remaining Risks
CODEX_HOMESQLite locking was reproduced independently with concurrent Codex launches against one disposable home. That appears related to runtime-home concurrency/migration, not the same startup prefill delivery bug, and remains a separate follow-up.Made with Orca 🐋