Skip to content

server: leave spec.sessionId empty when omitted - #760

Closed
mayawang wants to merge 1 commit into
google:mainfrom
mayawang:fix/drop-session-id-default
Closed

mayawang wants to merge 1 commit into
google:mainfrom
mayawang:fix/drop-session-id-default

Conversation

@mayawang

Copy link
Copy Markdown
Collaborator

Stop defaulting spec.sessionId to metadata.uid in CreateTask so one-off tasks write an empty AX_SESSION_FILE.

Motivation

Launchers read AX_SESSION_FILE to tell one-off tasks apart from multi-turn sessions. In agentexecutor/images#30 (and #31), ax-antigravity only deletes the remote Gemini API environment on exit when AX_SESSION_FILE is empty. Because ax-server defaulted spec.sessionId to metadata.uid, every server-created task passed a non-empty AX_SESSION_FILE and left its remote environment behind after finishing.

This changes the default added in #587 (from #542). metadata.uid still uniquely identifies each task; callers that want durable session state or lineage grouping set spec.sessionId explicitly.

Changes

  • internal/server/server.go: remove the task.Spec.SessionId = task.Metadata.Uid defaulting in CreateTask, and simplify taskSpecMatchesExisting to a nil-safe proto.Equal check.
  • pkg/apis/v1alpha1/task.proto and pkg/apis/v1alpha1/task.pb.go: update the session_id comment (regenerated via make verify; no descriptor/field changes).
  • internal/apivalidation/task.go, runner/launcher.go, docs/manifests.md, docs/local_installer.md: update comments and docs to note spec.sessionId stays empty when omitted.
  • internal/server/server_test.go: assert omitted sessionId stays empty in the lifecycle test and add TestServer_TaskSessionID covering omitted/explicit values and QUEUED retry immutability mismatches.
  • test/e2e/promote_test.go: set an explicit sessionId in promoteManifest so TestE2E_Promote keeps verifying non-empty sessionId preservation across ax promote.

Impact check

  • In-flight QUEUED retry across upgrade: dropping the UID shim in taskSpecMatchesExisting means a QUEUED task created by an older ax-server (with defaulted sessionId == metadata.uid) will reject a retry that omits sessionId with FailedPrecondition.
  • agentexecutor/images (antigravity/): empty AX_SESSION_FILE keeps per-task state under <workspace>/.ax and deletes the remote environment on exit; non-empty retains it under <workspace>/.ax/sessions/<id>.
  • agentexecutor/images (agents/antigravity): empty AX_SESSION_FILE skips symlinking ~/.gemini/antigravity-cli into /workspace/.ax/sessions/<id>. hack/hero-demo/task-starter.yaml already sets sessionId: hero-demo-session.
  • ax describe task / ax promote: ax describe already hides empty sessionId; ax promote copies task.Spec verbatim.
  • agentexecutor/studio: already falls back to task:<name> when sessionId is empty.

Follow-up note for agentexecutor/images: once this merges, remove the note about server-side spec.sessionId defaulting in antigravity/README.md.

Verification

make verify && git diff --exit-code && test -z "$(git ls-files --others --exclude-standard)"
go build -o /dev/null ./cmd/ax
go build -o /dev/null ./cmd/ax-server
go build -o /dev/null ./cmd/ax-runner
go test -c -o /dev/null ./test/e2e
go test -count=1 ./...
go test -race -count=1 ./internal/server/... ./cmd/ax/... ./runner/... ./pkg/apis/v1alpha1/... ./internal/apivalidation/...

Note: Postgres store integration tests skip locally when AX_TEST_POSTGRES_URL is unset and run in CI against postgres:17-alpine.

Stop defaulting spec.sessionId to metadata.uid inside CreateTask so
one-off tasks write an empty AX_SESSION_FILE.

Launchers use an empty AX_SESSION_FILE to distinguish one-off tasks from
multi-turn sessions. In agentexecutor/images#30 / google#31, ax-antigravity
deletes the remote Gemini API environment on exit only when
AX_SESSION_FILE is empty; defaulting spec.sessionId to metadata.uid
meant every server-created task looked like a named session and kept its
remote environment alive forever.

Reverses the server-side default introduced from google#542 / google#587. Callers
that want durable session state or lineage grouping (such as multi-turn
antigravity or agy runs) should set spec.sessionId explicitly.

Changes:
- internal/server/server.go: stop defaulting task.Spec.SessionId in
  CreateTask and simplify taskSpecMatchesExisting to direct proto.Equal
  comparison (dropping the clone + UID patch shim).
- pkg/apis/v1alpha1/task.proto (and regenerated task.pb.go): update the
  session_id field comment.
- internal/apivalidation/task.go, runner/launcher.go: update comments.
- docs/manifests.md, docs/local_installer.md: document optional empty
  default.
- internal/server/server_test.go: update the lifecycle check and add
  TestServer_TaskSessionID covering omitted/explicit sessionId and
  QUEUED retry immutability checks.
- test/e2e/promote_test.go: set an explicit spec.sessionId in
  promoteManifest so TestE2E_Promote keeps asserting non-empty sessionId
  preservation across ax promote.

Verification:
- make verify (buf format/lint/generate, go mod tidy, go fmt, golangci-lint: 0 issues)
- go build -o /dev/null ./cmd/ax ./cmd/ax-server ./cmd/ax-runner
- go test -c -o /dev/null ./test/e2e
- go test -count=1 ./... (pass; postgres store tests skip locally without AX_TEST_POSTGRES_URL)
- go test -race -count=1 ./internal/server/... ./cmd/ax/... ./runner/... ./pkg/apis/v1alpha1/... ./internal/apivalidation/...
@mayawang
mayawang requested a review from rakyll as a code owner November 25, 2026 00:38
Comment thread docs/manifests.md
- **`spec.goal.text`** is an optional natural-language description of the task's objective, delivered as part of the task metadata.
- **`spec.retry`** configures retry limits and backoff (`maxRetries >= 0`, non-negative `initialBackoff` and `maxBackoff` with `initialBackoff <= maxBackoff`, and `backoffMultiplier >= 1.0` when set). *Not available yet: ax-server rejects `spec.retry` until task retries are wired.*
- **`spec.sessionId`** groups related tasks or multi-turn runs under one correlation ID. When omitted, `CreateTask` defaults it to the server-assigned `metadata.uid`.
- **`spec.sessionId`** is an optional correlation ID for grouping related tasks or multi-turn runs. When omitted, it stays empty.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we generate a UUID instead of allowing an empty one. It's better to have a non-empty session_id.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, keeping session_id non-empty is better and main already defaults it to metadata.uid (a generated UUID) with docs and test coverage. Closing this out and I'll handle remote environment cleanup on the agentexecutor/images side instead (deleting the self-hosted environment after each turn while keeping last_interaction_id saved for follow-up turns).

@mayawang mayawang closed this Nov 25, 2026
mayawang added a commit to agentexecutor/images that referenced this pull request Nov 25, 2026
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 added a commit to agentexecutor/images that referenced this pull request Nov 25, 2026
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.
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