Repository navigation
Record workload hibernation - #89
Merged
Merged
Conversation
Nothing in the platform knew a workload that is neither running nor stopped: an idle agent either costs its flavor until the idle timeout or cold-starts for every message. The k8s-microvm-runner will pause a workload, persist it and resume it in under a second, and the Orchestrator will decide when. This is what the Runners service holds for them; the k8s-runner is unaffected and nothing advertises hibernate yet. The workload record gains hibernating, hibernated and waking, with hibernated_at, woken_at and snapshot_size_bytes. What a status change carries is derived from the recorded status, never from who is writing, so a runner's report and the Orchestrator's reconciliation leave the record identical: entering hibernated stamps hibernated_at unless the writer supplied it; waking -> running records woken_at, moves last_metering_sampled_at to now so compute billing resumes at the wake and never covers the sleep, puts agent_state back to processing, opens a fresh keepalive window and clears the fields that described the sleep. A hibernation that did not take (hibernating -> running) resets nothing. ReportWorkloadState accepts the three states and, with hibernated, the size of the persisted state. ReportWorkloadIdle is the turn-boundary report: agynd calls it after acking a turn's inbox items, and the workload goes idle at once instead of after the keepalive grace, with the event the sweep would have published -- the event the Orchestrator hibernates on. It is authorized as TouchWorkload is, and the chart's policy requires an identity on it the same way. wake_failed and snapshot_lost name the two ways a sleep ends badly. pending_sample needed no change: a hibernated workload has removed_at NULL, which already returns it to the sampler for its compute tail and its snapshot storage. hibernate passes the catalog's name rule as any capability does.
This was referenced Oct 30, 2026
The Orchestrator hibernates an agent on the agent_state flip that ends its turn, and it holds only the cluster-wide rooms: it reconciles every workload and cannot subscribe per workload without racing the creation of the next one. workload.updated went to the organization's room and the workload's own alone, so the flip that ReportWorkloadIdle, TouchWorkload and the activity sweep record never reached it, and the hibernation decision waited for the next poll tick instead of following the turn end. Every workload.updated now goes to the flat workloads room as well, whoever emits it, as the spec now says. workload.status_changed is as it was.
The Terminal Proxy touches the workload of every attached TTY session, a sandbox's or an agent's, and carries no identity as it never did; the mesh policy admits an identity-less TouchWorkload from its principal alone. touchWorkloadForOwner refused every such call on an agent workload, so an agent that had finished its turn was hibernated under the person at its shell, the one thing the touch exists to prevent. An identity-less touch on an agent workload is now the Terminal Proxy's and runs as the agent's own keepalive does: an idle agent flips back to processing and workload.updated goes out, a processing one only moves its timestamp. A present identity still has to be the owner's, and the sandbox case is as it was.
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.
Runners-service half of workload hibernation: the record, the write path and the turn-boundary report the Orchestrator and the coming k8s-microvm-runner need. The k8s-runner is unaffected and nothing advertises
hibernateyet.Design: agynio/architecture#192, change doc
changes/2026-10-27-workload-hibernation.md(Runners service row), specarchitecture/runners.md(Workload Resource, Workload State Management, Runner-Reported Workload State, Idle Timeout, Agent Activity Sweep). Interface:buf.build/agynio/apias merged in agynio/api#199.What changed
hibernating,hibernated,wakingin the Go maps and in the DB check (migrations/0017_workload_hibernation.sqlreplacesworkloads_status_check). None of the three is terminal: a hibernated workload is live.hibernated_at,woken_at,snapshot_size_bytes(nullable), scanned, returned on every read, accepted byUpdateWorkload.hibernatedstampshibernated_at = now()unless the writer supplied it;waking → runningsetswoken_atandlast_metering_sampled_atto now (explicit values win),agent_state = processing,last_activity_at = now(), and clearssnapshot_size_bytesandhibernated_at;hibernating → running(the runner could not persist) resets nothing: the agent stays idle for the retry.ReportWorkloadStateaccepts the three statuses and carriessnapshot_size_bytesthrough theUpdateWorkloadpath; theobserved_atordering and the no-change-no-event rule are unchanged.ReportWorkloadIdleflips a running agent workload fromprocessingtoidlein one conditionalUPDATEand publishesworkload.updatedthe wayTouchWorkloadand the sweep do. Authorized asTouchWorkload: the workload's own identity, agent-instance owners only. A no-op (no event, no error) when already idle or not running, so a retry is not a second event.TouchWorkloadadmits the identity-less call on an agent workload as the Terminal Proxy's, which touches every attached TTY session's workload whatever its owner kind and carries nox-identity-id(the mesh policy admits that call from its principal alone). It runs as the agent's own keepalive: an idle agent flips toprocessingwithworkload.updated, a processing one only moveslast_activity_at, so an agent is not hibernated under the person at its shell. A present identity still has to be the owner's; the sandbox case is unchanged.wake_failedandsnapshot_lost.workload.updated, whether fromUpdateWorkload,TouchWorkload,ReportWorkloadIdleor the sweep, goes to the cluster-wideworkloadsroom as well as the organization's and the workload's own, so the Orchestrator, which holds only the cluster-wide rooms, hears theagent_stateflip at the turn boundary instead of on its poll tick (architecture/notifications.md, Cluster-wide rooms).workload.status_changedkeeps its two rooms.ReportWorkloadIdlejoinsTouchWorkloadin the Istio policy's identity-required gateway paths.hibernatealready passes the capability name rule; a test pins it.Decisions where the spec left room
hibernated_atis cleared on the wake. The field table says it is NULL while the workload is awake; the step-5 write list in Workload State Management did not mention it. Nothing reads it after a wake (TTL and the sampler key onstatus = hibernated).snapshot_size_byteswith a status other thanhibernatedis refused withInvalidArgument: the size describes a sleep, and onrunningit would outlive the wake meant to clear it.pending_sampleneeded no code change. Every hibernated workload hasremoved_at IS NULL, which the existing clause already returns, covering both the compute tail up tohibernated_atand the snapshot storage. A comment at the clause says so.ReportWorkloadIdledoes not touchlast_activity_at; the idle clock keeps running from the last keepalive, andhibernate_afteris measured from there..gen/is ignored; CI and the Dockerfile generate from the module's latestmain).buf dep updatecannot run in this repo because it has no local protos, sobuf.lockis unchanged.Verification
go build ./...,go vet ./...,gofmt -l,go test ./...green; 25 new tests across vocabulary, transitions,UpdateWorkload,ReportWorkloadState,ReportWorkloadIdle,TouchWorkload, notification rooms and the catalog.helm templateandhelm lintof the chart with its dependency fetched.