fix(labs): persist Antigravity resume state when a turn ends early - #6765
Open
LHMQ878 wants to merge 1 commit into
Open
fix(labs): persist Antigravity resume state when a turn ends early#6765LHMQ878 wants to merge 1 commit into
LHMQ878 wants to merge 1 commit into
Conversation
_run_async_impl renamed the trajectory and wrote the resume step index after the `async with`, so neither ran unless the turn reached the end of the step stream. Two ordinary paths skip it. A caller that stops reading closes the generator at a yield: the runner wraps agent generators in `aclosing` (runners.py:1415), so a disconnected client or a cancelled run does exactly that. The harness has already flushed traj-<random>, but the rename never happens, so the next turn finds no trajectory under the derived id, starts a brand new conversation, and leaves the old file behind for good. A harness error mid-stream loses the resume index the same way. Steps emitted before the failure are already recorded in the session, so the next turn replays them and records them a second time. Move both writes into a finally, and read conversation_id before the step loop rather than after it, so it is available on those paths. A turn that never reached the harness still writes nothing: there is no trajectory to rename and no step to remember.
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
What's wrong
AntigravityAgent._run_async_implrenamed the harness trajectory and wrote the resume step index after theasync withblock, so neither happened unless the turn ran to the end of the step stream. Two ordinary paths skip it.A caller that stops reading. The runner wraps agent generators in
contextlib.aclosing(runners.py:1415), so a disconnected SSE client or a cancelled run closes this generator at ayield.__aexit__still runs and the harness still flushestraj-<random>, but the statements after thewithdo not.A harness error mid-stream. Same skip, and here the events emitted before the failure are already in the session.
Reproduced
Driving
_run_async_implwith a stubbed SDK agent, on735402d:So in A the conversation is silently abandoned: the ADK session holds the turn's events, the harness is told nothing about it next time, and
traj-harness-randomis orphaned insave_dirpermanently. In B step 2 gets recorded twice.The fix
Move the rename and the index write into a
finally, and readactive_agent.conversation_idbefore the step loop rather than after it, so it is available when the loop does not finish.Both writes are plain synchronous file operations, which is what makes them safe in a
finallythat may be running underGeneratorExit— nothing is awaited and nothing is yielded there.The condition is
resumed or harness_conversation_id, so a turn that never reached the harness at all (sayAgent(config)raises) still writes nothing: there is no trajectory to rename and no step worth remembering, and a straytraj-<cid>.resumewould describe a conversation that never began.Tests
Three added to
tests/unittests/labs/antigravity/test_antigravity_agent.py:test_trajectory_is_claimed_when_the_caller_stops_readingtest_resume_index_survives_a_harness_error_mid_turn1test_a_turn_that_never_reaches_the_harness_records_nothingThe third passes on
mainby construction — it is a guard against this change writing state for a conversation that does not exist, not a regression test for the bug. Calling that out rather than presenting three red-to-green tests.Verification
pytest tests/unittests/labs/antigravity/→50 passed(was47 passed)2 failed, 48 passedpytest tests/unittests/labs/ tests/unittests/agents/→986 passed, 2 xfailed, no failurespyink --check→2 files would be left unchanged;isort --check-only→ exit 0Deliberately not in this PR
_trajectory_files.save_resume_step_indextruncates and then writes, so an interruption during the write leaves an empty file.load_resume_step_indextreats that as-1, and with the trajectory still present the whole conversation then replays. Putting the write in afinallymakes that window slightly more reachable, so it is worth a temp-file-plus-os.replacefollow-up — but it needs a crash to trigger and I have no test that demonstrates it, so I left it out rather than mixing a shown bug with a reasoned one. Happy to add it here if you would rather have both together.Follows on from #6040.