Skip to content

fix(terminal): preserve multiline Windows Codex host prompts - #35902

Open
Tomauskasz wants to merge 3 commits into
stablyai:mainfrom
Tomauskasz:fix/windows-codex-host-prompts
Open

Tomauskasz wants to merge 3 commits into
stablyai:mainfrom
Tomauskasz:fix/windows-codex-host-prompts

Conversation

@Tomauskasz

@Tomauskasz Tomauskasz commented Oct 29, 2026 •

Copy link
Copy Markdown

ELI5

Windows Codex should receive a worker brief as one message, with all its lines intact.

What Changed

Host launch and driving prompts reuse the existing Windows input-record newline encoder. The foreground process determines the consumer; WSL keeps Linux semantics even when its transport is Windows ConPTY. Renderer exports are preserved. Encoding and submit timing select the same foreground consumer, with launch identity as startup fallback. Frame-specific tests explicitly select Linux; native Windows behavior has separate coverage.

sendTerminalAgentPrompt
  native Windows + input-record consumer -> shared newline encoder
  WSL / other platforms / other agents   -> existing paste framing
  -> existing payload admission and serialized submit
  -> same consumer for submit delay, held-submit budget and retry delay

Why

Raw newlines in the host bracketed-paste path can submit preamble fragments as separate Codex turns. Sharing the existing encoder fixes that host entry point in source so releases can carry the correction.

Linked Issue

Fixes #35898.

Related renderer work: #22703 / #22705. Held-Enter timing in #33295 / #35558 is a separate mechanism.

Visual Proof

Programmatic behavior evidence:

Probe Before After
Actual host-method Windows launch/driving/foreground cases Three targeted failures; four controls passed Expanded dispatch suite 9/9
Renderer paste suite Existing behavior 18/18
Rebuilt hidden host + native Windows Codex + loopback provider No successful rebuilt-host proof Two intact multiline messages, two completed native turns, two replies, zero tool calls
Restarted installed host + actual Windows Codex0.164 + loopback fake provider Production split-preamble reports and compiled bad-protocol baseline 90 fixture lines delivered as one user item and one completed turn, one reply, no tools or queued fragments

Native bootstrap adds a separate environment-context item. The rebuilt-host fixture made three HTTP requests because Codex separately generated a title; its native rollout contains exactly two completed fixture turns. The successful installed-host and rebuilt-host fixtures used a loopback fake provider. No rebuilt-app video is attached; the production screenshot contains private workspace context.

