Repository navigation
feat(adapters): snapshots, fork and pause/resume on GKE for agent-sandbox - #131
Merged
Merged
Conversation
reachjalil
force-pushed
the
feat/agent-sandbox-gke-pod-snapshots
branch
from
November 20, 2026 02:07
03acbf4 to
155dab7
Compare
…dbox The agent-sandbox adapter (experimental) gains GKE Pod Snapshots (podsnapshot.gke.io/v1) for Sandboxes that run under gVisor, turned on with config.podSnapshotPolicy: - Snapshot: a PodSnapshotManualTrigger for the sandbox's pod, waited on until the PodSnapshot is Ready. It captures memory, processes and the root filesystem; the sandbox keeps running. - Fork: a Sandbox with the source's pod spec and snapshot group, naming the snapshot in podsnapshot.gke.io/ps-name. - Pause/resume (lifecycle.pause-checkpoint): checkpoint, then suspend, so the pod is deleted and the sandbox holds no slot; resume restores it. Only the newest pause checkpoint is kept, and delete removes them. GKE restores any new pod whose spec matches the newest snapshot unless snapshots are grouped, which could start one tenant's sandbox from another's memory. Every sandbox's pod therefore gets a snapshot-group label of its own, and the pool is unhealthy unless the PodSnapshotPolicy selects on and groups by it, is manual, keeps whole pods and does not evict per group. GKE also starts a pod fresh, silently, when it cannot restore it, so the adapter writes a token before each checkpoint and reads it back after a restore: a fork without it fails and is deleted, and a resume without it suspends the sandbox again. Tested with a fake API server that plays GKE's snapshot controller; the fake now applies real JSON merge patches. TestLivePodSnapshots is written but has not run on GKE. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Jalil <reachjalil@gmail.com>
…il closed Addresses an independent review of the GKE Pod Snapshots support: - A fork stayed in its source's snapshot group, so a source whose pod GKE recreated (a node drain, or stop/start) could come back from its fork's newer snapshot, crossing projects within an org. Once its restore is verified, a fork now moves to a group of its own and stops naming the snapshot; agent-sandbox's controller patches the running pod's labels rather than recreating it, and the adapter waits until it has. - After a resume the template kept naming the pause checkpoint, so a recreated pod rolled back to it. Resume now clears it. - Stop/start would restore the newest checkpoint over a newer volume; it is no longer offered with snapshots. - A pause whose suspend did not finish left the Sandbox suspended while the scheduler recorded it running. It is now set running again, and the timeout is sandbox_failed. - A resume GKE never restores retried for ever. After three, the sandbox reports an error, which fails it. - One marker file was shared by concurrent checkpoints. Each checkpoint now has its own. - Pause checkpoints of Sandboxes deleted behind Differently's back (the TTL backstop) are collected on List; triggers carry the installation label. - A fork ran at its source's size whatever was asked for, so capacity and quotas under-counted it. A fork at another size is now refused. The fake now restores as GKE documents it (the named snapshot, or else the newest in the pod's group), and new tests cover each case above. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Jalil <reachjalil@gmail.com>
…view - A pause whose context is cancelled (the reconciler recorded the pause and the scheduler stopped waiting) is no longer undone; only a suspend that times out is. A sandbox reports paused only once its pod is gone, pending until then. A failed undo is reported. - Only a pod that answers without the marker counts as not restored; a check that could not run suspends the sandbox again without counting. A sandbox that reaches the limit keeps its pause checkpoint, relabelled unrestored, when it is deleted: it is the only copy of its state. - A fork whose Create was interrupted is finished by List (checked and moved to its own group) or deleted so it is created again; it is never listed while still in its source's group, where the reconciler would adopt it. - Orphaned pause checkpoints are collected only when older than 15 minutes, so a sandbox created during a long List keeps its own. The Role in the docs gains patch on podsnapshotmanualtriggers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Jalil <reachjalil@gmail.com>
reachjalil
force-pushed
the
feat/agent-sandbox-gke-pod-snapshots
branch
from
November 20, 2026 02:15
54e37d6 to
f6c0ed9
Compare
The GKE Agent Sandbox entry named the agentsandbox adapter, which the agent-sandbox entry already does; the console's catalog test requires each adapter name once. The GKE page links to the agent-sandbox adapter instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Jalil <reachjalil@gmail.com>
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
Fast sandboxes that can be snapshotted, on GCP without running VMs ourselves: the experimental
agent-sandboxadapter now drives GKE Pod Snapshots (podsnapshot.gke.io/v1) for Sandboxes under gVisor. A pool turns it on withconfig.podSnapshotPolicy(andruntimeClassName: gvisor), and then advertisessnapshots.memory,snapshots.disk,fork,lifecycle.pause-resumeandlifecycle.pause-checkpoint.PodSnapshotManualTriggerfor the pod, waited on until thePodSnapshotisReady. Captures memory, processes and the root filesystem; the sandbox keeps runningpodsnapshot.gke.io/ps-namenaming the snapshotoperatingMode: Suspended(the pod is deleted, no slot held); resume restores it. Only the newest pause checkpoint is kept, and delete removes themPodSnapshot(GKE removes the files) and its triggerWith the existing warm pools (adopting a pod in 0.5–1 s on kind), this gives the fast-start path. Warm pools and snapshots don't combine (see the docs for why).
Two GKE behaviours handled fail-closed
differently.dev/snapshot-groupwith a value of its own (a fork gets its source's), and the pool is unhealthy unless the policy selects on and groups by that label. It must also bemanual, keepwhole-podand not setmaxSnapshotCountPerGroup./tmp/.differently-snapshotbefore each checkpoint and reads it back after a restore. A fork without it fails (sandbox_failed) and is deleted. A resume without it suspends the sandbox again (it stayspaused) and fails, and the scheduler retries later.A paused sandbox reports
paused, notstopped, so the reconciler doesn't mark it as stopped unexpectedly.Docs:
docs/providers/agent-sandbox.mdgets a GKE section (cluster, bucket, storage config, policy, RBAC, pool config).gke-agent-sandbox.mdno longer says there is no adapter. The catalog, feature parity, site data and changelog are updated.After an independent review (second commit)
A review of the first version found no cross-org path (the server only forks snapshots from the caller's own org), but did find these, now fixed and tested:
sandbox_failed.error, which fails it.List.The fake now restores as GKE documents it (the named snapshot, or else the newest in the pod's group). New tests cover each case. Deliberately breaking the regrouping or the template clearing makes them fail.
After a second review of those fixes (third commit)
pausedonly once its pod is gone.unrestored) when the sandbox is deleted, since it's the only copy of the state.List(verified and regrouped), or deleted so it is created again. It is never listed while still in its source's group.patchon triggers.Deliberately disabling the cancelled-pause guard makes its test fail.
What ran
make verifypassed locally on the first two commits. On the third, every package passed exceptinternal/loadsim'sTestSplitFollowsShares, which timed out once under machine load. It passes alone (-race -count=3), and this branch doesn't touchinternal/loadsim. CI runs it again.npm run buildinsite/passed, with all links valid.podsnapshot_test.go): the fake API also plays GKE's snapshot controller, restoring only when GKE would. It covers the policy checks, snapshot, fork, both shapes ofstatus.snapshotCreated, a failed checkpoint, two pause/resume rounds, a fork or resume GKE didn't restore, and clean-up. Disabling the marker check makes the two restore tests fail. The fake's PATCH now applies real JSON merge patches; the existing tests still pass.What did not run
Nothing ran on GKE.
TestLivePodSnapshots(build tagslive,experimental_adapters,AGENTSANDBOX_SNAPSHOT_POLICY) is written to check a running process and a file through a fork and a pause/resume, that a new sandbox does not restore anything, and to log each step's time. It needs a GKE cluster with--enable-pod-snapshots. Other gaps:status.snapshotCreated: Google's docs disagree (string or{name}), so both are read.Fail/Error, otherwise a checkpoint waits untilsnapshotTimeout.v1beta1API.🤖 Generated with Claude Code