Skip to content

MUL-5657 fix(agent): add missing streamingCurrentTurn gate to kimi ACP backend - #6308

Merged
Bohan-J merged 1 commit into
multica-ai:mainfrom
liuguiyuan3:fix/kimi-streaming-current-turn-gate
Aug 3, 2026
Merged

MUL-5657 fix(agent): add missing streamingCurrentTurn gate to kimi ACP backend#6308
Bohan-J merged 1 commit into
multica-ai:mainfrom
liuguiyuan3:fix/kimi-streaming-current-turn-gate

Conversation

@liuguiyuan3

Copy link
Copy Markdown
Contributor

Summary

  • Add streamingCurrentTurn gate to kimi backend, matching hermes/grok/traecli/kiro/qoder
  • Without the gate, session resume replays prior-turn history into output and message stream
  • Add TestKimiBackendDropsHistoryReplayOnResume regression test

Problem

When a Kimi session is resumed (session/resume), the ACP runtime replays prior-turn transcripts as session/update notifications before the client sends session/prompt. All other ACP backends gate these notifications with a streamingCurrentTurn atomic.Bool that is only flipped to true after session/prompt is sent — but kimi.go was missing this gate entirely.

The result: on resume, the previous answer is duplicated into Result.Output and streamed to the UI alongside the new answer.

Root Cause

The gate was introduced in PR #2024 (2026-05-03) for hermes only. Kimi already existed at that time but was not patched. Subsequent backends (grok #5285, traecli #4724) were written after the fix and included the gate from the start.

Fix

Add the identical gate pattern (6 touch points):

  1. var streamingCurrentTurn atomic.Bool
  2. acceptNotification callback → return streamingCurrentTurn.Load()
  3. onMessage gate → if !streamingCurrentTurn.Load() { return }
  4. onPromptDone gate → if !streamingCurrentTurn.Load() { return }
  5. streamingCurrentTurn.Store(true) before session/prompt
  6. streamingCurrentTurn.Store(false) after drain

Test plan

  • go build ./... passes
  • go test ./pkg/agent/ -run TestKimi -count=1 — all 7 kimi tests pass (including new one)
  • New test verifies: history replay blocked from Output AND message stream; current-turn answer passes through; session ID preserved
  • Verified the new test FAILS without the fix (history leaks into output)

kimi.go was the only ACP backend missing the streamingCurrentTurn gate.
Without it, history replay emitted by the Kimi CLI during session/resume
contaminates Result.Output and the message stream with previous-turn
content — the user sees the old answer duplicated alongside the new one.

The root cause is chronological: the gate was introduced for Hermes in
PR multica-ai#2024 (2026-05-03) but kimi already existed at that point and was not
updated. Later backends (grok, traecli) were written after the fix and
included the gate from day one.

Add the same atomic.Bool gate + acceptNotification callback pattern used
by hermes, grok, traecli, kiro, and qoder. Pin with
TestKimiBackendDropsHistoryReplayOnResume.
@vercel

vercel Bot commented Aug 3, 2026

Copy link
Copy Markdown

@liuguiyuan3 is attempting to deploy a commit to the IndexLabs Team on Vercel.

A member of the Team first needs to authorize it.

@liuguiyuan3

Copy link
Copy Markdown
Contributor Author

Hi @Bohan-J 👋

I noticed the kimi backend was missing the streamingCurrentTurn gate that you introduced in PR #2024 for hermes. I've added the same pattern here and included a regression test.

Could you please take a look when you get a chance? Thanks!

@Bohan-J Bohan-J changed the title fix(agent): add missing streamingCurrentTurn gate to kimi ACP backend MUL-5657 fix(agent): add missing streamingCurrentTurn gate to kimi ACP backend Aug 3, 2026
@Bohan-J

Bohan-J commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Thanks a lot for this — and welcome! This is an unusually well-researched first contribution.

Two things stood out. First, the root cause writeup: identifying that the gate landed in #2024 for hermes while kimi already existed and simply never got patched explains why this backend was the odd one out, which is far more useful than just describing the symptom. Second, you verified the new test fails without the fix. That's the step that separates a real regression guard from an assertion that happens to be true — please keep doing it.

We independently confirmed the behaviour on our side:

  • Reverting only kimi.go to base while keeping kimi_test.go makes TestKimiBackendDropsHistoryReplayOnResume fail with history replay leaked into Result.Output: "old history from previous turnfresh answer" — the test genuinely reproduces the reported regression.
  • The gate touch points line up exactly with hermes/grok/traecli/qoder, and streamingCurrentTurn.Store(false) sits after both <-readerDone and <-stderrDone, so it can't truncate a late final chunk. TestKimiDrainsNotificationsAfterPromptResponse still passes, which was the failure mode we were most worried about.
  • Nothing before session/prompt depends on the notification stream — the resumed session id comes from the session/resume RPC response, and the only consumer of onActivity runs after the prompt — so gating early is safe here.
  • Full ./pkg/agent/ package regression, go vet, and -race on the kimi tests are all clean.

Merging as-is. Two follow-ups we'll pick up separately, neither of which needs anything from you:

  • kiro.go is now the only ACP backend without the closing Store(false). It's a per-Execute local so it isn't a bug, but the backends should be uniform.
  • The gate is time-based rather than content-based: it assumes history replay always precedes session/prompt. That assumption is shared by every ACP backend and is worth pinning in a cross-backend test matrix — which is exactly the kind of shared assertion that would have caught this gap in kimi years earlier.

Thanks again.

@Bohan-J
Bohan-J merged commit 6890812 into multica-ai:main Aug 3, 2026
9 checks passed
multica-eve pushed a commit that referenced this pull request Aug 3, 2026
Co-authored-by: multica-agent <github@multica.ai>
Bohan-J pushed a commit that referenced this pull request Aug 3, 2026
…6311)

* docs(changelog): add v0.4.17 release entry (2026-08-03) (MUL-5655)

Co-authored-by: multica-agent <github@multica.ai>

* docs(changelog): drop the MCP allowlist fix, reverted in #6314 (MUL-5655)

Co-authored-by: multica-agent <github@multica.ai>

* docs(changelog): add the Kimi resume fix from #6308 (MUL-5655)

Co-authored-by: multica-agent <github@multica.ai>

---------

Co-authored-by: Eve <eve@multica-ai.local>
Co-authored-by: multica-agent <github@multica.ai>
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.

2 participants