Skip to content

fix(agent-core-v2): flush wire before agent disposal - #2812

Draft
LouisDM wants to merge 2 commits into
MoonshotAI:mainfrom
LouisDM:codex/issue-2727-acp-persistence
Draft

fix(agent-core-v2): flush wire before agent disposal#2812
LouisDM wants to merge 2 commits into
MoonshotAI:mainfrom
LouisDM:codex/issue-2727-acp-persistence

Conversation

@LouisDM

@LouisDM LouisDM commented Aug 11, 2026

Copy link
Copy Markdown

Related Issue

Refs #2727

Problem

Agent removal waits for active turns and compaction, but it can dispose the agent scope before queued replayable wire records are flushed. In ACP, this allows session/close to return while the latest assistant content is not yet durable.

On current main, the normal-speed prompt/close path did not reproduce persistent loss. A controlled delayed wire append did reproduce the lifecycle race: agent removal completed before the final records were durable.

What changed

  • Flush the per-agent replayable wire after turns and compaction settle, before disposing the child scope.
  • Guarantee scope cleanup and the disposal event even if the flush rejects, while preserving that error for the caller.
  • Add regression tests proving both the wait barrier and the rejecting-flush cleanup path.
  • Add a patch changeset for @moonshot-ai/kimi-code.

This closes the verified close/dispose durability gap without claiming to explain every persistent-history symptom reported in #2727.

Validation

  • pnpm --filter @moonshot-ai/agent-core-v2 exec vitest run test/session/agentLifecycle/agentLifecycle.test.ts (29 passed)
  • pnpm --filter @moonshot-ai/acp-server exec vitest run test/close.test.ts test/lifecycle.test.ts (18 passed)
  • pnpm --filter @moonshot-ai/agent-core-v2 typecheck
  • pnpm --filter @moonshot-ai/acp-server typecheck
  • pnpm --filter @moonshot-ai/agent-core-v2 lint:imports (1135 files checked)
  • pnpm exec oxlint packages/agent-core-v2/src/session/agentLifecycle/agentLifecycleService.ts packages/agent-core-v2/test/session/agentLifecycle/agentLifecycle.test.ts
  • pnpm changeset status --since=origin/main

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • 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 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1a0b873

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

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