Skip to content

Hibernation settings on the Agent class, and waking a hibernated sandbox - #109

Merged
vitramir merged 2 commits into
mainfrom
claude/hibernation-fields-a478bf
Oct 31, 2026
Merged

vitramir merged 2 commits into
mainfrom
claude/hibernation-fields-a478bf

Conversation

@vitramir

Copy link
Copy Markdown
Contributor

The Agents service side of workload hibernation. Spec: agynio/architecture#192, change doc changes/2026-10-27-workload-hibernation.md (the Agent class and Sandboxes rows of its Delta table). The interface is on agents/v1 as of agynio/api#199.

Agent class: hibernate, hibernate_after, hibernation_ttl

  • Stored on agents by migration 0029_agent_hibernation.sql, with column defaults equal to the documented ones (true, 0s, 168h). An agent that predates the columns therefore hibernates as a new one does.
  • CreateAgent applies the same defaults when a field is unset. UpdateAgent changes any of the three, and each one on its own counts as a field for the "at least one field" check.
  • Validation runs on create and update before anything is written, as it does for idle_timeout:
    • hibernate_after must be a non-negative Go duration. 0s is accepted, although idle_timeout's validator refuses it. A value at or above idle_timeout is also accepted.
    • hibernation_ttl is refused below 1h with hibernation_ttl: must be at least 1h.
  • All three are returned by GetAgent, ListAgents and the create and update responses. hibernate is a plain bool that the Orchestrator reads without presence, so it is always set.

Sandboxes: hibernated

  • hibernated is in the store vocabulary, in the sandboxes_status_check constraint (migration 0030_sandbox_hibernated_status.sql replaces the unnamed check from 0014), and in both directions through the proto. The Orchestrator in Hibernate idle workloads on runners that can agents-orchestrator#288 writes SANDBOX_STATUS_HIBERNATED through UpdateSandboxRuntimeState and reads it back on every pass. Without this change, the write is refused as an unknown status and reading such a sandbox panics in sandboxStatusToProto.
  • EnsureSandboxRunning on a hibernated sandbox is a wake, not a restart. It takes the path a stopped sandbox's restart already takes: the sandbox is written starting and sandbox.updated is published. The difference is that it keeps workload_id. #288 handles a starting sandbox whose workload is hibernated by calling WakeWorkload on it. No new Orchestrator-facing call is needed.
  • ListSandboxes hides only terminated by default, so a hibernated sandbox stays listed. No other query in the service enumerates sandbox statuses.

Notes

  • Terminal tickets are issued by the Terminal Proxy to clients that call EnsureSandboxRunning first. This service issues none, so it has nothing to order. It returns only after the starting write and the publish.
  • .gen/ is generated in CI, as before. buf dep update fails here with "had no .proto files" because the repository has no local protos, and buf.lock is unchanged. Regenerating also rewrites the two identity bindings that are still tracked. Those changes are unrelated, so they are left out.
  • gofmt also fixed one misaligned field (PersistentShells) in internal/store/types.go, which this PR touches. internal/server/authorization.go was already unformatted on main and is untouched.

Testing

  • go build ./..., go vet ./... and go test ./... pass. CI runs the last two of those (plus generation).
  • Unit tests cover:
    • both validators, including that the refusal names the 1h minimum
    • create and update refusing bad values before the store is reached
    • the converter
    • the EnsureSandboxRunning dispatch for hibernated
    • every sandbox status round-tripping through the proto
  • DB-backed tests are skipped unless AGENTS_TEST_DATABASE_URL or AGENTS_MIGRATION_TEST_DATABASE_URL is set, like the existing ones. I ran them against a throwaway Postgres 16. They cover:
    • the defaults on create, get and list
    • explicit values and updates, and a refused update leaving the stored values alone
    • a wake keeping the workload id, persisting starting and publishing sandbox.updated
    • a hibernated sandbox staying in the default list
    • an agent that predates 0029 reading the defaults
    • the replaced status check accepting hibernated and still refusing an undefined status
  • Two migration tests already fail on main when AGENTS_MIGRATION_TEST_DATABASE_URL is set: TestEnvOrganizationBackfillFollowsTheTargetsParentChain and TestImagePullSecretAttachmentOrganizationBackfillFollowsTheTargetsParentChain. They read hooks and image pull secret attachments that 0022 and 0023 later drop. They fail the same way without this change.

A runner that can hibernate pauses an idle workload and resumes it in under a
second, so the Orchestrator needs to know, per agent, whether to do that, how
long after a turn ends to wait first, and how long a sleeping workload is kept
before it is stopped. Those are hibernate, hibernate_after and hibernation_ttl
on agents/v1, beside idle_timeout, and this stores and serves them on every
read and write.

The defaults are the documented ones -- on, 0s and 168h -- and the column
defaults are the same, so an agent that predates the columns hibernates as a
new one does. hibernate is returned on every agent: the Orchestrator reads it
without presence, as the proto states it.

hibernate_after admits 0s, which idle_timeout's validation refuses, and a value
at or above idle_timeout, which means the stop comes first. hibernation_ttl is
refused below 1h, and the refusal names the minimum. Both are checked on
CreateAgent and UpdateAgent before anything is written, as idle_timeout is.

Nothing hibernates on a runner that does not advertise the capability, so on
the k8s-runner none of this changes what an agent does.
On a runner that can hibernate, a sandbox's idle timeout puts its workload to
sleep instead of stopping it: shells, processes and scratch space frozen, and
the next connect wakes them where they were. The Orchestrator records that as a
hibernated sandbox that keeps its workload id, and reads it back on every pass,
so the status has to exist here -- in the store's vocabulary, in the column's
check, and both ways through the proto. Without it the write is refused as an
unknown status and any read of such a sandbox panics in the converter.

EnsureSandboxRunning treats hibernated as a wake, not a restart. It writes the
sandbox starting and publishes sandbox.updated, the path a stopped sandbox's
restart already takes to reach the Orchestrator, but keeps the workload id
rather than clearing it: the Orchestrator sees a starting sandbox whose
workload is hibernated and wakes that workload instead of starting a new one.

A hibernated sandbox is not stopped, and the default list -- everything but
terminated -- keeps showing it.
@vitramir
vitramir merged commit 6e63cd0 into main Oct 31, 2026
1 of 2 checks passed
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.

1 participant