Testing

  • Automated tests added/updated.
  • Actual installed Windows app and Codex TUI exercised after applying the same correction to its exact 1.4.244 bundle.
  • 50/50 targeted tests pass: nine Windows dispatch, 18 renderer paste, six held-retry, 12 worker-start contract and five consumer/fallback tests. Formatting, changed-file oxlint and LSP diagnostics pass for all ten files.
  • The two mismatched-consumer retry regressions failed before the timing follow-up: foreground Codex/launch Claude missed its second Enter; the inverse used an inappropriate Codex retry. Both pass with foreground-first timing, alongside aligned-agent and launch-only controls.
  • Final top-level pnpm build exited 0 after the selector change: four typecheck projects, Electron main/preload/renderer, WSL guest, CLI, web projection, mobile assets and Windows native executables. An independent native build and static-CRT check passed.
  • Final hidden rebuilt-host/native Codex fixture exited 0. Two direct terminal.send operations into idle Codex preserved each full multiline message and rendered both fake replies. Independent native rollout proof: one exact item per fixture prompt, two matching started/completed turn IDs, zero tools. Isolated apps and children were cleaned up.
  • Final affected runtime/writer/RPC suites: 1,497 passed, 27 failed, two skipped (1,526 total), with one unhandled selector_not_found rejection. Every failed name and that rejection also occur in the untouched base's 28-failure runtime set; writer/RPC files pass. One baseline concurrency failure did not recur, with no causal improvement claimed.
  • Six additional Windows test failures were frame-only mock incompatibilities introduced by the new protocol: four runtime cases and two contract cases. Explicit Linux test hosts correct them; pristine comparison and focused reruns verify the distinction from baseline failures.
  • Adjacent tests: 50/52 pass; both Claude bash/zsh startup failures reproduce on the explicit untouched base on Windows. A related PTY launch-parity run also reproduces its sole failure on the pristine base.
  • Full lint completed 38 steps: 37 passed, one failed with five flaky-test ratchet findings in two unchanged watcher files. Missing origin/main caused whole-tree fallback. The failed gate passes with ORCA_CODE_QUALITY_BASE=f8cf31797e15cb82fc2559e6f0c244700cdaea3d; a pristine all-files scan reproduces exactly the same five findings. Original full-command exit 1 is retained.
  • The original full standard unit run stopped without final totals or a command-result receipt. Its wrapper and Vitest coordinator are no longer running; the log ends at 15:54:59 local. Full standard unit validation remains incomplete. Independent parsing of the retained log found 278 distinct failing-file summaries and 1,590 logged failed-test counts, excluding seven skipped-only summaries; these are partial counts, not final suite totals. The run began before the test-mock and timing corrections and continued while those changes landed, so its log is historical diagnostic evidence. Broader failures are not all classified as baseline; final corrected areas were rerun separately. No duplicate broad run was started.
  • Local exact-build backport tests verify encoding, timing-consumer selection, WSL/host controls, integrity, backup, exact prior-patch migration, check and restore. Setup script suite: 107/107 pass, zero skips. Initial normal app restart preserved all 16 original coding-agent processes; the later timing backport is now active after an independently observed 16:13 restart. The new installed app process started after the verified patched archive was written; no further restart or live fixture was initiated on resumption.
  • Narrow pristine comparisons also reproduce the six client-recovery failure names (six failed, one passed, with local socket listen EACCES errors) and the startup prompt-carry failure name (one failed, 28 passed). Original startup assertion-value parity remains unavailable without the interrupted run's final failure detail; name/runtime parity does not prove cold-launch delivery.
  • Limits: rebuilt-host proof covers direct sends into idle Codex. Cold native argv launch produced no turn; guarded reuse returned not-delivered. Actual fresh/reused workers can retain an intact mixed/partial composer draft that the ownership guard refuses to retry. This remaining submit limitation is unresolved; no screen-matcher relaxation is included. No actual SSH/WSL remote sessions or rebuilt-app before/after video were tested.
  • Fixture incident: an earlier failed isolation attempt used machine configuration and produced a real-provider response. It is excluded from successful evidence. Final launchers force the absolute native executable, owned temporary Codex home and explicit loopback provider with refusal guards.

Review

Reviewed the encoder move, execution-platform guard, foreground precedence for encoding and timing, payload bounds and existing serialized submit path. Audited timing-selector callers and reproduced both mismatched-agent retry cases. The renderer encoder body is moved unchanged; embedded ESC sanitization stays intact.

Agent skill upstream boundary

  • No skill-installer source, tests or metadata are copied.

Notes

Medium merge risk: terminal protocol selection is execution-context sensitive. Reverting restores prior framing; no persisted data schema changes. Official update durability depends on merging and releasing this source correction; local archive edits alone are replaced by updates.

Checklist

  • Small and focused correction.
  • Mechanism and before/after behavior explained.
  • Self-reviewed for correctness, security and performance.
  • Cross-platform, WSL and remote impact considered.
  • Rebuilt-app before/after video attached.
  • Full standard lint/test/build all green: lint has the documented failure and the broad unit run was interrupted without final totals.

Context:
Host dispatch frames launch and driving prompts with bracketed paste. Native Windows Codex reads input records, where raw newlines can submit separate turns.

Changes:
- Move the existing Windows input-record newline encoder and type into shared paste code while preserving renderer exports.
- Select the foreground consumer before launch identity and retain Linux semantics for WSL transported through Windows ConPTY.
- Add host-method regressions for launch/driving newlines, Unicode/ESC handling, byte accounting, foreground identity and platform controls.

Impact:
Native Windows Codex host prompts use the same newline protocol as terminal paste. Existing payload admission and serialized submission remain in their owning path.

Validation:
- Nine host regressions and eighteen renderer paste tests passed.
- Changed-file formatting, oxlint and LSP error diagnostics passed.
- All four full typecheck projects passed under the documented Bun compiler.
- Main/preload/renderer, WSL, CLI and projected web bundles built and verified.
- Exact installed 1.4.244 backport passed archive integrity/rollback and actual Codex fake-provider ninety-line single-turn validation.

