Repository navigation
Description
What version of Kimi Code is running?
0.39.1 (runtime reproduction); same handler confirmed in 0.41.0 and current main by source inspection
Which open platform/subscription were you using?
OpenAI-compatible API via a custom provider
Which model were you using?
qwen3.8-max; declared context window 1,000,000 tokens
What platform is your computer?
Linux x86_64, native standalone binary, kimi acp
What issue are you seeing?
During a successful automatic compaction, the ACP client receives these ordinary agent_message_chunk texts in sequence:
Compacting conversation context…
Compaction is blocked by the current turn; retry when the turn is idle.
Compaction completed.
[compaction summary]
[the original turn continues and answers successfully]
The middle message tells the user that compaction cannot proceed and asks them to retry, although the engine is already compacting and the turn is simply waiting for it. The misleading text is also retained as assistant text by clients that persist agent_message_chunk.
This was reproduced on 0.39.1 with sequential prompts: no manual /compact, no concurrent session/prompt, and no retry action. Native full_compaction.complete and successful continuation were both observed.
What steps can reproduce the bug?
- Start
kimi acpfrom an ACP client, initialize it, and create a session using a configured model/provider. - Build a long conversation with synthetic filler sent in successive normal
session/promptrequests; wait for each request to finish before sending the next. - Continue until automatic compaction starts and the next model step waits at the blocking threshold. The exact input size depends on tokenization and context-window configuration.
- Inspect
session/updatenotifications whoseupdate.sessionUpdateisagent_message_chunk. Observe the start -> misleading blocked/retry text -> completed -> normal answer sequence above.
A small regression fixture can drive the same ACP subscription with compaction.started(trigger=auto), compaction.blocked(turnId=...), and compaction.completed. The existing engine test blocks the turn until auto compaction finishes already demonstrates that the blocked event belongs to a successful wait path, before full_compaction.complete and turn.step.started:
kimi-code/packages/agent-core-v2/test/agent/fullCompaction/fullCompaction.test.ts
Lines 1662 to 1704 in 5efca0c
| it('blocks the turn until auto compaction finishes', async () => { | |
| const records: TelemetryRecord[] = []; | |
| const ctx = testAgent({ telemetry: recordingTelemetry(records) }); | |
| ctx.configure({ | |
| provider: CATALOGUED_PROVIDER, | |
| modelCapabilities: CATALOGUED_MODEL_CAPABILITIES, | |
| tools: SNAPSHOT_VISIBLE_TOOLS, | |
| }); | |
| ctx.appendExchange(1, 'old user one', 'old assistant one', 100); | |
| ctx.appendExchange(2, 'old user two', 'old assistant two', 200); | |
| ctx.appendExchange(3, 'recent user three', 'recent assistant three', 950_000); | |
| ctx.mockNextResponse({ type: 'text', text: 'Auto compacted summary.' }); | |
| ctx.mockNextResponse({ type: 'text', text: 'I can answer after compaction.' }); | |
| await ctx.rpc.prompt({ input: [{ type: 'text', text: 'Answer after compacting' }] }); | |
| const events = await ctx.untilTurnEnd(); | |
| expect(events).toEqual( | |
| expect.arrayContaining([ | |
| expect.objectContaining({ type: '[wire]', event: 'context.append_message' }), | |
| expect.objectContaining({ type: '[wire]', event: 'turn.prompt' }), | |
| expect.objectContaining({ type: '[rpc]', event: 'turn.started' }), | |
| expect.objectContaining({ type: '[wire]', event: 'full_compaction.begin' }), | |
| expect.objectContaining({ type: '[rpc]', event: 'compaction.blocked' }), | |
| expect.objectContaining({ type: '[wire]', event: 'full_compaction.complete' }), | |
| expect.objectContaining({ type: '[rpc]', event: 'turn.step.started' }), | |
| expect.objectContaining({ type: '[rpc]', event: 'turn.ended' }), | |
| ]), | |
| ); | |
| expect(eventIndex(events, 'turn.prompt')).toBeLessThan( | |
| eventIndex(events, 'full_compaction.begin'), | |
| ); | |
| expect(eventIndex(events, 'full_compaction.begin')).toBeLessThan( | |
| eventIndex(events, 'full_compaction.complete'), | |
| ); | |
| expect(eventIndex(events, 'compaction.blocked')).toBeLessThan( | |
| eventIndex(events, 'full_compaction.complete'), | |
| ); | |
| expect(eventIndex(events, 'full_compaction.complete')).toBeLessThan( | |
| eventIndex(events, 'turn.step.started'), | |
| ); | |
| expect(ctx.llmInputs()).toMatchInlineSnapshot(` | |
| call 1: |
What is the expected behavior?
Describe the actual state, for example: "Waiting for context compaction to finish; the turn will continue automatically." Alternatively, keep only the existing compacting progress message.
Do not ask the user to retry when the turn is already waiting for an active compaction. Genuine cancellation, failure, and a rejected manual request should retain their separate meanings. Add an ACP regression test for the successful start -> blocked/wait -> completed sequence.
Additional information
Root cause:
FullCompactionService.block()requires an existing active compaction, emitsCompactionBlocked, then awaitsactive.promise. The turn is blocked on compaction, not the other way around.AcpSession.init()translates everycompaction.blockedinto the reversed sentence above.emitLocalChunk()sends it as plain assistant text.
Latest stable 0.41.0 (npm latest as checked on 2026-09-08) still contains both sides of this logic:
- Wait implementation:
kimi-code/packages/agent-core-v2/src/agent/fullCompaction/fullCompactionService.ts
Lines 547 to 560 in 95478e8
private async block(signal?: AbortSignal, turnId?: number): Promise<void> { const active = this._compacting; if (active === null) return; active.blockedByTurn = true; this.propagateBlockingAbort(active, signal); void this.dispatcher.dispatch( new CompactionBlocked({ agentId: this.agent.agentId, turnId }), ); try { await active.promise; } catch (error) { if (this.wasBlockingWaitAborted(active, signal, error)) return; throw error; } - ACP wording:
kimi-code/packages/acp-server/src/session.ts
Lines 325 to 329 in 95478e8
events.on('compaction.blocked', () => { this.emitLocalChunk( 'Compaction is blocked by the current turn; retry when the turn is idle.', ); }),
Current main f12d59e089e2531a33fbca30b26ffeabd5862b45 also retains the sentence. Version 0.41.0 and main were source-checked; they were not claimed as new live E2E reproductions. The 0.39.1 installed binary was inspected, and a local replay of its corresponding unmodified block/subscription methods reproduced the misleading message while the waiting promise subsequently resolved successfully.
Only generic reproduction details and public source references are included; no private session logs or credentials are attached.
Contribution
- I am willing to submit a PR for this bug fix myself (please wait for maintainer approval in this issue first)
Activity
535628443 commentedon Sep 8, 2026
I've opened #3650 to fix this. The change is a single-line string replacement in
packages/acp-server/src/session.ts:Before:
Compaction is blocked by the current turn; retry when the turn is idle.After:
Waiting for context compaction to finish; the turn will continue automatically.The old wording reversed the causality (the turn waits for compaction, not the other way around) and asked the user to retry when the turn continues automatically. The engine's own test
blocks the turn until auto compaction finishesconfirms the correct lifecycle.Typecheck and lint pass. Could a maintainer please
/approvethis issue so the PR can be reviewed?