Repository navigation
fix(antigravity): keep turns open when a background wake is still pending - #39989
Merged
juliusmarminge merged 3 commits intoNov 21, 2026
Merged
juliusmarminge merged 3 commits into
juliusmarminge merged 3 commits into
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When an Antigravity (
agy) turn has a background task complete while a model reply is already in flight, T3 Code can finalize the turn early and (for delegated tasks) sendsession/close, terminatingagybefore it streams the follow-up wake reply.Observed live on
0.1.12-nightly.20261120.4994(gemini-4-neon, delegated task):bin/gates backandEmailBodyAsDocumentTest.php) stayed running pastsession/prompt(end_turnat16:46:10.537Z).16:46:21.356Zand started wake reply oxc stack #1 (~9 s TTFB on 357k tokens).16:46:21.859Z) while reply oxc stack #1 was still in flight;agyqueued itsMESSAGE_PRIORITY_HIGHcompletion in.system_generated/messages/.16:46:30.295Z) and ended withusage_updateat~16:46:30.739Z.agyimmediately dequeued command Add open-in-editor feature with Cmd+O shortcut #2 intotranscript.jsonl(step_index: 163,SYSTEM_MESSAGE,16:46:30Z) and started wake reply Add open-in-editor feature with Cmd+O shortcut #2.usage_updateoxc stack #1, T3 saw no running tools left, setcontext.replyOpen = false, armed the 3 sACP_DEFERRED_FINALIZE_DEBOUNCE, finalized the turn at16:46:33.739Zbefore reply Add open-in-editor feature with Cmd+O shortcut #2's first token could arrive, and sentsession/closeat16:46:34.201Z.The same race also occurs when a single background command finishes while the initial prompt's final
PLANNER_RESPONSEis still in flight, so the tool is alreadycompletedwhensession/promptreturnsend_turnwhile its wake sits unread in the inbox.Fix
hasPendingReply(sessionId)hook onAcpAdapterV2Flavorinpackages/provider-acp/src/server/adapter.ts:scheduleDeferredFinalize, when the 3 s post-usage_updatedebounce expires (!replyOpen), checkhasPendingReply. If true, re-opencontext.replyOpen = trueand extend into a singleACP_OPEN_REPLY_QUIET_LIMIT(2 min) wait instead of finalizing early; serialize the final check andfinalizeTurnunderruntimeCallbackPermit. Because it only extends from!replyOpen, a stalled wake still finishes after the 2-minute quiet limit and cannot loop.session/promptcompletion (status === "completed"), checkhasPendingReplywhen no background tool or subagent is still running so a pre-end_turnbackground completion holds the turn open until its wake reply finishes.readAntigravityPendingReplyinapps/server/src/provider/acp/AntigravityChildWork.tsand wire it inapps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.tswhenprofileDirectoryis set:.system_generated/messages/againstread.jsonfor unreadMESSAGE_PRIORITY_HIGHmessages (ignoringMESSAGE_PRIORITY_LOWnotices such as cancelled tasks or restart notices)..system_generated/logs/transcript.jsonl(64 KiB fast path, 256 KiB cap) for a trailing wakingSYSTEM_MESSAGEstep with no subsequentPLANNER_RESPONSE.antigravityManagedPathandO_NOFOLLOWand fails closed on missing, linked, or corrupt records.agybatches multiple completions into a single reply (all receipts read and transcript ends inPLANNER_RESPONSE), finalizing in 3 s as before.Tests
apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts:session/promptreturnsend_turnwith an unread high-priority wake.apps/server/src/provider/acp/AntigravityChildWork.test.ts:readAntigravityPendingReplycovering high vs. low priority unread messages,read.jsonreceipts, trailingSYSTEM_MESSAGEvs.PLANNER_RESPONSE, >64 KiB transcript tails, corruptread.json, invalid session IDs, and symlinks.vp run check:changed(format, lint, knip, graphql, typecheck across 14 packages, 47 tests) andvp test run apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts -t "defer|background|usage_update|wake"(14 passed).Written by Gemini 4 Neon, in Antigravity.