oficina / equipo Public

hostedctl: pause generations and prepared resume epochs

Drain, Quiescent, Suspend and Reopen implement the pause barrier: a new
generation per drain, suspend only on a timely quiescent acknowledgement
for the current generation, lazy cancellation after 2 minutes, and a
reopen that keeps the counter. Resume prepares epoch + 1 durably before
the provider call and commits only once Get shows the VM running; an
operation ID raises the epoch once, and done operations are remembered
for the attempt's lifetime. Refresh calls mirrorLive in place of
mirrorState, so it never overwrites draining, suspending or resuming and
finishes pending suspends and resumes after a crash or lost reply.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev ab73319c5fabb63d7e591818c7d3c309fdb2f51a parent fd6a8ce
7 files changed, +1,510 −1
  • docs/superpowers/plans/HOSTED-SLICE1-PROGRESS.md +30 −0
  • internal/hostedctl/pause.go +371 −0
  • internal/hostedctl/pause_test.go +326 −0
  • internal/hostedctl/refresh.go +1 −1
  • internal/hostedctl/resume.go +432 −0
  • internal/hostedctl/resume_test.go +337 −0
  • internal/hostedctl/states.go +13 −0

CI passed — run details

CI log
=== prepare ===
ci-box: machine: aarch64, 32 CPUs, 62 GiB memory, kernel 7.0.0-1017-aws
ci-box: python 3.12.3; Docker version 29.1.3, build 29.1.3-0ubuntu3~24.04.2
ci-box: user namespaces allowed: 233151
ci-box: cgroup: cgroup2fs
ci-box: disk /home/ci/work/repos/oficina__equipo/wt/hosted-runners-1a: Type  Size Avail | ext4   96G   85G
ci-box: disk /home/ci/.cache/equipo-ci-box: Type  Size Avail | ext4   96G   85G
ci-box: bwrap: fetched and verified in 0.3s
ci-box: claude: fetched and verified in 1.4s
ci-box: codex: fetched and verified in 3.4s
ci-box: codex-code-mode-host: fetched and verified in 1.3s
ci-box: libwrap: fetched and verified in 0.3s
ci-box: socat: fetched and verified in 0.3s
npm warn deprecated node-domexception@1.0.0: Use your platform's native DOMException instead
ci-box: image pulled in 10.2s
ci-box: pi: installed and verified in 7.7s
ci-box: opencode: installed and verified in 1.9s
ci-box: chromium 156.0.8078.79-1~deb13u1: 76 packages fetched, verified and unpacked in 8.9s
ci-box: clone deepened in 3.5s
ci-box: file times set from content: 2881 files, 192 directories
ci-box: ready in 16.9s
=== copy ===
EQUIPO_RELEASE_COPY_CHECK=1 CGO_ENABLED=0 go test ./internal/equipotest -run '^TestReleaseCopyReviewed$' -count=1
ok  	amadan.net/oficina/equipo/internal/equipotest	0.251s
=== compile ===
go build ./...
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py compile
+ go build -tags testbuild ./...
  1.2s
+ go list -export -test -tags testbuild -f  ./...
  1.0s
+ go list -export -test -tags browser,testbuild -f  ./internal/equipo ./internal/headless ./internal/idtest ./internal/plan3test ./internal/thintest
  0.3s
go run honnef.co/go/tools/cmd/staticcheck@v0.7.0 -version
staticcheck 2026.1 (v0.7.0)
go run golang.org/x/vuln/cmd/govulncheck@v1.8.0 -version
Go: go1.26.11
Scanner: govulncheck@v1.8.0
DB: https://vuln.go.dev
DB updated: 2026-11-11 02:51:11 +0000 UTC

go run github.com/zricethezav/gitleaks/v8@v8.30.1 version
version is set by build process
=== check ===
--- shard 0 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
test lane headless-work: ./internal/headless
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m -run '^TestHeadless$/^4c_rebase$|^TestHeadless$/^4b_ask$|^TestHeadless$/^4c_checks_card$|^TestHeadless$/^4_step_crash$' ./internal/headless
cache miss: amadan.net/oficina/equipo/internal/headless: its inputs changed

receipt: test step 1m21.65s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 1m19.984s amadan.net/oficina/equipo/internal/headless
receipt: slow test 1m19.98s amadan.net/oficina/equipo/internal/headless TestHeadless
machine: 32 CPUs, load 39.07, cpu waiting 21.54%, memory waiting 0.00%, io waiting 0.56%
--- shard 1 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
test lane headless-review: ./internal/headless
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m -run '^TestHeadless$/^4_review$|^TestHeadless$/^2b_access$|^TestHeadless$/^runner_crash$|^TestHeadless$/^2b_first_message$|^TestHeadless$/^4_checks_honest$|^TestHeadless$/^7_stream_resume$|^TestHeadless$/^2b_notebook$|^TestHeadless$/^2b_move_in$|^TestHeadless$/^2b_desk_failure$|^TestHeadless$/^cancel$' ./internal/headless
cache miss: amadan.net/oficina/equipo/internal/headless: its inputs changed
--- FAIL amadan.net/oficina/equipo/internal/headless TestHeadless
=== RUN   TestHeadless
--- FAIL: TestHeadless (75.17s)

--- FAIL amadan.net/oficina/equipo/internal/headless TestHeadless/4_review
=== RUN   TestHeadless/4_review
time=2026-11-22T17:58:57.974Z level=INFO msg="startup phase" phase=state_lock
time=2026-11-22T17:58:57.974Z level=INFO msg="startup phase done" phase=state_lock took=73µs
time=2026-11-22T17:58:57.974Z level=INFO msg="startup phase" phase=claim_roots
time=2026-11-22T17:58:57.974Z level=INFO msg="startup phase done" phase=claim_roots took=80µs
time=2026-11-22T17:58:57.974Z level=INFO msg="startup phase" phase=sweep
time=2026-11-22T17:58:58.006Z level=INFO msg="startup phase done" phase=sweep took=31.874ms
time=2026-11-22T17:58:58.006Z level=INFO msg="startup phase" phase=credentials
time=2026-11-22T17:58:58.006Z level=INFO msg="startup phase done" phase=credentials took=103µs
time=2026-11-22T17:58:58.006Z level=INFO msg="startup phase" phase=open_state
time=2026-11-22T17:58:58.049Z level=INFO msg="startup phase done" phase=open_state took=43.001ms
time=2026-11-22T17:58:58.050Z level=WARN msg="no seal key: token connections cannot be added" err=*fs.PathError
time=2026-11-22T17:58:58.050Z level=INFO msg=connecting host=127.0.0.1:35513 protocol=28
time=2026-11-22T17:58:58.053Z level=INFO msg=connected host=127.0.0.1:35513 took=2.177ms
time=2026-11-22T17:58:58.053Z level=INFO msg="capabilities gathering"
time=2026-11-22T17:58:58.053Z level=INFO msg="capabilities gathered" took=607µs tags=linux,claude,go
time=2026-11-22T17:58:58.054Z level=INFO msg="hello sent" protocol=28
time=2026-11-22T17:58:58.058Z level=INFO msg=welcome protocol=28 role=primary generation=1
time=2026-11-22T17:58:58.998Z level=INFO msg="connection checked" connection=claude-1 state=healthy
time=2026-11-22T17:59:03.329Z level=INFO msg="kept sessions" kept=1 bytes=3061 expired=0
time=2026-11-22T17:59:06.107Z level=INFO msg="kept sessions" kept=2 bytes=8233 expired=0
    review_test.go:99: checks and the branch do not refer to one SHA: task tks6rv3sjtf2 candidate "c018d4111b6259c098c8b4daf514bb82ea72946b", engineering "c018d4111b6259c098c8b4daf514bb82ea72946b", checks {BaseChecks: ID:s_l2p6wx5wd6bidldb7syzxm3hgy Revision:1 TaskID:tks6rv3sjtf2 Index:4 Specialist:checks State:queued Reason: Attempt:1 BaseSHA:53048c907110420ebc20176d6cfc077344e65e1a CandidateSHA:c018d4111b6259c098c8b4daf514bb82ea72946b Pushed:false Terminated:false Summary: Headline: LogTail: StartedAt:<nil> FinishedAt:<nil> Round:1 Family: Account: Model: Verdict: ReviewLabel: Findings:[] Checks: Gate: ExitCode:<nil> Askable:false Rebase:false MergeSHA: Into: Strategy: WithoutChecks:false Switched:<nil> Activity:[] RunnerID:ZYQLALVBT5U6XMPKVQR3FB6TLE RunnerLabel:Headless runner Needs:[] Placement: Publication: TerminationKind: ChecksSandbox: Preview:<nil> Research:<nil> Hold:<nil> Publish:<nil>}
time=2026-11-22T17:59:06.129Z level=WARN msg="step sweep" err=cancelled
time=2026-11-22T17:59:06.129Z level=WARN msg="kept sessions" err=cancelled
--- FAIL: TestHeadless/4_review (8.57s)

--- FAIL amadan.net/oficina/equipo/internal/headless (package output)
FAIL
rastrillo-budget/v1 ran 1m15.175s
FAIL	amadan.net/oficina/equipo/internal/headless	75.505s


