fix(antigravity): keep turns open when a background wake is still pending #39989
Mergedmkantautas(GitHub profile, opens in a new tab)merged 3 commits into
main fromrefs/pull/39989/headmerged by juliusmarminge View on GitHubtanstack-source added labelsbug
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- @@ -653,0 +670,21 @@670+671+async function hasUnreadWakingInboxMessage(672+ profileRoot: string,673+ sessionId: string,674+): Promise<boolean> {675+ const directory = ["antigravity-acp", "brain", sessionId, ".system_generated", "messages"];676+ const inbox = await antigravityManagedPath(profileRoot, directory, "directory");677+ if (inbox === undefined) return false;678+ const entries = await NodeFSP.readdir(inbox.path).catch(() => undefined);679+ if (entries === undefined) return false;680+ const messageNames = entries.filter((name) => name.endsWith(".json") && name !== "read.json");681+ if (messageNames.length === 0 || messageNames.length > MAX_MESSAGE_FILES) return false;682+ let readReceipts: Readonly<Record<string, boolean>> = {};683+ if (entries.includes("read.json")) {684+ const receiptFile = await antigravityManagedPath(685+ profileRoot,686+ [...directory, "read.json"],687+ "file",688+ );689+ if (receiptFile === undefined || receiptFile.info.size > MAX_STEP_BYTES) return false;690+ const rawReceipts = await NodeFSP.readFile(receiptFile.path, "utf8").catch(() => undefined);@@ -653,0 +722,21 @@722+ transcript.path,723+ NodeFS.constants.O_RDONLY | (NodeFS.constants.O_NOFOLLOW ?? 0),724+ );725+ try {726+ const stat = await handle.stat();727+ if (!stat.isFile() || stat.size === 0) return undefined;728+ for (const byteCap of [PENDING_REPLY_TAIL_BYTES, TRANSCRIPT_BYTE_CAP]) {729+ const start = Math.max(0, stat.size - byteCap);730+ const buffer = Buffer.alloc(stat.size - start);731+ const { bytesRead } = await handle.read(buffer, 0, buffer.length, start);732+ let end = bytesRead;733+ while (end > 0 && (buffer[end - 1] === 0x0a || buffer[end - 1] === 0x0d)) {734+ end -= 1;735+ }736+ if (end === 0) {737+ if (start === 0) return undefined;738+ continue;739+ }740+ const trimmed = buffer.subarray(0, end);741+ const lastNewline = trimmed.lastIndexOf(0x0a);742+ if (lastNewline === -1 && start > 0) continue;@@ -8691,8 +8695,13 @@8691- context.interrupted ||8692- context.backgroundFinalizeGeneration !== generation8693- ) {8694- return;8695- }8696- if (hasDeferredBackgroundWork(context)) return;8697- const status = context.promptSettledStatus ?? "completed";8698- yield* finalizeTurn(context, status);8695+ const stillCurrent = () =>8696+ !context.finalized &&8697+ !context.interrupted &&8698+ context.backgroundFinalizeGeneration === generation &&8699+ !hasDeferredBackgroundWork(context);8700+ if (!stillCurrent()) return;8701+ const pendingReply =8702+ !replyOpen && flavor.hasPendingReply !== undefined8703+ ? yield* flavor.hasPendingReply(context.nativeThreadId)8704+ : false;8705+ yield* runtimeCallbackPermit.withPermit(8706+ Effect.gen(function* () {8707+ if (!stillCurrent()) return;
juliusmarminge added labelstakeover:in-progress
Pushedcb1da2b
- @@ -9153,8 +9171,17 @@91539171 }91549172 yield* idleReportedSubagents(context);91559173 if (context.finalized) return;9156- if (9174+ const deferredBackgroundWork =91579175 defersFinalizeForBackgroundWork &&91589176 !context.interrupted &&9159- hasDeferredBackgroundWork(context)9160- ) {9177+ hasDeferredBackgroundWork(context);9178+ const pendingReply =9179+ !deferredBackgroundWork &&9180+ defersFinalizeForBackgroundWork &&9181+ status === "completed" &&9182+ !context.interrupted &&9183+ flavor.hasPendingReply !== undefined9184+ ? yield* flavor.hasPendingReply(context.nativeThreadId)9185+ : false;9186+ if (context.finalized) return;9187+ if (deferredBackgroundWork || pendingReply) {
Sign in to join this conversation.


No actionable comments were generated in the recent review.
Walkthrough
The ACP adapter can check whether an Antigravity session has a pending reply. It keeps the turn open when a reply is pending and rechecks during deferred finalization. New tests cover inbox and transcript detection, multiple background replies, and a wake received before prompt settlement.
Changes: Pending reply handling
apps/server/src/provider/acp/AntigravityChildWork.ts,apps/server/src/provider/acp/AntigravityChildWork.test.ts,apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.tspackages/provider-acp/src/server/adapter.ts,apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.tsEstimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix
Sequence Diagram(s)#
Possibly related issues
Possibly related PRs
Suggested labels:
bugfixSuggested reviewers:
macroscopeapp,juliusmarminge,codder13Merge Risk:
Moderate · up to
6fbcbThis change keeps Antigravity turns open while a background wake reply is pending. Several edge cases remain open. A reply can still be cut off when it is already streaming at prompt settlement or when a wake arrives just before finalization. A transport exit during the hold can be reported as a normal completion. Two minor robustness gaps remain in the inbox and transcript readers. These are bounded, non-destructive problems, but they should be resolved or explicitly accepted before merge.
Pre-merge checks:
4
Full details: Title check
Explanation
The title "fix(antigravity): keep turns open when a background wake is still pending" matches the main change. The diff adds a hasPendingReply hook to the ACP adapter and an Antigravity probe that keeps turns open while a high-priority wake reply is unread or still in the transcript tail. The title is a conventional commit that states the fix in plain language, and it stays under the 73-character length it reports.
Full details: Description check
Explanation
The description follows the template sections: Problem, Change (Fix), Scope, Verification, and Tests. The Problem section gives a concrete reproduction with timestamps and versions. The Change section explains the hook, the probe, and the fail-closed behavior. The Verification section lists specific commands and pass counts. The Scope section does not link an issue or state that a maintainer requested the PR, so the description leaves that template item incomplete. It also does not include an agent attribution line in the form the template asks for, although it does end with "Written by Gemini 4 Neon, in Antigravity." The main requirements are covered, so the check passes with a minor gap.
Finishing Touches
Generate unit tests (beta)
15e6cbcb-1f8a-459a-96b6-0c61797f1990Reviewing files that changed from the base of the PR and between cb1da2b6748e21462f699a08ace25bd9c92823d7 and 6fbcbb185053529f86af172e71e1eb687b476175.
packages/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.