Skip to content

fix(agent-core-v2): remove duplicate launch-time subagent.spawned - #3134

Merged
sailist merged 1 commit into
MoonshotAI:mainfrom
sailist:bug-043-08-18-session-subagent-stale-running
Aug 20, 2026
Merged

fix(agent-core-v2): remove duplicate launch-time subagent.spawned#3134
sailist merged 1 commit into
MoonshotAI:mainfrom
sailist:bug-043-08-18-session-subagent-stale-running

Conversation

@sailist

@sailist sailist commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue — the problem was found while investigating an internal report of subagent task rows stuck in the "running" state.

Problem

Every Agent-tool subagent emits subagent.spawned twice: once inside launch() right after the agent scope is created (without a task id), and once after registerTask succeeds (carrying the task id). The launch-time emission had been deliberately removed by #3005 and was accidentally reintroduced by the model-as-container refactor #3103.

Downstream effects of the duplicate:

  • Transcript-protocol consumers (AgentTranscriptProjector.onSubagentSpawned) create a second task row keyed by the agent id; subagent.started/completed/failed fold only into the task-id-keyed row, so the agent-id-keyed row stays running forever after the subagent has finished.
  • The spawning tool frame gets the same agent ref appended twice.
  • The subagent_created telemetry event is double-counted.

What changed

  • packages/agent-core-v2/src/agent/tools/agent/agentTool.ts: removed the launch-time emitAgentRunSpawned call (and the runInBackground local that only fed it), restoring the fix(agent-core-v2): emit subagent.spawned after task registration #3005 semantics — subagent.spawned is emitted exactly once, after task registration, carrying the task id, followed by subagent.started.
  • packages/agent-core-v2/test/tool/tool.test.ts: added a regression test asserting the Agent tool emits subagent.spawned exactly once and that the event carries the registered task id.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: the issue must have a maintainer's /approve).
  • 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.

@changeset-bot

changeset-bot Bot commented Aug 20, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 82adc1c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@pkg-pr-new

pkg-pr-new Bot commented Aug 20, 2026

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

commit: 82adc1c

@sailist
sailist merged commit 3b69765 into MoonshotAI:main Aug 20, 2026
16 checks passed
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Aug 20, 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.

1 participant