receipt: test step 1m16.793s against a 60s target (the gate's other steps are not in this figure)
receipt: 0 packages ran, 0 cached, 0 without tests, 1 failed
receipt: slow package 1m15.175s amadan.net/oficina/equipo/internal/headless
receipt: slow test 1m15.17s amadan.net/oficina/equipo/internal/headless TestHeadless
rastrillo: budget test: go test failed
exit status 1
+ go test -tags testbuild -timeout 15m -run '^TestHeadless$/^4_review$|^TestHeadless$/^2b_access$|^TestHeadless$/^runner_crash$|^TestHeadless$/^2b_first_message$|^TestHeadless$/^4_checks_honest$|^TestHeadless$/^7_stream_resume$|^TestHeadless$/^2b_notebook$|^TestHeadless$/^2b_move_in$|^TestHeadless$/^2b_desk_failure$|^TestHeadless$/^cancel$' -v -run '^TestHeadless$/^4_review$' -count=1 ./internal/headless   (retry, once)
##############################################################################
FLAKE ./internal/headless:TestHeadless/4_review headless-review ab73319c5fabb63d7e591818c7d3c309fdb2f51a 8.57s 39.08
##############################################################################
failed, then passed on its one retry: the step stays green and the flake is on record
machine: 32 CPUs, load 33.56, cpu waiting 18.05%, memory waiting 0.00%, io waiting 0.44%
--- shard 2 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
test lane headless-connections: ./internal/headless
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m -run '^TestHeadlessConnections$|^TestHeadlessTokenPasteEndToEnd$|^TestHeadlessTokenConnection$' ./internal/headless
cache miss: amadan.net/oficina/equipo/internal/headless: its inputs changed

receipt: test step 1m25.464s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 1m23.253s amadan.net/oficina/equipo/internal/headless
receipt: slow test 1m12.63s amadan.net/oficina/equipo/internal/headless TestHeadlessConnections
receipt: slow test 5.86s amadan.net/oficina/equipo/internal/headless TestHeadlessTokenPasteEndToEnd
receipt: slow test 4.76s amadan.net/oficina/equipo/internal/headless TestHeadlessTokenConnection
machine: 32 CPUs, load 37.46, cpu waiting 20.67%, memory waiting 0.00%, io waiting 0.53%
--- shard 3 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
test lane headless-mac: ./internal/headless
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m -run '^TestMacWorker$|^TestHeadlessAttachments$|^TestHeadlessPrewarm$|^TestHeadless$/^1_first_token$|^TestHeadless$/^6_quick_messages$|^TestHeadless$/^8_instance_restart$|^TestHeadless$/^3_runner_offline$' ./internal/headless
cache miss: amadan.net/oficina/equipo/internal/headless: its inputs changed

receipt: test step 1m20.781s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 1m19.038s amadan.net/oficina/equipo/internal/headless
receipt: slow test 38.22s amadan.net/oficina/equipo/internal/headless TestMacWorker
receipt: slow test 20.45s amadan.net/oficina/equipo/internal/headless TestHeadless
receipt: slow test 10.76s amadan.net/oficina/equipo/internal/headless TestHeadlessAttachments
receipt: slow test 9.61s amadan.net/oficina/equipo/internal/headless TestHeadlessPrewarm
machine: 32 CPUs, load 39.07, cpu waiting 21.54%, memory waiting 0.00%, io waiting 0.56%
--- shard 4 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
test lane headless-guards: ./internal/headless
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m -run '^TestHeadlessCopyRotation$|^TestHeadlessPolicyGuards$|^TestHeadlessRunnerKillLeavesNoCopies$|^TestHeadlessNewHouseRuleStartsFresh$|^TestHeadless$/^3_engineering$|^TestHeadless$/^3_step_cancel$|^TestHeadless$/^3_step_contained$|^TestHeadless$/^3_empty_repo$|^TestHeadless$/^3_empty_engineering$|^TestHeadless$/^3_empty_merge$|^TestHeadless$/^3_empty_merge_rebuilt$|^TestHeadless$/^3_empty_fix_round$' ./internal/headless
cache miss: amadan.net/oficina/equipo/internal/headless: its inputs changed

receipt: test step 1m38.568s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 1m36.801s amadan.net/oficina/equipo/internal/headless
receipt: slow test 1m0.47s amadan.net/oficina/equipo/internal/headless TestHeadless
receipt: slow test 11.33s amadan.net/oficina/equipo/internal/headless TestHeadlessRunnerKillLeavesNoCopies
receipt: slow test 10.26s amadan.net/oficina/equipo/internal/headless TestHeadlessCopyRotation
receipt: slow test 8.94s amadan.net/oficina/equipo/internal/headless TestHeadlessPolicyGuards
receipt: slow test 5.79s amadan.net/oficina/equipo/internal/headless TestHeadlessNewHouseRuleStartsFresh
machine: 32 CPUs, load 31.11, cpu waiting 16.95%, memory waiting 0.00%, io waiting 0.41%
--- shard 5 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
test lane headless-rest: ./internal/headless
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m -skip '^TestHeadless$/^4c_rebase$|^TestHeadless$/^4b_ask$|^TestHeadless$/^4c_checks_card$|^TestHeadless$/^4_step_crash$|^TestHeadless$/^4_review$|^TestHeadless$/^2b_access$|^TestHeadless$/^runner_crash$|^TestHeadless$/^2b_first_message$|^TestHeadless$/^4_checks_honest$|^TestHeadless$/^7_stream_resume$|^TestHeadless$/^2b_notebook$|^TestHeadless$/^2b_move_in$|^TestHeadless$/^2b_desk_failure$|^TestHeadless$/^cancel$|^TestHeadlessConnections$|^TestHeadlessTokenPasteEndToEnd$|^TestHeadlessTokenConnection$|^TestMacWorker$|^TestHeadlessAttachments$|^TestHeadlessPrewarm$|^TestHeadless$/^1_first_token$|^TestHeadless$/^6_quick_messages$|^TestHeadless$/^8_instance_restart$|^TestHeadless$/^3_runner_offline$|^TestHeadlessCopyRotation$|^TestHeadlessPolicyGuards$|^TestHeadlessRunnerKillLeavesNoCopies$|^TestHeadlessNewHouseRuleStartsFresh$|^TestHeadless$/^3_engineering$|^TestHeadless$/^3_step_cancel$|^TestHeadless$/^3_step_contained$|^TestHeadless$/^3_empty_repo$|^TestHeadless$/^3_empty_engineering$|^TestHeadless$/^3_empty_merge$|^TestHeadless$/^3_empty_merge_rebuilt$|^TestHeadless$/^3_empty_fix_round$' ./internal/headless
cache miss: amadan.net/oficina/equipo/internal/headless: its inputs changed

receipt: test step 3m11.506s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 3m9.494s amadan.net/oficina/equipo/internal/headless
receipt: slow test 1m45.63s amadan.net/oficina/equipo/internal/headless TestHeadlessAssistant
receipt: slow test 24.68s amadan.net/oficina/equipo/internal/headless TestHeadless
receipt: slow test 11.86s amadan.net/oficina/equipo/internal/headless TestHeadlessResearchHandoff
receipt: slow test 8.21s amadan.net/oficina/equipo/internal/headless TestHeadlessClaudeSignIn
receipt: slow test 7.4s amadan.net/oficina/equipo/internal/headless TestHeadlessTurnBatching
machine: 32 CPUs, load 10.03, cpu waiting 3.70%, memory waiting 0.00%, io waiting 0.08%
--- shard 6 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
test lane thintest: ./internal/thintest
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m -run '^Test([^C]|C[^o]|Co[^n]|Con[^t])|^TestContract(Assistant|Outcome|Team|Handoff|HostAllowlist|HostIsPerPerson|Look|Use[A-Z]|RemoteCall|LanesRunAtOnce|NoMergeQuestionWhenGateMerges|PreviewHeldUntilPublishAnswer|PreviewNotHeldBelow19|PublishNeedsOwnerAnswer)' ./internal/thintest

receipt: test step 1.15s against a 60s target (the gate's other steps are not in this figure)
receipt: 0 packages ran, 1 cached, 0 without tests, 0 failed
receipt: slow package 2m1.624s amadan.net/oficina/equipo/internal/thintest
receipt: slow test 7.84s amadan.net/oficina/equipo/internal/thintest TestContractTeamJobSettledStates
receipt: slow test 6.74s amadan.net/oficina/equipo/internal/thintest TestExplorePreviewsOff
receipt: slow test 4.31s amadan.net/oficina/equipo/internal/thintest TestContractTeamUpdatePersonNeeds
receipt: slow test 3.81s amadan.net/oficina/equipo/internal/thintest TestContractPreviewHeldUntilPublishAnswer
receipt: slow test 3.52s amadan.net/oficina/equipo/internal/thintest TestContractTeamNudgePersonNeeds
machine: 32 CPUs, load 1.04, cpu waiting 0.28%, memory waiting 0.00%, io waiting 2.16%
--- shard 7 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
test lane thintest-contract: ./internal/thintest
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m -skip '^Test([^C]|C[^o]|Co[^n]|Con[^t])|^TestContract(Assistant|Outcome|Team|Handoff|HostAllowlist|HostIsPerPerson|Look|Use[A-Z]|RemoteCall|LanesRunAtOnce|NoMergeQuestionWhenGateMerges|PreviewHeldUntilPublishAnswer|PreviewNotHeldBelow19|PublishNeedsOwnerAnswer)' ./internal/thintest

receipt: test step 1.115s against a 60s target (the gate's other steps are not in this figure)
receipt: 0 packages ran, 1 cached, 0 without tests, 0 failed
receipt: slow package 1m26.784s amadan.net/oficina/equipo/internal/thintest
receipt: slow test 9.08s amadan.net/oficina/equipo/internal/thintest TestContractPreviewNotScheduled
receipt: slow test 5.03s amadan.net/oficina/equipo/internal/thintest TestContractPublishNotOffered
receipt: slow test 4.41s amadan.net/oficina/equipo/internal/thintest TestContractMacRecheckMergeAuthority
receipt: slow test 2.4s amadan.net/oficina/equipo/internal/thintest TestContractPreview
receipt: slow test 2.34s amadan.net/oficina/equipo/internal/thintest TestContractPublishNameTaken
machine: 32 CPUs, load 1.04, cpu waiting 0.28%, memory waiting 0.00%, io waiting 2.16%
--- shard 8 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
test lane runner-thin: ./internal/runner/thin
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m ./internal/runner/thin
cache miss: amadan.net/oficina/equipo/internal/runner/thin: its inputs changed
budget note: internal/runner/thin took 4m30.673s, over the 45s its record on line 44 allows; reported only, timing fails on CI

receipt: test step 4m43.656s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 4m30.673s amadan.net/oficina/equipo/internal/runner/thin
receipt: slow test 36.96s amadan.net/oficina/equipo/internal/runner/thin TestModelsProbeAnsweredByAnotherModel
receipt: slow test 36.88s amadan.net/oficina/equipo/internal/runner/thin TestModelsEngineeringProbesThenRunsTheStrongest
receipt: slow test 36.78s amadan.net/oficina/equipo/internal/runner/thin TestModelsUnhealthyRetriedOnDemand
receipt: slow test 18.47s amadan.net/oficina/equipo/internal/runner/thin TestModelsProbeRunsInsideTheAdmission
receipt: slow test 6.93s amadan.net/oficina/equipo/internal/runner/thin TestOpenCodeStepsRealOpenCode
machine: 32 CPUs, load 2.60, cpu waiting 0.79%, memory waiting 0.00%, io waiting 0.01%
--- shard 9 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
test lane runner-bug: ./internal/runner
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m -run '^TestDirectBugWorkflow$|^TestEnrolKeepsTheRole$' ./internal/runner
cache miss: amadan.net/oficina/equipo/internal/runner: its inputs changed

receipt: test step 47.659s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 46.617s amadan.net/oficina/equipo/internal/runner
receipt: slow test 26.59s amadan.net/oficina/equipo/internal/runner TestDirectBugWorkflow
receipt: slow test 20.02s amadan.net/oficina/equipo/internal/runner TestEnrolKeepsTheRole
machine: 32 CPUs, load 35.16, cpu waiting 20.35%, memory waiting 0.00%, io waiting 1.00%
--- shard 10 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
test lane runner-plans: ./internal/runner
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m -run '^TestPlanWorkflowCandidateOrder$|^TestPlanWorkflowFeature$|^TestCoordinatorRecoveryCallRefusalKeepsServing$|^TestCoordinatorRefusalMatrix$' ./internal/runner
cache miss: amadan.net/oficina/equipo/internal/runner: its inputs changed

receipt: test step 47.777s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 45.786s amadan.net/oficina/equipo/internal/runner
receipt: slow test 35.73s amadan.net/oficina/equipo/internal/runner TestPlanWorkflowCandidateOrder
receipt: slow test 30.62s amadan.net/oficina/equipo/internal/runner TestPlanWorkflowFeature
receipt: slow test 8.41s amadan.net/oficina/equipo/internal/runner TestCoordinatorRecoveryCallRefusalKeepsServing
receipt: slow test 1.63s amadan.net/oficina/equipo/internal/runner TestCoordinatorRefusalMatrix
machine: 32 CPUs, load 35.16, cpu waiting 20.35%, memory waiting 0.00%, io waiting 1.00%
--- shard 11 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
test lane runner-rest: ./internal/runner
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m -skip '^TestDirectBugWorkflow$|^TestEnrolKeepsTheRole$|^TestPlanWorkflowCandidateOrder$|^TestPlanWorkflowFeature$|^TestCoordinatorRecoveryCallRefusalKeepsServing$|^TestCoordinatorRefusalMatrix$' ./internal/runner
cache miss: amadan.net/oficina/equipo/internal/runner: its inputs changed

receipt: test step 34.958s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 34.142s amadan.net/oficina/equipo/internal/runner
receipt: slow test 5.14s amadan.net/oficina/equipo/internal/runner TestDirectFaultIsolation
receipt: slow test 3.12s amadan.net/oficina/equipo/internal/runner TestCoordinatorRecoveryRefusedKeepsServing
receipt: slow test 3.08s amadan.net/oficina/equipo/internal/runner TestClaimRefusalsBackOff
receipt: slow test 2.39s amadan.net/oficina/equipo/internal/runner TestToolVerbUnderFakeHarness
receipt: slow test 1.61s amadan.net/oficina/equipo/internal/runner TestReportPostsRetryExactRequest
machine: 32 CPUs, load 26.78, cpu waiting 14.54%, memory waiting 0.00%, io waiting 1.22%
--- shard 12 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
stagger: equipotest-a started 30s late; cpu waiting 26.6%, load 16.14
test lane equipotest-a: ./internal/equipotest
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m -run '^Test[A-D]|^TestQ' ./internal/equipotest
cache miss: amadan.net/oficina/equipo/internal/equipotest: its inputs changed

receipt: test step 1m5.116s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 1m3.195s amadan.net/oficina/equipo/internal/equipotest
receipt: slow test 26.77s amadan.net/oficina/equipo/internal/equipotest TestAuthorityCoreIntegration
receipt: slow test 26.74s amadan.net/oficina/equipo/internal/equipotest TestBootstrapNamesOwnersSetting
receipt: slow test 24.62s amadan.net/oficina/equipo/internal/equipotest TestAccountLabelMigration
receipt: slow test 22.15s amadan.net/oficina/equipo/internal/equipotest TestBudgetConfigurationFailuresAreAtomic
receipt: slow test 21.99s amadan.net/oficina/equipo/internal/equipotest TestAuthorityRejectsMismatchedTarget
machine: 32 CPUs, load 33.56, cpu waiting 18.05%, memory waiting 0.00%, io waiting 0.44%
--- shard 13 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
stagger: equipotest-e started 30s late; cpu waiting 26.6%, load 16.14
test lane equipotest-e: ./internal/equipotest
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m -run '^Test[E-P]' ./internal/equipotest

receipt: test step 1.276s against a 60s target (the gate's other steps are not in this figure)
receipt: 0 packages ran, 1 cached, 0 without tests, 0 failed
receipt: slow package 1m12.399s amadan.net/oficina/equipo/internal/equipotest
receipt: slow test 19.2s amadan.net/oficina/equipo/internal/equipotest TestProjectWritesRequireCurrentOwner
receipt: slow test 19.12s amadan.net/oficina/equipo/internal/equipotest TestProjectOwnersAreMembers
receipt: slow test 19.11s amadan.net/oficina/equipo/internal/equipotest TestProjectsReopen
receipt: slow test 19.11s amadan.net/oficina/equipo/internal/equipotest TestProjectRetryAndRevision
receipt: slow test 19.08s amadan.net/oficina/equipo/internal/equipotest TestProjectsFailuresRollBack
machine: 32 CPUs, load 16.14, cpu waiting 11.62%, memory waiting 0.00%, io waiting 1.31%
--- shard 14 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
stagger: equipotest-r started 30s late; cpu waiting 26.6%, load 16.14
test lane equipotest-r: ./internal/equipotest
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m -run '^TestR' ./internal/equipotest
cache miss: amadan.net/oficina/equipo/internal/equipotest: its inputs changed

receipt: test step 1m16.622s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 1m4.496s amadan.net/oficina/equipo/internal/equipotest
receipt: slow test 14.83s amadan.net/oficina/equipo/internal/equipotest TestReleaseStampContract
receipt: slow test 12.79s amadan.net/oficina/equipo/internal/equipotest TestRosterChangesAffectExistingSession
receipt: slow test 9.78s amadan.net/oficina/equipo/internal/equipotest TestRosterRemovalWhileAssigned
receipt: slow test 9.71s amadan.net/oficina/equipo/internal/equipotest TestRosterRemovalRollsBack
receipt: slow test 6.68s amadan.net/oficina/equipo/internal/equipotest TestRosterProtectsLastOwner
machine: 32 CPUs, load 28.86, cpu waiting 14.87%, memory waiting 0.00%, io waiting 0.36%
--- shard 15 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
stagger: equipotest-rest started 30s late; cpu waiting 28.3%, load 16.14
test lane equipotest-rest: ./internal/equipotest
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m -skip '^Test[A-D]|^TestQ|^Test[E-P]|^TestR' ./internal/equipotest

receipt: test step 460ms against a 60s target (the gate's other steps are not in this figure)
receipt: 0 packages ran, 1 cached, 0 without tests, 0 failed
receipt: slow package 1m4.231s amadan.net/oficina/equipo/internal/equipotest
receipt: slow test 24.45s amadan.net/oficina/equipo/internal/equipotest TestSigninNoProof
receipt: slow test 23.28s amadan.net/oficina/equipo/internal/equipotest TestSpecialistsSeedExistingTeam
receipt: slow test 23.2s amadan.net/oficina/equipo/internal/equipotest TestSpecialistsSeedRollback
receipt: slow test 21.61s amadan.net/oficina/equipo/internal/equipotest TestSpecialistsUpgrade
receipt: slow test 21.57s amadan.net/oficina/equipo/internal/equipotest TestSpecialistSettingsRollbackAndUnavailable
machine: 32 CPUs, load 16.14, cpu waiting 11.62%, memory waiting 0.00%, io waiting 1.31%
--- shard 16 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
stagger: plan3test started 30s late; cpu waiting 26.6%, load 16.14
test lane plan3test: ./internal/plan3test
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m ./internal/plan3test

receipt: test step 638ms against a 60s target (the gate's other steps are not in this figure)
receipt: 0 packages ran, 1 cached, 0 without tests, 0 failed
receipt: slow package 48.756s amadan.net/oficina/equipo/internal/plan3test
receipt: slow test 3.61s amadan.net/oficina/equipo/internal/plan3test TestPlan3Upgrade
receipt: slow test 3.41s amadan.net/oficina/equipo/internal/plan3test TestCoordinatorAcceptance3B
receipt: slow test 1.5s amadan.net/oficina/equipo/internal/plan3test TestConversationQuestionRace
receipt: slow test 1.47s amadan.net/oficina/equipo/internal/plan3test TestCoordinatorAcceptance3A
receipt: slow test 1.21s amadan.net/oficina/equipo/internal/plan3test TestPlanMigrationUpgrade
machine: 32 CPUs, load 16.14, cpu waiting 11.62%, memory waiting 0.00%, io waiting 1.31%
--- shard 17 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
stagger: rest started 30s late; cpu waiting 28.3%, load 16.14
test lane rest: ./cmd/equipo ./cmd/equipo-runner ./cmd/equipo-tool-proxy ./internal/advice ./internal/attach ./internal/attach/attachtest ./internal/chatmarkdown ./internal/chatsend ./internal/chatstream ./internal/coordinator ./internal/coordinatorcontract ./internal/coordinatormail ./internal/copydesk ./internal/equipo ./internal/equipo/activity ./internal/equipo/assist ./internal/equipo/chat ./internal/equipo/conversation ./internal/equipo/conversation/chatstate ./internal/equipo/housekeeping ./internal/equipo/icons ./internal/equipo/identity ./internal/equipo/kernel ./internal/equipo/library ./internal/equipo/mergegate ./internal/equipo/notifications ./internal/equipo/oficina ./internal/equipo/oficina/oficinatest ./internal/equipo/oficinaid ./internal/equipo/ownermode ./internal/equipo/personapi ./internal/equipo/planning ./internal/equipo/push ./internal/equipo/setup ./internal/equipo/team ./internal/equipo/teamcontract ./internal/equipo/triage ./internal/fakeclaude ./internal/fakecodex ./internal/fakeopencode ./internal/fakepi ./internal/hostedctl ./internal/hostedwire ./internal/idtest ./internal/isolatedjob ./internal/isolatedjob/awsjob ./internal/isolatedjob/guardfixture ./internal/isolatedjob/isolatedjobtest ./internal/ownermodetest ./internal/release ./internal/runner/checks ./internal/runner/connect ./internal/runner/containment ./internal/runner/containment/sysunix ./internal/runner/egress ./internal/runner/forge ./internal/runner/forge/forgetest ./internal/runner/heartbeat ./internal/runner/mac ./internal/runner/mcpresource ./internal/runner/metered ./internal/runner/planflow ./internal/runner/provider ./internal/runner/provider/claude ./internal/runner/provider/codex ./internal/runner/provider/gotoolchain ./internal/runner/provider/opencode ./internal/runner/provider/pi ./internal/runner/setup ./internal/runner/transporttest ./internal/runner/webread ./internal/runner/workspace ./internal/runnerproto ./internal/schedule ./internal/sealbox ./internal/specialist ./internal/stagingtest ./internal/taskplan ./internal/testci ./internal/toolproxy ./internal/websource ./internal/wire ./internal/wire/wireschema ./internal/wire/wiretest ./tools/drive
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags testbuild -timeout 15m ./cmd/equipo ./cmd/equipo-runner ./cmd/equipo-tool-proxy ./internal/advice ./internal/attach ./internal/attach/attachtest ./internal/chatmarkdown ./internal/chatsend ./internal/chatstream ./internal/coordinator ./internal/coordinatorcontract ./internal/coordinatormail ./internal/copydesk ./internal/equipo ./internal/equipo/activity ./internal/equipo/assist ./internal/equipo/chat ./internal/equipo/conversation ./internal/equipo/conversation/chatstate ./internal/equipo/housekeeping ./internal/equipo/icons ./internal/equipo/identity ./internal/equipo/kernel ./internal/equipo/library ./internal/equipo/mergegate ./internal/equipo/notifications ./internal/equipo/oficina ./internal/equipo/oficina/oficinatest ./internal/equipo/oficinaid ./internal/equipo/ownermode ./internal/equipo/personapi ./internal/equipo/planning ./internal/equipo/push ./internal/equipo/setup ./internal/equipo/team ./internal/equipo/teamcontract ./internal/equipo/triage ./internal/fakeclaude ./internal/fakecodex ./internal/fakeopencode ./internal/fakepi ./internal/hostedctl ./internal/hostedwire ./internal/idtest ./internal/isolatedjob ./internal/isolatedjob/awsjob ./internal/isolatedjob/guardfixture ./internal/isolatedjob/isolatedjobtest ./internal/ownermodetest ./internal/release ./internal/runner/checks ./internal/runner/connect ./internal/runner/containment ./internal/runner/containment/sysunix ./internal/runner/egress ./internal/runner/forge ./internal/runner/forge/forgetest ./internal/runner/heartbeat ./internal/runner/mac ./internal/runner/mcpresource ./internal/runner/metered ./internal/runner/planflow ./internal/runner/provider ./internal/runner/provider/claude ./internal/runner/provider/codex ./internal/runner/provider/gotoolchain ./internal/runner/provider/opencode ./internal/runner/provider/pi ./internal/runner/setup ./internal/runner/transporttest ./internal/runner/webread ./internal/runner/workspace ./internal/runnerproto ./internal/schedule ./internal/sealbox ./internal/specialist ./internal/stagingtest ./internal/taskplan ./internal/testci ./internal/toolproxy ./internal/websource ./internal/wire ./internal/wire/wireschema ./internal/wire/wiretest ./tools/drive
cache miss: amadan.net/oficina/equipo/internal/runner/webread: its inputs changed
cache miss: amadan.net/oficina/equipo/internal/isolatedjob: its inputs changed
cache miss: amadan.net/oficina/equipo/internal/copydesk: its inputs changed
cache miss: amadan.net/oficina/equipo/internal/runner/provider/opencode: its inputs changed
cache miss: amadan.net/oficina/equipo/internal/runner/forge: its inputs changed
cache miss: amadan.net/oficina/equipo/internal/runner/workspace: its inputs changed
cache miss: amadan.net/oficina/equipo/internal/equipo/team: its inputs changed
cache miss: amadan.net/oficina/equipo/internal/runner/provider/claude: its inputs changed
cache miss: amadan.net/oficina/equipo/internal/runner/provider/codex: its inputs changed
cache miss: amadan.net/oficina/equipo/internal/runner/checks: its inputs changed
cache miss: amadan.net/oficina/equipo/internal/runner/containment: its inputs changed
cache miss: amadan.net/oficina/equipo/internal/runner/provider/pi: its inputs changed
budget note: internal/equipo took 45.275s, over the 10s the default allows (measured on the run this cached result came from); reported only, timing fails on CI
budget note: internal/equipo/chat took 12.529s, over the 10s the default allows (measured on the run this cached result came from); reported only, timing fails on CI
budget note: internal/idtest took 39.84s, over the 10s the default allows (measured on the run this cached result came from); reported only, timing fails on CI
budget note: internal/release took 34.981s, over the 10s the default allows (measured on the run this cached result came from); reported only, timing fails on CI
budget note: internal/runner/containment took 40.062s, over the 15s its record on line 40 allows; reported only, timing fails on CI

receipt: test step 2m18.3s against a 60s target (the gate's other steps are not in this figure)
receipt: 13 packages ran, 52 cached, 20 without tests, 0 failed
receipt: slow package 54.274s amadan.net/oficina/equipo/internal/runner/provider/opencode
receipt: slow package 53.07s amadan.net/oficina/equipo/internal/runner/provider/pi
receipt: slow package 45.275s amadan.net/oficina/equipo/internal/equipo
receipt: slow package 40.062s amadan.net/oficina/equipo/internal/runner/containment
receipt: slow package 39.84s amadan.net/oficina/equipo/internal/idtest
receipt: slow test 22.41s amadan.net/oficina/equipo/internal/runner/provider/opencode TestOpenCodeAcceptanceHostileRepository
receipt: slow test 15.44s amadan.net/oficina/equipo/internal/runner/containment TestEngineeringOfflineGo
receipt: slow test 10.89s amadan.net/oficina/equipo/internal/idtest TestIDCallbackGuardAndPendingNonce
receipt: slow test 10.82s amadan.net/oficina/equipo/internal/equipo TestAgentReadRechecksIdentity
receipt: slow test 9.54s amadan.net/oficina/equipo/internal/runner/containment TestEngineeringMissingModuleCache
machine: 32 CPUs, load 13.62, cpu waiting 5.33%, memory waiting 0.00%, io waiting 0.12%
--- shard 18 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
browser: /opt/chromium-156.0.8078.79-1_deb13u1/chrome: Chromium 156.0.8078.79
browser lane browser-headless-chat: ./internal/headless
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags browser,testbuild -timeout 15m -run '^TestBrowserChat$|^TestBrowserChatSendStaysOnPage$|^TestBrowserComposer$|^TestBrowserComposerReconcile$|^TestBrowserComposerFocus$|^TestBrowserComposerDock$|^TestBrowserDraftStreamsFormatted$|^TestBrowserDraftIsTheMessage$' ./internal/headless
cache miss: amadan.net/oficina/equipo/internal/headless: its inputs changed

receipt: test step 1m23.093s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 1m21.514s amadan.net/oficina/equipo/internal/headless
receipt: slow test 37.41s amadan.net/oficina/equipo/internal/headless TestBrowserDraftIsTheMessage
receipt: slow test 15.44s amadan.net/oficina/equipo/internal/headless TestBrowserDraftStreamsFormatted
receipt: slow test 10.4s amadan.net/oficina/equipo/internal/headless TestBrowserChat
receipt: slow test 7.85s amadan.net/oficina/equipo/internal/headless TestBrowserComposer
receipt: slow test 5.79s amadan.net/oficina/equipo/internal/headless TestBrowserChatSendStaysOnPage
machine: 32 CPUs, load 37.46, cpu waiting 20.67%, memory waiting 0.00%, io waiting 0.53%
--- shard 19 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
browser: /opt/chromium-156.0.8078.79-1_deb13u1/chrome: Chromium 156.0.8078.79
browser lane browser-headless-work: ./internal/headless
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags browser,testbuild -timeout 15m -run '^TestBrowserTaskCard$|^TestBrowserReceiptFollowsReview$|^TestBrowserRailFollowsWork$|^TestBrowserTaskThread$|^TestBrowserAskAfterMerge$|^TestBrowserReceiptsDesktop$|^TestBrowserReceiptsTouch$' ./internal/headless
cache miss: amadan.net/oficina/equipo/internal/headless: its inputs changed

receipt: test step 1m34.319s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 1m32.695s amadan.net/oficina/equipo/internal/headless
receipt: slow test 26.98s amadan.net/oficina/equipo/internal/headless TestBrowserRailFollowsWork
receipt: slow test 22.73s amadan.net/oficina/equipo/internal/headless TestBrowserTaskThread
receipt: slow test 14.35s amadan.net/oficina/equipo/internal/headless TestBrowserReceiptFollowsReview
receipt: slow test 10.42s amadan.net/oficina/equipo/internal/headless TestBrowserAskAfterMerge
receipt: slow test 8.18s amadan.net/oficina/equipo/internal/headless TestBrowserTaskCard
machine: 32 CPUs, load 33.56, cpu waiting 17.52%, memory waiting 0.00%, io waiting 0.43%
--- shard 20 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
browser: /opt/chromium-156.0.8078.79-1_deb13u1/chrome: Chromium 156.0.8078.79
browser lane browser-headless-connections: ./internal/headless
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags browser,testbuild -timeout 15m -run '^TestBrowserConnections|^TestBrowserPasteBox$|^TestBrowserPasteCopiesItsBox$' ./internal/headless
cache miss: amadan.net/oficina/equipo/internal/headless: its inputs changed

receipt: test step 1m40.837s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 1m39.086s amadan.net/oficina/equipo/internal/headless
receipt: slow test 13.88s amadan.net/oficina/equipo/internal/headless TestBrowserConnectionsConversation
receipt: slow test 13.38s amadan.net/oficina/equipo/internal/headless TestBrowserConnectionsAdd
receipt: slow test 13.05s amadan.net/oficina/equipo/internal/headless TestBrowserConnectionsAddPage
receipt: slow test 10.25s amadan.net/oficina/equipo/internal/headless TestBrowserConnectionsMeteredLimitRequired
receipt: slow test 10.18s amadan.net/oficina/equipo/internal/headless TestBrowserConnectionsOpenCodeGoLimitRequired
machine: 32 CPUs, load 31.11, cpu waiting 16.40%, memory waiting 0.00%, io waiting 0.40%
--- shard 21 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
browser: /opt/chromium-156.0.8078.79-1_deb13u1/chrome: Chromium 156.0.8078.79
browser lane browser-headless-rest: ./internal/headless
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags browser,testbuild -timeout 15m -run '^(TestBrowserAskAfterMerge|TestBrowserChat|TestBrowserChatSendStaysOnPage|TestBrowserComposer|TestBrowserComposerDock|TestBrowserComposerFocus|TestBrowserComposerReconcile|TestBrowserConnectionsAdd|TestBrowserConnectionsAddPage|TestBrowserConnectionsConversation|TestBrowserConnectionsCopyLink|TestBrowserConnectionsEndedNote|TestBrowserConnectionsMeteredLimitRequired|TestBrowserConnectionsOpenCodeGoLimitRequired|TestBrowserConnectionsSignIn|TestBrowserConnectionsSignInSwitch|TestBrowserConnectionsToken|TestBrowserCopyContinue|TestBrowserCopySettingAndFlag|TestBrowserDraftIsTheMessage|TestBrowserDraftStreamsFormatted|TestBrowserEmptyExplore|TestBrowserMoveIn|TestBrowserNotebook|TestBrowserNotebookLook|TestBrowserPasteBox|TestBrowserPasteBoxLook|TestBrowserPasteCopiesItsBox|TestBrowserRailFollowsWork|TestBrowserReceiptFollowsReview|TestBrowserReceiptsDesktop|TestBrowserReceiptsTouch|TestBrowserRefreshRace|TestBrowserStalePageReloads|TestBrowserTaskCard|TestBrowserTaskThread|TestBrowserThinkingAndCards|TestBrowserUsageAndAdvice|TestBrowserWaitingTurns|TestNotebookScreenshots)$' -skip '^TestBrowserChat$|^TestBrowserChatSendStaysOnPage$|^TestBrowserComposer$|^TestBrowserComposerReconcile$|^TestBrowserComposerFocus$|^TestBrowserComposerDock$|^TestBrowserDraftStreamsFormatted$|^TestBrowserDraftIsTheMessage$|^TestBrowserTaskCard$|^TestBrowserReceiptFollowsReview$|^TestBrowserRailFollowsWork$|^TestBrowserTaskThread$|^TestBrowserAskAfterMerge$|^TestBrowserReceiptsDesktop$|^TestBrowserReceiptsTouch$|^TestBrowserConnections|^TestBrowserPasteBox$|^TestBrowserPasteCopiesItsBox$' ./internal/headless
rastrillo: budget test: go test failed
--- FAIL amadan.net/oficina/equipo/internal/headless TestBrowserCopyContinue
=== RUN   TestBrowserCopyContinue
time=2026-11-22T17:58:37.953Z level=INFO msg="startup phase" phase=state_lock
time=2026-11-22T17:58:37.954Z level=INFO msg="startup phase done" phase=state_lock took=288µs
time=2026-11-22T17:58:37.954Z level=INFO msg="startup phase" phase=claim_roots
time=2026-11-22T17:58:37.954Z level=INFO msg="startup phase done" phase=claim_roots took=218µs
time=2026-11-22T17:58:37.954Z level=INFO msg="startup phase" phase=sweep
time=2026-11-22T17:58:37.995Z level=INFO msg="startup phase done" phase=sweep took=40.795ms
time=2026-11-22T17:58:37.995Z level=INFO msg="startup phase" phase=credentials
time=2026-11-22T17:58:37.996Z level=INFO msg="startup phase done" phase=credentials took=1.301ms
time=2026-11-22T17:58:37.996Z level=INFO msg="startup phase" phase=open_state
time=2026-11-22T17:58:38.060Z level=INFO msg="startup phase done" phase=open_state took=63.324ms
time=2026-11-22T17:58:38.060Z level=WARN msg="no seal key: token connections cannot be added" err=*fs.PathError
time=2026-11-22T17:58:38.061Z level=INFO msg=connecting host=127.0.0.1:39893 protocol=28
time=2026-11-22T17:58:38.062Z level=INFO msg=connected host=127.0.0.1:39893 took=1.147ms
time=2026-11-22T17:58:38.062Z level=INFO msg="capabilities gathering"
time=2026-11-22T17:58:38.064Z level=INFO msg="capabilities gathered" took=2.151ms tags=linux,claude,go
time=2026-11-22T17:58:38.068Z level=INFO msg="hello sent" protocol=28
time=2026-11-22T17:58:38.071Z level=INFO msg=welcome protocol=28 role=primary generation=1
    browser_copy_test.go:93: continue did not reach Checks: 0 <nil>
--- FAIL: TestBrowserCopyContinue (1.96s)

--- FAIL amadan.net/oficina/equipo/internal/headless TestBrowserEmptyExplore
=== RUN   TestBrowserEmptyExplore
time=2026-11-22T17:59:09.387Z level=INFO msg="startup phase" phase=state_lock
time=2026-11-22T17:59:09.387Z level=INFO msg="startup phase done" phase=state_lock took=93µs
time=2026-11-22T17:59:09.387Z level=INFO msg="startup phase" phase=claim_roots
time=2026-11-22T17:59:09.387Z level=INFO msg="startup phase done" phase=claim_roots took=147µs
time=2026-11-22T17:59:09.387Z level=INFO msg="startup phase" phase=sweep
time=2026-11-22T17:59:09.418Z level=INFO msg="startup phase done" phase=sweep took=31.358ms
time=2026-11-22T17:59:09.418Z level=INFO msg="startup phase" phase=credentials
time=2026-11-22T17:59:09.418Z level=INFO msg="startup phase done" phase=credentials took=113µs
time=2026-11-22T17:59:09.418Z level=INFO msg="startup phase" phase=open_state
time=2026-11-22T17:59:09.459Z level=INFO msg="startup phase done" phase=open_state took=40.102ms
time=2026-11-22T17:59:09.459Z level=WARN msg="no seal key: token connections cannot be added" err=*fs.PathError
time=2026-11-22T17:59:09.460Z level=INFO msg=connecting host=127.0.0.1:32861 protocol=28
time=2026-11-22T17:59:09.461Z level=INFO msg=connected host=127.0.0.1:32861 took=893µs
time=2026-11-22T17:59:09.461Z level=INFO msg="capabilities gathering"
time=2026-11-22T17:59:09.462Z level=INFO msg="capabilities gathered" took=549µs tags=linux,claude,go
time=2026-11-22T17:59:09.462Z level=INFO msg="hello sent" protocol=28
time=2026-11-22T17:59:09.468Z level=INFO msg=welcome protocol=28 role=primary generation=1
time=2026-11-22T17:59:10.417Z level=INFO msg="connection checked" connection=claude-1 state=healthy
    browser_receipts_test.go:169: waiting for [...document.querySelectorAll('[equipo-markdown]:not([data-stream-text])')].some(e=>e.textContent.includes("I'm your coordinator")): context deadline exceeded (last evaluation: context deadline exceeded)
--- FAIL: TestBrowserEmptyExplore (5.82s)

--- FAIL amadan.net/oficina/equipo/internal/headless (package output)
FAIL
rastrillo-budget/v1 ran 1m27.892s
FAIL	amadan.net/oficina/equipo/internal/headless	88.165s


receipt: test step 1m29.272s against a 60s target (the gate's other steps are not in this figure)
receipt: 0 packages ran, 0 cached, 0 without tests, 1 failed
receipt: slow package 1m27.892s amadan.net/oficina/equipo/internal/headless
receipt: slow test 15.43s amadan.net/oficina/equipo/internal/headless TestBrowserThinkingAndCards
receipt: slow test 11.24s amadan.net/oficina/equipo/internal/headless TestBrowserWaitingTurns
receipt: slow test 10.53s amadan.net/oficina/equipo/internal/headless TestBrowserMoveIn
receipt: slow test 10.46s amadan.net/oficina/equipo/internal/headless TestBrowserStalePageReloads
receipt: slow test 8.13s amadan.net/oficina/equipo/internal/headless TestBrowserRefreshRace
exit status 1
+ go test -tags browser,testbuild -timeout 15m -run '^(TestBrowserAskAfterMerge|TestBrowserChat|TestBrowserChatSendStaysOnPage|TestBrowserComposer|TestBrowserComposerDock|TestBrowserComposerFocus|TestBrowserComposerReconcile|TestBrowserConnectionsAdd|TestBrowserConnectionsAddPage|TestBrowserConnectionsConversation|TestBrowserConnectionsCopyLink|TestBrowserConnectionsEndedNote|TestBrowserConnectionsMeteredLimitRequired|TestBrowserConnectionsOpenCodeGoLimitRequired|TestBrowserConnectionsSignIn|TestBrowserConnectionsSignInSwitch|TestBrowserConnectionsToken|TestBrowserCopyContinue|TestBrowserCopySettingAndFlag|TestBrowserDraftIsTheMessage|TestBrowserDraftStreamsFormatted|TestBrowserEmptyExplore|TestBrowserMoveIn|TestBrowserNotebook|TestBrowserNotebookLook|TestBrowserPasteBox|TestBrowserPasteBoxLook|TestBrowserPasteCopiesItsBox|TestBrowserRailFollowsWork|TestBrowserReceiptFollowsReview|TestBrowserReceiptsDesktop|TestBrowserReceiptsTouch|TestBrowserRefreshRace|TestBrowserStalePageReloads|TestBrowserTaskCard|TestBrowserTaskThread|TestBrowserThinkingAndCards|TestBrowserUsageAndAdvice|TestBrowserWaitingTurns|TestNotebookScreenshots)$' -skip '^TestBrowserChat$|^TestBrowserChatSendStaysOnPage$|^TestBrowserComposer$|^TestBrowserComposerReconcile$|^TestBrowserComposerFocus$|^TestBrowserComposerDock$|^TestBrowserDraftStreamsFormatted$|^TestBrowserDraftIsTheMessage$|^TestBrowserTaskCard$|^TestBrowserReceiptFollowsReview$|^TestBrowserRailFollowsWork$|^TestBrowserTaskThread$|^TestBrowserAskAfterMerge$|^TestBrowserReceiptsDesktop$|^TestBrowserReceiptsTouch$|^TestBrowserConnections|^TestBrowserPasteBox$|^TestBrowserPasteCopiesItsBox$' -v -run '^TestBrowserCopyContinue$|^TestBrowserEmptyExplore$' -count=1 ./internal/headless   (retry, once)
##############################################################################
FLAKE ./internal/headless:TestBrowserCopyContinue browser-headless-rest ab73319c5fabb63d7e591818c7d3c309fdb2f51a 1.96s 35.27
##############################################################################
failed, then passed on its one retry: the step stays green and the flake is on record
##############################################################################
FLAKE ./internal/headless:TestBrowserEmptyExplore browser-headless-rest ab73319c5fabb63d7e591818c7d3c309fdb2f51a 5.82s 35.27
##############################################################################
failed, then passed on its one retry: the step stays green and the flake is on record
machine: 32 CPUs, load 31.11, cpu waiting 15.86%, memory waiting 0.00%, io waiting 0.39%
--- shard 22 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
timing budgets: reported, not enforced: a shared runner's load is not this change's time (set EQUIPO_CI_DEDICATED=1 on a dedicated runner)
browser: /opt/chromium-156.0.8078.79-1_deb13u1/chrome: Chromium 156.0.8078.79
browser lane browser-rest: ./internal/equipo
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags browser,testbuild -timeout 15m -run '^(TestBrowserPreviewBlocksNavigation)$' ./internal/equipo

receipt: test step 1.102s against a 60s target (the gate's other steps are not in this figure)
receipt: 0 packages ran, 1 cached, 0 without tests, 0 failed
receipt: slow package 573ms amadan.net/oficina/equipo/internal/equipo
receipt: slow test 570ms amadan.net/oficina/equipo/internal/equipo TestBrowserPreviewBlocksNavigation
browser lane browser-rest: ./internal/idtest
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags browser,testbuild -timeout 15m -run '^(TestBrowserOficinaIDDoor)$' ./internal/idtest

receipt: test step 841ms against a 60s target (the gate's other steps are not in this figure)
receipt: 0 packages ran, 1 cached, 0 without tests, 0 failed
receipt: slow package 1.673s amadan.net/oficina/equipo/internal/idtest
receipt: slow test 1.67s amadan.net/oficina/equipo/internal/idtest TestBrowserOficinaIDDoor
browser lane browser-rest: ./internal/plan3test
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags browser,testbuild -timeout 15m -run '^(TestTeamsHierarchyBrowser)$' ./internal/plan3test

receipt: test step 287ms against a 60s target (the gate's other steps are not in this figure)
receipt: 0 packages ran, 1 cached, 0 without tests, 0 failed
receipt: slow package 1.856s amadan.net/oficina/equipo/internal/plan3test
receipt: slow test 1.86s amadan.net/oficina/equipo/internal/plan3test TestTeamsHierarchyBrowser
browser lane browser-rest: ./internal/thintest
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -tags browser,testbuild -timeout 15m -run '^(TestBrowserAccessEmojiByline|TestBrowserAccessFinalOutcomes|TestBrowserAccessRequest|TestBrowserAccessReview|TestBrowserActivitySubjects|TestBrowserAutonomySettings|TestBrowserCoordinatorQueue|TestBrowserEmptyConversation|TestBrowserEndedNoteStaysGone|TestBrowserHousekeeping|TestBrowserInnerGallery|TestBrowserInnerScreens|TestBrowserInstantThinking|TestBrowserInstantThinkingQueued|TestBrowserMachines|TestBrowserPhoneIndex|TestBrowserPlacementQuestionAndPending|TestBrowserProjectPlacement|TestBrowserProjectsList|TestBrowserReportActionFeedback|TestBrowserReportNextSteps|TestBrowserReportThread|TestBrowserRollup|TestBrowserRosterAlignment|TestBrowserRosterDecisionStates|TestBrowserRosterQuietDay|TestBrowserRosterReports|TestBrowserRosterSetAside|TestBrowserRosterSubchat|TestBrowserRosterThinking|TestBrowserRosterVisual|TestBrowserSettingsHousekeepingGroups|TestBrowserSettingsMenu|TestBrowserSettingsRail|TestBrowserSettingsSaveBar|TestBrowserSettingsShots|TestBrowserSettingsStayOnPage|TestBrowserSettingsTeams|TestBrowserShipsButtons|TestBrowserSpecialistRows|TestBrowserSpendFollowsAnswers|TestBrowserTaskRows|TestBrowserTeamPanel|TestBrowserThinkingCycles|TestBrowserThinkingLinesClear|TestBrowserThinkingSteady|TestBrowserThinkingWords|TestBrowserTokenRowEmail|TestBrowserTrackPulse|TestBrowserTrackStarCentre|TestBrowserTryAgain)$' ./internal/thintest

receipt: test step 1.195s against a 60s target (the gate's other steps are not in this figure)
receipt: 0 packages ran, 1 cached, 0 without tests, 0 failed
receipt: slow package 3m20.199s amadan.net/oficina/equipo/internal/thintest
receipt: slow test 17.52s amadan.net/oficina/equipo/internal/thintest TestBrowserAccessRequest
receipt: slow test 14.35s amadan.net/oficina/equipo/internal/thintest TestBrowserSettingsTeams
receipt: slow test 12.02s amadan.net/oficina/equipo/internal/thintest TestBrowserThinkingCycles
receipt: slow test 10.55s amadan.net/oficina/equipo/internal/thintest TestBrowserPlacementQuestionAndPending
receipt: slow test 7.93s amadan.net/oficina/equipo/internal/thintest TestBrowserInnerScreens
machine: 32 CPUs, load 2.72, cpu waiting 2.02%, memory waiting 0.00%, io waiting 2.02%
--- shard 23 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
shard 23: make test-quarantine
python3 scripts/ci-test.py quarantine
quarantine: 12 tests from scripts/ci-quarantine.txt; a failure is retried once, and a pass on the retry is reported as a flake
+ go test -tags testbuild -timeout 15m -v -run '^TestHeadlessConnections$/^A5_cancel_and_sign_out$|^TestHeadlessConnections$/^C4_claude_sign_in$|^TestHeadlessConnections$/^C5_engineering_failover$|^TestHeadlessConnections$/^C5_engineering_to_codex$|^TestHeadlessConnections$/^C5_engineering_waits$' ./internal/headless   (53s)
ok ./internal/headless TestHeadlessConnections/A5_cancel_and_sign_out 5.26s
ok ./internal/headless TestHeadlessConnections/C4_claude_sign_in 1.40s
ok ./internal/headless TestHeadlessConnections/C5_engineering_failover 9.55s
ok ./internal/headless TestHeadlessConnections/C5_engineering_to_codex 10.00s
ok ./internal/headless TestHeadlessConnections/C5_engineering_waits 24.96s
+ go test -tags testbuild -timeout 15m -v -run '^TestHeadlessConnections$/^C5_review_auth$|^TestHeadlessConnections$/^C5_review_failover$|^TestHeadlessConnections$/^C5_review_on_codex$|^TestHeadlessConnections$/^C5_review_other_family_first$' ./internal/headless   (63s)
ok ./internal/headless TestHeadlessConnections/C5_review_auth 12.91s
ok ./internal/headless TestHeadlessConnections/C5_review_failover 14.42s
ok ./internal/headless TestHeadlessConnections/C5_review_on_codex 20.57s
ok ./internal/headless TestHeadlessConnections/C5_review_other_family_first 13.35s
+ go test -tags testbuild -timeout 15m -v -run '^TestMixedVersions$' ./internal/headless   (22s)
ok ./internal/headless TestMixedVersions 20.56s
+ go test -tags testbuild -timeout 15m -v -run '^TestCheckSandboxDeniedPathsTampering$' ./internal/runner/checks   (2s)
ok ./internal/runner/checks TestCheckSandboxDeniedPathsTampering 0.81s
+ go test -tags testbuild -timeout 15m -v -run '^TestRunnerCancelAndSupersede$' ./internal/runner/thin   (1s)
ok ./internal/runner/thin TestRunnerCancelAndSupersede 0.05s
quarantine: 0 flaked (passed on the retry), 0 failed
machine: 32 CPUs, load 41.55, cpu waiting 21.91%, memory waiting 0.00%, io waiting 0.74%
--- shard 24 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
shard 24: make runner-host
python3 scripts/runner-prerequisites.py
CGO_ENABLED=0 RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py retried runner-host -run 'TestDirect|TestProvider|TestCheckSandbox' -count=1 ./internal/runner/provider/... ./internal/runner/checks
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -no-time -run 'TestDirect|TestProvider|TestCheckSandbox' -count=1 ./internal/runner/provider/... ./internal/runner/checks

receipt: test step 8.595s against a 60s target (the gate's other steps are not in this figure)
receipt: 4 packages ran, 0 cached, 3 without tests, 0 failed
receipt: slow package 7.298s amadan.net/oficina/equipo/internal/runner/checks
receipt: slow package 173ms amadan.net/oficina/equipo/internal/runner/provider/claude
receipt: slow package 86ms amadan.net/oficina/equipo/internal/runner/provider/codex
receipt: slow package 1ms amadan.net/oficina/equipo/internal/runner/provider
receipt: slow package 0s amadan.net/oficina/equipo/internal/runner/provider/gotoolchain
receipt: slow test 5.3s amadan.net/oficina/equipo/internal/runner/checks TestCheckSandboxDeniedPathsGoFixture
receipt: slow test 1.61s amadan.net/oficina/equipo/internal/runner/checks TestCheckSandboxDeniedPaths
receipt: slow test 310ms amadan.net/oficina/equipo/internal/runner/checks TestCheckSandboxDeniedPathsCache
receipt: slow test 170ms amadan.net/oficina/equipo/internal/runner/provider/claude TestDirectJournalAdapterBarrier
receipt: slow test 80ms amadan.net/oficina/equipo/internal/runner/provider/codex TestDirectJournalAdapterBarrier
CGO_ENABLED=0 EQUIPO_REQUIRE_USER_SESSION=1 RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py retried runner-host -run '^TestNamespace' -count=1 ./internal/runner/containment
+ go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -no-time -run '^TestNamespace' -count=1 ./internal/runner/containment

receipt: test step 3.177s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 0 without tests, 0 failed
receipt: slow package 2.844s amadan.net/oficina/equipo/internal/runner/containment
receipt: slow test 270ms amadan.net/oficina/equipo/internal/runner/containment TestNamespaceReadOnlyScratch
receipt: slow test 190ms amadan.net/oficina/equipo/internal/runner/containment TestNamespaceRecoveryUnavailableProof
receipt: slow test 120ms amadan.net/oficina/equipo/internal/runner/containment TestNamespaceDirectPolicyAdmission
receipt: slow test 100ms amadan.net/oficina/equipo/internal/runner/containment TestNamespaceRecoveryCleansScratch
receipt: slow test 100ms amadan.net/oficina/equipo/internal/runner/containment TestNamespaceReapsOrphans
machine: 32 CPUs, load 4.18, cpu waiting 5.12%, memory waiting 0.00%, io waiting 1.77%
--- shard 25 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
stagger: runner-dead-references started 30s late; cpu waiting 26.6%, load 16.14
shard 25: make runner-dead-references lanes-check build vet fmt-check budget migration-check
python3 scripts/runner-dead-references.py
reference scan: 2594 text files, 2854 matches, 0 failures
python3 scripts/ci-test.py check
lanes: 18 lanes and 5 browser lanes run every test once; 20-check@29
CGO_ENABLED=0 go build ./...
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o /dev/null ./cmd/equipo-runner
go vet ./...
go vet -tags testbuild ./internal/runner/thin ./internal/headless
GOOS=darwin GOARCH=arm64 go vet ./cmd/equipo-runner/... ./internal/runner/... ./internal/wire/... ./internal/release/...
go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget size
budget size: 94 directories within budget
CGO_ENABLED=0 go test ./internal/equipo -run '^TestMigrationModels$' -count=1
ok  	amadan.net/oficina/equipo/internal/equipo	2.586s
machine: 32 CPUs, load 35.16, cpu waiting 19.27%, memory waiting 0.00%, io waiting 1.07%
--- shard 26 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
stagger: staticcheck started 30s late; cpu waiting 28.3%, load 16.14
shard 26: make staticcheck
go run honnef.co/go/tools/cmd/staticcheck@v0.7.0 -tags browser,perf,testbuild ./...
machine: 32 CPUs, load 16.14, cpu waiting 12.94%, memory waiting 0.00%, io waiting 1.27%
--- shard 27 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
stagger: govulncheck started 30s late; cpu waiting 28.3%, load 16.14
shard 27: make govulncheck
go run golang.org/x/vuln/cmd/govulncheck@v1.8.0 ./...
=== Symbol Results ===

No vulnerabilities found.

Your code is affected by 0 vulnerabilities.
This scan also found 0 vulnerabilities in packages you import and 5
vulnerabilities in modules you require, but your code doesn't appear to call
these vulnerabilities.
Use '-show verbose' for more details.
machine: 32 CPUs, load 26.78, cpu waiting 15.90%, memory waiting 0.00%, io waiting 1.18%
--- shard 28 of 29 ---
RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py shard
stagger: gitleaks started 30s late; cpu waiting 26.6%, load 16.14
shard 28: make gitleaks
5:58PM INF Unknown SCM platform. Use --platform to include links in findings. host=amadan.net
5:58PM INF 1122 commits scanned.
5:58PM INF scanned ~61799524 bytes (61.80 MB) in 13.6s
5:58PM INF no leaks found
machine: 32 CPUs, load 35.16, cpu waiting 19.27%, memory waiting 0.00%, io waiting 1.07%
=== perf ===
go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -no-time -require TestPerfScreens,TestPerfBoot -tags perf -count=1 -p 1 -parallel 1 -run '^TestPerf' ./...
perf: GET /: median 1.089ms, worst 1.126ms, budget 150ms
perf: GET /api/runner/protocol: median 94µs, worst 112µs, budget 150ms
perf: GET /api/v1/account-setups/{id}: median 602µs, worst 615µs, budget 150ms
perf: GET /api/v1/accounts: median 429µs, worst 447µs, budget 150ms
perf: GET /api/v1/auth/devices: median 459µs, worst 505µs, budget 150ms
perf: GET /api/v1/budgets: median 499µs, worst 530µs, budget 150ms
perf: GET /api/v1/capabilities: median 244µs, worst 264µs, budget 150ms
perf: GET /api/v1/cards/{id}: median 1.191ms, worst 1.29ms, budget 150ms
perf: GET /api/v1/connections: median 622µs, worst 675µs, budget 150ms
perf: GET /api/v1/connections/{id}: median 599µs, worst 643µs, budget 150ms
perf: GET /api/v1/conversation: median 968µs, worst 1.069ms, budget 150ms
perf: GET /api/v1/conversation/cards: median 1.587ms, worst 1.715ms, budget 150ms
perf: GET /api/v1/coordinator: median 1.932ms, worst 2ms, budget 150ms
perf: GET /api/v1/invites/{id}: median 443µs, worst 466µs, budget 150ms
perf: GET /api/v1/journey: median 7.783ms, worst 7.904ms, budget 150ms
perf: GET /api/v1/me: median 429µs, worst 471µs, budget 150ms
perf: GET /api/v1/me/settings: median 520µs, worst 548µs, budget 150ms
perf: GET /api/v1/needs-you: median 7.805ms, worst 8.11ms, budget 150ms
perf: GET /api/v1/notifications: median 1.806ms, worst 1.964ms, budget 150ms
perf: GET /api/v1/onboarding: median 425µs, worst 465µs, budget 150ms
perf: GET /api/v1/people: median 470µs, worst 497µs, budget 150ms
perf: GET /api/v1/playbooks: median 626µs, worst 725µs, budget 150ms
perf: GET /api/v1/playbooks/{id}: median 566µs, worst 607µs, budget 150ms
perf: GET /api/v1/playbooks/{id}/template-diff: median 919µs, worst 983µs, budget 150ms
perf: GET /api/v1/preferences: median 847µs, worst 920µs, budget 150ms
perf: GET /api/v1/projects/{id}: median 516µs, worst 536µs, budget 150ms
perf: GET /api/v1/projects/{id}/settings: median 740µs, worst 789µs, budget 150ms
perf: GET /api/v1/roster: median 587µs, worst 612µs, budget 150ms
perf: GET /api/v1/runners/{id}: median 517µs, worst 550µs, budget 150ms
perf: GET /api/v1/specialists: median 8.383ms, worst 8.468ms, budget 150ms
perf: GET /api/v1/specialists/{id}: median 8.205ms, worst 8.346ms, budget 150ms
perf: GET /api/v1/specialists/{id}/template-diff: median 881µs, worst 927µs, budget 150ms
perf: GET /api/v1/tasks/{id}/plan: median 1.172ms, worst 1.199ms, budget 150ms
perf: GET /api/v1/tasks/{id}/thread: median 765µs, worst 814µs, budget 150ms
perf: GET /api/v1/teams: median 453µs, worst 512µs, budget 150ms
perf: GET /api/v1/templates: median 604µs, worst 650µs, budget 150ms
perf: GET /api/v1/templates/{id}: median 460µs, worst 508µs, budget 150ms
perf: GET /auth/callback: median 85µs, worst 106µs, budget 150ms
perf: GET /auth/devices/{id}: median 3.413ms, worst 3.492ms, budget 150ms
perf: GET /auth/verify: median 76µs, worst 99µs, budget 150ms
perf: GET /connections: median 3.911ms, worst 4.02ms, budget 150ms
perf: GET /conversation: median 7.753ms, worst 7.987ms, budget 150ms
perf: GET /conversation/connections: median 245µs, worst 280µs, budget 150ms
perf: GET /conversation/notebook: median 250µs, worst 283µs, budget 150ms
perf: GET /conversation/settings: median 4.173ms, worst 4.308ms, budget 150ms
perf: GET /conversation/settings/autonomy: median 3.793ms, worst 3.868ms, budget 150ms
perf: GET /conversation/settings/connections: median 7.279ms, worst 7.418ms, budget 150ms
perf: GET /conversation/settings/connections/add: median 7.344ms, worst 8.896ms, budget 150ms
perf: GET /conversation/settings/copy: median 4.24ms, worst 4.437ms, budget 150ms
perf: GET /conversation/settings/housekeeping: median 4.742ms, worst 4.817ms, budget 150ms
perf: GET /conversation/settings/machines: median 4.549ms, worst 4.649ms, budget 150ms
perf: GET /conversation/settings/machines/add: median 4.716ms, worst 4.805ms, budget 150ms
perf: GET /conversation/settings/notebook: median 3.454ms, worst 3.543ms, budget 150ms
perf: GET /conversation/settings/thinking: median 4.112ms, worst 4.135ms, budget 150ms
perf: GET /housekeeping: median 3.802ms, worst 3.924ms, budget 150ms
perf: GET /invites/new: median 589µs, worst 665µs, budget 150ms
perf: GET /invites/{id}: median 631µs, worst 670µs, budget 150ms
perf: GET /jobs: median 3.376ms, worst 3.516ms, budget 150ms
perf: GET /jobs/{id}: median 4.851ms, worst 6.066ms, budget 150ms
perf: GET /journey: median 12.866ms, worst 13.317ms, budget 150ms
perf: GET /nav/rail: median 3.282ms, worst 3.368ms, budget 150ms
perf: GET /needs-you: median 12.302ms, worst 12.482ms, budget 150ms
perf: GET /onboarding: median 4.541ms, worst 4.656ms, budget 150ms
perf: GET /people: median 3.789ms, worst 3.959ms, budget 150ms
perf: GET /playbook-suggestions/{suggestion}: median 5.458ms, worst 5.577ms, budget 150ms
perf: GET /playbooks: median 4.81ms, worst 5.001ms, budget 150ms
perf: GET /playbooks/new: median 5.029ms, worst 5.169ms, budget 150ms
perf: GET /playbooks/{id}: median 4.863ms, worst 6.379ms, budget 150ms
perf: GET /playbooks/{id}/edit: median 4.764ms, worst 4.855ms, budget 150ms
perf: GET /playbooks/{id}/template-diff: median 3.873ms, worst 3.942ms, budget 150ms
perf: GET /preferences: median 4.267ms, worst 4.448ms, budget 150ms
perf: GET /preferences/sources/{source}: median 4.084ms, worst 4.181ms, budget 150ms
perf: GET /projects: median 5.247ms, worst 5.46ms, budget 150ms
perf: GET /projects/accounts: median 3.56ms, worst 3.698ms, budget 150ms
perf: GET /projects/new: median 3.702ms, worst 3.858ms, budget 150ms
perf: GET /projects/{id}: median 10.524ms, worst 10.858ms, budget 150ms
perf: GET /projects/{id}/edit: median 3.812ms, worst 4.054ms, budget 150ms
perf: GET /runners/enrol: median 5.044ms, worst 6.422ms, budget 150ms
perf: GET /settings: median 3.727ms, worst 3.847ms, budget 150ms
perf: GET /settings/coordinator: median 5.844ms, worst 6.045ms, budget 150ms
perf: GET /settings/devices: median 3.404ms, worst 3.701ms, budget 150ms
perf: GET /settings/recovery: median 3.604ms, worst 3.733ms, budget 150ms
perf: GET /settings/recovery/release: median 3.623ms, worst 3.745ms, budget 150ms
perf: GET /settings/thinking: median 255µs, worst 294µs, budget 150ms
perf: GET /signin: median 324µs, worst 340µs, budget 150ms
perf: GET /specialists/new: median 3.406ms, worst 3.469ms, budget 150ms
perf: GET /specialists/{key}: median 11.058ms, worst 11.141ms, budget 150ms
perf: GET /specialists/{key}/edit: median 3.642ms, worst 3.727ms, budget 150ms
perf: GET /specialists/{key}/template-diff: median 3.743ms, worst 3.78ms, budget 150ms
perf: GET /tasks: median 5.36ms, worst 7.039ms, budget 150ms
perf: GET /tasks/new: median 3.335ms, worst 3.456ms, budget 150ms
perf: GET /tasks/{id}: median 5.742ms, worst 5.919ms, budget 150ms
perf: GET /tasks/{id}/merge: median 4.853ms, worst 5.058ms, budget 150ms
perf: GET /tasks/{id}/move: median 4.632ms, worst 4.785ms, budget 150ms
perf: GET /tasks/{id}/plan: median 6.015ms, worst 6.163ms, budget 150ms
perf: GET /tasks/{id}/preview: median 1.607ms, worst 1.652ms, budget 150ms
perf: GET /tasks/{id}/questions/{question}: median 5.402ms, worst 5.541ms, budget 150ms
perf: GET /tasks/{id}/rendered-change: median 4.813ms, worst 4.905ms, budget 150ms
perf: GET /tasks/{id}/rendered-change/{hash}.png: median 4.395ms, worst 4.516ms, budget 150ms
perf: GET /tasks/{id}/thread: median 8.817ms, worst 11.43ms, budget 150ms
perf: GET /team/{specialist}: median 4.574ms, worst 4.781ms, budget 150ms
perf: GET /teams: median 10.429ms, worst 10.543ms, budget 150ms
perf: GET /templates: median 3.592ms, worst 3.744ms, budget 150ms
perf: GET /usage: median 4.339ms, worst 4.464ms, budget 150ms
perf: GET /work: median 3.21ms, worst 3.309ms, budget 150ms
perf: cold boot: median 265ms of [261.715773ms 264.556679ms 269.555009ms], budget 500ms

receipt: test step 32.909s against a 60s target (the gate's other steps are not in this figure)
receipt: 1 packages ran, 0 cached, 90 without tests, 0 failed
receipt: slow package 9.126s amadan.net/oficina/equipo/internal/equipotest
receipt: slow package 0s amadan.net/oficina/equipo/cmd/equipo-runner
receipt: slow package 0s amadan.net/oficina/equipo/cmd/equipo-tool-proxy
receipt: slow package 0s amadan.net/oficina/equipo/internal/advice
receipt: slow package 0s amadan.net/oficina/equipo/internal/attach
receipt: slow test 8.27s amadan.net/oficina/equipo/internal/equipotest TestPerfScreens
receipt: slow test 850ms amadan.net/oficina/equipo/internal/equipotest TestPerfBoot
=== cache ===
ci-box: build cache /home/ci/work/repos/oficina__equipo/cache/go-build: 4.50 GiB in 26282 files
ci-box: module cache /home/ci/work/repos/oficina__equipo/cache/go-mod: 0.90 GiB in 32632 files
ci-box: build cache over 4.0 GiB: dropped 1.85 GiB this job did not read, kept 2.66 GiB
diff --git a/docs/superpowers/plans/HOSTED-SLICE1-PROGRESS.md b/docs/superpowers/plans/HOSTED-SLICE1-PROGRESS.md
index c87fc390..6337b1ec 100644
--- a/docs/superpowers/plans/HOSTED-SLICE1-PROGRESS.md
+++ b/docs/superpowers/plans/HOSTED-SLICE1-PROGRESS.md
@@ -442,3 +442,33 @@ Changes: `attemptlock.go` (new: `func (c *Controller) lockAttempt(id string) fun
| TX3 Refresh's get inside a transaction | `^TestStopRecordsRequestBeforeProvider$` | `stop_test.go:252: provider get (call 2): a store read waited 2 s; ...` | yes, passes |
| TX4 Refresh's list inside a transaction | `^TestStopRecordsRequestBeforeProvider$` | `stop_test.go:252: provider list (call 3): a store read waited 2 s; ...` | yes, passes |
| N1, M1, M5 rechecked | `^TestStopNotFoundThenRunning$`, `^TestStopProofNeedsTerminalState$`, `^TestRestartDowntimeExceedsWallDelta$` | `stop_test.go:473: after one not-found: proof {...}; want no proof and a since time`; `stop_test.go:272: Stop while the VM is stopping = <nil>, want ErrStopPending`; `stop_test.go:778: att-1 with no age: requested {0 false} ...` | yes, passes |
+
+## Task 12
+
+Pause generations (Drain, Quiescent, Suspend, Reopen) and prepared resume epochs (Resume) in
+`internal/hostedctl/pause.go` and `resume.go`; tests in `pause_test.go` and `resume_test.go`. All five
+methods take the verified key, as Stop does, for the instance-role check, and run under the attempt
+lock (R18). Refresh's one change: refreshOne calls `mirrorLive` in place of `mirrorState`, which
+leaves `draining`, `suspending` and `resuming` to the controller, settles only the expected moves,
+and still clears `notfound_since_t` on every live sighting. States `JobDraining` and `JobResuming`
+added to states.go. No schema change.
+
+- RED (compile-only stubs returning an error): all 13 tests fail on their first assertion, e.g.
+ `pause_test.go:91: Drain = (0, stub), want a new generation`.
+- GREEN: `go test ./internal/hostedctl -run 'TestSuspend|TestLateAck|TestResume' -count=1` ok 3.5 s;
+ whole package ok 13.3 s at load average 5 to 7 (10.1 s with the Task 12 tests skipped); vet,
+ gofmt, staticcheck v0.7.0 clean; `make budget` (size) within budget.
+
+| Mutation | Test | Observed failure | Restored |
+| --- | --- | --- | --- |
+| M1 generations compared with `>=` | `^TestSuspendNeedsCurrentAck$` | `pause_test.go:118: Suspend(2) with current generation 1 = hostedctl: record suspend of att-1: 0 rows (<nil>), want hostedctl: pause generation is cancelled or not the current one` | yes, passes |
+| M2 provider called before preparing | `^TestResumePreparesEpochBeforeProvider$` | `resume_test.go:161: store at the provider call: {state:suspended epoch:0 status:{String: Valid:false} prep:{Int64:0 Valid:false} err:<nil>}; want resuming at epoch 0 with op-1 pending at epoch 1` | yes, passes |
+| M3 epoch raised on each call (a done operation re-prepared and committed again) | `^TestResumeRetrySameOperation$` | `resume_test.go:255: Resume(op-1) = (2, <nil>), want (1, nil)` | yes, passes |
+| M4 commit without Get showing running | `^TestResumeLostReply$` | `resume_test.go:229: retry while the VM is suspended = (1, <nil>), want (0, ErrResumePending)` | yes, passes |
+| M5 only the latest operation looked up | `^TestResumeOperationsRemembered$` | `resume_test.go:282: Resume(op-a) = (0, isolatedjob: conflict: only a suspended job can resume; att-1 is running), want (1, nil)` | yes, passes |
+| M6 creator check dropped | `^TestSuspendAndResumeRoles$` | `pause_test.go:252: reopen_refused by another instance = <nil>, want ErrForbidden` | yes, passes |
+| M7 no lazy cancellation | `^TestLateAckIgnored$` | `pause_test.go:150: Quiescent at 2m1s = <nil>, want ErrGenerationCancelled` | yes, passes |
+| M8 no ErrPastDeadline check | `^TestResumePastDeadlineRefused$` | `resume_test.go:317: Resume at the stop time = hostedctl: a resume is pending; ...: VM vm-0001 is suspended, want ErrPastDeadline` | yes, passes |
+| M9 Refresh hook bypassed (plain mirrorState) | `^TestSuspendRefreshSettles$` | `pause_test.go:276: Refresh of a draining job with a running VM left "running", not-found since {0 false}; want draining, cleared` | yes, passes |
+| M10 hook leaves `notfound_since_t` for pause states | `^TestSuspendRefreshSettles$` | `pause_test.go:276: Refresh of a draining job with a running VM left "draining", not-found since {1 true}; want draining, cleared` | yes, passes |
+| M11 a failed resume re-send fails Refresh | `^TestSuspendRefreshSettles$` | `pause_test.go:310: Refresh = isolatedjob: throttled: fake resume` | yes, passes |
diff --git a/internal/hostedctl/pause.go b/internal/hostedctl/pause.go
new file mode 100644
index 00000000..e44b802b
--- /dev/null
+++ b/internal/hostedctl/pause.go
@@ -0,0 +1,371 @@
+package hostedctl
+
+import (
+ "context"
+ "database/sql"
+ "errors"
+ "fmt"
+ "time"
+
+ "amadan.net/oficina/equipo/internal/hostedwire"
+ "amadan.net/oficina/equipo/internal/isolatedjob"
+)
+
+// PauseAckTimeout is how long, in controller time from Drain, the runner has
+// to acknowledge quiescent for a pause generation. Without an
+// acknowledgement by then the generation is cancelled, and a later one is
+// ignored (spec §3, the pause barrier).
+const PauseAckTimeout = 2 * time.Minute
+
+var (
+ // ErrGenerationCancelled: the pause generation named is not the
+ // job's current one (an older or a later one), or it is cancelled, or
+ // the pause it opened is closed.
+ ErrGenerationCancelled = errors.New("hostedctl: pause generation is cancelled or not the current one")
+ // ErrNotQuiescent: the current pause generation has no quiescent
+ // acknowledgement yet, so the VM may not be suspended.
+ ErrNotQuiescent = errors.New("hostedctl: no quiescent acknowledgement for this pause generation")
+ // ErrPastDeadline: the job's stop time has passed. Suspended time
+ // counts, so a suspended job may reach it.
+ ErrPastDeadline = errors.New("hostedctl: the job's stop time has passed")
+)
+
+// Audit actions written by the pause barrier.
+const (
+ actionDrain = "drain"
+ actionDrainRefused = "drain_refused"
+ actionQuiescent = "quiescent"
+ actionQuiescentRepeated = "quiescent_repeated"
+ actionQuiescentRefused = "quiescent_refused"
+ actionSuspendRequested = "suspend_requested"
+ actionSuspendRepeated = "suspend_repeated"
+ actionSuspendRefused = "suspend_refused"
+ actionSuspendFailed = "suspend_failed"
+ actionSuspendResent = "suspend_resent"
+ actionSuspendSettled = "suspend_settled"
+ actionReopen = "reopen"
+ actionReopenRepeated = "reopen_repeated"
+ actionReopenRefused = "reopen_refused"
+ actionPauseCancelled = "pause_cancelled"
+)
+
+// pauseJob is a job row with its pause fields.
+type pauseJob struct {
+ jobRow
+ generation int64
+ started sql.NullInt64 // pause_started_t; absent unless a pause is open
+ quiescent, cancelled bool
+}
+
+// loadPauseJob reads attempt's row and its pause fields inside tx.
+func loadPauseJob(ctx context.Context, tx *sql.Tx, attempt string) (pauseJob, bool, error) {
+ j, found, err := loadJob(ctx, tx, attempt)
+ if err != nil || !found {
+ return pauseJob{}, found, err
+ }
+ p := pauseJob{jobRow: j}
+ if err := tx.QueryRowContext(ctx, `SELECT pause_generation, pause_started_t, pause_quiescent, pause_cancelled
+ FROM jobs WHERE attempt_id = ?`, attempt).Scan(&p.generation, &p.started, &p.quiescent, &p.cancelled); err != nil {
+ return pauseJob{}, false, fmt.Errorf("hostedctl: read pause fields of %s: %w", attempt, err)
+ }
+ return p, true, nil
+}
+
+// currentGen reports whether gen is the job's current pause generation.
+// Only an exact match counts: an older generation was superseded and a later
+// one was never opened.
+func currentGen(gen int64, j *pauseJob) bool { return gen == j.generation }
+
+// creatorCall runs fn in one transaction for a call by `by`, holding key, on
+// attemptID. It refuses a key that is not an instance key, a malformed
+// attempt ID, an unknown attempt and another key's attempt, with
+// ErrForbidden (isolatedjob.ErrInvalid for the ID) and an audit row under
+// refused; an unknown attempt and another key's get the same text. fn gets
+// the job and an audit row filled in for it at the current controller time,
+// and appends its own row when it goes ahead. A refusal fn returns is
+// audited under refused, committed with anything fn wrote before it (a lazy
+// cancellation), and returned.
+func (c *Controller) creatorCall(ctx context.Context, by hostedwire.KeyID, key hostedwire.VerifyKey, attemptID, refused string,
+ fn func(tx *sql.Tx, j *pauseJob, a Audit) (refusal, err error)) error {
+ var refusal error
+ err := c.store.Tx(ctx, func(tx *sql.Tx) error {
+ refusal = nil
+ a := Audit{Actor: by, At: c.store.Clock().Now()}
+ valid := printableASCII(attemptID, maxNameLen)
+ if valid {
+ a.Attempt = attemptID
+ }
+ switch {
+ case by == "" || key.Role != hostedwire.RoleInstance:
+ refusal = fmt.Errorf("%w: needs the instance key that launched the attempt", ErrForbidden)
+ case !valid:
+ refusal = fmt.Errorf("%w: attempt id must be 1 to %d printable ASCII characters", isolatedjob.ErrInvalid, maxNameLen)
+ default:
+ j, found, err := loadPauseJob(ctx, tx, attemptID)
+ if err != nil {
+ return err
+ }
+ if found {
+ a.Account, a.Task = j.account, j.task
+ }
+ if !found || j.actor != string(by) {
+ refusal = notCreator(attemptID)
+ break
+ }
+ if refusal, err = fn(tx, &j, a); err != nil {
+ return err
+ }
+ }
+ if refusal == nil {
+ return nil
+ }
+ a.Action, a.Reason = refused, refusal.Error()
+ return appendAudit(tx, a)
+ })
+ if err != nil {
+ return err
+ }
+ return refusal
+}
+
+// notPausable refuses, with isolatedjob.ErrConflict, a job that holds stop
+// proof or has a stop request: neither may pause or resume.
+func notPausable(j *pauseJob) error {
+ switch {
+ case j.stopProof.Valid:
+ return fmt.Errorf("%w: %s has stopped", isolatedjob.ErrConflict, j.attempt)
+ case j.stopRequested.Valid:
+ return fmt.Errorf("%w: a stop was asked for %s", isolatedjob.ErrConflict, j.attempt)
+ }
+ return nil
+}
+
+// expire cancels j's open generation, inside tx, when it is draining with no
+// quiescent acknowledgement and more than PauseAckTimeout of controller time
+// has passed since Drain. Every call that touches a generation runs it
+// first, so cancellation needs no timer; the reaper may sweep too. A
+// generation acknowledged in time never expires.
+func expire(ctx context.Context, tx *sql.Tx, j *pauseJob, now T) error {
+ if j.state != JobDraining || j.cancelled || j.quiescent || !j.started.Valid ||
+ now-T(j.started.Int64) <= T(PauseAckTimeout) {
+ return nil
+ }
+ res, err := tx.ExecContext(ctx, `UPDATE jobs SET pause_cancelled = 1, revision = revision + 1
+ WHERE attempt_id = ? AND pause_generation = ? AND pause_cancelled = 0`, j.attempt, j.generation)
+ if err != nil {
+ return fmt.Errorf("hostedctl: cancel pause of %s: %w", j.attempt, err)
+ }
+ if n, err := res.RowsAffected(); err != nil || n != 1 {
+ return fmt.Errorf("hostedctl: cancel pause of %s: %d rows (%v)", j.attempt, n, err)
+ }
+ j.cancelled = true
+ return appendAudit(tx, Audit{Account: j.account, Task: j.task, Attempt: j.attempt, Action: actionPauseCancelled,
+ Reason: fmt.Sprintf("generation %d: no quiescent acknowledgement within %v; a late one is ignored",
+ j.generation, PauseAckTimeout), At: now})
+}
+
+// Drain opens a new pause generation for attemptID and returns it: the
+// generation counter goes up by one, its start is the current controller
+// time, and the job's state becomes JobDraining. Only a running job, or one
+// already draining, may drain; draining again supersedes the open
+// generation, so an acknowledgement for it is refused from then on. A job
+// in any other state, or with a stop request or proof, gets
+// isolatedjob.ErrConflict.
+//
+// Drain, Quiescent, Suspend, Reopen and Resume are for the instance key
+// that launched the attempt (see creatorCall). Each call and each refusal
+// appends an audit row, and each runs under the attempt's lock.
+func (c *Controller) Drain(ctx context.Context, by hostedwire.KeyID, key hostedwire.VerifyKey, attemptID string) (int64, error) {
+ defer c.lockAttempt(attemptID)()
+ var gen int64
+ err := c.creatorCall(ctx, by, key, attemptID, actionDrainRefused, func(tx *sql.Tx, j *pauseJob, a Audit) (error, error) {
+ gen = 0
+ if r := notPausable(j); r != nil {
+ return r, nil
+ }
+ if j.state != JobRunning && j.state != JobDraining {
+ return fmt.Errorf("%w: only a running job can drain; %s is %s", isolatedjob.ErrConflict, j.attempt, j.state), nil
+ }
+ next := j.generation + 1
+ res, err := tx.ExecContext(ctx, `UPDATE jobs SET state = ?, pause_generation = ?, pause_started_t = ?,
+ pause_quiescent = 0, pause_cancelled = 0, revision = revision + 1
+ WHERE attempt_id = ? AND pause_generation = ?`, JobDraining, next, int64(a.At), j.attempt, j.generation)
+ if err != nil {
+ return nil, fmt.Errorf("hostedctl: drain %s: %w", j.attempt, err)
+ }
+ if n, err := res.RowsAffected(); err != nil || n != 1 {
+ return nil, fmt.Errorf("hostedctl: drain %s: %d rows (%v)", j.attempt, n, err)
+ }
+ a.Action = actionDrain
+ a.Reason = fmt.Sprintf("pause generation %d opened; quiescent due within %v", next, PauseAckTimeout)
+ if j.state == JobDraining {
+ a.Reason += fmt.Sprintf("; generation %d superseded", j.generation)
+ }
+ gen = next
+ return nil, appendAudit(tx, a)
+ })
+ if err != nil {
+ return 0, err
+ }
+ return gen, nil
+}
+
+// Quiescent records the runner's acknowledgement that it has stopped taking
+// work for generation. The generation must be the current one, open
+// (draining), not cancelled, and the acknowledgement must come at most
+// PauseAckTimeout after Drain; otherwise ErrGenerationCancelled, and a late
+// acknowledgement also cancels the generation. Acknowledging the same
+// generation again while its pause is open is accepted and changes nothing.
+func (c *Controller) Quiescent(ctx context.Context, by hostedwire.KeyID, key hostedwire.VerifyKey, attemptID string, generation int64) error {
+ defer c.lockAttempt(attemptID)()
+ return c.creatorCall(ctx, by, key, attemptID, actionQuiescentRefused, func(tx *sql.Tx, j *pauseJob, a Audit) (error, error) {
+ if r := notPausable(j); r != nil {
+ return r, nil
+ }
+ if err := expire(ctx, tx, j, a.At); err != nil {
+ return nil, err
+ }
+ switch {
+ case !currentGen(generation, j):
+ return fmt.Errorf("%w: generation %d is not the current one (%d)", ErrGenerationCancelled, generation, j.generation), nil
+ case j.quiescent:
+ a.Action, a.Reason = actionQuiescentRepeated, fmt.Sprintf("generation %d acknowledged again", generation)
+ return nil, appendAudit(tx, a)
+ case j.cancelled:
+ return fmt.Errorf("%w: generation %d was cancelled", ErrGenerationCancelled, generation), nil
+ case j.state != JobDraining:
+ return fmt.Errorf("%w: no pause is open for generation %d; the job is %s", ErrGenerationCancelled, generation, j.state), nil
+ }
+ res, err := tx.ExecContext(ctx, `UPDATE jobs SET pause_quiescent = 1, revision = revision + 1
+ WHERE attempt_id = ? AND pause_generation = ? AND state = ?`, j.attempt, generation, JobDraining)
+ if err != nil {
+ return nil, fmt.Errorf("hostedctl: record quiescent for %s: %w", j.attempt, err)
+ }
+ if n, err := res.RowsAffected(); err != nil || n != 1 {
+ return nil, fmt.Errorf("hostedctl: record quiescent for %s: %d rows (%v)", j.attempt, n, err)
+ }
+ a.Action, a.Reason = actionQuiescent, fmt.Sprintf("generation %d acknowledged after %v", generation,
+ time.Duration(a.At-T(j.started.Int64)))
+ return nil, appendAudit(tx, a)
+ })
+}
+
+// Suspend suspends attemptID's VM for generation. The generation must be
+// the current one and open, not cancelled (ErrGenerationCancelled), and
+// acknowledged quiescent (ErrNotQuiescent). One transaction records the
+// state JobSuspending; then, outside it, Runner.Suspend. A failed provider
+// call is audited and returned; the job stays suspending and Refresh sends
+// the suspend again while the VM still runs. Refresh moves the job to
+// JobSuspended once the provider reports the VM suspended. Asking again for
+// a generation already suspending or suspended returns nil with no provider
+// call.
+func (c *Controller) Suspend(ctx context.Context, by hostedwire.KeyID, key hostedwire.VerifyKey, attemptID string, generation int64) error {
+ defer c.lockAttempt(attemptID)()
+ var send *pauseJob
+ err := c.creatorCall(ctx, by, key, attemptID, actionSuspendRefused, func(tx *sql.Tx, j *pauseJob, a Audit) (error, error) {
+ send = nil
+ if r := notPausable(j); r != nil {
+ return r, nil
+ }
+ if err := expire(ctx, tx, j, a.At); err != nil {
+ return nil, err
+ }
+ if !currentGen(generation, j) {
+ return fmt.Errorf("%w: generation %d is not the current one (%d)", ErrGenerationCancelled, generation, j.generation), nil
+ }
+ switch j.state {
+ case JobSuspending, JobSuspended:
+ a.Action, a.Reason = actionSuspendRepeated, fmt.Sprintf("generation %d: suspend asked for again; job is %s", generation, j.state)
+ return nil, appendAudit(tx, a)
+ case JobDraining:
+ default:
+ return fmt.Errorf("%w: no pause is open for generation %d; the job is %s", ErrGenerationCancelled, generation, j.state), nil
+ }
+ if j.cancelled {
+ return fmt.Errorf("%w: generation %d was cancelled", ErrGenerationCancelled, generation), nil
+ }
+ if !j.quiescent {
+ return fmt.Errorf("%w: generation %d", ErrNotQuiescent, generation), nil
+ }
+ res, err := tx.ExecContext(ctx, `UPDATE jobs SET state = ?, revision = revision + 1
+ WHERE attempt_id = ? AND state = ? AND pause_generation = ?`, JobSuspending, j.attempt, JobDraining, generation)
+ if err != nil {
+ return nil, fmt.Errorf("hostedctl: record suspend of %s: %w", j.attempt, err)
+ }
+ if n, err := res.RowsAffected(); err != nil || n != 1 {
+ return nil, fmt.Errorf("hostedctl: record suspend of %s: %d rows (%v)", j.attempt, n, err)
+ }
+ a.Action, a.Reason = actionSuspendRequested, fmt.Sprintf("generation %d quiescent; suspending VM %s", generation, j.ref.String)
+ send = j
+ return nil, appendAudit(tx, a)
+ })
+ if err != nil || send == nil {
+ return err
+ }
+ perr, aerr := c.sendSuspend(ctx, by, send, "")
+ return errors.Join(perr, aerr)
+}
+
+// sendSuspend calls Runner.Suspend for j's VM, outside any transaction. A
+// failure is audited, with a fixed reason, and returned as perr; aerr is a
+// failure to write the audit row. resent names the audit action for a
+// successful call, or is empty for none.
+func (c *Controller) sendSuspend(ctx context.Context, actor hostedwire.KeyID, j *pauseJob, resent string) (perr, aerr error) {
+ ref := isolatedjob.Ref(j.ref.String)
+ perr = c.runner.Suspend(ctx, ref)
+ action, reason := resent, "refresh: the VM still runs; suspend sent again"
+ if perr != nil {
+ action, reason = actionSuspendFailed, "provider suspend call failed; refresh sends it again while the VM runs"
+ }
+ if action != "" {
+ aerr = c.auditPause(context.WithoutCancel(ctx), actor, j, action, reason)
+ }
+ if perr != nil {
+ perr = fmt.Errorf("hostedctl: suspend %s: VM %s: %w", j.attempt, ref, perr)
+ }
+ return perr, aerr
+}
+
+// Reopen records that the runner takes work again after a cancelled or
+// abandoned pause of generation, the current one (else
+// ErrGenerationCancelled). The job returns to JobRunning and its pause
+// fields are cleared; the generation counter stays. A job already running
+// at that generation gets nil; a suspending, suspended or resuming job gets
+// isolatedjob.ErrConflict, as its VM is paused and needs Resume.
+func (c *Controller) Reopen(ctx context.Context, by hostedwire.KeyID, key hostedwire.VerifyKey, attemptID string, generation int64) error {
+ defer c.lockAttempt(attemptID)()
+ return c.creatorCall(ctx, by, key, attemptID, actionReopenRefused, func(tx *sql.Tx, j *pauseJob, a Audit) (error, error) {
+ if r := notPausable(j); r != nil {
+ return r, nil
+ }
+ if err := expire(ctx, tx, j, a.At); err != nil {
+ return nil, err
+ }
+ if !currentGen(generation, j) {
+ return fmt.Errorf("%w: generation %d is not the current one (%d)", ErrGenerationCancelled, generation, j.generation), nil
+ }
+ switch j.state {
+ case JobRunning:
+ a.Action, a.Reason = actionReopenRepeated, fmt.Sprintf("generation %d: admission already open", generation)
+ return nil, appendAudit(tx, a)
+ case JobDraining:
+ default:
+ return fmt.Errorf("%w: %s is %s; it needs a resume, not a reopen", isolatedjob.ErrConflict, j.attempt, j.state), nil
+ }
+ res, err := tx.ExecContext(ctx, `UPDATE jobs SET state = ?, pause_started_t = NULL, pause_quiescent = 0,
+ pause_cancelled = 0, revision = revision + 1 WHERE attempt_id = ? AND state = ? AND pause_generation = ?`,
+ JobRunning, j.attempt, JobDraining, generation)
+ if err != nil {
+ return nil, fmt.Errorf("hostedctl: reopen %s: %w", j.attempt, err)
+ }
+ if n, err := res.RowsAffected(); err != nil || n != 1 {
+ return nil, fmt.Errorf("hostedctl: reopen %s: %d rows (%v)", j.attempt, n, err)
+ }
+ why := "abandoned"
+ if j.cancelled {
+ why = "cancelled"
+ }
+ a.Action, a.Reason = actionReopen, fmt.Sprintf("generation %d %s; the runner takes work again", generation, why)
+ return nil, appendAudit(tx, a)
+ })
+}
diff --git a/internal/hostedctl/pause_test.go b/internal/hostedctl/pause_test.go
new file mode 100644
index 00000000..332ccc30
--- /dev/null
+++ b/internal/hostedctl/pause_test.go
@@ -0,0 +1,326 @@
+package hostedctl
+
+import (
+ "database/sql"
+ "errors"
+ "testing"
+ "time"
+
+ "amadan.net/oficina/equipo/internal/hostedwire"
+ "amadan.net/oficina/equipo/internal/isolatedjob"
+)
+
+// pauseCols are the jobs columns the pause barrier and resume write.
+type pauseCols struct {
+ state string
+ gen, epoch int64
+ started sql.NullInt64
+ quiescent, cancelled bool
+}
+
+func (e *launchEnv) pauseCols(attempt string) pauseCols {
+ e.t.Helper()
+ var p pauseCols
+ if err := e.store.Tx(e.ctx, func(tx *sql.Tx) error {
+ return tx.QueryRowContext(e.ctx, `SELECT state, pause_generation, epoch, pause_started_t, pause_quiescent,
+ pause_cancelled FROM jobs WHERE attempt_id = ?`, attempt).Scan(
+ &p.state, &p.gen, &p.epoch, &p.started, &p.quiescent, &p.cancelled)
+ }); err != nil {
+ e.t.Fatalf("read pause columns of %s = %v", attempt, err)
+ }
+ return p
+}
+
+// runningJob is a controller with att-1 launched for inst-1 (lifetime 2 h),
+// its VM running and the job's state saved as running.
+func runningJob(t *testing.T) *launchEnv {
+ t.Helper()
+ e := newLaunchEnv(t)
+ e.launchWith("att-1", 2*time.Hour)
+ e.fake.Tick()
+ e.refresh()
+ if p := e.pauseCols("att-1"); p.state != JobRunning {
+ t.Fatalf("att-1 after launch and refresh is %q, want running", p.state)
+ }
+ return e
+}
+
+func (e *launchEnv) drain() int64 {
+ e.t.Helper()
+ g, err := e.c.Drain(e.ctx, "inst-1", instKey, "att-1")
+ if err != nil || g < 1 {
+ e.t.Fatalf("Drain = (%d, %v), want a new generation", g, err)
+ }
+ return g
+}
+
+func (e *launchEnv) ack(g int64) {
+ e.t.Helper()
+ if err := e.c.Quiescent(e.ctx, "inst-1", instKey, "att-1", g); err != nil {
+ e.t.Fatalf("Quiescent(%d) = %v", g, err)
+ }
+}
+
+// suspendJob drains att-1, acknowledges, suspends, and lets the VM and the
+// job settle as suspended. It returns the generation.
+func (e *launchEnv) suspendJob() int64 {
+ e.t.Helper()
+ g := e.drain()
+ e.ack(g)
+ if err := e.c.Suspend(e.ctx, "inst-1", instKey, "att-1", g); err != nil {
+ e.t.Fatalf("Suspend(%d) = %v", g, err)
+ }
+ e.fake.Tick()
+ e.refresh()
+ if p := e.pauseCols("att-1"); p.state != JobSuspended {
+ e.t.Fatalf("att-1 after suspend and refresh is %q, want suspended", p.state)
+ }
+ return g
+}
+
+func TestSuspendNeedsCurrentAck(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ // setup opens generations and acknowledges as the case needs; it
+ // returns the generation Suspend is asked for, the current one, and
+ // whether the current one may still be suspended afterwards.
+ setup func(e *launchEnv) (asked, current int64, live bool)
+ wantErr error
+ }{
+ {"no acknowledgement", func(e *launchEnv) (int64, int64, bool) {
+ g := e.drain()
+ return g, g, true
+ }, ErrNotQuiescent},
+ {"an older generation", func(e *launchEnv) (int64, int64, bool) {
+ g1 := e.drain()
+ g2 := e.drain()
+ if err := e.c.Quiescent(e.ctx, "inst-1", instKey, "att-1", g1); !errors.Is(err, ErrGenerationCancelled) {
+ t.Fatalf("Quiescent for a superseded generation = %v, want ErrGenerationCancelled", err)
+ }
+ e.ack(g2)
+ return g1, g2, true
+ }, ErrGenerationCancelled},
+ {"the next generation", func(e *launchEnv) (int64, int64, bool) {
+ g := e.drain()
+ e.ack(g)
+ return g + 1, g, true
+ }, ErrGenerationCancelled},
+ {"a cancelled generation", func(e *launchEnv) (int64, int64, bool) {
+ g := e.drain()
+ e.clk.AdvanceMono(PauseAckTimeout + time.Second)
+ return g, g, false
+ }, ErrGenerationCancelled},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ e := runningJob(t)
+ asked, current, live := tc.setup(e)
+ if err := e.c.Suspend(e.ctx, "inst-1", instKey, "att-1", asked); !errors.Is(err, tc.wantErr) {
+ t.Fatalf("Suspend(%d) with current generation %d = %v, want %v", asked, current, err, tc.wantErr)
+ }
+ if a := e.lastAudit(); a.Actor != "inst-1" || a.Action != actionSuspendRefused {
+ t.Fatalf("audit after the refusal = %+v, want suspend_refused by inst-1", a)
+ }
+ if n := e.fake.Calls(isolatedjob.OpSuspend); n != 0 {
+ t.Fatalf("a refused Suspend reached the provider %d times", n)
+ }
+ if p := e.pauseCols("att-1"); p.state != JobDraining || p.gen != current {
+ t.Fatalf("after the refusal: %+v, want draining at generation %d", p, current)
+ }
+ if !live {
+ return
+ }
+ if p := e.pauseCols("att-1"); !p.quiescent {
+ e.ack(current)
+ }
+ if err := e.c.Suspend(e.ctx, "inst-1", instKey, "att-1", current); err != nil {
+ t.Fatalf("Suspend of the acknowledged current generation %d = %v", current, err)
+ }
+ if p := e.pauseCols("att-1"); p.state != JobSuspending || e.fake.Calls(isolatedjob.OpSuspend) != 1 {
+ t.Fatalf("after Suspend: %+v, %d provider suspends; want suspending, 1", p, e.fake.Calls(isolatedjob.OpSuspend))
+ }
+ })
+ }
+}
+
+func TestLateAckIgnored(t *testing.T) {
+ e := runningJob(t)
+ g := e.drain()
+ e.clk.AdvanceMono(PauseAckTimeout + time.Second)
+ if err := e.c.Quiescent(e.ctx, "inst-1", instKey, "att-1", g); !errors.Is(err, ErrGenerationCancelled) {
+ t.Fatalf("Quiescent at 2m1s = %v, want ErrGenerationCancelled", err)
+ }
+ if p := e.pauseCols("att-1"); !p.cancelled || p.quiescent || p.state != JobDraining {
+ t.Fatalf("after a late ack: %+v, want draining, cancelled, not quiescent", p)
+ }
+ if !e.hasAudit("", "att-1", actionPauseCancelled, "no quiescent acknowledgement") {
+ t.Fatal("no pause_cancelled audit row")
+ }
+ if err := e.c.Suspend(e.ctx, "inst-1", instKey, "att-1", g); !errors.Is(err, ErrGenerationCancelled) {
+ t.Fatalf("Suspend after a late ack = %v, want ErrGenerationCancelled", err)
+ }
+ if n := e.fake.Calls(isolatedjob.OpSuspend); n != 0 {
+ t.Fatalf("provider suspends = %d, want 0", n)
+ }
+
+ // The runner takes work again: admission reopens; the counter stays.
+ if err := e.c.Reopen(e.ctx, "inst-1", instKey, "att-1", g+1); !errors.Is(err, ErrGenerationCancelled) {
+ t.Fatalf("Reopen of another generation = %v, want ErrGenerationCancelled", err)
+ }
+ if err := e.c.Reopen(e.ctx, "inst-1", instKey, "att-1", g); err != nil {
+ t.Fatalf("Reopen(%d) = %v", g, err)
+ }
+ if p := e.pauseCols("att-1"); p.state != JobRunning || p.gen != g || p.started.Valid || p.quiescent || p.cancelled {
+ t.Fatalf("after Reopen: %+v, want running at generation %d with the pause fields reset", p, g)
+ }
+
+ // An acknowledgement at exactly PauseAckTimeout is in time.
+ g2 := e.drain()
+ if g2 != g+1 {
+ t.Fatalf("next Drain = %d, want %d", g2, g+1)
+ }
+ e.clk.AdvanceMono(PauseAckTimeout)
+ e.ack(g2)
+ e.clk.AdvanceMono(time.Hour) // a timely ack does not expire
+ if err := e.c.Suspend(e.ctx, "inst-1", instKey, "att-1", g2); err != nil {
+ t.Fatalf("Suspend after an ack at exactly 2m = %v", err)
+ }
+}
+
+func TestSuspendedTimeCountsToDeadline(t *testing.T) {
+ e := runningJob(t)
+ before := e.stopCols("att-1")
+ e.suspendJob()
+ e.clk.AdvanceMono(30 * time.Minute)
+ e.refresh()
+ v, err := e.c.Get(e.ctx, "inst-1", "att-1")
+ if err != nil {
+ t.Fatal(err)
+ }
+ now := e.store.Clock().Now()
+ if want := time.Duration(T(before.stop) - now); v.StopIn != want || v.DeadlineIn != time.Duration(T(before.deadline)-now) {
+ t.Fatalf("while suspended: StopIn %v DeadlineIn %v, want %v and %v (suspended time counts)",
+ v.StopIn, v.DeadlineIn, want, time.Duration(T(before.deadline)-now))
+ }
+ if _, err := e.c.Resume(e.ctx, "inst-1", instKey, "att-1", "op-1"); !errors.Is(err, ErrResumePending) {
+ t.Fatalf("Resume = %v, want ErrResumePending until the VM runs", err)
+ }
+ e.fake.Tick()
+ if ep, err := e.c.Resume(e.ctx, "inst-1", instKey, "att-1", "op-1"); err != nil || ep != 1 {
+ t.Fatalf("Resume after the VM runs = (%d, %v), want (1, nil)", ep, err)
+ }
+ after := e.stopCols("att-1")
+ if after.launched != before.launched || after.deadline != before.deadline || after.drain != before.drain || after.stop != before.stop {
+ t.Fatalf("times moved across suspend and resume: %+v, want %+v", after, before)
+ }
+}
+
+func TestSuspendAndResumeRoles(t *testing.T) {
+ e := runningJob(t)
+ g := e.drain()
+ calls := map[string]func(by hostedwire.KeyID, key hostedwire.VerifyKey, attempt string) error{
+ actionDrainRefused: func(by hostedwire.KeyID, key hostedwire.VerifyKey, attempt string) error {
+ _, err := e.c.Drain(e.ctx, by, key, attempt)
+ return err
+ },
+ actionQuiescentRefused: func(by hostedwire.KeyID, key hostedwire.VerifyKey, attempt string) error {
+ return e.c.Quiescent(e.ctx, by, key, attempt, g)
+ },
+ actionSuspendRefused: func(by hostedwire.KeyID, key hostedwire.VerifyKey, attempt string) error {
+ return e.c.Suspend(e.ctx, by, key, attempt, g)
+ },
+ actionReopenRefused: func(by hostedwire.KeyID, key hostedwire.VerifyKey, attempt string) error {
+ return e.c.Reopen(e.ctx, by, key, attempt, g)
+ },
+ actionResumeRefused: func(by hostedwire.KeyID, key hostedwire.VerifyKey, attempt string) error {
+ _, err := e.c.Resume(e.ctx, by, key, attempt, "op-1")
+ return err
+ },
+ }
+ for refused, call := range calls {
+ for _, tc := range []struct {
+ name string
+ by hostedwire.KeyID
+ key hostedwire.VerifyKey
+ attempt string
+ }{
+ {"another instance", "inst-2", instKey, "att-1"},
+ {"an operator key with the creator's id", "inst-1", opKey, "att-1"},
+ {"no key id", "", instKey, "att-1"},
+ {"an unknown attempt", "inst-1", instKey, "att-9"},
+ } {
+ if err := call(tc.by, tc.key, tc.attempt); !errors.Is(err, ErrForbidden) {
+ t.Fatalf("%s by %s = %v, want ErrForbidden", refused, tc.name, err)
+ }
+ if a := e.lastAudit(); a.Actor != tc.by || a.Action != refused {
+ t.Fatalf("audit after %s by %s = %+v, want %s by %q", refused, tc.name, a, refused, tc.by)
+ }
+ }
+ }
+ if p := e.pauseCols("att-1"); p.state != JobDraining || p.gen != g || p.quiescent || p.epoch != 0 {
+ t.Fatalf("refused calls changed the job: %+v", p)
+ }
+ if n := e.fake.Calls(isolatedjob.OpSuspend) + e.fake.Calls(isolatedjob.OpResume); n != 0 {
+ t.Fatalf("refused calls reached the provider %d times", n)
+ }
+ if ops := e.resumeOps("att-1"); len(ops) != 0 {
+ t.Fatalf("refused calls prepared resume operations: %+v", ops)
+ }
+}
+
+func TestSuspendRefreshSettles(t *testing.T) {
+ e := runningJob(t)
+ g := e.drain()
+ e.exec(`UPDATE jobs SET notfound_since_t = 1 WHERE attempt_id = 'att-1'`) // a first not-found
+ e.refresh()
+ if p, s := e.pauseCols("att-1"), e.stopCols("att-1"); p.state != JobDraining || s.notFoundSince.Valid {
+ t.Fatalf("Refresh of a draining job with a running VM left %q, not-found since %v; want draining, cleared",
+ p.state, s.notFoundSince)
+ }
+ e.ack(g)
+
+ // The suspend call is throttled and does nothing: Refresh sends it again.
+ e.fake.Inject(isolatedjob.OpSuspend, isolatedjob.FaultThrottle)
+ if err := e.c.Suspend(e.ctx, "inst-1", instKey, "att-1", g); !errors.Is(err, isolatedjob.ErrThrottled) {
+ t.Fatalf("throttled Suspend = %v, want ErrThrottled", err)
+ }
+ if p := e.pauseCols("att-1"); p.state != JobSuspending {
+ t.Fatalf("after a throttled suspend call the job is %q, want suspending", p.state)
+ }
+ e.refresh()
+ if p, n := e.pauseCols("att-1"), e.fake.Calls(isolatedjob.OpSuspend); p.state != JobSuspending || n != 2 {
+ t.Fatalf("Refresh with the VM still running: %q, %d provider suspends; want suspending, 2", p.state, n)
+ }
+ e.refresh() // the VM is suspending now: nothing to send
+ if n := e.fake.Calls(isolatedjob.OpSuspend); n != 2 {
+ t.Fatalf("provider suspends = %d after a refresh of a suspending VM, want 2", n)
+ }
+ e.fake.Tick()
+ e.refresh()
+ if p := e.pauseCols("att-1"); p.state != JobSuspended {
+ t.Fatalf("Refresh with the VM suspended left %q, want suspended", p.state)
+ }
+
+ // A prepared resume: Refresh keeps resuming while the VM is suspended,
+ // sends the resume again, and commits once the VM runs.
+ if _, err := e.c.Resume(e.ctx, "inst-1", instKey, "att-1", "op-1"); !errors.Is(err, ErrResumePending) {
+ t.Fatalf("Resume = %v, want ErrResumePending", err)
+ }
+ // A re-send that fails is audited and tried again; Refresh goes on.
+ e.fake.Inject(isolatedjob.OpResume, isolatedjob.FaultThrottle)
+ e.refresh()
+ if !e.hasAudit("", "att-1", actionResumeCallFailed, "op-1") {
+ t.Fatal("no resume_call_failed audit row for a failed re-send")
+ }
+ e.refresh()
+ if p, n := e.pauseCols("att-1"), e.fake.Calls(isolatedjob.OpResume); p.state != JobResuming || p.epoch != 0 || n != 3 {
+ t.Fatalf("Refresh with the VM suspended: %+v, %d provider resumes; want resuming at epoch 0, 3", p, n)
+ }
+ e.fake.Tick()
+ e.refresh()
+ if p := e.pauseCols("att-1"); p.state != JobRunning || p.epoch != 1 || p.started.Valid || p.quiescent || p.gen != g {
+ t.Fatalf("Refresh with the VM running: %+v, want running at epoch 1, pause closed, generation %d", p, g)
+ }
+ if ops := e.resumeOps("att-1"); len(ops) != 1 || ops[0].status != "done" || ops[0].result.Int64 != 1 {
+ t.Fatalf("resume operations = %+v, want op-1 done at epoch 1", ops)
+ }
+}
diff --git a/internal/hostedctl/refresh.go b/internal/hostedctl/refresh.go
index 51701773..a856afa8 100644
--- a/internal/hostedctl/refresh.go
+++ b/internal/hostedctl/refresh.go
@@ -192,7 +192,7 @@ func (c *Controller) refreshOne(ctx context.Context, attempt string) error {
if job.State.Live() {
// First, so a live sighting clears any first not-found even when
// the restart handling below stops the job.
- if err := c.mirrorState(rec, attempt, job.State); err != nil {
+ if err := c.mirrorLive(rec, j, job.State); err != nil {
return err
}
}
diff --git a/internal/hostedctl/resume.go b/internal/hostedctl/resume.go
new file mode 100644
index 00000000..b7955f71
--- /dev/null
+++ b/internal/hostedctl/resume.go
@@ -0,0 +1,432 @@
+package hostedctl
+
+import (
+ "context"
+ "database/sql"
+ "errors"
+ "fmt"
+ "time"
+
+ "amadan.net/oficina/equipo/internal/hostedwire"
+ "amadan.net/oficina/equipo/internal/isolatedjob"
+)
+
+// ErrResumePending: a resume operation is prepared but not committed: the
+// VM does not run yet, or the provider call failed or its reply was lost.
+// Retry with the same operation ID; Refresh also finishes it. A new
+// operation ID while another is pending gets it too.
+var ErrResumePending = errors.New("hostedctl: a resume is pending; retry with its operation ID")
+
+// maxOperationIDLen bounds a resume operation ID.
+const maxOperationIDLen = 64
+
+// resume_ops.status values.
+const (
+ opPending = "pending"
+ opDone = "done"
+ opFailed = "failed"
+)
+
+// Audit actions written by Resume and by Refresh finishing a resume.
+const (
+ actionResumePrepared = "resume_prepared"
+ actionResumeContinued = "resume_continued"
+ actionResumeRepeated = "resume_repeated"
+ actionResumeRefused = "resume_refused"
+ actionResumeCallFailed = "resume_call_failed"
+ actionResumeResent = "resume_resent"
+ actionResumeCommitted = "resume_committed"
+ actionResumeFailed = "resume_failed"
+)
+
+// resumeOp is one resume_ops row.
+type resumeOp struct {
+ id, status string
+ prepared int64
+ result sql.NullInt64
+}
+
+// validOperationID reports whether s is 1 to maxOperationIDLen characters,
+// each a letter, a digit or '-'.
+func validOperationID(s string) bool {
+ if len(s) == 0 || len(s) > maxOperationIDLen {
+ return false
+ }
+ for i := 0; i < len(s); i++ {
+ switch b := s[i]; {
+ case b >= 'a' && b <= 'z', b >= 'A' && b <= 'Z', b >= '0' && b <= '9', b == '-':
+ default:
+ return false
+ }
+ }
+ return true
+}
+
+// loadResumeOp reads the row for (attempt, op) inside tx, whatever other
+// operations the attempt has had since.
+func loadResumeOp(ctx context.Context, tx *sql.Tx, attempt, op string) (resumeOp, bool, error) {
+ r := resumeOp{id: op}
+ err := tx.QueryRowContext(ctx, `SELECT status, prepared_epoch, result_epoch FROM resume_ops
+ WHERE attempt_id = ? AND operation_id = ?`, attempt, op).Scan(&r.status, &r.prepared, &r.result)
+ switch {
+ case errors.Is(err, sql.ErrNoRows):
+ return resumeOp{}, false, nil
+ case err != nil:
+ return resumeOp{}, false, fmt.Errorf("hostedctl: read resume operation %s of %s: %w", op, attempt, err)
+ }
+ return r, true, nil
+}
+
+// pendingResumeOp reads attempt's pending resume row, if any (at most one).
+func pendingResumeOp(ctx context.Context, tx *sql.Tx, attempt string) (resumeOp, bool, error) {
+ r := resumeOp{status: opPending}
+ err := tx.QueryRowContext(ctx, `SELECT operation_id, prepared_epoch FROM resume_ops
+ WHERE attempt_id = ? AND status = ?`, attempt, opPending).Scan(&r.id, &r.prepared)
+ switch {
+ case errors.Is(err, sql.ErrNoRows):
+ return resumeOp{}, false, nil
+ case err != nil:
+ return resumeOp{}, false, fmt.Errorf("hostedctl: read pending resume of %s: %w", attempt, err)
+ }
+ return r, true, nil
+}
+
+// failDeadResume marks j's pending resume failed, inside tx, when the job
+// holds stop proof or has a stop request: that resume is never committed.
+func failDeadResume(ctx context.Context, tx *sql.Tx, j *pauseJob, now T) error {
+ if !j.stopProof.Valid && !j.stopRequested.Valid {
+ return nil
+ }
+ res, err := tx.ExecContext(ctx, `UPDATE resume_ops SET status = ?, completed_t = ?
+ WHERE attempt_id = ? AND status = ?`, opFailed, int64(now), j.attempt, opPending)
+ if err != nil {
+ return fmt.Errorf("hostedctl: fail pending resume of %s: %w", j.attempt, err)
+ }
+ if n, err := res.RowsAffected(); err != nil || n == 0 {
+ return err
+ }
+ return appendAudit(tx, Audit{Account: j.account, Task: j.task, Attempt: j.attempt, Action: actionResumeFailed,
+ Reason: "a stop was asked for before the pending resume committed", At: now})
+}
+
+// commitResume is step 3 inside tx, once the provider reports the VM
+// running: the job's epoch becomes op's prepared epoch, which must be one
+// above the stored epoch, the job is running with its pause closed (the
+// generation counter stays), and op is done with that epoch. op must be
+// pending, so an operation raises the epoch at most once.
+func commitResume(ctx context.Context, tx *sql.Tx, j *pauseJob, op resumeOp, actor hostedwire.KeyID, now T) error {
+ res, err := tx.ExecContext(ctx, `UPDATE jobs SET epoch = ?, state = ?, pause_started_t = NULL, pause_quiescent = 0,
+ pause_cancelled = 0, revision = revision + 1 WHERE attempt_id = ? AND epoch = ?`,
+ op.prepared, JobRunning, j.attempt, op.prepared-1)
+ if err != nil {
+ return fmt.Errorf("hostedctl: commit resume of %s: %w", j.attempt, err)
+ }
+ if n, err := res.RowsAffected(); err != nil || n != 1 {
+ return fmt.Errorf("hostedctl: commit resume %s of %s: epoch is not %d (%d rows, %v)", op.id, j.attempt, op.prepared-1, n, err)
+ }
+ res, err = tx.ExecContext(ctx, `UPDATE resume_ops SET status = ?, result_epoch = ?, completed_t = ?
+ WHERE attempt_id = ? AND operation_id = ? AND status = ?`, opDone, op.prepared, int64(now), j.attempt, op.id, opPending)
+ if err != nil {
+ return fmt.Errorf("hostedctl: commit resume of %s: %w", j.attempt, err)
+ }
+ if n, err := res.RowsAffected(); err != nil || n != 1 {
+ return fmt.Errorf("hostedctl: commit resume %s of %s: %d rows (%v)", op.id, j.attempt, n, err)
+ }
+ return appendAudit(tx, Audit{Actor: actor, Account: j.account, Task: j.task, Attempt: j.attempt,
+ Action: actionResumeCommitted, Reason: fmt.Sprintf("operation %s: the VM runs; epoch %d", op.id, op.prepared), At: now})
+}
+
+// Resume resumes attemptID's suspended VM under operationID (1 to 64
+// letters, digits and '-') and returns the job's new epoch. An operation
+// raises the epoch exactly once, however often it is retried. Under the
+// attempt's lock, in three steps:
+//
+// 1. Prepare, in one transaction. A done operation returns its epoch with
+// no provider call, whatever operations came after it; a failed one
+// gets isolatedjob.ErrConflict. Then a stop request or proof gives
+// ErrConflict, and the job's stop time reached gives ErrPastDeadline,
+// with no provider call and no new row. A pending operation carries on
+// with its prepared epoch. A new operation while another is pending
+// gets ErrResumePending; one for a job that is not suspended gets
+// ErrConflict. Otherwise a pending row with prepared epoch = epoch + 1
+// is saved and the job becomes JobResuming.
+// 2. Outside any transaction, Runner.Resume. A failure is audited and
+// returned wrapped in ErrResumePending; the row stays pending.
+// 3. Runner.Get. Running: one transaction sets the job's epoch to the
+// prepared one and marks the row done (commitResume). Terminal: the row
+// is failed, the stop proof saved, and ErrConflict returned. Anything
+// else, still suspended included (the provider reports suspended while
+// the VM's resume hook runs): ErrResumePending, epoch 0.
+//
+// New-epoch credentials come from the prepared epoch, so the resume hook
+// can finish before the commit. After a crash or a lost reply, a retry with
+// the same ID or Refresh (mirrorLive) finishes the operation.
+func (c *Controller) Resume(ctx context.Context, by hostedwire.KeyID, key hostedwire.VerifyKey, attemptID, operationID string) (int64, error) {
+ defer c.lockAttempt(attemptID)()
+ var epoch int64
+ var send *pauseJob
+ var op resumeOp
+ err := c.creatorCall(ctx, by, key, attemptID, actionResumeRefused, func(tx *sql.Tx, j *pauseJob, a Audit) (error, error) {
+ epoch, send = 0, nil
+ if !validOperationID(operationID) {
+ return fmt.Errorf("%w: operation id must be 1 to %d letters, digits or '-'", isolatedjob.ErrInvalid, maxOperationIDLen), nil
+ }
+ if err := failDeadResume(ctx, tx, j, a.At); err != nil {
+ return nil, err
+ }
+ o, found, err := loadResumeOp(ctx, tx, j.attempt, operationID)
+ if err != nil {
+ return nil, err
+ }
+ switch {
+ case found && o.status == opDone:
+ epoch = o.result.Int64
+ a.Action, a.Reason = actionResumeRepeated, fmt.Sprintf("operation %s already done at epoch %d", operationID, epoch)
+ return nil, appendAudit(tx, a)
+ case found && o.status != opPending:
+ return fmt.Errorf("%w: resume operation %s failed", isolatedjob.ErrConflict, operationID), nil
+ }
+ if r := notPausable(j); r != nil {
+ return r, nil
+ }
+ if a.At >= T(j.stopT) {
+ return fmt.Errorf("%w: %v ago", ErrPastDeadline, time.Duration(a.At-T(j.stopT))), nil
+ }
+ if found {
+ a.Action, a.Reason = actionResumeContinued, fmt.Sprintf("operation %s pending at epoch %d; resume sent again", operationID, o.prepared)
+ op, send = o, j
+ return nil, appendAudit(tx, a)
+ }
+ other, busy, err := pendingResumeOp(ctx, tx, j.attempt)
+ if err != nil {
+ return nil, err
+ }
+ if busy {
+ return fmt.Errorf("%w: operation %s is pending", ErrResumePending, other.id), nil
+ }
+ if j.state != JobSuspended {
+ return fmt.Errorf("%w: only a suspended job can resume; %s is %s", isolatedjob.ErrConflict, j.attempt, j.state), nil
+ }
+ o = resumeOp{id: operationID, status: opPending, prepared: j.epoch + 1}
+ if _, err := tx.ExecContext(ctx, `INSERT INTO resume_ops (attempt_id, operation_id, status, prepared_epoch, prepared_t)
+ VALUES (?, ?, ?, ?, ?)`, j.attempt, operationID, opPending, o.prepared, int64(a.At)); err != nil {
+ return nil, fmt.Errorf("hostedctl: prepare resume of %s: %w", j.attempt, err)
+ }
+ res, err := tx.ExecContext(ctx, `UPDATE jobs SET state = ?, revision = revision + 1
+ WHERE attempt_id = ? AND state = ? AND epoch = ?`, JobResuming, j.attempt, JobSuspended, j.epoch)
+ if err != nil {
+ return nil, fmt.Errorf("hostedctl: prepare resume of %s: %w", j.attempt, err)
+ }
+ if n, err := res.RowsAffected(); err != nil || n != 1 {
+ return nil, fmt.Errorf("hostedctl: prepare resume of %s: %d rows (%v)", j.attempt, n, err)
+ }
+ a.Action, a.Reason = actionResumePrepared, fmt.Sprintf("operation %s prepared at epoch %d", operationID, o.prepared)
+ op, send = o, j
+ return nil, appendAudit(tx, a)
+ })
+ if err != nil {
+ return 0, err
+ }
+ if send == nil {
+ return epoch, nil
+ }
+ return c.driveResume(ctx, by, send, op)
+}
+
+// driveResume is Resume's steps 2 and 3 for a prepared or pending op.
+func (c *Controller) driveResume(ctx context.Context, actor hostedwire.KeyID, j *pauseJob, op resumeOp) (int64, error) {
+ ref := isolatedjob.Ref(j.ref.String)
+ rec := context.WithoutCancel(ctx) // record what the provider said even if the caller has gone
+ if perr := c.runner.Resume(ctx, ref); perr != nil {
+ aerr := c.auditPause(rec, actor, j, actionResumeCallFailed,
+ fmt.Sprintf("operation %s: provider resume call failed; the operation stays pending", op.id))
+ return 0, errors.Join(fmt.Errorf("%w: operation %s: resume VM %s: %w", ErrResumePending, op.id, ref, perr), aerr)
+ }
+ job, gerr := c.runner.Get(ctx, ref)
+ at := c.store.Clock().Now()
+ switch {
+ case gerr != nil:
+ return 0, fmt.Errorf("%w: operation %s: read VM %s: %w", ErrResumePending, op.id, ref, gerr)
+ case job.State == isolatedjob.StateRunning || job.State.Terminal():
+ return c.finishResume(rec, actor, j.attempt, op.id, job.State, at)
+ }
+ return 0, fmt.Errorf("%w: operation %s: VM %s is %s", ErrResumePending, op.id, ref, job.State)
+}
+
+// finishResume settles operation opID of attempt once Get, ending at at,
+// reported st, running or terminal. Running commits it and returns the
+// epoch. Terminal marks it failed, saves the stop proof and returns
+// isolatedjob.ErrConflict. An operation already done returns its epoch.
+func (c *Controller) finishResume(ctx context.Context, actor hostedwire.KeyID, attempt, opID string, st isolatedjob.State, at T) (int64, error) {
+ var epoch int64
+ var refusal error
+ var ref isolatedjob.Ref
+ err := c.store.Tx(ctx, func(tx *sql.Tx) error {
+ epoch, refusal = 0, nil
+ j, found, err := loadPauseJob(ctx, tx, attempt)
+ if err != nil {
+ return err
+ }
+ if !found {
+ return fmt.Errorf("hostedctl: resume %s: job is missing", attempt)
+ }
+ ref = isolatedjob.Ref(j.ref.String)
+ now := c.store.Clock().Now()
+ if err := failDeadResume(ctx, tx, &j, now); err != nil {
+ return err
+ }
+ op, found, err := loadResumeOp(ctx, tx, attempt, opID)
+ switch {
+ case err != nil:
+ return err
+ case !found:
+ return fmt.Errorf("hostedctl: resume %s: operation %s is missing", attempt, opID)
+ case op.status == opDone:
+ epoch = op.result.Int64
+ return nil
+ case op.status != opPending:
+ refusal = fmt.Errorf("%w: resume operation %s failed", isolatedjob.ErrConflict, opID)
+ return nil
+ case st == isolatedjob.StateRunning:
+ epoch = op.prepared
+ return commitResume(ctx, tx, &j, op, actor, now)
+ }
+ if _, err := tx.ExecContext(ctx, `UPDATE resume_ops SET status = ?, completed_t = ?
+ WHERE attempt_id = ? AND operation_id = ? AND status = ?`, opFailed, int64(now), attempt, opID, opPending); err != nil {
+ return fmt.Errorf("hostedctl: fail resume %s of %s: %w", opID, attempt, err)
+ }
+ refusal = fmt.Errorf("%w: VM %s is %s; resume operation %s failed", isolatedjob.ErrConflict, ref, st, opID)
+ return appendAudit(tx, Audit{Actor: actor, Account: j.account, Task: j.task, Attempt: attempt,
+ Action: actionResumeFailed, Reason: fmt.Sprintf("operation %s: provider reports the VM %s", opID, st), At: now})
+ })
+ if err != nil {
+ return 0, err
+ }
+ if refusal == nil {
+ return epoch, nil
+ }
+ if st.Terminal() {
+ if _, err := c.recordProof(ctx, actor, attempt, StopProof{AttemptID: attempt, VMRef: ref, State: st, ObservedAt: at},
+ "resume: provider reports the VM "+string(st)); err != nil {
+ return 0, errors.Join(refusal, err)
+ }
+ }
+ return 0, refusal
+}
+
+// auditPause writes one audit row about j in a short transaction.
+func (c *Controller) auditPause(ctx context.Context, actor hostedwire.KeyID, j *pauseJob, action, reason string) error {
+ return c.store.Tx(ctx, func(tx *sql.Tx) error {
+ return appendAudit(tx, Audit{Actor: actor, Account: j.account, Task: j.task, Attempt: j.attempt,
+ Action: action, Reason: reason, At: c.store.Clock().Now()})
+ })
+}
+
+// pauseState reports whether state is one the controller sets for the pause
+// barrier or a resume and settles itself: Refresh never overwrites it with
+// the VM's live state.
+func pauseState(state string) bool {
+ return state == JobDraining || state == JobSuspending || state == JobResuming
+}
+
+// mirrorLive is Refresh's hook for the pause barrier and resumes. refreshOne
+// calls it, in place of mirrorState, with j as it read the job under the
+// attempt's lock (so j is current; the hook does not take the lock again)
+// and the live state st that Get just reported. No transaction is held
+// across a provider call.
+//
+// A job in none of the pause states, with no stop request, is mirrored as
+// before. A job with a stop request is mirrored too, as the stop wins, and
+// its pending resume, if any, is marked failed. Otherwise the job's state
+// is left alone (a live sighting still clears notfound_since_t, as
+// mirrorState does) and only the transitions the controller expects are
+// settled:
+//
+// - draining: the generation is cancelled if its acknowledgement is late;
+// - suspending: a suspended VM makes the job JobSuspended; a VM still
+// running gets Runner.Suspend again (the first call may never have
+// reached the provider);
+// - resuming: a running VM commits the pending operation (commitResume);
+// a suspended one gets Runner.Resume again.
+//
+// Every live sighting clears notfound_since_t before the hook returns, so
+// refreshOne's restart handling after it sees the cleared value. A provider
+// call the hook makes that fails is audited and sent again next pass, not
+// returned: only store errors are, so a failing re-send never holds up
+// refreshOne's restart handling.
+//
+// Unknown states never get here (refreshOne leaves them), so a pending
+// resume stays pending for the next pass; a terminal VM gets proof from
+// refreshOne, and its pending resume is marked failed by the next call that
+// touches the job (failDeadResume) or the reaper.
+func (c *Controller) mirrorLive(ctx context.Context, j jobRow, st isolatedjob.State) error {
+ if !pauseState(j.state) && !j.stopRequested.Valid {
+ return c.mirrorState(ctx, j.attempt, st)
+ }
+ var next func() error
+ err := c.store.Tx(ctx, func(tx *sql.Tx) error {
+ next = nil
+ p, found, err := loadPauseJob(ctx, tx, j.attempt)
+ if err != nil || !found || p.stopProof.Valid {
+ return err
+ }
+ now := c.store.Clock().Now()
+ if p.stopRequested.Valid || !pauseState(p.state) {
+ next = func() error { return c.mirrorState(ctx, p.attempt, st) }
+ return failDeadResume(ctx, tx, &p, now)
+ }
+ if _, err := tx.ExecContext(ctx, `UPDATE jobs SET notfound_since_t = NULL, revision = revision + 1
+ WHERE attempt_id = ? AND notfound_since_t IS NOT NULL`, p.attempt); err != nil {
+ return fmt.Errorf("hostedctl: clear not-found of %s: %w", p.attempt, err)
+ }
+ a := Audit{Account: p.account, Task: p.task, Attempt: p.attempt, At: now}
+ switch {
+ case p.state == JobDraining:
+ return expire(ctx, tx, &p, now)
+ case p.state == JobSuspending && st == isolatedjob.StateSuspended:
+ if _, err := tx.ExecContext(ctx, `UPDATE jobs SET state = ?, revision = revision + 1
+ WHERE attempt_id = ? AND state = ?`, JobSuspended, p.attempt, JobSuspending); err != nil {
+ return fmt.Errorf("hostedctl: settle suspend of %s: %w", p.attempt, err)
+ }
+ a.Action, a.Reason = actionSuspendSettled, fmt.Sprintf("generation %d: provider reports the VM suspended", p.generation)
+ return appendAudit(tx, a)
+ case p.state == JobSuspending && st == isolatedjob.StateRunning:
+ next = func() error {
+ _, aerr := c.sendSuspend(ctx, "", &p, actionSuspendResent) // a failed call is audited and sent again next pass
+ return aerr
+ }
+ return nil
+ case p.state != JobResuming:
+ return nil
+ }
+ op, ok, err := pendingResumeOp(ctx, tx, p.attempt)
+ switch {
+ case err != nil:
+ return err
+ case !ok: // nothing to finish; the VM's own state is the best record
+ next = func() error { return c.mirrorState(ctx, p.attempt, st) }
+ return nil
+ case st == isolatedjob.StateRunning:
+ return commitResume(ctx, tx, &p, op, "", now)
+ case st == isolatedjob.StateSuspended:
+ next = func() error { return c.resendResume(ctx, &p, op) }
+ }
+ return nil
+ })
+ if err != nil || next == nil {
+ return err
+ }
+ return next()
+}
+
+// resendResume is Refresh sending the provider resume again for j's
+// pending op while the VM still reports suspended. The call's outcome is
+// audited; only a failure to write that row is returned. A failed call is
+// sent again on the next pass.
+func (c *Controller) resendResume(ctx context.Context, j *pauseJob, op resumeOp) error {
+ if perr := c.runner.Resume(ctx, isolatedjob.Ref(j.ref.String)); perr != nil {
+ return c.auditPause(ctx, "", j, actionResumeCallFailed,
+ fmt.Sprintf("refresh: operation %s: provider resume call failed; the operation stays pending", op.id))
+ }
+ return c.auditPause(ctx, "", j, actionResumeResent, fmt.Sprintf("refresh: operation %s pending; the VM still reports suspended, resume sent again", op.id))
+}
diff --git a/internal/hostedctl/resume_test.go b/internal/hostedctl/resume_test.go
new file mode 100644
index 00000000..d99189dc
--- /dev/null
+++ b/internal/hostedctl/resume_test.go
@@ -0,0 +1,337 @@
+package hostedctl
+
+import (
+ "context"
+ "database/sql"
+ "errors"
+ "testing"
+ "time"
+
+ "amadan.net/oficina/equipo/internal/isolatedjob"
+)
+
+// opRow is one resume_ops row.
+type opRow struct {
+ id, status string
+ prepared int64
+ result sql.NullInt64
+}
+
+func (e *launchEnv) resumeOps(attempt string) []opRow {
+ e.t.Helper()
+ var out []opRow
+ if err := e.store.Tx(e.ctx, func(tx *sql.Tx) error {
+ out = out[:0]
+ rows, err := tx.QueryContext(e.ctx, `SELECT operation_id, status, prepared_epoch, result_epoch FROM resume_ops
+ WHERE attempt_id = ? ORDER BY prepared_t, operation_id`, attempt)
+ if err != nil {
+ return err
+ }
+ defer rows.Close()
+ for rows.Next() {
+ var r opRow
+ if err := rows.Scan(&r.id, &r.status, &r.prepared, &r.result); err != nil {
+ return err
+ }
+ out = append(out, r)
+ }
+ return rows.Err()
+ }); err != nil {
+ e.t.Fatalf("read resume operations of %s = %v", attempt, err)
+ }
+ return out
+}
+
+func (e *launchEnv) resume(op string) (int64, error) {
+ e.t.Helper()
+ return e.c.Resume(e.ctx, "inst-1", instKey, "att-1", op)
+}
+
+// resumeDone wants Resume(op) to return epoch with no error.
+func (e *launchEnv) resumeDone(op string, epoch int64) {
+ e.t.Helper()
+ if got, err := e.resume(op); err != nil || got != epoch {
+ e.t.Fatalf("Resume(%s) = (%d, %v), want (%d, nil)", op, got, err, epoch)
+ }
+}
+
+// wantResume checks the job's state and epoch, the one pending or settled
+// row, and how many provider resumes were made.
+func (e *launchEnv) wantResume(state string, epoch int64, ops []opRow, calls int) {
+ e.t.Helper()
+ p := e.pauseCols("att-1")
+ got := e.resumeOps("att-1")
+ n := e.fake.Calls(isolatedjob.OpResume)
+ ok := p.state == state && p.epoch == epoch && len(got) == len(ops) && n == calls
+ for i := 0; ok && i < len(ops); i++ {
+ ok = got[i].id == ops[i].id && got[i].status == ops[i].status && got[i].prepared == ops[i].prepared &&
+ got[i].result == ops[i].result
+ }
+ if !ok {
+ e.t.Fatalf("job %q at epoch %d, ops %+v, %d provider resumes; want %q at %d, %+v, %d",
+ p.state, p.epoch, got, n, state, epoch, ops, calls)
+ }
+}
+
+func pending(id string, prepared int64) opRow {
+ return opRow{id: id, status: "pending", prepared: prepared}
+}
+
+func done(id string, epoch int64) opRow {
+ return opRow{id: id, status: "done", prepared: epoch, result: sql.NullInt64{Int64: epoch, Valid: true}}
+}
+
+// resumeProbe wraps the fake provider's Resume with a hook before the call
+// (a non-nil error from it is returned without calling the provider) and one
+// after it.
+type resumeProbe struct {
+ *isolatedjob.Fake
+ before func() error
+ after func()
+}
+
+func (p *resumeProbe) Resume(ctx context.Context, ref isolatedjob.Ref) error {
+ if p.before != nil {
+ if err := p.before(); err != nil {
+ return err
+ }
+ }
+ err := p.Fake.Resume(ctx, ref)
+ if p.after != nil {
+ p.after()
+ }
+ return err
+}
+
+// probe puts p in front of the fake provider for a new controller.
+func (e *launchEnv) probe(p *resumeProbe) {
+ e.t.Helper()
+ p.Fake = e.fake
+ e.run = p
+ e.newController()
+}
+
+// restart is a controller restart over the same fake provider, with no
+// probe: Close (already done by the crash) is followed by Open and New.
+func (e *launchEnv) restart() {
+ e.t.Helper()
+ e.run = e.fake
+ e.up()
+}
+
+func TestResumePreparesEpochBeforeProvider(t *testing.T) {
+ e := runningJob(t)
+ e.suspendJob()
+ type seen struct {
+ state string
+ epoch int64
+ status sql.NullString
+ prep sql.NullInt64
+ err error
+ }
+ var at []seen
+ e.probe(&resumeProbe{before: func() error {
+ // A transaction held across the call would make this read wait;
+ // the deadline turns that into an error.
+ rctx, cancel := context.WithTimeout(e.ctx, 2*time.Second)
+ defer cancel()
+ var s seen
+ s.err = e.store.Tx(rctx, func(tx *sql.Tx) error {
+ if err := tx.QueryRowContext(rctx, `SELECT state, epoch FROM jobs WHERE attempt_id = 'att-1'`).Scan(&s.state, &s.epoch); err != nil {
+ return err
+ }
+ err := tx.QueryRowContext(rctx, `SELECT status, prepared_epoch FROM resume_ops
+ WHERE attempt_id = 'att-1' AND operation_id = 'op-1'`).Scan(&s.status, &s.prep)
+ if errors.Is(err, sql.ErrNoRows) {
+ return nil
+ }
+ return err
+ })
+ at = append(at, s)
+ return nil
+ }})
+ if _, err := e.resume("op-1"); !errors.Is(err, ErrResumePending) {
+ t.Fatalf("Resume = %v, want ErrResumePending while the VM still reports suspended", err)
+ }
+ if len(at) != 1 {
+ t.Fatalf("provider resumes = %d, want 1", len(at))
+ }
+ s := at[0]
+ if s.err != nil || s.state != JobResuming || s.epoch != 0 || s.status.String != "pending" || s.prep.Int64 != 1 {
+ t.Fatalf("store at the provider call: %+v; want resuming at epoch 0 with op-1 pending at epoch 1", s)
+ }
+}
+
+func TestResumeCrashBeforeProvider(t *testing.T) {
+ e := runningJob(t)
+ e.suspendJob()
+ e.probe(&resumeProbe{before: func() error {
+ if err := e.store.Close(); err != nil {
+ t.Errorf("Close = %v", err)
+ }
+ return errors.New("the controller died before the call")
+ }})
+ if _, err := e.resume("op-1"); err == nil {
+ t.Fatal("Resume across a crash = nil error")
+ }
+ e.restart()
+ e.wantResume(JobResuming, 0, []opRow{pending("op-1", 1)}, 0)
+
+ e.refresh() // the VM is suspended: the resume is sent
+ e.wantResume(JobResuming, 0, []opRow{pending("op-1", 1)}, 1)
+ e.fake.Tick()
+ e.refresh() // the VM runs: commit
+ e.wantResume(JobRunning, 1, []opRow{done("op-1", 1)}, 1)
+ e.resumeDone("op-1", 1)
+ e.refresh()
+ e.wantResume(JobRunning, 1, []opRow{done("op-1", 1)}, 1)
+}
+
+func TestResumeCrashAfterProvider(t *testing.T) {
+ e := runningJob(t)
+ e.suspendJob()
+ e.probe(&resumeProbe{after: func() {
+ e.fake.Tick() // the VM runs before the controller can commit
+ if err := e.store.Close(); err != nil {
+ t.Errorf("Close = %v", err)
+ }
+ }})
+ if _, err := e.resume("op-1"); err == nil {
+ t.Fatal("Resume across a crash = nil error")
+ }
+ e.restart()
+ e.wantResume(JobResuming, 0, []opRow{pending("op-1", 1)}, 1)
+
+ // The client retries: a no-op provider resume, then the commit.
+ e.resumeDone("op-1", 1)
+ e.wantResume(JobRunning, 1, []opRow{done("op-1", 1)}, 2)
+ e.refresh()
+ e.resumeDone("op-1", 1)
+ e.wantResume(JobRunning, 1, []opRow{done("op-1", 1)}, 2)
+ if got := e.fake.LiveByAttempt()["att-1"]; got != 1 {
+ t.Fatalf("live VMs for att-1 = %d, want 1", got)
+ }
+}
+
+func TestResumeLostReply(t *testing.T) {
+ e := runningJob(t)
+ e.suspendJob()
+ e.fake.Inject(isolatedjob.OpResume, isolatedjob.FaultLostReply)
+ _, err := e.resume("op-1")
+ if !errors.Is(err, ErrResumePending) || !errors.Is(err, isolatedjob.ErrLostReply) {
+ t.Fatalf("Resume with a lost reply = %v, want ErrResumePending and the lost reply", err)
+ }
+ e.wantResume(JobResuming, 0, []opRow{pending("op-1", 1)}, 1)
+
+ // The resume took effect but the VM still reports suspended: neither a
+ // retry nor Refresh may commit yet.
+ if ep, err := e.resume("op-1"); !errors.Is(err, ErrResumePending) || ep != 0 {
+ t.Fatalf("retry while the VM is suspended = (%d, %v), want (0, ErrResumePending)", ep, err)
+ }
+ e.wantResume(JobResuming, 0, []opRow{pending("op-1", 1)}, 2)
+ e.refresh()
+ e.wantResume(JobResuming, 0, []opRow{pending("op-1", 1)}, 3)
+
+ e.fake.Tick()
+ e.resumeDone("op-1", 1)
+ e.wantResume(JobRunning, 1, []opRow{done("op-1", 1)}, 4)
+ e.refresh()
+ e.resumeDone("op-1", 1)
+ e.wantResume(JobRunning, 1, []opRow{done("op-1", 1)}, 4)
+}
+
+func TestResumeRetrySameOperation(t *testing.T) {
+ e := runningJob(t)
+ e.suspendJob()
+ for i := 0; i < 2; i++ {
+ if ep, err := e.resume("op-1"); !errors.Is(err, ErrResumePending) || ep != 0 {
+ t.Fatalf("Resume %d while suspended = (%d, %v), want (0, ErrResumePending)", i+1, ep, err)
+ }
+ }
+ e.wantResume(JobResuming, 0, []opRow{pending("op-1", 1)}, 2)
+ e.fake.Tick()
+ e.resumeDone("op-1", 1)
+ for i := 0; i < 3; i++ {
+ e.resumeDone("op-1", 1)
+ e.refresh()
+ }
+ e.wantResume(JobRunning, 1, []opRow{done("op-1", 1)}, 3)
+ if !e.hasAudit("inst-1", "att-1", actionResumeRepeated, "op-1") {
+ t.Fatal("no resume_repeated audit row for a retry of a done operation")
+ }
+}
+
+func TestResumeOperationsRemembered(t *testing.T) {
+ e := runningJob(t)
+ e.suspendJob()
+ if _, err := e.resume("op-a"); !errors.Is(err, ErrResumePending) {
+ t.Fatalf("Resume(op-a) = %v, want ErrResumePending", err)
+ }
+ e.fake.Tick()
+ e.resumeDone("op-a", 1)
+
+ e.clk.AdvanceMono(time.Minute) // op-b is the latest operation by time
+ e.suspendJob()
+ if _, err := e.resume("op-b"); !errors.Is(err, ErrResumePending) {
+ t.Fatalf("Resume(op-b) = %v, want ErrResumePending", err)
+ }
+ e.fake.Tick()
+ e.resumeDone("op-b", 2)
+ calls := e.fake.Calls(isolatedjob.OpResume)
+
+ e.resumeDone("op-a", 1)
+ e.resumeDone("op-b", 2)
+ e.wantResume(JobRunning, 2, []opRow{done("op-a", 1), done("op-b", 2)}, calls)
+}
+
+func TestResumeOtherOperationWhilePending(t *testing.T) {
+ e := runningJob(t)
+ e.suspendJob()
+ if _, err := e.resume("op-a"); !errors.Is(err, ErrResumePending) {
+ t.Fatalf("Resume(op-a) = %v, want ErrResumePending", err)
+ }
+ if ep, err := e.resume("op-b"); !errors.Is(err, ErrResumePending) || ep != 0 {
+ t.Fatalf("Resume(op-b) while op-a is pending = (%d, %v), want (0, ErrResumePending)", ep, err)
+ }
+ e.wantResume(JobResuming, 0, []opRow{pending("op-a", 1)}, 1)
+ e.fake.Tick()
+ e.resumeDone("op-a", 1)
+ if _, err := e.resume("op-b"); !errors.Is(err, isolatedjob.ErrConflict) {
+ t.Fatalf("Resume(op-b) of a running job = %v, want ErrConflict", err)
+ }
+ e.wantResume(JobRunning, 1, []opRow{done("op-a", 1)}, 2)
+
+ for _, bad := range []string{"", "op 1", "op_1", "op/1", string(make([]byte, 65))} {
+ if _, err := e.resume(bad); !errors.Is(err, isolatedjob.ErrInvalid) {
+ t.Fatalf("Resume(%q) = %v, want ErrInvalid", bad, err)
+ }
+ }
+}
+
+func TestResumePastDeadlineRefused(t *testing.T) {
+ e := runningJob(t)
+ e.suspendJob()
+ stop := e.stopCols("att-1").stop
+ e.clk.AdvanceMono(time.Duration(T(stop) - e.store.Clock().Now()))
+ if _, err := e.resume("op-1"); !errors.Is(err, ErrPastDeadline) {
+ t.Fatalf("Resume at the stop time = %v, want ErrPastDeadline", err)
+ }
+ e.wantResume(JobSuspended, 0, nil, 0)
+ if a := e.lastAudit(); a.Action != actionResumeRefused || a.Actor != "inst-1" {
+ t.Fatalf("audit = %+v, want resume_refused by inst-1", a)
+ }
+
+ // A pending operation gets no further provider call past the stop time.
+ e2 := runningJob(t)
+ e2.suspendJob()
+ e2.fake.Inject(isolatedjob.OpResume, isolatedjob.FaultThrottle)
+ if _, err := e2.resume("op-1"); !errors.Is(err, ErrResumePending) {
+ t.Fatalf("throttled Resume = %v, want ErrResumePending", err)
+ }
+ stop = e2.stopCols("att-1").stop
+ e2.clk.AdvanceMono(time.Duration(T(stop)-e2.store.Clock().Now()) + time.Second)
+ if _, err := e2.resume("op-1"); !errors.Is(err, ErrPastDeadline) {
+ t.Fatalf("retry of a pending Resume past the stop time = %v, want ErrPastDeadline", err)
+ }
+ e2.wantResume(JobResuming, 0, []opRow{pending("op-1", 1)}, 1)
+}
diff --git a/internal/hostedctl/states.go b/internal/hostedctl/states.go
index fdaecc37..baab37ec 100644
--- a/internal/hostedctl/states.go
+++ b/internal/hostedctl/states.go
@@ -26,3 +26,16 @@ const (
// moves it out of this state.
JobStopped = "stopped"
)
+
+// Job states of the pause barrier and resume (pause.go, resume.go). The
+// controller sets them and settles them itself; Refresh never overwrites
+// them, or JobSuspending set by Suspend, with the VM's live state
+// (mirrorLive).
+const (
+ // JobDraining: a pause generation is open; admission is closed until
+ // the VM is suspended or Reopen confirms the runner takes work again.
+ JobDraining = "draining"
+ // JobResuming: a resume operation is prepared (resume_ops pending) and
+ // not yet committed.
+ JobResuming = "resuming"
+)