Repository navigation
Hibernation settings on the Agent class, and waking a hibernated sandbox - #109
Merged
Merged
Conversation
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.
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.
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 onagents/v1as of agynio/api#199.Agent class:
hibernate,hibernate_after,hibernation_ttlagentsby migration0029_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.CreateAgentapplies the same defaults when a field is unset.UpdateAgentchanges any of the three, and each one on its own counts as a field for the "at least one field" check.idle_timeout:hibernate_aftermust be a non-negative Go duration.0sis accepted, althoughidle_timeout's validator refuses it. A value at or aboveidle_timeoutis also accepted.hibernation_ttlis refused below1hwithhibernation_ttl: must be at least 1h.GetAgent,ListAgentsand the create and update responses.hibernateis a plain bool that the Orchestrator reads without presence, so it is always set.Sandboxes:
hibernatedhibernatedis in the store vocabulary, in thesandboxes_status_checkconstraint (migration0030_sandbox_hibernated_status.sqlreplaces 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 writesSANDBOX_STATUS_HIBERNATEDthroughUpdateSandboxRuntimeStateand reads it back on every pass. Without this change, the write is refused as an unknown status and reading such a sandbox panics insandboxStatusToProto.EnsureSandboxRunningon ahibernatedsandbox is a wake, not a restart. It takes the path astoppedsandbox's restart already takes: the sandbox is writtenstartingandsandbox.updatedis published. The difference is that it keepsworkload_id. #288 handles astartingsandbox whose workload is hibernated by callingWakeWorkloadon it. No new Orchestrator-facing call is needed.ListSandboxeshides onlyterminatedby default, so a hibernated sandbox stays listed. No other query in the service enumerates sandbox statuses.Notes
EnsureSandboxRunningfirst. This service issues none, so it has nothing to order. It returns only after thestartingwrite and the publish..gen/is generated in CI, as before.buf dep updatefails here with "had no .proto files" because the repository has no local protos, andbuf.lockis unchanged. Regenerating also rewrites the two identity bindings that are still tracked. Those changes are unrelated, so they are left out.PersistentShells) ininternal/store/types.go, which this PR touches.internal/server/authorization.gowas already unformatted onmainand is untouched.Testing
go build ./...,go vet ./...andgo test ./...pass. CI runs the last two of those (plus generation).1hminimumEnsureSandboxRunningdispatch forhibernatedAGENTS_TEST_DATABASE_URLorAGENTS_MIGRATION_TEST_DATABASE_URLis set, like the existing ones. I ran them against a throwaway Postgres 16. They cover:startingand publishingsandbox.updated0029reading the defaultshibernatedand still refusing an undefined statusmainwhenAGENTS_MIGRATION_TEST_DATABASE_URLis set:TestEnvOrganizationBackfillFollowsTheTargetsParentChainandTestImagePullSecretAttachmentOrganizationBackfillFollowsTheTargetsParentChain. They read hooks and image pull secret attachments that 0022 and 0023 later drop. They fail the same way without this change.