Skip to content

fix(acp): fail open post-settle replies and cancel pending requests on agent exit - #40484

Open
itsthecsguy wants to merge 1 commit into
pingdotgg:mainfrom
itsthecsguy:fix/acp-post-settle-crash-finalization
Open

itsthecsguy wants to merge 1 commit into
pingdotgg:mainfrom
itsthecsguy:fix/acp-post-settle-crash-finalization

Conversation

@itsthecsguy

Copy link
Copy Markdown
Contributor

Problem

In packages/provider-acp/src/server/adapter.ts, handleRuntimeTerminationAtGeneration handles !followsAgentWorkState runtimes (such as Antigravity) by returning early whenever !hasDeferredBackgroundWork(held). As a result:

  1. If the agent process crashes/exits after a background command completes while streaming its post-settle reply (held.replyOpen === true, before usage_update), handleRuntimeTerminationAtGeneration does nothing—the turn hangs for the 2-minute ACP_OPEN_REPLY_QUIET_LIMIT and then falsely settles as "completed".
  2. Even when hasDeferredBackgroundWork(held) is true, the !followsAgentWorkState branch does not clear agentRequests, wakeBuffer, or continuationRequested, nor call cancelPendingRuntimeRequests(), leaving pending approval/question cards stuck in "pending" / "waiting".

Change

  • packages/provider-acp/src/server/adapter.ts: Updated the !followsAgentWorkState path in handleRuntimeTerminationAtGeneration to:
    • Fail any unfinalized post-settle turn when either hasDeferredBackgroundWork(held) or held.replyOpen is true (preserving normal completion during the short debounce once replyOpen is false and no deferred work remains).
    • Clear agentRequests, wakeBuffer, and continuationRequested, and call cancelPendingRuntimeRequests() before failing open tools and finalizing the turn as "failed" (transport_error).
  • apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts: Added "fails a post-settle reply immediately and cancels pending requests when the agent exits" covering both an agent exit mid post-settle reply and an agent exit with a pending interaction_* question request.

Scope

Small, focused bug fix for post-settle runtime crash cleanup in AcpAdapterV2; no separate tracking issue is needed.

Verification

  • Reproduced before fix: Ran vp test run apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts -t "fails a post-settle" on main (194025ef11) with only the new test; the test hung on the 2-minute ACP_OPEN_REPLY_QUIET_LIMIT timer (Test timed out in 120000ms).
  • Verified after fix:
    • vp test run apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts: 33/33 passed (new test completes in ~720 ms).
    • vp run check:changed: passed format, lint, knip, graphql (apps/server), typecheck (14 packages), and tests (35/35 passed across AntigravityAdapterV2.test.ts and AgentContextBudget.test.ts).

Built with Gemini 4 Neon in T3 Code (Antigravity harness).

@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Nov 21, 2026
@coderabbitai

coderabbitai Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The ACP adapter now handles runtime termination for settled turns that have deferred background work or an open reply. It clears request and continuation state, cancels pending runtime requests, fails open tools, and finalizes the turn with a transport error. Tests cover partial replies and permission requests after agent exit.

Changes: ACP runtime termination handling

Layer / File(s) Summary
Handle runtime termination for settled turns
packages/provider-acp/src/server/adapter.ts, apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts
The adapter handles settled turns with an open reply, even without deferred background work. Before finalizing, it clears agent requests and buffered continuation state, then cancels pending runtime requests and fails open tools. Tests verify that a partial reply leads to a failed turn and that an outstanding permission request is cancelled when the agent exits.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: t3dotgg, juliusmarminge

Merge Risk: Minimal · up to 25219

When an ACP agent exits after a prompt settles, the turn now fails immediately and pending approval or question requests are cancelled, instead of waiting out the quiet limit and falsely completing. The added tests cover both cases, and no concrete merge-blocking risk was found in review.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: failing open post-settle replies and cancelling pending requests when an ACP agent exits. It follows the conventional commit format and matches the adapter change and …
Description check Passed The description follows the repository template closely. It has Problem, Change, Scope, and Verification sections. The Problem and Change sections explain the bug and the fix in detail. Scope states t…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: failing open post-settle replies and cancelling pending requests when an ACP agent exits. It follows the conventional commit format and matches the adapter change and the added test.

Full details: Description check

Explanation

The description follows the repository template closely. It has Problem, Change, Scope, and Verification sections. The Problem and Change sections explain the bug and the fix in detail. Scope states this is a small bug fix and why no issue is needed. Verification gives the focused test commands, the failure reproduced before the fix, and the passing results after it. It also names the model and harness used, as the template asks.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 1ffa099 and 25219da.

Files selected for processing: 2

  • apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts
  • packages/provider-acp/src/server/adapter.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant