Skip to content

feat(acp): preserve causal prompt correlation - #1239

Open
sethkarten wants to merge 33 commits into
v080/acp-p1-final-corefrom
v080/acp-p2-final-core
Open

feat(acp): preserve causal prompt correlation#1239
sethkarten wants to merge 33 commits into
v080/acp-p1-final-corefrom
v080/acp-p2-final-core

Conversation

@sethkarten

@sethkarten sethkarten commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • serialize ACP session/update publication and attach causal promptTurnId and monotonic eventSequence metadata
  • emit explicit response-boundary and terminal-quiescence envelopes without conflating them with ACP transport stop reasons
  • preserve nested child lifecycle truth across attachment, deletion, cancellation, and session close
  • prevent duplicate outer retries for intercepted model requests and attach a protected logical relay identifier
  • add verified exact-socket daemon shutdown for rollout-owned Unix-domain sockets
  • wait for process teardown before cleanup and exclude local Python caches from release archives

Stack

Merge #1236 first, then retarget this PR to main and merge it second.

Protocol contract

The new correlation fields are additive metadata under _meta. eventSequence is connection-wide and strictly increasing. A scoreable terminal envelope is emitted only after authoritative child-lifecycle quiescence; cancellation cannot relabel an already sealed terminal pair.

Validation

  • all required CI and CodeQL checks pass at the current head
  • deterministic coverage exercises update ordering, admission races, nested children, cancellation cuts, retry boundaries, exact-socket targeting, and process teardown
  • the stack has been exercised through local OOLONG evaluation; no paid or live evaluation is part of GitHub CI

Note

High Risk
ACP prompt correlation, terminal sealing, and quiescence semantics are easy for clients to misread if any publish path regresses; exact-socket shutdown and intercept no-retry boundaries also touch operational safety and request idempotency.

Overview
This PR tightens ACP client correlation and several lifecycle boundaries around prompts, children, and daemon rollouts.

ACP now routes all session/update traffic through AcpUpdateProducer, which serializes publication and stamps promptTurnId, monotonic eventSequence, phase (event / responseBoundary / terminalQuiescence), and outcome on _meta. Updates are buffered until session/new’s JSON-RPC response is on the wire; each prompt ends with a response boundary plus a quiescence envelope (outstanding subagents, remaining autonomous continuations) when work is truly terminal. Child updates stay tied to their origin turn (or turn 0 after seal), and cancellation cannot relabel a sealed terminal pair.

RLM snapshots add getRlmChildSnapshots() (live registry + retained sessions, including nested/hidden-delete cases) and feed children on connection snapshots; the daemon connection patches the cached roster on rlm_child_update.

Intercept / retry: the agent loop injects a fresh, caller-overwritable X-Prime-Agent-Relay-ID per intercept completion; AgentSession skips outer auto-retry (and related auth-retry paths) for intercept so idempotency stays at the provider layer.

CLI: shutdown --daemon-socket <path> calls shutdownExactDaemonAndWait, which shuts down only a verified same-build daemon at that path (no --force).

Smaller fixes: test teardown waits on child processes / retries ENOTEMPTY cleanup; release packing skips __pycache__ / .pyc.

Reviewed by Cursor Bugbot for commit a6f6d52. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Add causal prompt correlation and event sequencing to ACP session updates

  • Introduces AcpUpdateProducer in acp-mode.ts to serialize ACP session updates with strictly increasing eventSequence and promptTurnId, correlating child agent updates to their origin prompt turn.
  • Adds phase (event, responseBoundary, terminalQuiescence) and outcome (result | error) fields to PrimeAgentSessionMeta in acp-meta.ts to annotate each update's causal role.
  • Gates update publication until the session/new response is written to the transport, preventing out-of-order delivery.
  • Emits terminal quiescence only when no outstanding subagents remain, and includes outstandingSubagents and remainingAutonomousContinuations counters.
  • Adds a per-call X-Prime-Agent-Relay-ID header (32-char hex) for intercept providers, preventing auto-retry on auth failures from the intercept provider.
  • Adds shutdownExactDaemonAndWait to verify daemon build identity before issuing shutdown, and exposes it via the shutdown --daemon-socket CLI flag.
  • Behavioral Change: session/close now halts update admission before draining, preventing post-close boundary publications; cancellation no longer relabels a durable boundary/terminal pair.

Macroscope summarized a6f6d52.

Comment thread packages/coding-agent/src/modes/acp/acp-mode.ts
Comment thread packages/coding-agent/src/modes/acp/acp-mode.ts
Comment thread packages/coding-agent/src/core/agent-session.ts Outdated
Comment thread packages/coding-agent/src/modes/acp/acp-mode.ts Outdated
Comment thread packages/coding-agent/src/modes/acp/acp-mode.ts
Comment thread packages/coding-agent/src/modes/acp/acp-mode.ts Outdated
Comment thread packages/coding-agent/src/modes/acp/acp-mode.ts Outdated
@sethkarten
sethkarten marked this pull request as ready for review August 12, 2026 06:18
Comment thread packages/coding-agent/src/modes/acp/acp-mode.ts Outdated
Comment thread packages/coding-agent/src/core/agent-session.ts
@sethkarten
sethkarten requested a review from alexzhang13 August 13, 2026 01:18
Comment thread packages/coding-agent/src/core/agent-session.ts
Comment thread packages/coding-agent/src/cli/daemon-launch.ts
Comment thread packages/coding-agent/src/modes/acp/acp-mode.ts Outdated
Comment thread packages/coding-agent/src/modes/acp/acp-mode.ts
Comment thread packages/coding-agent/src/modes/acp/acp-mode.ts
Comment thread packages/coding-agent/test/suite/acp-mode.test.ts Outdated
Comment thread packages/coding-agent/src/core/agent-session.ts
Comment thread packages/coding-agent/src/modes/acp/acp-mode.ts
Comment thread packages/coding-agent/src/modes/acp/acp-mode.ts Outdated

@cursor cursor 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c2c5000. Configure here.

Comment thread packages/coding-agent/src/modes/acp/acp-mode.ts Outdated
@sethkarten
sethkarten requested a review from samsja August 17, 2026 21:30
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