Skip to content

fix(kimi): wait for welcome banner before stdin prompt injection - #10369

Closed
innocarpe wants to merge 4 commits into
stablyai:mainfrom
innocarpe:fix/kimi-prompt-wait-for-welcome
Closed

innocarpe wants to merge 4 commits into
stablyai:mainfrom
innocarpe:fix/kimi-prompt-wait-for-welcome

Conversation

@innocarpe

@innocarpe innocarpe commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Description

Kimi Code stdin-after-start prompt injection now waits for the Welcome to Kimi banner (and a longer readiness budget) before writing the follow-up prompt. Orchestration tui-idle also treats that banner as ready and no longer false-positives on a quiet kimi process alone.

Focused fix

Preserves

  • Other agents’ readiness signals and the existing 8s draft-paste quiet timeout for paste-settle paths
  • worker-start / sendTerminalAgentPrompt write contract (accepted still means the write path completed)

Evidence

  • Tests: pnpm exec vitest run --config config/vitest.config.ts src/shared/draft-paste-ready-scanner.test.ts src/shared/tui-agent-startup.test.ts (83)
  • Tests: pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/orca-runtime.test.ts -t 'tui-idle|Kimi|#10336' (including banner ready + quiet-kimi not idle)
  • Field: issuecomment-5204525896 on v1.4.175 remote orchestration (banner signal missing on release; quiet race + 8s budget)

User-regression-tradeoffs

  • On timeout after process start without banner, worktree follow-up still skips the prompt (warn log) rather than writing into scrollback
  • Kimi tui-idle waits for the banner instead of process quiet — slower ready on hosts where Kimi is quiet mid-boot, but avoids silent empty dispatch

Fixes #10336

@coderabbitai

coderabbitai Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 53f79234-0e0b-48d4-b842-e9dbbbe425ce

📥 Commits

Reviewing files that changed from the base of the PR and between 7df7aa5 and 0563058.

📒 Files selected for processing (6)
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/shared/draft-paste-ready-scanner.test.ts
  • src/shared/draft-paste-ready-scanner.ts
  • src/shared/tui-agent-config.ts
  • src/shared/tui-agent-startup.test.ts
🚧 Files skipped from review as they are similar to previous changes (6)
  • src/shared/tui-agent-config.ts
  • src/shared/tui-agent-startup.test.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/shared/draft-paste-ready-scanner.ts
  • src/shared/draft-paste-ready-scanner.test.ts
  • src/main/runtime/orca-runtime.ts

📝 Walkthrough

Walkthrough

