Repository navigation
fix(kimi): deliver Kimi's first prompt on Windows and after it is ready - #33581
Conversation
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes.
|
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]>
1122777 to
b04dc3b
Compare
There was a problem hiding this comment.
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
Files selected for processing: 16-
src/main/automations/headless-automation-agent-launch.test.tssrc/main/automations/headless-automation-agent-launch.tssrc/main/runtime/launched-agent-foreground.tssrc/main/runtime/launched-agent-write-guard.tssrc/main/runtime/rpc/methods/agent-launch-surfaces.tssrc/main/runtime/rpc/methods/agent-launch-terminal-prompt.test.tssrc/main/runtime/rpc/methods/agent-launch-terminal-prompt.tssrc/main/runtime/runtime-worktree-agent-startup.tssrc/main/runtime/runtime-worktree-startup-readiness.test.tssrc/main/runtime/runtime-worktree-startup-readiness.tssrc/main/runtime/terminal-run-facts-input.test.tssrc/main/runtime/workspaces/workspace-activation.tssrc/renderer/src/lib/agent-followup-delivery.test.tssrc/renderer/src/lib/agent-followup-delivery.tssrc/renderer/src/lib/new-workspace.test.tssrc/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.
-
| 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 } |
There was a problem hiding this comment.
🔎 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]>
There was a problem hiding this comment.
🧹 Nitpick comments: 1
src/main/runtime/runtime-worktree-startup-readiness.test.ts: 1
78-103:Trivial · Maintainability & Code Quality · Quick win Add local Windows
agentLaunchintegration coverage.The launch-prompt tests already cover the
write-if-shell-provablepolicy, but they calldeliverTerminalAgentLaunchPromptdirectly. They do not cover the readiness path indeliverStartupFollowupPrompt.Add two cases with
fixture('kimi', false, true, 'unknown'):
agentLaunch: truedelivers throughsendTerminalAgentPromptwithout callingwrite.- A launched foreground of
'shell'returnsfalseafter 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
Files selected for processing: 9-
src/main/runtime/orca-runtime-tests/worktree-setup-and-startup-part-04.spec.tssrc/main/runtime/rpc/methods/agent-launch-surfaces.tssrc/main/runtime/runtime-worktree-startup-readiness.test.tssrc/main/runtime/runtime-worktree-startup-readiness.tssrc/main/runtime/workspaces/workspace-activation.tssrc/renderer/src/lib/agent-followup-delivery.test.tssrc/renderer/src/lib/agent-followup-delivery.tssrc/renderer/src/lib/agent-paste-draft.tssrc/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.
-
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:orca worktree create --agent kimi --prompt(and anyagent.launchwhose 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.prompt\ras soon as thekimiprocess 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)\x1b[?2004his 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 fromProcessTerminal.start()on (setRawMode, then?2004h, then the stdin listener): upstreamMoonshotAI/kimi-codepackages/pi-tui/src/terminal.ts:172-200. A singletext\rwrite also lands as a newline in the composer, not as a submit. Bracketed paste followed by a separate Enter submits.agent-launch-surfaces.tsdeliverTerminalPromptuseddeliverTerminalAgentLaunchPrompt's defaultunprovableHost: 'refuse'. On WindowsreadLaunchedAgentForegroundnever returnsagent, so the guard threwagent_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.deliverWorktreeStartupFollowupand the renderer'ssendFollowupPromptWhenAgentReadywaited only for the agent process to be in front, then wroteprompt\r.What changed
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 whenlaunchedAgentHostProvesShellAloneholds, 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.exealways reads as unknown) and SSH-to-Windows keeprefuse. POSIX is unchanged: it still needs positive agent proof. Worker briefs keep their existingwrite-unless-shellpolicy.deliverStartupFollowupPrompt(runtime-worktree-startup-readiness.ts):deliverTerminalAgentLaunchPrompt,write-if-shell-provable).agent.launchstill refuses.[agent-startup].agent.launchfresh launches (agent-launch-surfaces.ts): these go through the startup delivery above (inagent.launchmode). If the runtime lacksdeliverStartupFollowup(partial or mixed runtimes), they fall back to the plain launch-prompt delivery. Reused terminals are unchanged.agent-followup-delivery.ts): keeps its wait for the agent to be in front. It then usespasteDraftToAgentPtyWhenReady({ submit: true })instead of typingprompt\r, and re-checks that the agent is still in front right before the paste.Verification (Windows, hidden dev Electron with
ORCA_BACKGROUND_LAUNCH=1in 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)6c9c7b0orca worktree create --agent kimi --prompt …(desktop runtime)agent_not_in_foreground, empty composerReply with PONG branch 1/2/3received; Kimi answeredPONGin the pane, CDP screenshot)orca automations runkimi, fresh session, headlessorca servedispatchedorca orchestration worker-start --agent kimipnpm tc, the targeted vitest files andcheck:code-quality:changedpass.Re-verified after review (commit b04dc3b, Windows, real Kimi 2.3.2):
worktree create --agent kimi --prompt: 2/2 delivered.orca serveautomation: 2/2 delivered.kiminot recognized, and the prompt (Write-Output LEAKED-INTO-SHELL/LEAKED-HEADLESS) is not typed into the shell, for bothworktree createand 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
agent.launchprompts are refused.dispatchedand 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.