fix(provider-acp): deferred finalization no longer reports hidden post-background errors as completed #40232
ClosedKyleDerZweite(GitHub profile, opens in a new tab)wants to merge 1 commit into
main fromrefs/pull/40232/headopened View on GitHubtanstack-source added labelsbug
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- @@ -1640,0 +1662,21 @@1662+ };1663+ let sessionUpdateHandler: Parameters<RuntimeService["handleSessionUpdate"]>[0] | undefined;1664+ const subagentStatuses = new Map<string, "running" | "completed">([1665+ ["tool-call-generic-1", "running"],1666+ ]);1667+ const promptRuntimes: Array<number> = [];1668+ const checkStopReasons: Array<string> = [];1669+ let nextOutcome: () => Effect.Effect<PromptOutcome | undefined> = () => Effect.undefined;1670+ const promptSettled = yield* Queue.unbounded<void>();1671+ const deferredScheduled = yield* Queue.unbounded<void>();1672+ const deferredFinalized = yield* Queue.unbounded<void>();1673+ const adapter = yield* makeAcpAdapterV2({1674+ instanceId,1675+ selfInvocation,1676+ testHooks: {1677+ afterPromptSettledWithBackgroundWork: () =>1678+ Queue.offer(promptSettled, undefined).pipe(Effect.asVoid),1679+ onDeferredFinalizeScheduled: () =>1680+ Queue.offer(deferredScheduled, undefined).pipe(Effect.asVoid),1681+ afterDeferredFinalize: () =>1682+ Queue.offer(deferredFinalized, undefined).pipe(Effect.asVoid),
juliusmarminge added labelstakeover:in-progress
Pushed86cef12
- @@ -8755,3 +8760,20 @@87558760 }87568761 const status = context.promptSettledStatus ?? "completed";8757- yield* finalizeTurn(context, status);8762+ const checkPromptOutcome =8763+ status === "completed" ? context.checkPromptOutcome : undefined;8764+ if (checkPromptOutcome === undefined) {8765+ yield* finalizeTurn(context, status);8766+ yield* options.testHooks?.afterDeferredFinalize?.() ?? Effect.void;8767+ return;8768+ }8769+ if (8770+ (yield* Ref.get(runtimeTeardownState))._tag !== "Idle" ||8771+ (yield* Ref.get(runtimeCallbackGeneration)) !== runtimeGeneration8772+ ) {8773+ return;8774+ }8775+ // A completed status implies end_turn. Deferred finalization reports hidden failures8776+ // directly rather than re-running followPrompt's resumeWith retry loop.8777+ const hiddenFailure = yield* Effect.suspend(() =>8778+ checkPromptOutcome({ stopReason: "end_turn" }),8779+ ).pipe(
juliusmarminge added labelstakeover:blocked
juliusmarminge removed labelstakeover:in-progress
github-actions[bot](GitHub profile, opens in a new tab) added labelsneeds-rebase
Pushed4c5b430
- @@ -9158,0 +9174,21 @@9174+ return;9175+ }9176+ // A completed status implies end_turn. Deferred finalization reports hidden failures9177+ // directly rather than re-running followPrompt's resumeWith retry loop.9178+ const hiddenFailure = yield* Effect.suspend(() =>9179+ checkPromptOutcome({ stopReason: "end_turn" }),9180+ ).pipe(9181+ Effect.catchDefect(() =>9182+ Effect.logWarning("Could not check deferred ACP prompt outcome.").pipe(9183+ Effect.as(undefined),9184+ ),9185+ ),9186+ );9187+ yield* runRuntimeCallbackAtGeneration(9188+ runtimeGeneration,9189+ Effect.gen(function* () {9190+ if (!stillCurrent()) return;9191+ if (hiddenFailure !== undefined) {9192+ yield* Ref.set(runtimeRestartRequired, true);9193+ yield* terminalizeOpenForegroundTools(context, "failed");9194+ yield* finalizeTurn(context, "failed", hiddenFailure.failure, {
github-actions[bot](GitHub profile, opens in a new tab) removed labelsneeds-rebase
Pusheda0348e2
- @@ -1839,0 +2006,21 @@2006+ subagentStatuses.set("tool-call-generic-1", "running");2007+ yield* startTurn(2);2008+ yield* Queue.take(promptSettled);2009+ assert.deepEqual(promptRuntimes, [1, 2], "hidden deferred failure must restart runtime");2010+2011+ const workRaceStarted = yield* Deferred.make<void>();2012+ nextOutcome = () =>2013+ Deferred.succeed(workRaceStarted, undefined).pipe(Effect.andThen(Effect.never));2014+ yield* emitSubagent("tool-call-generic-1", "completed");2015+ yield* Queue.take(deferredScheduled);2016+ yield* TestClock.adjust("3000 millis");2017+ yield* Deferred.await(workRaceStarted);2018+2019+ yield* emitSubagent("tool-call-generic-2", "running", "tool_call");2020+ const workRaceSettled = yield* Deferred.make<void>();2021+ nextDeferredFinalized = workRaceSettled;2022+ nextOutcome = () => Effect.undefined;2023+ // The first check times out while the second subagent still holds the turn open.2024+ yield* TestClock.adjust("5 seconds");2025+ yield* Deferred.await(workRaceSettled);2026+ assert.deepEqual(yield* Queue.clear(terminals), []);@@ -9817,0 +9843,21 @@9843+ checkPromptOutcome({ stopReason: "end_turn" }),9844+ ).pipe(9845+ Effect.timeoutOrElse({9846+ duration: PROMPT_OUTCOME_CHECK_TIMEOUT,9847+ orElse: () =>9848+ Effect.logWarning("Deferred ACP prompt outcome check timed out.").pipe(9849+ Effect.as(undefined),9850+ ),9851+ }),9852+ Effect.catchDefect(() =>9853+ Effect.logWarning("Could not check deferred ACP prompt outcome.").pipe(9854+ Effect.as(undefined),9855+ ),9856+ ),9857+ );9858+ if (hiddenFailure !== undefined) {9859+ const toolsTerminalized = yield* runRuntimeCallbackAtGeneration(9860+ runtimeGeneration,9861+ Effect.gen(function* () {9862+ if (!stillCurrent()) return false;9863+ yield* terminalizeOpenForegroundTools(context, "failed");@@ -9817,0 +9867,21 @@9867+ );9868+ if (Option.isSome(toolsTerminalized) && toolsTerminalized.value) {9869+ // Release the permit so queued soft Stop can claim the turn before failure.9870+ yield* runRuntimeCallbackAtGeneration(9871+ runtimeGeneration,9872+ Effect.gen(function* () {9873+ if (!stillCurrent()) return;9874+ yield* finalizeTurn(context, "failed", hiddenFailure.failure, {9875+ restartRuntimeOnFailure: true,9876+ childTurnsContinue: hasSurvivingBackgroundWork(context),9877+ threadDisposition: hiddenFailure.threadDisposition,9878+ });9879+ }),9880+ );9881+ }9882+ } else {9883+ yield* runRuntimeCallbackAtGeneration(9884+ runtimeGeneration,9885+ Effect.suspend(() =>9886+ stillCurrent() ? finalizeTurn(context, status) : Effect.void,9887+ ),
Pushed9397cbf
Sign in to join this conversation.
Note
Reviews paused#
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review.
Walkthrough
The ACP adapter stores a prompt-outcome check for each active turn and uses it during deferred finalization. A current hidden failure can fail the turn and request a runtime restart. Soft-interrupt settlement now checks prompt and wire settlement under the runtime callback permit.
Changes: Deferred prompt outcome checks
packages/provider-acp/src/server/adapter.tspackages/provider-acp/src/server/adapter.ts,apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.tspackages/provider-acp/src/server/adapter.tsEstimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix
Sequence Diagram(s)#
Possibly related issues
Merge Risk:
Moderate · up to
a0348This change makes deferred ACP turn finalization re-check for hidden upstream failures such as quota errors, and the main path looks sound. Edge cases remain around a native approval arriving during the outcome check, a foreground tool failure re-arming finalization and discarding the detected failure, and a reply that becomes pending during the check. One test assertion is also weaker than it should be. These are narrow, timing-dependent cases, but the approval case should be resolved before merge.
Pre-merge checks:
4
Full details: Title check
Explanation
The title names the main change: deferred finalization in provider-acp no longer reports hidden post-background errors as completed. The changeset re-runs the prompt-outcome check at deferred finalize and fails the turn when a hidden failure is found, which matches the title. The title is a conventional commit, single sentence, and specific. It is 101 characters, which is long, but it stays readable and clear.
Full details: Description check
Explanation
The description covers the problem, the change, scope, and verification in detail. The Problem section explains that a deferred finalize reported a turn as completed when a hidden quota failure appeared after background work, and it gives the effect on usage-limit classification and auto-resume. The Change section lists the adapter.ts edits and the new regression tests. The Scope section states the bug-fix scope, explains why no issue was filed, and links related issues. The Verification section gives focused test counts, the before/after result for the Antigravity fixture, and the checks not run. The template asks for a conventional commit title, and the PR title was not in the provided context, so that item cannot be confirmed. The template also asks for the model and harness to be named at the end, and the author did so. The description meets the template requirements.
Finishing Touches
Generate unit tests (beta)
2630d2b3-2805-4cee-ae3e-ce60380803caReviewing files that changed from the base of the PR and between 77b5c02a02a6fc68b26b17bac49f49c09896fa85 and a0348e2fd22ba43f6b8df88b2ea85ddd9f550273.
apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.tspackages/provider-acp/src/server/adapter.tsIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.