Adds a kimi-welcome-banner draft paste readiness signal that detects “Welcome to Kimi” across incremental PTY output without using the quiet-window fallback. Configures the Kimi agent to use this signal with stdin-after-start prompt injection. Startup follow-up data now carries the agent configuration and waits for the configured readiness signal before sending the follow-up prompt. Kimi runtime readiness checks use the banner and avoid generic quiet-process detection. Tests cover scanner behavior, startup plans, and runtime readiness.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the fix, scope, tradeoffs, and tests, but omits required Screenshots, AI Review Report, Security Audit, and Notes sections. Add the missing template sections, state “No visual change” where applicable, document AI and security reviews, and include the required validation checklist.
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the Kimi startup readiness fix and matches the primary change.
Linked Issues check ✅ Passed The implementation adds banner-gated Kimi prompt injection and prevents pre-banner quiet-idle readiness, matching the linked issue requirements [#10336].
Out of Scope Changes check ✅ Passed All changes target Kimi banner readiness, prompt injection, and tui-idle behavior described in the linked issue [#10336].

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.

@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/orca-runtime.ts (1)

17924-17953: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Reused paste-quiet timeout may be too short for full TUI mount readiness.

waitForStartupDraftReady (invoked here for the followup gate) hard-times-out via DRAFT_PASTE_READY_TIMEOUT_MS (8000ms), a constant originally scoped to the "paste then wait for render to go quiet" flow. It's now reused to gate on an agent fully mounting its TUI and printing a banner (e.g., Kimi's "Welcome to Kimi"), which is a materially slower/more variable operation than post-paste render settling. If this signal doesn't fire within 8s on a slow machine/SSH session, the code silently skips the follow-up prompt entirely (only a console warning), which regresses back to the original bug's user-visible symptom — the agent starts autonomously without its prompt — just via a different failure path.

Consider a dedicated (and possibly longer or per-agent-configurable) timeout constant for this readiness gate instead of coupling it to the bracketed-paste-quiet semantics.

♻️ Proposed fix: separate timeout constant
+const STARTUP_FOLLOWUP_DRAFT_READY_TIMEOUT_MS = 15000
 const DRAFT_PASTE_READY_TIMEOUT_MS = 8000

And thread a timeout override through waitForStartupDraftReady (or a small wrapper) so the follow-up gate uses the longer bound while the original paste-quiet flow keeps its existing 8s.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 04d62d3e-e6f0-4f4b-90a3-d9a61922c2c6

📥 Commits

Reviewing files that changed from the base of the PR and between 1bd36ce and 2ba7549.

📒 Files selected for processing (5)
  • src/main/runtime/orca-runtime.ts
  • src/shared/draft-paste-ready-scanner.test.ts
  • src/shared/draft-paste-ready-scanner.ts
  • src/shared/tui-agent-config.ts
  • src/shared/tui-agent-startup.test.ts

@AmethystLiang
AmethystLiang requested a review from OrcaWin July 24, 2026 16:49
@nwparker nwparker added the bug Something isn't working label Jul 27, 2026
@innocarpe
innocarpe force-pushed the fix/kimi-prompt-wait-for-welcome branch from 2ba7549 to c462212 Compare August 6, 2026 13:40
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@innocarpe

Copy link
Copy Markdown
Contributor Author

Follow-up after field report on #10336:

  • Rebased onto latest main
  • STARTUP_FOLLOWUP_DRAFT_READY_TIMEOUT_MS = 20s for the banner gate (keep 8s for paste-quiet)
  • tui-idle: recognize Welcome to Kimi; do not quiet-fallback idle while kimi is mounting

Evidence: draft-paste-ready + tui-agent-startup (83) and new/updated tui-idle Kimi cases in orca-runtime.test.ts.

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

⚠️ Outside diff range comments (1)
src/main/runtime/orca-runtime.ts (1)

36461-36480: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Scope the Kimi welcome-banner matcher to startup readiness.

findKimiReadyPromptIndex reports readiness from any welcome to kimi match without a later busy/idle guard, while Cursor’s variant falls back to the absence of a spinner after its active prompt. Since isKnownReadyPromptPreview is used by waitForTerminal, this can make a later wait --for tui-idle resolve after the welcome banner remains in the tail buffer, even while Kimi is generating. Gate this match on a working/idle signal if Kimi has one, or limit the banner check to the initial startup/draft-paste-ready flow and use a separate mechanism for later turns.

🧹 Nitpick comments (1)
src/main/runtime/orca-runtime.ts (1)

21155-21186: 🧹 Nitpick | 🔵 Trivial | 💤 Low value

Confirm silent follow-up drop on draft-ready timeout is acceptable.

When waitForStartupDraftReady times out (20 seconds), the function logs a warning and returns without ever sending followup.prompt. The prompt is dropped with no signal back to the worktree.create caller or to orchestration. This matches the PR's stated intent ("skips delivery when readiness fails"), and the fire-and-forget pattern already existed before this change, so this is a design confirmation rather than a new defect.

[reliability_and_resilience]


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a0eba0d9-0e78-42e3-8d7d-aa8e165db6ed

📥 Commits

Reviewing files that changed from the base of the PR and between f713739 and c4622129e374135cb78d236ff2d1ff59b0e22be7.

📒 Files selected for processing (6)
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/shared/draft-paste-ready-scanner.test.ts
  • src/shared/draft-paste-ready-scanner.ts
  • src/shared/tui-agent-config.ts
  • src/shared/tui-agent-startup.test.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/shared/tui-agent-startup.test.ts
  • src/shared/draft-paste-ready-scanner.ts
  • src/shared/draft-paste-ready-scanner.test.ts
  • src/shared/tui-agent-config.ts

@innocarpe
innocarpe force-pushed the fix/kimi-prompt-wait-for-welcome branch from c462212 to c690571 Compare August 6, 2026 23:18
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@innocarpe

Copy link
Copy Markdown
Contributor Author

Addressed CodeRabbit major: Welcome to Kimi is no longer a global isKnownReadyPromptPreview match (that could satisfy later tui-idle waits while generation continued and the banner stayed in the tail).

Instead:

  • stdin follow-up still uses kimi-welcome-banner draft-ready scanner
  • Kimi quiet-idle requires a once-seen welcome banner flag (kimiWelcomeBannerSeen), then normal quiet quiescence for later turns

Regression: banner+quiet resolves; banner with continuous output does not; quiet before banner does not.

@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: 2

🧹 Nitpick comments (1)
src/main/runtime/orca-runtime.ts (1)

21353-21357: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Stamp kimiWelcomeBannerSeen when waitForStartupDraftReady observes Kimi readiness.

createDraftPasteReadyScanner('kimi-welcome-banner') returns { ready: true } on Welcome to Kimi, but finish(ptyId) never writes ptysById.get(ptyId).kimiWelcomeBannerSeen. Set it only when the ready signal is Kimi, so later idle fallback does not remain gated on a later tail rescan that can miss the banner due to the MAX_TAIL_* bounds.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 50e5df43-bc4d-4580-bd45-7ebf751f4fb4

📥 Commits

Reviewing files that changed from the base of the PR and between 01d3bc5 and c690571a0402b3255dce76b78c7feaa14ca59353.

📒 Files selected for processing (6)
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/shared/draft-paste-ready-scanner.test.ts
  • src/shared/draft-paste-ready-scanner.ts
  • src/shared/tui-agent-config.ts
  • src/shared/tui-agent-startup.test.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/shared/tui-agent-startup.test.ts
  • src/shared/draft-paste-ready-scanner.ts
  • src/shared/tui-agent-config.ts
  • src/shared/draft-paste-ready-scanner.test.ts

Comment thread src/main/runtime/orca-runtime.test.ts Resolved
Comment thread src/main/runtime/orca-runtime.ts Resolved
stdin-after-start only waited for the kimi process to own the PTY, so
worktree-create --prompt always wrote the brief before the TUI composer
existed and the text echoed above "Welcome to Kimi".

Add a kimi-welcome-banner ready signal and gate follow-up prompt delivery
on it after process liveness, matching the draft-paste readiness pattern.

Closes stablyai#10336
Field report on stablyai#10336 (orchestration worker-start on remote headless):
tui-idle could false-positive on Kimi process quiet before the TUI mounts,
and the follow-up draft-ready gate reused the 8s paste-quiet timeout.

Wait longer for the banner marker on stdin-after-start follow-up, treat
"Welcome to Kimi" as a tui-idle ready preview, and skip quiet-only idle
while the kimi process is still mounting.

Refs: stablyai#10336 issuecomment-5204525896
CodeRabbit: matching "Welcome to Kimi" in isKnownReadyPromptPreview made
every subsequent tui-idle wait succeed while the banner remained in the
tail, even during generation. Gate Kimi quiet-idle on a once-seen banner
flag instead, and keep the draft-paste ready scanner for stdin follow-up.
When draft-ready sees the Kimi banner, set kimiWelcomeBannerSeen so later
tui-idle quiet fallback does not depend on a scrolled-away tail. Clear the
flag on PTY process-generation reset, and assert quiet has not elapsed
before the banner+quiet settle window.
@innocarpe
innocarpe force-pushed the fix/kimi-prompt-wait-for-welcome branch from c690571 to 0563058 Compare August 7, 2026 01:34
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@innocarpe

Copy link
Copy Markdown
Contributor Author

Addressed latest CodeRabbit notes:

  1. Stamp kimiWelcomeBannerSeen when waitForStartupDraftReady hits kimi-welcome-banner
  2. Reset that flag in resetTrackedTerminalStateForProviderGeneration (reused ptyId / new process)
  3. Test now asserts still pending before quiet elapses, then resolves after the quiet window

tip: 0563058650

@nwparker

Copy link
Copy Markdown
Contributor

Thanks @innocarpe — your diagnosis that Kimi's stdin-after-start delivery only waited for process liveness is what #33581 builds on. #33581 (merged, with you credited as co-author) delivers Kimi's first prompt once its composer is ready, including on Windows. Closing as superseded.

@nwparker nwparker closed this Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: --agent kimi --prompt injection never reaches Kimi Code input — prompt echoes above welcome banner (v1.4.152)

3 participants