Skip to content

fix(kimi): deliver Kimi's first prompt on Windows and after it is ready - #33581

Merged
nwparker merged 4 commits into
mainfrom
nwparker/agint-kimi-startup-readiness
Oct 26, 2026
Merged

nwparker merged 4 commits into
mainfrom
nwparker/agint-kimi-startup-readiness

Conversation

@nwparker

@nwparker nwparker commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​185 $\color{#cf222e}{\Huge{\mathbf{−}}}$​53 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​132
Prod 11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​151 $\color{#cf222e}{\Huge{\mathbf{−}}}$​79 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​72

ELI5

Kimi Code takes its first prompt over stdin, typed after it starts. Two Orca paths lost that prompt, so Kimi sat at an empty > box:

  1. Windows orca worktree create --agent kimi --prompt (and any agent.launch whose prompt is pasted after start). Orca refused to paste because Windows can't prove which process is in front. Every Kimi prompt sent this way on Windows was dropped.
  2. Headless automations, and the other places that type a "follow-up" prompt. Orca typed prompt\r as soon as the kimi process was in front. But Kimi is in front before its TUI switches to raw mode, so the console echoed the text and threw it away.

Both paths now wait for Kimi's composer, paste the prompt, and press Enter, using the shared launch-prompt delivery that worker starts already use.

Root cause (reproduced on Windows 11 / awin, Kimi Code 2.3.2 pinned in a temp dir, local mock model server, main 6c9c7b0)

  • Raw-mode race. A raw ConPTY probe (node-pty, no Orca) found that input written before Kimi's \x1b[?2004h is lost: writes at 0 ms and 500 ms never reached the model. Writes at ≥850 ms (Kimi turned on bracketed paste and raw mode at ~840 ms) were all received. Kimi's TUI only reads stdin from ProcessTerminal.start() on (setRawMode, then ?2004h, then the stdin listener): upstream MoonshotAI/kimi-code packages/pi-tui/src/terminal.ts:172-200. A single text\r write also lands as a newline in the composer, not as a submit. Bracketed paste followed by a separate Enter submits.
  • Path 1: agent-launch-surfaces.ts deliverTerminalPrompt used deliverTerminalAgentLaunchPrompt's default unprovableHost: 'refuse'. On Windows readLaunchedAgentForeground never returns agent, so the guard threw agent_not_in_foreground. Main log: [agent-launch] the terminal agent started, its launch prompt was not delivered Error: agent_not_in_foreground. Per feat(agent-launch): keep long prompts off the launch line and paste them after readiness (step 1 of 7) #24257, argv agents ride the launch line on Windows, so this paste is reached there only by stdin-after-start agents like Kimi. For them, "refuse" means the prompt is always lost.
  • Path 2: deliverWorktreeStartupFollowup and the renderer's sendFollowupPromptWhenAgentReady waited only for the agent process to be in front, then wrote prompt\r.

What changed

  • Windows unknown-foreground policy (launched-agent-write-guard.ts, launched-agent-foreground.ts): a new guard mode, write-if-shell-provable. It allows writing on an unknown foreground only when launchedAgentHostProvesShellAlone holds, which is true only for local non-WSL Windows panes (isWsl === false). Those panes can prove a shell alone in its job, so a proven shell still refuses. WSL panes (wsl.exe always reads as unknown) and SSH-to-Windows keep refuse. POSIX is unchanged: it still needs positive agent proof. Worker briefs keep their existing write-unless-shell policy.
  • deliverStartupFollowupPrompt (runtime-worktree-startup-readiness.ts):
    • Windows hosts (agent can't be proven in front): first waits for the agent process to be in front. This wait honours the launch's abort signal.
    • Local non-WSL Windows, macOS and Linux: composer readiness, then bracketed paste and Enter (deliverTerminalAgentLaunchPrompt, write-if-shell-provable).
    • WSL and SSH-to-Windows panes: keep main's behaviour. Headless automations and worktree-startup follow-ups type the prompt as before, and agent.launch still refuses.
    • Failures are caught and logged under [agent-startup].
  • agent.launch fresh launches (agent-launch-surfaces.ts): these go through the startup delivery above (in agent.launch mode). If the runtime lacks deliverStartupFollowup (partial or mixed runtimes), they fall back to the plain launch-prompt delivery. Reused terminals are unchanged.
  • Renderer (agent-followup-delivery.ts): keeps its wait for the agent to be in front. It then uses pasteDraftToAgentPtyWhenReady({ submit: true }) instead of typing prompt\r, and re-checks that the agent is still in front right before the paste.
  • Tests: startup follow-up pastes through readiness and never types raw input; on Windows with the shell still in front, nothing is written. Guard: a local Windows pane with an unknown foreground writes, a shell proven alone refuses, and an unknown WSL or SSH-to-Windows pane refuses. The renderer "zsh in front → nothing written" tests run the real foreground wait.

Verification (Windows, hidden dev Electron with ORCA_BACKGROUND_LAUNCH=1 in a non-interactive session, CDP only; isolated USERPROFILE/APPDATA/LOCALAPPDATA/KIMI_CODE_HOME, KIMI_CODE_NO_AUTO_UPDATE=1, paid keys unset, a mock OpenAI-compatible provider that logs each prompt it receives)

Flow main 6c9c7b0 this branch
orca worktree create --agent kimi --prompt … (desktop runtime) 0/2 delivered, agent_not_in_foreground, empty composer 3/3 delivered (Reply with PONG branch 1/2/3 received; Kimi answered PONG in the pane, CDP screenshot)
orca automations run kimi, fresh session, headless orca serve 0/1 delivered: empty composer, run left dispatched 3/3 delivered
orca orchestration worker-start --agent kimi ready, brief delivered ready, brief delivered (no regression)
Desktop automation run (renderer path) 4/4 delivered delivered (no regression)

pnpm tc, the targeted vitest files and check:code-quality:changed pass.

Re-verified after review (commit b04dc3b, Windows, real Kimi 2.3.2):

  • worktree create --agent kimi --prompt: 2/2 delivered.
  • Headless orca serve automation: 2/2 delivered.
  • Kimi missing from PATH: PowerShell reports kimi not recognized, and the prompt (Write-Output LEAKED-INTO-SHELL / LEAKED-HEADLESS) is not typed into the shell, for both worktree create and the headless automation. Orca logs [agent-launch] … not delivered Error: timeout. In these runs the shell-alone proof (daemon PTYs implement it) is what blocked the write. The pre-paste foreground check passed because Windows foreground reads report the launched agent's identity.

Risk

  • A local non-WSL Windows pane with an unknown foreground now gets the prompt; on main it was dropped. A shell proven alone still blocks it. WSL and SSH-to-Windows behave exactly as on main: follow-ups are typed once the agent is in front, and agent.launch prompts are refused.
  • A startup prompt can now take up to 60 s (composer readiness) before it is written.
  • With Kimi missing, a headless run stays dispatched and is not marked failed. That is pre-existing behaviour and out of scope here.

Fixes #10336
Fixes #28005

Diagnosis credit: @innocarpe (#10369) found that Kimi's stdin-after-start delivery waited only for process liveness.

@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

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: 48aff046-82c0-43cf-89e4-290f0dcebee1
Commits

Reviewing files that changed from the base of the PR and between 486dcd8 and 519d354.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
Walkthrough

Startup follow-ups now identify the agent and use readiness checks before prompt delivery. Fresh terminal launches use a guarded delivery path that requires proof of a lone shell when the agent foreground is unproven. Renderer follow-ups use submitted, forced-paste delivery. Tests cover host proof, readiness, and prompt delivery.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Low · up to 486dc

The change is mergeable with awareness that the local Windows launch path lacks a targeted regression test. No current prompt-delivery failure was established.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 26.32% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 18 files. 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 clearly identifies the main change: reliable Kimi first-prompt delivery on Windows and after startup readiness.
Description check Passed The description is detailed and covers the user impact, root cause, implementation, linked issues, testing, platform behavior, risks, and verification results. It does not include several template hea…
Linked Issues check Passed Both direct issues are open and apply. [#10336] Fresh terminal launches now route through deliverStartupFollowupPrompt; the path waits for the agent foreground, waits for composer readiness, uses br…
Out of Scope Changes check Passed The changed production code supports the linked objectives. Foreground-host classification and write-guard policy provide the safety rule for Windows prompt delivery. Startup readiness changes provide…
Full details: Description check

Explanation

The description is detailed and covers the user impact, root cause, implementation, linked issues, testing, platform behavior, risks, and verification results. It does not include several template headings or checklist items, but the core required information is present.

Full details: Linked Issues check

Explanation

Both direct issues are open and apply. [#10336] Fresh terminal launches now route through deliverStartupFollowupPrompt; the path waits for the agent foreground, waits for composer readiness, uses bracketed paste, and submits with Enter. The launch guard prevents writes when a shell is proven in front. Tests cover readiness, paste delivery, and shell refusal. [#28005] Headless fresh launches now send the automation prompt through runtime.deliverStartupFollowup. The changed tests cover prompt delivery for new and existing automation launches. The issue's documented --quiet incompatibility is not changed, but the linked issue's expected coding outcome is prompt delivery or a loud failure, and the changed terminal path addresses prompt delivery.

Full details: Out of Scope Changes check

Explanation

The changed production code supports the linked objectives. Foreground-host classification and write-guard policy provide the safety rule for Windows prompt delivery. Startup readiness changes provide composer-aware paste and submit behavior. Renderer changes apply the same ready-and-paste behavior to follow-up prompts. Runtime type changes and test updates support these delivery paths. No unrelated production behavior is established by the reviewed changes.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • 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.

nwparker and others added 2 commits October 25, 2026 09:48
Kimi Code takes its prompt over stdin after start. Two paths lost it:
- agent.launch (orca worktree create --agent kimi --prompt) refused every
  post-start paste on Windows because no read can prove the agent is in
  front; worker briefs already accept an unprovable host unless a shell is
  proven alone. Use the same rule.
- The worktree-create follow-up (headless automations, createAgentSession)
  and the renderer follow-up typed `prompt\r` as soon as the process was in
  front, before Kimi's TUI enters raw mode, so the text was echoed and
  dropped. Route them through composer readiness, bracketed paste and Enter.

Co-authored-by: Wooseong Kim <[email protected]>
… is provable

Review follow-up: wait for the agent process in front before pasting on
hosts that cannot prove the agent (renderer and main), and permit an
unknown foreground only on local non-WSL Windows panes, whose lone shell is
provable. WSL and SSH-to-Windows keep refusing.

Co-authored-by: Wooseong Kim <[email protected]>
@nwparker
nwparker force-pushed the nwparker/agint-kimi-startup-readiness branch from 1122777 to b04dc3b Compare October 25, 2026 16:52

@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
  • 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: 91224f47-8be9-4815-b440-511290e03b57
Commits

Reviewing files that changed from the base of the PR and between a944e37 and b04dc3b.

Files selected for processing: 16
  • src/main/automations/headless-automation-agent-launch.test.ts
  • src/main/automations/headless-automation-agent-launch.ts
  • src/main/runtime/launched-agent-foreground.ts
  • src/main/runtime/launched-agent-write-guard.ts
  • src/main/runtime/rpc/methods/agent-launch-surfaces.ts
  • src/main/runtime/rpc/methods/agent-launch-terminal-prompt.test.ts
  • src/main/runtime/rpc/methods/agent-launch-terminal-prompt.ts
  • src/main/runtime/runtime-worktree-agent-startup.ts
  • src/main/runtime/runtime-worktree-startup-readiness.test.ts
  • src/main/runtime/runtime-worktree-startup-readiness.ts
  • src/main/runtime/terminal-run-facts-input.test.ts
  • src/main/runtime/workspaces/workspace-activation.ts
  • src/renderer/src/lib/agent-followup-delivery.test.ts
  • src/renderer/src/lib/agent-followup-delivery.ts
  • src/renderer/src/lib/new-workspace.test.ts
  • src/renderer/src/lib/new-workspace.ts

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

Comment on lines +24 to +30
pty: { connectionId: string | null; isWsl: boolean | null } | undefined,
remotePathFlavor: () => 'posix' | 'win32'
): LaunchedAgentHost {
const remote = !!pty?.connectionId
// A local WSL pane still runs on a Windows host, whose process reads cannot see into it.
const windows = remote ? remotePathFlavor() === 'win32' : process.platform === 'win32'
return { remote, windows, shellAloneProvable: windows && !remote && pty?.isWsl === false }

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.

Minor · Functional Correctness · Quick win

🔎 Supported by static analysis

Script executed:

rg -n 'isWsl\s*[:=]|\.isWsl\s*=|wslDistro\s*[:=]' src/main/runtime/terminal src/main/runtime/workspaces/workspace-activation.ts | head -130
sed -n '65,115p' src/main/runtime/terminal/identity/pty-worktree-record.ts

Repository: stablyai/orca

Length of output: 4464


Script executed:

set -o pipefail
printf '%s\n' '--- record update ---'
nl -ba src/main/runtime/terminal/identity/pty-worktree-record.ts | sed -n '150,220p'
printf '%s\n' '--- launch registration ---'
nl -ba src/main/runtime/terminal/launch/terminal-create.ts | sed -n '190,255p'
printf '%s\n' '--- dedup producer ---'
nl -ba src/main/runtime/terminal/launch/terminal-create-deduplication.ts | sed -n '70,135p'
printf '%s\n' '--- execution context producer ---'
nl -ba src/main/runtime/terminal/launch/terminal-execution-context.ts | sed -n '1,60p'
printf '%s\n' '--- startup follow-up and host description references ---'
rg -n -F --glob '*.ts' -e 'describeLaunchedAgentHost' -e 'runtime-worktree-startup-readiness' -e 'write-if-shell-provable' -e 'registerPty(' src/main/runtime | head -160

Repository: stablyai/orca

Length of output: 33215


Script executed:

set -o pipefail
printf '%s\n' '--- inventory refresh producer ---'
nl -ba src/main/runtime/terminal/lifecycle/pty-controller-inventory-refresh.ts | sed -n '145,195p'
printf '%s\n' '--- startup host classification ---'
nl -ba src/main/runtime/workspaces/workspace-activation.ts | sed -n '260,310p'
printf '%s\n' '--- startup readiness ---'
nl -ba src/main/runtime/runtime-worktree-startup-readiness.ts | sed -n '1,105p'
printf '%s\n' '--- launch result and wslDistro references ---'
rg -n -F --glob '*.ts' -e 'wslDistro' src/main/runtime/terminal/launch/terminal-create.ts src/main/runtime/terminal/launch src/main/runtime/terminal | head -180
printf '%s\n' '--- inventory refresh callers ---'
rg -n -F --glob '*.ts' -e 'refreshPtyControllerInventory' -e 'pty-controller-inventory-refresh' -e 'recordPtyWorktree(' src/main/runtime/terminal src/main/runtime/workspaces | head -180

Repository: stablyai/orca

Length of output: 20033


Script executed:

set -o pipefail
printf '%s\n' '--- refresh entrypoints and scheduling ---'
rg -n -F --glob '*.ts' -e 'refreshControllerInventory' -e 'refreshPtyInventory' -e 'refreshPtyController' -e 'listProcesses(' -e 'inventoryRefresh' src/main/runtime src/main | head -220
printf '%s\n' '--- inventory owner outline and methods ---'
ast-grep outline src/main/runtime/terminal/lifecycle/pty-controller-inventory-refresh.ts --view expanded
printf '%s\n' '--- PTY session declarations ---'
rg -n -F --glob '*.ts' -e 'wslDistro?:' -e 'wslDistro:' -e 'interface PseudoTerminal' -e 'type PseudoTerminal' -e 'listProcesses' src/main src/shared | head -240
printf '%s\n' '--- controller/provider implementations ---'
rg -n -F --glob '*.ts' -e 'listProcesses' -e 'wslDistro' src/main/pty src/main/terminal src/main/runtime/terminal | head -260

Repository: stablyai/orca

Length of output: 41419


Script executed:

set -o pipefail
printf '%s\n' '--- inventory refresh file ---'
nl -ba src/main/runtime/terminal/lifecycle/pty-controller-inventory-refresh.ts | sed -n '1,145p'
printf '%s\n' '--- inventory refresh remainder ---'
nl -ba src/main/runtime/terminal/lifecycle/pty-controller-inventory-refresh.ts | sed -n '190,330p'
printf '%s\n' '--- inventory refresh references ---'
rg -n -F --glob '*.ts' -e 'OrcaRuntimeWithRefreshPtyWorktreeRecordsWithControllerInventory' -e 'refreshPtyWorktreeRecords' -e 'refreshPtyWorktree' -e 'reconcilePty' src/main/runtime/terminal src/main/runtime | head -180
printf '%s\n' '--- provider contract ---'
nl -ba src/main/providers/pty-provider-contract.ts | sed -n '1,240p'
printf '%s\n' '--- local provider metadata ---'
nl -ba src/main/providers/local-pty-provider.ts | sed -n '150,235p'
printf '%s\n' '--- Windows provider tests for wslDistro ---'
nl -ba src/main/providers/local-pty-provider-windows-shell-launch.test.ts | sed -n '420,475p'

Repository: stablyai/orca

Length of output: 42481


Script executed:

set -o pipefail
printf '%s\n' '--- refresh wrapper ---'
nl -ba src/main/runtime/terminal/lifecycle/pty-worktree-refresh.ts | sed -n '1,75p'
printf '%s\n' '--- workspace process listing ---'
nl -ba src/main/runtime/workspaces/workspace-process-listing.ts | sed -n '1,105p'
printf '%s\n' '--- startup provisioning callers ---'
rg -n -F --glob '*.ts' -e 'refreshPtyWorktreeRecordsFromController' -e 'listWorkspaceProcesses' -e 'provisionManagedWorktreeTerminals' src/main/runtime/workspaces src/main/runtime | head -180
printf '%s\n' '--- process info declaration ---'
cat src/main/providers/pty-process-info.ts
printf '%s\n' '--- local non-WSL inventory assertions ---'
rg -n -F --glob '*.{ts,tsx}' -e 'wslDistro).toBeNull' -e 'wslDistro: null' -e 'wslDistro).toBe(null)' src/main/providers src/main/runtime/terminal | head -180

Repository: stablyai/orca

Length of output: 13280


Initialize isWsl from the fresh spawn result.

A fresh launch registers the PTY without isWsl, so the record starts with null. An inventory refresh can later set native Windows PTYs to false, but that refresh is not guaranteed to run before the startup follow-up. Until it does, describeLaunchedAgentHost cannot prove a lone shell and the startup prompt can be rejected on Windows.

PtyProcessInfo defines wslDistro: null as native Windows, so preserve undefined as unknown and derive the boolean at registration.

Suggested fix
           this.registerPty(result.id, workspace.id, workspace.connectionId, {
             tabId,
             leafId,
             terminalHandle: preAllocatedHandle,
+            ...(result.wslDistro !== undefined
+              ? { isWsl: result.wslDistro !== null }
+              : {}),
             ...(result.incarnationId ? { incarnationId: result.incarnationId } : {})
           })

…the agent before a renderer paste

Review follow-up: fresh agent.launch falls back to the plain launch-prompt
delivery on runtimes without deliverStartupFollowup; the Windows pre-wait
honours the launch's abort signal; WSL and SSH-to-Windows panes keep main's
typed follow-up (and agent.launch's refusal); the renderer rechecks the
agent in front right before pasting.

Co-authored-by: Wooseong Kim <[email protected]>

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

🧹 Nitpick comments: 1
src/main/runtime/runtime-worktree-startup-readiness.test.ts: 1

78-103: Trivial · Maintainability & Code Quality · Quick win

Add local Windows agentLaunch integration coverage.

The launch-prompt tests already cover the write-if-shell-provable policy, but they call deliverTerminalAgentLaunchPrompt directly. They do not cover the readiness path in deliverStartupFollowupPrompt.

Add two cases with fixture('kimi', false, true, 'unknown'):

  • agentLaunch: true delivers through sendTerminalAgentPrompt without calling write.
  • A launched foreground of 'shell' returns false after the readiness wait and does not write.

These cases protect the readiness-to-guard wiring. They are coverage improvements, not evidence of a current production failure.


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: de9e611e-401e-42fc-b342-706ffce5374f
Commits

Reviewing files that changed from the base of the PR and between b04dc3b and 486dcd8.

Files selected for processing: 9
  • src/main/runtime/orca-runtime-tests/worktree-setup-and-startup-part-04.spec.ts
  • src/main/runtime/rpc/methods/agent-launch-surfaces.ts
  • src/main/runtime/runtime-worktree-startup-readiness.test.ts
  • src/main/runtime/runtime-worktree-startup-readiness.ts
  • src/main/runtime/workspaces/workspace-activation.ts
  • src/renderer/src/lib/agent-followup-delivery.test.ts
  • src/renderer/src/lib/agent-followup-delivery.ts
  • src/renderer/src/lib/agent-paste-draft.ts
  • src/renderer/src/lib/new-workspace.test.ts

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant