From 53046dab252fceb67f2cb2d7034ff2f15f4671c7 Mon Sep 17 00:00:00 2001 From: BarredEwe Date: Fri, 13 Nov 2026 16:41:13 +0300 Subject: [PATCH 1/3] fix(provider-acp-registry): keep Kimi Code threads working while Kimi self-resumes Kimi Code answers session/prompt (ACP v1) while a detached shell task is still running, then starts its own turn when that task terminates. The registry flavor set no continuation flags, so the follow-up output only landed in the local snapshot: the run settled to completed and the thread read Done while Kimi kept working. Enable the existing post-settle continuation path for kimi-code (and the archived kimi entry/local kimi binaries) so the buffered wake dispatches a continuation run; deferred finalize ends each run after the debounce since Kimi registers no background tasks. --- .../Adapters/AcpRegistryAdapterV2.test.ts | 151 +++++++++++++++++- .../src/server/adapter.ts | 17 ++ 2 files changed, 166 insertions(+), 2 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts index 70f45bc8a46c0..3bd1d84a10442 100644 --- a/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts @@ -29,6 +29,7 @@ import * as Schema from "effect/Schema"; import * as HttpClient from "effect/http/HttpClient"; import * as HttpClientResponse from "effect/http/HttpClientResponse"; import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner"; +import * as TestClock from "effect/testing/TestClock"; import * as EffectAcpErrors from "effect-acp/errors"; import { makeProviderFailure } from "@t3tools/provider-core/server/failure"; @@ -210,6 +211,9 @@ const openClaudeReplaySession = Effect.fn("openClaudeReplaySession")(function* ( replayGate?: ProviderReplayGate, continuationEnabled = true, agentId = "claude-acp", + // A flavor that buffers wakes without following the agent's work state still + // has the hook, so callers that only want the buffer opt the assertion out. + expectPendingBackgroundWork = continuationEnabled, ) { const fileSystem = yield* FileSystem.FileSystem; const path = yield* Path.Path; @@ -276,10 +280,10 @@ const openClaudeReplaySession = Effect.fn("openClaudeReplaySession")(function* ( runtimePolicy, }); yield* Effect.addFinalizer(() => Effect.sync(() => replayGate?.releaseAll())); - if (continuationEnabled) { + if (expectPendingBackgroundWork) { assert.isDefined( runtime.hasPendingBackgroundWork, - "Claude ACP v2 must report background work after foreground idle", + "an ACP flavor that keeps turns open must report background work", ); } const events = yield* Queue.unbounded(); @@ -1857,6 +1861,149 @@ describe("AcpRegistryAdapterV2", () => { }).pipe(Effect.provide(layerTest)), ); + // regression: Kimi Code answers `session/prompt` while a detached shell task is still + // running, then starts a turn of its own the moment that task terminates. + it.effect("replays Kimi's self-resume after a detached task ends into a continuation run", () => + Effect.gen(function* () { + const kimiSession = "kimi-session"; + const wakeText = "The detached check failed; rerunning it."; + const openKimi = Effect.fn("openKimi")(function* ( + agentId: string, + gate: ProviderReplayGate | undefined, + expectPendingBackgroundWork: boolean, + ) { + const update = (sessionUpdate: Record) => + claudeFrames.update(kimiSession, sessionUpdate); + const wake = { + ...update({ + sessionUpdate: "agent_message_chunk", + content: { type: "text", text: wakeText }, + }), + ...(gate === undefined ? {} : { label: "wake" }), + }; + return yield* openClaudeReplaySession( + [ + { + type: "expect_outbound", + frame: { kind: "request", method: "initialize", params: "" }, + }, + { + type: "emit_inbound", + frame: { + kind: "response", + method: "initialize", + // Kimi Code 2.6.1 negotiates ACP v1, so the prompt response is the turn's end. + result: { + protocolVersion: 1, + agentInfo: { name: "Kimi Code CLI", version: "2.6.1" }, + agentCapabilities: { loadSession: true }, + authMethods: [], + }, + }, + }, + { + type: "expect_outbound", + frame: { kind: "request", method: "session/new", params: "" }, + }, + { + type: "emit_inbound", + frame: { + kind: "response", + method: "session/new", + result: { sessionId: kimiSession }, + }, + }, + { + type: "expect_outbound", + frame: { kind: "request", method: "session/prompt", params: "" }, + }, + update({ + sessionUpdate: "tool_call", + toolCallId: "shell-1", + title: "rtk node tools/demo-cabinet.ts", + kind: "execute", + status: "completed", + rawInput: { command: "rtk node tools/demo-cabinet.ts", background: true }, + }), + update({ + sessionUpdate: "agent_message_chunk", + content: { type: "text", text: "Waiting for the detached check." }, + }), + { + type: "emit_inbound", + frame: { + kind: "response", + method: "session/prompt", + result: { stopReason: "end_turn" }, + }, + }, + update({ sessionUpdate: "session_info_update", title: "turn settled" }), + wake, + update({ sessionUpdate: "session_info_update", title: "wake delivered" }), + ], + gate, + true, + agentId, + expectPendingBackgroundWork, + ); + }); + + const gate = makeProviderReplayGate(["wake"]); + const session = yield* openKimi("kimi-code", gate, true); + assert.isDefined( + session.runtime.hasPendingBackgroundWork, + "Kimi must keep post-settle wake traffic for a continuation run", + ); + yield* session.runtime.startTurn(session.turnInput(1)); + const settled = yield* session.throughMarker("turn settled"); + assert.isFalse( + settled.some((event) => event.type === "turn.terminal"), + "the deferred finalize must hold the settled turn open for Kimi's self-resume", + ); + assert.lengthOf(session.offers, 0, "the settled turn must not invent a continuation"); + + gate.release("wake"); + const delivered = yield* session.throughMarker("wake delivered"); + assert.isFalse( + delivered.some( + (event) => event.type === "message.updated" && event.message.text === wakeText, + ), + "wake traffic must wait for its own run instead of landing in the settled one", + ); + assert.lengthOf(session.offers, 1, "Kimi's own follow-up turn must offer a continuation"); + assert.notEqual( + session.offers[0]?.delivery, + "message_text", + "Kimi's follow-up is buffered output, so nothing may re-prompt the agent", + ); + + yield* session.runtime.startTurn(session.turnInput(2, { continuation: true })); + yield* TestClock.adjust("4 seconds"); + const resumed = yield* session.until( + (event) => event.type === "turn.terminal" && event.runOrdinal === 2, + ); + assert.isTrue( + resumed.some( + (event) => event.type === "message.updated" && event.message.text === wakeText, + ), + "the buffered follow-up reply must appear in the continuation run", + ); + const continuationTerminal = resumed.at(-1)!; + if (continuationTerminal.type !== "turn.terminal") throw new Error("Missing continuation"); + assert.equal(continuationTerminal.status, "completed"); + + // A registry agent that never resumes on its own keeps the old behavior. + const plain = yield* openKimi("gemini", undefined, false); + assert.isUndefined( + plain.runtime.hasPendingBackgroundWork, + "an ACP Registry agent without self-resume support must not hold turns open", + ); + yield* plain.runtime.startTurn(plain.turnInput(1)); + yield* plain.throughMarker("wake delivered"); + assert.lengthOf(plain.offers, 0, "only Kimi is known to resume itself after the prompt"); + }).pipe(Effect.provide(layerTest)), + ); + it.effect.each([ { kind: "approval", stopReason: "end_turn", status: "completed" }, { kind: "question", stopReason: "error", status: "failed" }, diff --git a/packages/provider-acp-registry/src/server/adapter.ts b/packages/provider-acp-registry/src/server/adapter.ts index 25656a9d808e1..636525ca2cc88 100644 --- a/packages/provider-acp-registry/src/server/adapter.ts +++ b/packages/provider-acp-registry/src/server/adapter.ts @@ -210,6 +210,14 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu /^claude-agent-acp(\.exe|\.cmd)?$/i.test( options.settings.commandPath.split(/[\\/]/).pop() ?? "", )); + // The registry ships `kimi-code`; the archived legacy entry is `kimi`. + const isKimi = + registryAgentId === "kimi-code" || + registryAgentId === "kimi" || + (options.settings.source === "local" && + /^kimi(?:-code)?(\.exe|\.cmd)?$/i.test( + options.settings.commandPath.split(/[\\/]/).pop() ?? "", + )); const runtimeOptions = isClaude ? { ...options, @@ -253,6 +261,15 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu extractSubagentSessionEvent: extractClaudeSubagentSessionEvent, } : {}), + // Kimi Code ends its turn while a detached shell task runs, then self-starts a + // turn when the task terminates; the wake buffer surfaces that follow-up. + // Kimi registers no background tasks, so deferred finalize only ends turns. + ...(isKimi + ? { + enablePostSettleContinuation: true, + deferFinalizeForBackgroundWork: true, + } + : {}), ...(isDevin ? { clientCapabilitiesMeta: { From 82a213d54752f394f68ea7d0f665be893f3eff2f Mon Sep 17 00:00:00 2001 From: BarredEwe Date: Fri, 13 Nov 2026 16:59:01 +0300 Subject: [PATCH 2/3] test: sync the Kimi regression on the run-1 terminal, not the marker Kimi registers no background tasks, so the v1 prompt response completes run 1 without the debounce; the marker frame races the prompt callback's terminal, making an assertion on the settled window order-dependent. Await the terminal itself, then verify the gated wake creates a separate continuation run. --- .../Adapters/AcpRegistryAdapterV2.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts index 3bd1d84a10442..ff1029fb95761 100644 --- a/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts @@ -1955,11 +1955,11 @@ describe("AcpRegistryAdapterV2", () => { "Kimi must keep post-settle wake traffic for a continuation run", ); yield* session.runtime.startTurn(session.turnInput(1)); - const settled = yield* session.throughMarker("turn settled"); - assert.isFalse( - settled.some((event) => event.type === "turn.terminal"), - "the deferred finalize must hold the settled turn open for Kimi's self-resume", - ); + // Kimi registers no background tasks, so the v1 response completes the run + // directly, but the marker frame races the prompt callback's terminal. Sync on + // the terminal itself before waking the detached task's follow-up turn. + const settledTerminal = yield* session.terminal; + assert.equal(settledTerminal.status, "completed"); assert.lengthOf(session.offers, 0, "the settled turn must not invent a continuation"); gate.release("wake"); From de4da636715dabd9082c48f150525010b0c40d8d Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 14 Nov 2026 06:16:42 +0000 Subject: [PATCH 3/3] test(acp-registry): drop duplicate Kimi pending-work assertion Co-Authored-By: Claude Opus 5.5 --- .../orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts index ff1029fb95761..72ac4e57c219c 100644 --- a/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts @@ -211,8 +211,7 @@ const openClaudeReplaySession = Effect.fn("openClaudeReplaySession")(function* ( replayGate?: ProviderReplayGate, continuationEnabled = true, agentId = "claude-acp", - // A flavor that buffers wakes without following the agent's work state still - // has the hook, so callers that only want the buffer opt the assertion out. + // Registry agents without post-settle continuation lack the hook entirely. expectPendingBackgroundWork = continuationEnabled, ) { const fileSystem = yield* FileSystem.FileSystem; @@ -1950,10 +1949,6 @@ describe("AcpRegistryAdapterV2", () => { const gate = makeProviderReplayGate(["wake"]); const session = yield* openKimi("kimi-code", gate, true); - assert.isDefined( - session.runtime.hasPendingBackgroundWork, - "Kimi must keep post-settle wake traffic for a continuation run", - ); yield* session.runtime.startTurn(session.turnInput(1)); // Kimi registers no background tasks, so the v1 response completes the run // directly, but the marker frame races the prompt callback's terminal. Sync on