Notes:
Full unit/lint/build validation continues independently; no claim of a fully green source suite yet. Actual SSH/WSL sessions were not run. The encoder body is moved unchanged.
@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The reviewed changes appear safe to merge.

Summary

The PR shares the existing Windows newline encoder between renderer pastes and host prompts. Native Windows Codex receives modified Enter sequences instead of raw newlines.

  • Native Windows Codex keeps multiline host prompts together in one draft.

No actionable new issues were found in the changes since the previous review. No previous review threads were supplied. This review checked source and tests; it did not run them.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Agent prompt] --> B[Choose foreground agent or launch fallback]
  B --> C{Native Windows input-record consumer?}
  C -->|Yes| D[Encode newlines as modified Enter]
  C -->|No, including WSL| E[Keep existing paste framing]
  D --> F[Check payload size]
  E --> F
  F --> G[Serialize paste and submit]
  G --> H[Check whether another Enter is safe]
Loading

Reviews (3) · Last reviewed commit: "fix(terminal): Align prompt submit timin..." · Reviewed by Greptile

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9714fee4-25ba-46dd-be12-65f1eadfc775
Commits

Reviewing files that changed from the base of the PR and between f3e3ec4 and a11df45.

Files selected for processing: 3
  • src/main/runtime/rpc/methods/orchestration/worker/worker-start-prompt-contract.test.ts
  • src/main/runtime/terminal/wait/terminal-wait-permission.ts
  • src/main/runtime/windows-codex-consumer-held-prompt.test.ts

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

Walkthrough

The shared terminal paste module now provides Windows input-record newline types and an encoder that normalizes line endings and replaces embedded ESC characters. Terminal prompt dispatch selects Windows encoding for Windows TUI agents based on the execution platform, while WSL uses Linux semantics. Other launch inputs retain bracketed-paste framing. Tests cover agents, platforms, foreground selection, input kinds, payloads, receipt byte counts, and PTY write-host platform behavior.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Minimal · up to a11df

This change makes multiline Windows Codex prompts dispatch as a single message and prefers the foreground agent when choosing input timing. No concrete defect was found in the reviewed changes. Real SSH/WSL sessions were not exercised, so a quick manual check there is worthwhile but not blocking.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title is concise, specific, and accurately describes the main change: preserving multiline Windows Codex host prompts.
Linked Issues check Passed Issue #35898 requires one complete multiline user turn for native Windows Codex host launch and driving prompts. sendTerminalAgentPrompt now uses the shared Windows input-record encoder for native W…
Out of Scope Changes check Passed The changed production files implement issue #35898. The shared encoder move preserves the renderer export and behavior. The test updates pin frame-specific fixtures to Linux and add coverage for the …
Description check Passed The description is detailed and follows nearly all required sections. It explains the user impact, implementation, rationale, linked issue, testing, review scope, limitations, and checklist status. It…
Full details: Linked Issues check

Explanation

Issue #35898 requires one complete multiline user turn for native Windows Codex host launch and driving prompts. sendTerminalAgentPrompt now uses the shared Windows input-record encoder for native Windows consumers, while WSL keeps Linux framing even over Windows ConPTY. The change selects the foreground consumer with launch fallback and retains payload admission and serialized submission. Tests cover launch, driving, foreground precedence, WSL, non-Windows controls, newline variants, and ESC sanitization. The reported focused and integration results support the required behavior.

Full details: Out of Scope Changes check

Explanation

The changed production files implement issue #35898. The shared encoder move preserves the renderer export and behavior. The test updates pin frame-specific fixtures to Linux and add coverage for the required dispatch decisions. No unrelated production behavior or unrelated test scope is established.

Full details: Description check

Explanation

The description is detailed and follows nearly all required sections. It explains the user impact, implementation, rationale, linked issue, testing, review scope, limitations, and checklist status. It clearly documents incomplete full-suite validation and the missing rebuilt-app video. The AI Disclosure section is not included, but this may be optional for internal contributors.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 10 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Context:
Four runtime prompt tests simulate composer output only after bracketed-paste framing. Native Windows Codex now uses input-record newline encoding.

