Skip to content

fix(acp): stream agent-initiated turns - #2392

Open
lurenjia534 wants to merge 1 commit into
MoonshotAI:mainfrom
lurenjia534:fix/acp-agent-initiated-updates-2163
Open

fix(acp): stream agent-initiated turns#2392
lurenjia534 wants to merge 1 commit into
MoonshotAI:mainfrom
lurenjia534:fix/acp-agent-initiated-updates-2163

Conversation

@lurenjia534

Copy link
Copy Markdown
Contributor

Related Issue

Resolves #2163

Problem

ACP update projection was scoped to an active session/prompt request. After that request settled, a task- or cron-triggered main-agent turn could run successfully in the engine while the connected ACP client received no session/update notifications.

There were two related lifecycle gaps that made the same path unsafe to attach: v2 could start restored cron work before SDK event wiring existed, and a UserPromptSubmit hook that blocked or failed before a turn was created had no correlated terminal event, leaving ACP prompt admission occupied.

What changed

  • Keep one session-lifetime ACP event projection for main-agent turns, including display-safe task/cron trigger text, reasoning, tool lifecycle, and assistant output. Prompt settlement remains correlated by promptId/activationId, so autonomous turns cannot complete an unrelated prompt.
  • Carry prompt correlation through the v1/v2 engine, protocol, server, and klient contracts. v2 now emits prompt.completed when a pre-turn hook blocks or fails, allowing ACP to return refusal and admit the next request.
  • Install v2 SDK wiring before restored agents and cron producers can emit, and stage live events plus approval/question interactions while a cold session/resume is materializing. Setup is serialized per canonical session id and every temporary registration has ownership-aware failure/dispose cleanup.
  • Roll back the session registry, agents, session scope, and newly created session directory when lifecycle or cron startup fails.
  • Add a patch changeset for @moonshot-ai/kimi-code.

Scope: this guarantees live delivery for connected sessions and the cold session/resume handoff. It does not claim an atomic history/live cut for cold session/load; that requires a producer-side snapshot cursor rather than replaying a second consumer buffer.

Verification

The three real-engine E2E files were copied byte-for-byte to an untouched upstream/main worktree at 691ec467 and run on both trees:

  • Before: 4/4 failed — v1 and v2 autonomous task turns produced no ACP updates; both pre-turn hook cases hung until timeout.
  • After: 4/4 passed — both engines streamed the complete autonomous turn; hook blocking returned refusal, and the following prompt completed.

Additional validation:

  • pnpm test: 1,017 test files passed; 16,743 passed, 3 expected failures, 83 skipped, 2 todo.
  • ACP adapter: 359/359 passed.
  • agent-core-v2: 4,232/4,232 passed.
  • Node SDK: 336 passed, 1 todo.
  • pnpm typecheck, pnpm lint (0 errors), and pnpm build passed across the monorepo.
  • pnpm sherif, pnpm lint:pkg, SDK API Extractor, and package declaration builds passed.

An existing MCP initial-connect parity test intermittently observed v1 as pending while v2 had reached connected; the identical failure reproduced on untouched upstream, the affected assertion is outside this diff, and final SDK/root runs passed.

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. No command, configuration, or documented UI contract changed.

@changeset-bot

changeset-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0d7614c

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

@lurenjia534
lurenjia534 marked this pull request as ready for review July 30, 2026 04:00

Copy link
Copy Markdown
Contributor Author

@codex review

@pkg-pr-new

pkg-pr-new Bot commented Jul 30, 2026

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

commit: 0d7614c

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0d7614cba8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +613 to +614
params.mode === 'resume' &&
typeof this.harness.onSessionEvent === 'function'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Buffer cold-load events before replay

When session/load cold-loads a persisted session, autonomous work can begin inside harness.resumeSession()—for example, restored task reconciliation can launch a notification turn, and the lifecycle now starts the cron scheduler before resume returns. Because this temporary subscription is restricted to mode === 'resume', those live deltas and tool events occur before AcpSession installs its listener; replayHistory() cannot recover these transient events, so the client can miss part or all of an agent-initiated turn during load. The load path needs an atomic snapshot/live handoff rather than omitting the event bridge.

Useful? React with 👍 / 👎.

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.

ACP: agent-initiated turns (background task completions, cron fires) never emit session/update while no prompt is in flight

1 participant