Repository navigation
fix(antigravity): bound silent post-settle background command holds #40854
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -637,6 +637,11 @@ export interface AcpAdapterV2Flavor { | |
| * tool ends. With `deferFinalizeForBackgroundWork`, the turn stays open until then. | ||
| */ | ||
| readonly toolOutlivesPrompt?: (toolCall: AcpToolCallState) => boolean; | ||
| /** | ||
| * Bound a settled turn held open only by an outliving tool; finalize after this quiet period | ||
| * so a command that never reports back cannot leave the thread in Working forever. | ||
| */ | ||
| readonly postSettleBackgroundHoldTimeout?: Duration.Input; | ||
| readonly isProviderWakeNotification?: ( | ||
| notification: EffectAcpSchema.SessionNotification, | ||
| ) => boolean; | ||
|
|
@@ -8835,6 +8840,33 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( | |
| yield* options.testHooks?.onDeferredFinalizeScheduled?.(debounce) ?? Effect.void; | ||
| }); | ||
|
|
||
| /** | ||
| * Bound a settled turn held only by an outliving tool that never reports back, so the | ||
| * run cannot stay in Working forever with no visible background work. | ||
| */ | ||
| const schedulePostSettleHoldExpiry = Effect.fn("AcpAdapterV2.schedulePostSettleHoldExpiry")( | ||
| function* (context: ActiveAcpTurn) { | ||
| const timeout = flavor.postSettleBackgroundHoldTimeout; | ||
| if (timeout === undefined) return; | ||
| if (!context.promptSettled || context.finalized) return; | ||
| if (!hasDeferredBackgroundWork(context)) return; | ||
| yield* Effect.gen(function* () { | ||
| yield* Effect.sleep(timeout); | ||
| if (context.finalized || !context.promptSettled) return; | ||
| if (!hasDeferredBackgroundWork(context)) return; | ||
| // Only an outliving tool gets bounded here. Queued wakes, hydration and detached | ||
| // subagents still have their own settlement paths. | ||
| const heldCommand = [...context.tools.values()].some( | ||
| (tool) => | ||
| toolStatus(tool.status) === "running" && | ||
| flavor.toolOutlivesPrompt?.(tool) === true, | ||
| ); | ||
| if (!heldCommand) return; | ||
|
Comment on lines
+8859
to
+8864
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Expire the turn only when the outliving command is the sole hold.
Before finalizing, require that the outliving command is the only remaining hold. Subagents that block settlement, outstanding agent requests, and other holds in
|
||
| yield* finalizeTurn(context, context.promptSettledStatus ?? "completed"); | ||
| }).pipe(Effect.forkIn(sessionScope), Effect.asVoid); | ||
| }, | ||
| ); | ||
|
|
||
| const promptInactivityPaused = Effect.fn("AcpAdapterV2.promptInactivityPaused")(function* ( | ||
| context: ActiveAcpTurn, | ||
| ) { | ||
|
|
@@ -9265,6 +9297,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( | |
| if (context.finalized) return; | ||
| if (deferredBackgroundWork || pendingReply) { | ||
| yield* closeTextStreams(context); | ||
| if (deferredBackgroundWork) yield* schedulePostSettleHoldExpiry(context); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Arm expiry when a running tool arrives after settlement. If Arm expiry when a settled turn first acquires an eligible tool hold, not only when the prompt settles or a continuation drains its buffer. Keep one current expiry per hold.
|
||
| if (pendingReply) { | ||
| context.replyOpen = true; | ||
| yield* scheduleDeferredFinalize(context); | ||
|
|
@@ -9665,6 +9698,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( | |
| return; | ||
| } | ||
| if (!context.finalized) { | ||
| yield* schedulePostSettleHoldExpiry(context); | ||
| if (hasDeferredBackgroundWork(context)) { | ||
| yield* rearmDeferredFinalize(context); | ||
| } else { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bind each post-settle expiry to the settlement that scheduled it.
A steer on a settled turn clears
promptSettledand advancesbackgroundFinalizeGeneration(adapter.ts:9812-9814). When the steered prompt settles again,followPromptschedules a new expiry (adapter.ts:9300). The earlier expiry still wakes at its original deadline. Its guard atadapter.ts:8855checks onlycontext.finalizedandcontext.promptSettled, so it can finalize the turn during the new hold. For example: settle at minute 0, steer at minute 20, settle again at minute 21 with the command still running. The old timer then finalizes at minute 30, nine minutes into the new hold, and terminalizes the still-running command row as completed.The expiry callback should return when a later settlement has replaced the one that armed it. Capture a token when the expiry is scheduled, and compare it inside the callback before finalizing. Do not reuse
backgroundFinalizeGenerationfor this token.scheduleDeferredFinalizealso increments it (adapter.ts:8815), so a reschedule on that path can disable an armed expiry. The token should change only on settlement or hold replacement.Source: Learnings