Skip to content

fix(agy): delete self-hosted environment at end of every turn - #33

Merged
mayawang merged 1 commit into
mainfrom
fix/antigravity-cleanup-env-on-finish
Nov 25, 2026
Merged

mayawang merged 1 commit into
mainfrom
fix/antigravity-cleanup-env-on-finish

Conversation

@mayawang

@mayawang mayawang commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to google/ax#760 (closed in favor of keeping ax-server's non-empty spec.sessionId default).

What changed

  • agy/main.go (finish): Always delete the ephemeral remote self-hosted environment when a turn completes or exits with an error, and drop the cached environment.Key from disk. When AX_SESSION_FILE is set, retain last_interaction_id and the done digest under <workspace>/.ax/sessions/<id>/managed-agent.json so follow-up turns continue from previous_interaction_id. Mid-interaction suspends (exit 143) and transient poll errors keep the live environment and pending state intact to reattach on resume.
  • agy/README.md: Document the per-turn environment lifecycle and note that the environment key stays on disk only while an interaction is in flight.
  • agy/main_test.go: Update TestSession and TestRequiresActionClearsPendingAndDeletesEnv to verify remote environments are deleted after each turn while preserving last_interaction_id for subsequent turns.

Verification

  • ./scripts/verify/boilerplate.sh (pass)
  • cd agy && gofmt -l . (clean)
  • cd agy && go vet ./... (clean)
  • cd agy && go test -race -count=1 ./... (all unit tests pass against the fake Gemini API, 19.9s)
  • Live two-turn check against the real Gemini API (GEMINI_API_KEY + gemini-api v0.5.0, AX_SESSION_FILE set): Turn 1 created and deleted 51bfd12c-44b4-4955-bfc3-37ccbd8554c9, writing managed-agent.json (0600) with last_interaction_id only (environment omitted). Turn 2 created a fresh environment (352f219a-e0f4-476d-81d7-86d090f2dce4), chained via previous_interaction_id, recalled the in-memory codeword CEDAR-88, and deleted its environment on exit (0 leftover remote environments after each turn).

Follow up on google/ax#760 discussion: keep ax-server's non-empty
spec.sessionId default (metadata.uid) and stop skipping deleteEnvironment
when AX_SESSION_FILE is non-empty.

Each turn now deletes its ephemeral remote self-hosted environment on exit
and drops the environment key from disk while preserving last_interaction_id
and done digest under <workspace>/.ax/sessions/<id>/managed-agent.json so
follow-up turns continue via previous_interaction_id. Mid-interaction
suspends (exit 143) and transient poll errors keep the live environment and
pending state intact so resume still reattaches.

Verification:
- ./scripts/verify/boilerplate.sh (pass)
- cd agy && gofmt -l . (clean)
- cd agy && go vet ./... (clean)
- cd agy && go test -race -count=1 ./... (all unit tests pass; 19.851s)
- Live two-turn check against Gemini API (GEMINI_API_KEY + gemini-api v0.5.0
  on PATH, AX_SESSION_FILE set): Turn 1 created env 51bfd12c-44b4-4955-bfc3-37ccbd8554c9
  and deleted it on exit (0 remaining self-hosted envs, mode 0600 state with
  last_interaction_id only and no environment key); Turn 2 created fresh env
  352f219a-e0f4-476d-81d7-86d090f2dce4, chained via previous_interaction_id,
  recalled the in-memory codeword CEDAR-88, and deleted its env on exit (0
  remaining self-hosted envs).
  Reproduce: build ./agy, set GEMINI_API_KEY and AX_SESSION_FILE, run two
  sequential turns in the same workspace, and check `gemini-api environments
  list --mode self_hosted` and `managed-agent.json` after each turn.
@mayawang
mayawang force-pushed the fix/antigravity-cleanup-env-on-finish branch from 3cfbd98 to c97809c Compare November 25, 2026 04:59
@mayawang mayawang changed the title fix(antigravity): delete self-hosted environment at end of every turn fix(agy): delete self-hosted environment at end of every turn Nov 25, 2026
@mayawang
mayawang marked this pull request as ready for review November 25, 2026 04:59
@mayawang

Copy link
Copy Markdown
Collaborator Author

Rebased onto main after #34 (antigravity/ -> agy/) with no functional changes from 3cfbd98, and verified live two-turn continuity against the Gemini API with AX_SESSION_FILE set:

  • Turn 1 created env 51bfd12c-44b4-4955-bfc3-37ccbd8554c9, wrote managed-agent.json (0600) with last_interaction_id only (environment absent), and deleted the remote env on exit (0 remaining).
  • Turn 2 created a fresh env 352f219a-e0f4-476d-81d7-86d090f2dce4, chained via previous_interaction_id, recalled the in-memory codeword from Turn 1, and deleted the remote env on exit (0 remaining).

Marking ready for review.

@mayawang
mayawang merged commit 623e713 into main Nov 25, 2026
8 checks passed
mayawang added a commit that referenced this pull request Nov 25, 2026
Update agy-cli to match the google/ax runner, launcher, and data-plane
output changes (supersedes draft #29 after #34):

- agy-cli/Dockerfile: install the launcher at /usr/local/bin/ax-launcher
  (google/ax#734) and symlink /usr/local/bin/ax-harness -> ax-launcher
  for v0.4.0-rc.1 compatibility.
- agy-cli/verify_image.sh: fail if either ax-runner (google/ax#677) or
  ax-task-runner is present, and require both /usr/local/bin/ax-launcher
  and /usr/local/bin/ax-harness.
- agy-cli/ax-harness and .github/workflows/agy-cli.yaml: update comments,
  ax-launcher stderr prefixes, and workflow step title.
- agy-cli/README.md: update ax-task-runner -> ax-runner, ax-harness ->
  ax-launcher (with compatibility symlink note), and status.outcome.output
  -> <workspace>/.ax/output (google/ax#756).

Leaves agy/ untouched so #33 stays conflict-free.

Verification:
- ./scripts/verify/boilerplate.sh (pass)
- bash -n agy-cli/ax-harness agy-cli/verify_image.sh agy-cli/test_harness.sh (pass)
- ./agy-cli/test_harness.sh (ALL AX-HARNESS TESTS PASSED)
- ./fakes/mock-gemini/selftest.sh (ALL MOCK GEMINI SELFTEST CHECKS PASSED)
- python3 -c "import yaml; yaml.safe_load(open('.github/workflows/agy-cli.yaml'))" (pass)
- Mocked docker verification of ./agy-cli/verify_image.sh (runtime/bundled pass; rejects ax-runner, ax-task-runner, missing ax-launcher, missing ax-harness)
- (cd agy && go vet ./... && go test -race -count=1 ./...) (pass)
- Note: local docker build skipped (no Docker socket in this environment); covered by the agy-cli and Release Images dry-run PR workflows.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants