Repository navigation
fix(antigravity): advertise supportsBackgroundWait and honor awaited: false #39990
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
base: main
Are you sure you want to change the base?
Changes from all commits
69f68da
7ced33a
e140722
eb88dba
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 |
|---|---|---|
|
|
@@ -1693,6 +1693,7 @@ interface ActiveAcpTurn { | |
| { readonly status: "completed" | "failed"; readonly output?: string } | null | ||
| >; | ||
| readonly persistentBackgroundTaskIds: Set<string>; | ||
| readonly unawaitedToolCallIds: Set<string>; | ||
| /** Monitor end notices lack output; wait for hydration or the safety timeout. */ | ||
| readonly awaitingBackgroundHydration: Set<string>; | ||
| readonly pendingInjectedReport: Set<string>; | ||
|
|
@@ -2646,6 +2647,10 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( | |
| const detachedBackgroundCommands = yield* Ref.make<ReadonlyMap<string, ActiveAcpTurn>>( | ||
| new Map(), | ||
| ); | ||
| // Released outliving tool calls without a background task id → the completed turn that owns their row. | ||
| const detachedUnawaitedTools = yield* Ref.make<ReadonlyMap<string, ActiveAcpTurn>>( | ||
| new Map(), | ||
| ); | ||
| const endedDetachedBackgroundCommandLimit = 16; | ||
| const detachedBackgroundCommandTurn = (taskId: string) => | ||
| Ref.get(detachedBackgroundCommands).pipe(Effect.map((turns) => turns.get(taskId))); | ||
|
|
@@ -2656,8 +2661,8 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( | |
| const active = yield* Ref.get(activeTurn); | ||
| return active?.finalized === false ? active : undefined; | ||
| }); | ||
| const detachBackgroundCommands = (context: ActiveAcpTurn) => | ||
| Ref.update(detachedBackgroundCommands, (current) => { | ||
| const detachBackgroundCommands = Effect.fnUntraced(function* (context: ActiveAcpTurn) { | ||
| yield* Ref.update(detachedBackgroundCommands, (current) => { | ||
| const next = new Map(current); | ||
| for (const taskId of context.backgroundCommands.keys()) next.set(taskId, context); | ||
| const ended = [...next].filter(([taskId, turn]) => { | ||
|
|
@@ -2671,6 +2676,24 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( | |
| } | ||
| return next; | ||
| }); | ||
| if (context.unawaitedToolCallIds.size > 0) { | ||
| yield* Ref.update(detachedUnawaitedTools, (current) => { | ||
| const next = new Map(current); | ||
| for (const toolCallId of context.unawaitedToolCallIds) { | ||
| if (context.tools.has(toolCallId)) next.set(toolCallId, context); | ||
| } | ||
| const ended = [...next].filter(([toolCallId, turn]) => { | ||
| const tool = turn.tools.get(toolCallId); | ||
| const status = tool === undefined ? "completed" : toolStatus(tool.status); | ||
| return status !== "pending" && status !== "running"; | ||
| }); | ||
| for (const [toolCallId] of ended.slice(0, -endedDetachedBackgroundCommandLimit)) { | ||
| next.delete(toolCallId); | ||
| } | ||
| return next; | ||
| }); | ||
| } | ||
| }); | ||
| // Tombstones prevent mid-stream exit_code 0 and stale monitor events from resurrecting ended tasks. | ||
| const endedBackgroundTaskIds = yield* Ref.make<ReadonlySet<string>>(new Set()); | ||
| const endedBackgroundTaskIdLimit = 128; | ||
|
|
@@ -4297,7 +4320,11 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( | |
| // A tool that never started has nothing to report later. | ||
| for (const tool of context.tools.values()) { | ||
| if (ignoreTool?.(tool) === true) continue; | ||
| if (toolStatus(tool.status) === "running" && flavor.toolOutlivesPrompt(tool)) | ||
| if ( | ||
| toolStatus(tool.status) === "running" && | ||
| !context.unawaitedToolCallIds.has(tool.toolCallId) && | ||
| flavor.toolOutlivesPrompt(tool) | ||
| ) | ||
| return true; | ||
| } | ||
| } | ||
|
|
@@ -5395,6 +5422,25 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( | |
| return true; | ||
| }); | ||
|
|
||
| // A released outliving tool keeps its original row updated when its real completion arrives. | ||
| const projectDetachedUnawaitedTool = Effect.fnUntraced(function* ( | ||
| notification: EffectAcpSchema.SessionNotification, | ||
| active: ActiveAcpTurn | null, | ||
| ) { | ||
| const update = notification.update; | ||
| if (update.sessionUpdate !== "tool_call" && update.sessionUpdate !== "tool_call_update") { | ||
| return false; | ||
| } | ||
| if (active?.finalized === false && active.tools.has(update.toolCallId)) return false; | ||
| if (notification.sessionId !== (yield* Ref.get(activeSessionId))) return false; | ||
| const owner = (yield* Ref.get(detachedUnawaitedTools)).get(update.toolCallId); | ||
| if (owner === undefined) return false; | ||
| for (const event of parseSessionUpdateEvent(notification).events) { | ||
| if (event._tag === "ToolCallUpdated") yield* emitTool(owner, event.toolCall); | ||
| } | ||
| return true; | ||
| }); | ||
|
|
||
| const bufferPostSettleWake = Effect.fnUntraced(function* ( | ||
| notification: EffectAcpSchema.SessionNotification, | ||
| ) { | ||
|
|
@@ -5420,11 +5466,15 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( | |
| stopProcessing: false, | ||
| }; | ||
| } | ||
| const projectedDetachedUnawaitedTool = yield* projectDetachedUnawaitedTool( | ||
| notification, | ||
| null, | ||
| ); | ||
| if (!acpPostSettleWakeEvidence(notification, flavor)) { | ||
| return { | ||
| buffered: false, | ||
| offerContinuation: false, | ||
| stopProcessing: false, | ||
| stopProcessing: projectedDetachedUnawaitedTool, | ||
| }; | ||
| } | ||
| const update = notification.update; | ||
|
|
@@ -5468,6 +5518,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( | |
| let buffered = false; | ||
| if ( | ||
| !alreadyHandledToolUpdate && | ||
| !projectedDetachedUnawaitedTool && | ||
| !isInTurnHandledAgentChatter && | ||
| acpPostSettleWakeShouldBuffer(notification, backgroundWorkRunning) | ||
| ) { | ||
|
|
@@ -5775,6 +5826,12 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( | |
| return; | ||
| if (yield* projectAgentTerminalUpdate(notification, context)) return; | ||
| if (yield* projectDetachedBackgroundCommand(notification, context)) return; | ||
| if ( | ||
| context !== null && | ||
| !context.finalized && | ||
| (yield* projectDetachedUnawaitedTool(notification, context)) | ||
|
Comment on lines
+5831
to
+5832
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. A released command's completion can be dropped during deferred finalization. When a released command finishes while Require that a released command's completion updates its original tool row in every finalization state, including the window before detachment. Choose an ordering or gate change that guarantees this. Do not drop the update when the context is finalized.
|
||
| ) | ||
| return; | ||
| if (flavor.replyEndsWithUsageUpdate === true) { | ||
| if (context === null) { | ||
| // A reply can end before its continuation run starts; replay its end with its output. | ||
|
|
@@ -8011,6 +8068,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( | |
| yield* Ref.set(continuationRequested, false); | ||
| yield* Ref.set(runningBackgroundTaskIds, new Set()); | ||
| yield* Ref.set(detachedBackgroundCommands, new Map()); | ||
| yield* Ref.set(detachedUnawaitedTools, new Map()); | ||
| yield* Ref.set(endedBackgroundTaskIds, new Set()); | ||
| yield* Ref.set(midTurnUnreportedCompletedTaskIds, new Set()); | ||
| yield* Ref.set(handledBackgroundTaskIdsInActiveTurn, new Set()); | ||
|
|
@@ -8534,6 +8592,9 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( | |
| options?: { readonly unstartedOnly?: boolean }, | ||
| ) { | ||
| for (const tool of context.tools.values()) { | ||
| if (status === "completed" && context.unawaitedToolCallIds.has(tool.toolCallId)) { | ||
| continue; | ||
| } | ||
| if (!acpCompletedTurnShouldTerminalizeTool(tool, { ...flavor, extractSubagentUpdate })) | ||
| continue; | ||
| if (options?.unstartedOnly === true && tool.status !== "pending") continue; | ||
|
|
@@ -8575,6 +8636,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( | |
| yield* Ref.set(continuationRequested, false); | ||
| yield* Ref.set(runningBackgroundTaskIds, new Set()); | ||
| yield* Ref.set(detachedBackgroundCommands, new Map()); | ||
| yield* Ref.set(detachedUnawaitedTools, new Map()); | ||
| yield* Ref.set(midTurnUnreportedCompletedTaskIds, new Set()); | ||
| yield* Ref.set(carryoverSubagents, null); | ||
| yield* Ref.set(lastTurnRoute, null); | ||
|
|
@@ -9555,6 +9617,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( | |
| toolCallIdsByBackgroundTaskId: new Map(), | ||
| backgroundCommands: new Map(), | ||
| persistentBackgroundTaskIds: new Set(), | ||
| unawaitedToolCallIds: new Set(), | ||
| awaitingBackgroundHydration: new Set(), | ||
| pendingInjectedReport: new Set(), | ||
| earlyInjectedReportObserved: false, | ||
|
|
@@ -10239,19 +10302,38 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( | |
| awaitBackgroundTasks: Effect.fn("AcpAdapterV2.awaitBackgroundTasks")(function* ({ | ||
| providerThread, | ||
| taskIds, | ||
| awaited, | ||
| }) { | ||
| const outlives = flavor.toolOutlivesPrompt; | ||
| const context = yield* Ref.get(activeTurn); | ||
| const holdsCommand = | ||
| outlives !== undefined && | ||
| defersFinalizeForBackgroundWork && | ||
| context !== null && | ||
| !context.finalized && | ||
| context.nativeThreadId === providerThread.nativeThreadRef?.nativeId && | ||
| [...context.tools.values()].some( | ||
| (tool) => toolStatus(tool.status) === "running" && outlives(tool), | ||
| ); | ||
| return { matched: holdsCommand ? [...new Set(taskIds)] : [] }; | ||
| if ( | ||
| outlives === undefined || | ||
| !defersFinalizeForBackgroundWork || | ||
| context === null || | ||
| context.finalized || | ||
| context.nativeThreadId !== providerThread.nativeThreadRef?.nativeId | ||
| ) { | ||
| return { matched: [] }; | ||
| } | ||
| const runningOutliving = [...context.tools.values()].filter( | ||
| (tool) => toolStatus(tool.status) === "running" && outlives(tool), | ||
| ); | ||
| if (awaited) { | ||
| if (runningOutliving.length === 0) return { matched: [] }; | ||
| for (const tool of runningOutliving) { | ||
| context.unawaitedToolCallIds.delete(tool.toolCallId); | ||
| } | ||
| return { matched: [...new Set(taskIds)] }; | ||
| } | ||
| const held = runningOutliving.filter( | ||
| (tool) => !context.unawaitedToolCallIds.has(tool.toolCallId), | ||
| ); | ||
| if (held.length === 0) return { matched: [] }; | ||
| for (const tool of held) { | ||
| context.unawaitedToolCallIds.add(tool.toolCallId); | ||
| } | ||
| yield* rearmDeferredFinalize(context); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| return { matched: [...new Set(taskIds)] }; | ||
| }), | ||
| }), | ||
| interruptTurn: Effect.fn("AcpAdapterV2.interruptTurn")( | ||
|
|
||
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.
Assert that release does not cancel the command.
The fixture replaces
runtime.cancelwith a counter-only effect. A release path that incorrectly calls it could still pass because the test injects command completion manually. Assertrun.cancels() === 0after the terminal event to cover the PR's “without stopping them” requirement. Extend this test rather than adding another case. (raw.githubusercontent.com)As per path instructions, “Test behavior that can regress” and “avoid duplicating coverage.”
Source: Path instructions