Skip to content

fix(agent-core-v2): don't record turn.steer when an unconsumed steer … - #3933

Merged
liruifengv merged 1 commit into
mainfrom
fix/steer-dequeued-turn-duplicate-user-frame
Sep 19, 2026
Merged

liruifengv merged 1 commit into
mainfrom
fix/steer-dequeued-turn-duplicate-user-frame

Conversation

@liruifengv

@liruifengv liruifengv commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

N/A — internal bug, reproduced from a live desktop session (no tracking issue).

Problem

When a user steers a message while the agent is running, and the running turn then ends before the steer is consumed (cancelled via Esc, or completed before the next step boundary), the unconsumed steered prompt seeds the next turn as its opening prompt. The engine recorded both turn.prompt (the turn's opening) and turn.steer (steer consumption) for the same message, so the live transcript projected it twice — the chat showed the steered message as two identical user bubbles.

The cold transcript rebuild already deduplicates this case (a message whose id opened a turn is not folded as a steer), so reloading the session showed a single bubble — confirming the turn.steer record is spurious when the steered message itself opens the new turn.

What changed

  • In AgentLoopService.consumeDrainedNudges, skip dispatching TurnSteer when the nudge being consumed is the message that opened the active turn (nudge.contextMessage.id === active.prompt.message.id). The message is still materialized into context exactly once; only the durable turn.steer record is no longer written for it.
  • turn.steer now only fires when a steer is actually injected mid-turn into an already-running turn, which is the only case that needs a separate steer frame in the transcript. Live rendering then matches the cold rebuild: one user bubble (the turn's opening prompt).
  • Tests:
    • New loop-level test: steer during a held step, Esc-cancel the turn, let the steered prompt seed the next turn — asserts no turn.steer is published and the message lands in context exactly once.
    • Two existing steer-metadata tests covered the same seeded-turn path and asserted the spurious turn.steer; they now assert on the materialized context message (merged content, FIFO client metadata, reserved message id), which is the more direct seam for what they guard.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: the issue must have a maintainer's /approve). — N/A, internal bug
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

Copilot AI balanced review requested due to automatic review settings September 19, 2026 11:15
@changeset-bot

changeset-bot Bot commented Sep 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c7cfc8b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Sep 19, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@c7cfc8b
npx https://pkg.pr.new/@moonshot-ai/kimi-code@c7cfc8b

commit: c7cfc8b

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The targeted condition fixes duplicate transcript rendering and is covered by focused regression tests.

Review effort: Balanced
Findings: None

What changed in this PR

Prevents seeded post-cancellation prompts from being recorded as duplicate in-turn steer messages.

Changes:

  • Suppresses redundant turn.steer events for prompts seeding a new turn.
  • Updates regression coverage and adds a CLI patch changeset.
File Description
packages/​agent-core-v2/​src/​agent/​loop/​loopService.ts Avoids redundant steer dispatch.
packages/​agent-core-v2/​test/​agent/​prompt/​promptService.test.ts Verifies correct event and message materialization behavior.
.changeset/​steer-seeded-turn-duplicate-message.md Documents the user-visible fix.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@liruifengv
liruifengv merged commit 9721259 into main Sep 19, 2026
18 checks passed
@liruifengv
liruifengv deleted the fix/steer-dequeued-turn-duplicate-user-frame branch September 19, 2026 11:21
@github-actions github-actions Bot mentioned this pull request Sep 19, 2026
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.

3 participants