Changes:
- Set the mocked PTY write host to Linux in the four frame-specific scenarios.
- Preserve the focused native Windows dispatch regression coverage.

Impact:
The generic framed-paste scenarios exercise the protocol their write mocks implement on every test host.

Validation:
- Focused dispatch and renderer tests: 27 passed.
- Affected runtime plus focused suites: 1499 passed, 28 failed, 2 skipped; all 28 failure names and the selector_not_found unhandled rejection also occur on pristine f8cf317.
- Changed test formatting, oxlint and language diagnostics passed.

Notes:
Production behavior is unchanged by this commit. Full repository unit and lint checks remain active.

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

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

Minor · Select the foreground agent for held-submit timing. · terminal-input-dispatch.ts:210-231

src/main/runtime/terminal/input/terminal-input-dispatch.ts:210-231
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Select the foreground agent for held-submit timing.

When launchAgent is Claude and foregroundAgent is Codex on Windows, payloadFor encodes the prompt as Codex input records. The writer then calls getAgentPromptHeldSubmitBudgetMs with the launch-first agent, Claude. Claude has no Windows input-record newline or retry delay, so the budget is zero and no held-submit retry runs. A large Codex input-record paste can still be consuming the first Enter, leaving the prompt in the composer instead of starting a turn.

This behavior is introduced by the new Windows encoding branch. Make getPtyAgent use the foreground agent first so payload encoding and held-submit handling use the same consumer.

Suggested fix
 protected getPtyAgent(ptyId: string): TerminalAgent | null {
   const pty = this.ptysById.get(ptyId)
-  return pty?.launchAgent ?? pty?.foregroundAgent ?? null
+  return pty?.foregroundAgent ?? pty?.launchAgent ?? null
 }

Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 31542a6e-a74f-4988-b6c4-3ad8acc17f33
Commits

Reviewing files that changed from the base of the PR and between 660b573 and f3e3ec4.

Files selected for processing: 2
  • src/main/runtime/orca-runtime-tests/terminal-creation-and-readiness-part-07.spec.ts
  • src/main/runtime/orca-runtime-tests/terminal-creation-and-readiness-part-08.spec.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.

Context:
Windows prompt encoding selects the foreground agent while submit scheduling previously selected the launch agent first. A foreground Codex launched from Claude received no Codex held-submit retry; the inverse used Codex retries for Claude.

Changes:
- Select foregroundAgent before launchAgent in the input-timing resolver.
- Add five real-runtime consumer and launch-fallback scenarios that swallow the first Enter and assert encoded bytes plus retry counts.
- Pin the generic framed worker-start contract harness to a Linux write host.

Impact:
Payload encoding, submit delay, held-submit budget, retry delay and effect timeout use the consuming agent with launch identity as a startup fallback.

Validation:
- Two mismatched-agent retry scenarios failed before this change; the aligned Codex control passed.
- Five consumer controls, six existing held-retry tests, twelve worker-start contract tests and twenty-seven focused tests: 50 passed.
- Runtime/writer/RPC suites: 1497 passed, 27 failed, 2 skipped; all failure names occur in the pristine 28-failure baseline, with the same unhandled selector_not_found rejection.
- Final pnpm build exited 0; rebuilt-host native Codex fixture and offline two-completed-turn proof passed.
- Changed-file formatting, lint and language diagnostics passed.

Notes:
Mixed or partial composer displays remain a separate retry limitation. No matcher relaxation is included. The original broad unit run remains active.
@Tomauskasz

Copy link
Copy Markdown
Author

Addressed the submit-timing consumer mismatch in a11df45c. The foreground Codex/launch Claude case missed its retry before the change; the inverse used an inappropriate Codex retry. Both directions and launch-only controls now pass, within 50/50 targeted tests. Final pnpm build and a rebuilt-host/native Codex test with two completed loopback-provider turns also pass.

The description separately records unresolved mixed/partial composer retry behavior and broad-suite limitations. No ownership-matcher relaxation is included.

This branch has not been deployed

No deployments
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.

Windows Codex host dispatch splits multiline worker prompts into turns

1 participant