hostedtest: Task 30 review 1, feed-lost latch, gate barrier, full proof
- chat: an enrolled job whose latest admission record is the feed's lifetime old takes no new record, renews nothing and fails hosted_unavailable, also when its result arrives first (decision S2-3). - hostedtest: the gate writes a start marker inside the sandbox and waits at a bounded barrier; drills strike only after the marker. Stop proof, controller record, provider VM, runner revocation and settled usage are each checked. - Task 22 tests keep the admission record fresh across long clock moves.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
11 files changed,
+335
−56
.rastrillo/budgets.txt+2 −2docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md+26 −1internal/equipo/chat/hosted_enrol.go+3 −2internal/equipo/chat/hosted_feedlost_test.go+84 −0internal/equipo/chat/hosted_results.go+19 −1internal/equipo/chat/hosted_run.go+7 −1internal/equipo/hosted_enrol_test.go+22 −3internal/equipo/hostedrun/controller_test.go+23 −0internal/equipo/hostedrun/dispatcher.go+4 −3internal/hostedtest/chain.go+51 −7internal/hostedtest/chain_test.go+94 −36
CI failed — 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-2: Type Size Avail | ext4 96G 84G
ci-box: disk /home/ci/.cache/equipo-ci-box: Type Size Avail | ext4 96G 84G
ci-box: bwrap: fetched and verified in 0.3s
ci-box: claude: fetched and verified in 4.6s
ci-box: codex: fetched and verified in 4.9s
ci-box: codex-code-mode-host: fetched and verified in 1.9s
ci-box: libwrap: fetched and verified in 0.3s
ci-box: socat: fetched and verified in 0.4s
ci-box: tofu: fetched and verified in 1.9s
npm warn deprecated node-domexception@1.0.0: Use your platform's native DOMException instead
ci-box: image pulled in 9.8s
ci-box: pi: installed and verified in 7.4s
ci-box: opencode: installed and verified in 2.3s
ci-box: chromium 156.0.8078.79-1~deb13u1: 76 packages fetched, verified and unpacked in 9.5s
ci-box: clone deepened in 4.8s
ci-box: file times set from content: 4001 files, 299 directories
ci-box: ready in 19.8s
=== copy ===
EQUIPO_RELEASE_COPY_CHECK=1 CGO_ENABLED=0 go test ./internal/equipotest -run '^TestReleaseCopyReviewed$' -count=1
--- FAIL: TestReleaseCopyReviewed (0.09s)
task_pages_test.go:236: COPY REVIEW REQUIRED: copy-status.py verify found copy pending review or stale bookkeeping
FAIL
rastrillo-budget/v1 ran 87ms
FAIL amadan.net/oficina/equipo/internal/equipotest 0.239s
FAIL
make: *** [Makefile:322: copy-release-check] Error 1
amadan: step copy failed: exit status 2
amadan: job failed at step copy — its output is above, not at the tail of this log
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt| index 79e05513..ad76cb78 100644 |
| --- a/.rastrillo/budgets.txt |
| +++ b/.rastrillo/budgets.txt |
| @@ -16,7 +16,7 @@ time internal/equipotest 300s Final fix package rerun measured 187.035s (review |
| time internal/equipo/hostedrun 60s Hosted slice 2 Task 21: TestDispatcherSimulation runs 200 seeds of the real chat store (SQLite) and dispatcher against a fake controller, with unlinked VMs that run to their 90-minute lifetime since review round 1, and one test drives the real controller over TLS for 90 simulated minutes; about 35 s of CPU in parallel subtests; measured 14 s on a 16 CPU docs-t1 under load 2.4; 60s covers a loaded 4 CPU runner. |
| time internal/hostedtest 300s Hosted slice 2 Task 30 (build tag hostedchain, make hosted-chain-test, its own CI lane): the whole hosted chain in one process (instance, controller, two proxies, a primary) and a real equipo-runner per VM, built at TestMain, its checks in real bubblewrap; eight tests, the drills waiting out gates, stop proofs and retried VMs; measured 128s on a 16 CPU docs-t1 under load 84; 300s covers a loaded CI runner. |
| -size internal/equipo 25562 9319 Preview, retry, merges, kept work, check-db, notifications, places, GitHub routes, installer, abilities, lookups, Mac waits, slice F codes, D1, probe details, Design's copy, /api/team; measured 24735. Hosted slice 2 Task 15 review 1: work.reason.pack_incomplete (pending); 24736. Task 17: work.reason.deps_conflict, deps_new_module, deps_missing, deps_too_large and token_renewal_failed (pending); 24741. Task 18: the owner setting "Run checks in a hosted VM" (config flag, routes, section, handler, four pending keys); 24825. Its review round 1: chatMe reports a roster denial as chat.ErrForbidden too (chatDenied); 24837. Task 21: the hosted dispatcher started only with EQUIPO_HOSTED_RUNNERS=1, execution on and a controller configured (EQUIPO_HOSTED_* config, RevokeRunner wiring), and the work.reason words for hosted_enrol_timeout, hosted_vm_lost and hosted_unavailable (pending); 24867. Task 22: hosted_enrol.go, a hosted VM's enrolment (POST /api/hosted/enrol) and its runner's challenge and renewal under /api/runner/v2 (the store methods over the runner and credential rows, the handlers, the routes only with EQUIPO_HOSTED_RUNNERS=1 and an admission reader), and mintRunnerCredential's lifetime and cap; 25248. Its tests (hosted_enrol_test.go: the routes through the whole application, and the runner's hosted.Start end to end through the test proxy) drive the unexported store, router and admission reader, so they live beside them and take the directory past the 8000-line test default; measured 8563 test lines. Task 22 review 1: the controller's deadline in the credential cap, and tests for a stale admission after a newer refusal, the first sighting and its window, code single use alone and the controller's deadline; 25256/8669. Review 2: a renewal reads the controller's admission record first, outside the transaction, and is capped by its current deadline; its tests (a deadline moved earlier after launch, the controller away or without a record); 25304/8724. Review 3: enrolment tests for a deadline moved earlier before enrolment and one already passed; 25304/8741. Task 25: what the person sees of hosted work: the checks line and timeline for a hosted wait and for each hosted limit (hostedWaitLine), the hosted reasons' words on the checks line and the merge decision, the Usage page's Hosted machines block (unknown, never zero, when unread), the owner's per-person limit editor (form, parsing, save route, the members it lists) and nineteen pending keys; hosted_views_test.go drives the store through the production wiring; 25478/9069. Task 25 review round 1: the limit save keeps a stored figure submitted as shown (hostedLimitsFrom), refuses limits below one checks run in their own words (hosted.limits.too_low), and handler tests for the Usage block and the save (flag, unknown totals, session actor, target, revision, member); 25524/9235. Task 26: runner_update_needed waits for the runner's update on the pause line (tooOld) and its pending work.reason words; 25525/9235. Task 27: checkpoint_key.go, a runner's machine public key for pack receipts (chat.Authority.RunnerMachineKey: runner rows keep only the key's hash, so the key comes from the runner's exchanged enrolment and must hash to it), wired in chat_wiring.go, and checkpoint_key_test.go; 25562/9312. Task 27 review 1: an enrolment whose stored hash matches the runner beside another key's bytes; 25562/9319. |
| +size internal/equipo 25562 9338 Preview, retry, merges, kept work, check-db, notifications, places, GitHub routes, installer, abilities, lookups, Mac waits, slice F codes, D1, probe details, Design's copy, /api/team; measured 24735. Hosted slice 2 Task 15 review 1: work.reason.pack_incomplete (pending); 24736. Task 17: work.reason.deps_conflict, deps_new_module, deps_missing, deps_too_large and token_renewal_failed (pending); 24741. Task 18: the owner setting "Run checks in a hosted VM" (config flag, routes, section, handler, four pending keys); 24825. Its review round 1: chatMe reports a roster denial as chat.ErrForbidden too (chatDenied); 24837. Task 21: the hosted dispatcher started only with EQUIPO_HOSTED_RUNNERS=1, execution on and a controller configured (EQUIPO_HOSTED_* config, RevokeRunner wiring), and the work.reason words for hosted_enrol_timeout, hosted_vm_lost and hosted_unavailable (pending); 24867. Task 22: hosted_enrol.go, a hosted VM's enrolment (POST /api/hosted/enrol) and its runner's challenge and renewal under /api/runner/v2 (the store methods over the runner and credential rows, the handlers, the routes only with EQUIPO_HOSTED_RUNNERS=1 and an admission reader), and mintRunnerCredential's lifetime and cap; 25248. Its tests (hosted_enrol_test.go: the routes through the whole application, and the runner's hosted.Start end to end through the test proxy) drive the unexported store, router and admission reader, so they live beside them and take the directory past the 8000-line test default; measured 8563 test lines. Task 22 review 1: the controller's deadline in the credential cap, and tests for a stale admission after a newer refusal, the first sighting and its window, code single use alone and the controller's deadline; 25256/8669. Review 2: a renewal reads the controller's admission record first, outside the transaction, and is capped by its current deadline; its tests (a deadline moved earlier after launch, the controller away or without a record); 25304/8724. Review 3: enrolment tests for a deadline moved earlier before enrolment and one already passed; 25304/8741. Task 25: what the person sees of hosted work: the checks line and timeline for a hosted wait and for each hosted limit (hostedWaitLine), the hosted reasons' words on the checks line and the merge decision, the Usage page's Hosted machines block (unknown, never zero, when unread), the owner's per-person limit editor (form, parsing, save route, the members it lists) and nineteen pending keys; hosted_views_test.go drives the store through the production wiring; 25478/9069. Task 25 review round 1: the limit save keeps a stored figure submitted as shown (hostedLimitsFrom), refuses limits below one checks run in their own words (hosted.limits.too_low), and handler tests for the Usage block and the save (flag, unknown totals, session actor, target, revision, member); 25524/9235. Task 26: runner_update_needed waits for the runner's update on the pause line (tooOld) and its pending work.reason words; 25525/9235. Task 27: checkpoint_key.go, a runner's machine public key for pack receipts (chat.Authority.RunnerMachineKey: runner rows keep only the key's hash, so the key comes from the runner's exchanged enrolment and must hash to it), wired in chat_wiring.go, and checkpoint_key_test.go; 25562/9312. Task 27 review 1: an enrolment whose stored hash matches the runner beside another key's bytes; 25562/9319. Task 30 review 1: hosted_enrol_test.go keeps the admission record fresh across its long clock moves (hostedRig.pass), as the dispatcher does, now that a record the feed's lifetime old loses its job; 25562/9338. |
| size internal/wire 9962 - Protocols 31 to 35 (facts, diffs, evidence, CI units, files, places), abilities, 36 lookups, 37 Mac Engineering, 38 Design, unproven and probe detail codes, 39 hosted runners (hosted.go: placement, hosted_pack and deps transfer limits, enrolment types); measured 9848. Task 15 opened TransferHeader.Valid to hosted_pack (inbound, base then candidate) and added ReasonPackIncomplete; 9860. Its review round 1 registered it in StepReasons; 9862. Task 17: the hosted worker's reasons (deps_conflict, deps_new_module, deps_missing, deps_too_large, token_renewal_failed) registered in StepReasons, and TransferHeader.Valid opened to deps with the hosted_pack rules (the worker accepts the bundle; Task 23 sends it); 9884. Task 21: ReasonHostedEnrolTimeout, ReasonHostedVMLost and ReasonHostedUnavailable, registered in StepReasons; 9899. Task 23: SendPackCommand.Deps, refused below ProtocolHostedRunners; 9902. Task 26: ReasonRunnerUpdateNeeded registered in StepReasons, and ProtocolHostedRunners documented as marking Research's quoting; 9912. Task 27: checkpoint.go, the Checkpoint and PackReceipt types slice 4 sends, the notes bounds, ValidPackDigest and PackReceiptMessage (the receipt's domain-separated signed message); no frame; 9962. |
| size internal/equipotest - 12693 GitHub connect value search, lifecycle and sweep-log contracts; Task 21 migration fixtures, Rastrillo asset contract, renderer archive link; measured 0/12693 source/test lines. |
| time internal/runner/checks 90s CI worker measured 44.553s (44.6s rounded); |
| @@ -61,7 +61,7 @@ perf GET /api/v1/assistant/snapshot skip Assistant person API: bearer-only JSON |
| perf GET /api/v1/assistant/messages skip Assistant person API: bearer-only JSON for Base's chat, not a browser screen. |
| perf GET /api/v1/assistant/events skip Assistant event stream (Server-Sent Events), bearer-only and long-lived; not a screen. |
| perf GET /api/v1/assistant/abilities skip Assistant person API: bearer-only JSON for Base's Settings line, not a browser screen. |
| -size internal/equipo/chat 47548 22440 File facts/diffs, previews, merges, unfinished work, CI, receipts, Assistant files, places, abilities, lookups, go-aheads, Mac work, D1, Design specialists, grants, captures; 45093/18782. Hosted slice 2 Task 15: openHostedPack (the instance's send_pack for a hosted pack) and its test; 45105/18883. Its review round 1 added the report-ingestion test for pack_incomplete; 45105/18911. Task 18: hosted_setting.go (SetHostedChecks, hostedChecks, HostedSettings; owner only, roster in the transaction, audited) and its tests; 45208/19070. Its review round 1: the audit atomicity test; 45208/19113. Task 19: hosted_jobs.go (the hosted_jobs and hosted_challenges tables, HostedJob and its lifecycle: newHostedJob, the listed moves only, ended and failed only with stop proof or never-launched evidence, settleHostedJob once, hostedJobForRunner; each move audited in its transaction) and its tests, TestMigrationAdditive included; 45658/19577. Its review round 1: the never-launched evidence contract (HostedNeverLaunched, launch_by and launching_since, hostedLaunchReturned) and tests for it, settlement of unproven terminal records and audit atomicity; 45728/19739. Task 20: hosted_limits.go (per-person hosted limits, S2-9: hostedAdmit held in the write by a per-person lock row, hostedHoldFor, Allocate, hostedSettle at 4x the baseline, SetHostedLimits owner only with the roster, revision and audit in the transaction) and its tests; 46013/20214. Its coordinator ruling: a limit counts only while its setting owner is a current owner (defaults otherwise, checked in the admission transaction) and TestOwnerRaisesLimitRevoked; 46022/20284. Its review round 1: Allocate returns nothing for an empty or reversed span before widening, and its assertions; 46025/20290. Hosted slice 2 Task 21: placement on hosted VMs (placeHosted before the checks early return, its five rules), the bound runner's fits, Authorize by job identity, the hosted offline rule and withdrawal exemption, the hosted pack at dispatch, the step-terminal hook, and the dispatcher's store methods (HostedLive, HostedSweep, HostedLaunching with relaunch, HostedLaunched, HostedAdmitted, HostedFailed, HostedStopped, HostedNeverLaunched, HostedReplaces, PlaceHosted; end, settle, revoke, step moved on) in hosted_run.go, and hosted_place_test.go; 46665/20804. Task 21 review round 1: abandoned-intent evidence waits for the job's lifetime, the job keeps its lifetime and first running sight, admission takes the placing transaction's step attempt, provider-valid attempt IDs, HostedRunning, and the Retry, replacement-runner, cancelled-task and stopping-VM tests; 46709/20937. Its review round 2: TestHostedReplacesNeedsProof; 46709/20971. Task 22: hosted_enrol.go (the enrolment and renewal store steps inside the instance's write transaction: HostedClaimCode, HostedEnrolAdmit, HostedEnrolBind, HostedRunnerJob, HostedNewChallenge, HostedUseChallenge; hostedAdmitted shared with HostedAdmitted); its tests drive it through the instance's routes (internal/equipo); 46848/20971. Its review round 1: hostedAdmitted reports whether the record was kept, the enrolment records the first sighting and applies the window from it, and the launch view's deadline is kept (hosted_jobs.deadline, earliest wins); 46903/20971. Its review round 2: an admission record's current deadline is kept too (hostedAdmitted, for the dispatcher's refresh and the renewal's HostedRenewAdmit); 46932/20971. Round 3: HostedEnrolAdmit returns the job re-read after recording the admission, so the enrolment caps by its deadline; 46937/20971. Task 23: openHostedPack opens the deps bundle after the hosted pack (send_pack with Deps), the instance's chunk and byte checks per kind (wire.MaxChunks, wire.MaxBytes), deps_too_large for a bundle past its limit, and a hosted attempt's pack and bundle closed when its checks end; hosted_deps_test.go; 46957/21199. Task 24: hosted_results.go (hostedCertified, AdmissionFresh: a hosted worker's checks count as sandboxed and its base checks as trusted only through the job's fresh, valid admission record, never its hello; an uncertified hosted result is not kept, its job stops and the step goes again once; deps_new_module and deps_missing presented as needs_network), stepReport and acceptBaseChecks wired to it, the admission kept whole and the enrolment image (0129), and hosted_results_test.go; 47094/21522. Task 24 review round 1: the certification decision moved before any terminal checks report from a worker (done, failed, unsolicited cancelled, the early failure branches), the person's cancellation kept, and tests for those, a wrong step, a stopping job and each admission identity substitution; 47096/21714. Task 24 review round 2: hostedSettleCancel (under the person's cancellation or an ended task, an uncertified hosted runner's report settles only its termination, with no checks evidence, taint or retry) and TestHostedUncertifiedCancelRace; 47123/21758. Task 25: HostedUsage (a person's running jobs and this UTC day's and month's held or used figures, errors returned) and HostedLimitList (owner only, the roster in the transaction) in usage.go, with hostedCounted shared with hostedAdmit; 47210/21758. Task 25 review round 1: HostedMinLimits and ErrHostedLimitTooLow (SetHostedLimits refuses limits that could never admit one checks job) and hosted_limits_floor_test.go (the floor, and each limit chip's promise through admission); 47224/21852. Task 26: protocol_floor.go (Research placed and started only at ProtocolHostedRunners, runner_update_needed, rechecked at Authorize) and protocol_floor_test.go; 47304/21967. Task 26 review 1: the Research floor before the legacy protocol 13 check, and the reconnect fence's runner_update_needed for a step not started (a protocol 12 placement case, TestResearchFencedAtReconnect); 47301/21998. Task 27: checkpoint.go (AcknowledgeCheckpoint binds a hosted runner's checkpoint to its job's recorded task, repository, base, candidate, attempt and launch, needs the current primary's signed pack receipt, recomputes the notes digest and stores it immutably; RenderResume renders only from the acknowledgement's ID, each note JSON-quoted), Authority.RunnerMachineKey, the checkpoints model, and checkpoint_test.go; 47548/22421. Task 27 review 1: TestAckImmutable alters each digest-bound stored field separately; 47548/22440. |
| +size internal/equipo/chat 47573 22524 File facts/diffs, previews, merges, unfinished work, CI, receipts, Assistant files, places, abilities, lookups, go-aheads, Mac work, D1, Design specialists, grants, captures; 45093/18782. Hosted slice 2 Task 15: openHostedPack (the instance's send_pack for a hosted pack) and its test; 45105/18883. Its review round 1 added the report-ingestion test for pack_incomplete; 45105/18911. Task 18: hosted_setting.go (SetHostedChecks, hostedChecks, HostedSettings; owner only, roster in the transaction, audited) and its tests; 45208/19070. Its review round 1: the audit atomicity test; 45208/19113. Task 19: hosted_jobs.go (the hosted_jobs and hosted_challenges tables, HostedJob and its lifecycle: newHostedJob, the listed moves only, ended and failed only with stop proof or never-launched evidence, settleHostedJob once, hostedJobForRunner; each move audited in its transaction) and its tests, TestMigrationAdditive included; 45658/19577. Its review round 1: the never-launched evidence contract (HostedNeverLaunched, launch_by and launching_since, hostedLaunchReturned) and tests for it, settlement of unproven terminal records and audit atomicity; 45728/19739. Task 20: hosted_limits.go (per-person hosted limits, S2-9: hostedAdmit held in the write by a per-person lock row, hostedHoldFor, Allocate, hostedSettle at 4x the baseline, SetHostedLimits owner only with the roster, revision and audit in the transaction) and its tests; 46013/20214. Its coordinator ruling: a limit counts only while its setting owner is a current owner (defaults otherwise, checked in the admission transaction) and TestOwnerRaisesLimitRevoked; 46022/20284. Its review round 1: Allocate returns nothing for an empty or reversed span before widening, and its assertions; 46025/20290. Hosted slice 2 Task 21: placement on hosted VMs (placeHosted before the checks early return, its five rules), the bound runner's fits, Authorize by job identity, the hosted offline rule and withdrawal exemption, the hosted pack at dispatch, the step-terminal hook, and the dispatcher's store methods (HostedLive, HostedSweep, HostedLaunching with relaunch, HostedLaunched, HostedAdmitted, HostedFailed, HostedStopped, HostedNeverLaunched, HostedReplaces, PlaceHosted; end, settle, revoke, step moved on) in hosted_run.go, and hosted_place_test.go; 46665/20804. Task 21 review round 1: abandoned-intent evidence waits for the job's lifetime, the job keeps its lifetime and first running sight, admission takes the placing transaction's step attempt, provider-valid attempt IDs, HostedRunning, and the Retry, replacement-runner, cancelled-task and stopping-VM tests; 46709/20937. Its review round 2: TestHostedReplacesNeedsProof; 46709/20971. Task 22: hosted_enrol.go (the enrolment and renewal store steps inside the instance's write transaction: HostedClaimCode, HostedEnrolAdmit, HostedEnrolBind, HostedRunnerJob, HostedNewChallenge, HostedUseChallenge; hostedAdmitted shared with HostedAdmitted); its tests drive it through the instance's routes (internal/equipo); 46848/20971. Its review round 1: hostedAdmitted reports whether the record was kept, the enrolment records the first sighting and applies the window from it, and the launch view's deadline is kept (hosted_jobs.deadline, earliest wins); 46903/20971. Its review round 2: an admission record's current deadline is kept too (hostedAdmitted, for the dispatcher's refresh and the renewal's HostedRenewAdmit); 46932/20971. Round 3: HostedEnrolAdmit returns the job re-read after recording the admission, so the enrolment caps by its deadline; 46937/20971. Task 23: openHostedPack opens the deps bundle after the hosted pack (send_pack with Deps), the instance's chunk and byte checks per kind (wire.MaxChunks, wire.MaxBytes), deps_too_large for a bundle past its limit, and a hosted attempt's pack and bundle closed when its checks end; hosted_deps_test.go; 46957/21199. Task 24: hosted_results.go (hostedCertified, AdmissionFresh: a hosted worker's checks count as sandboxed and its base checks as trusted only through the job's fresh, valid admission record, never its hello; an uncertified hosted result is not kept, its job stops and the step goes again once; deps_new_module and deps_missing presented as needs_network), stepReport and acceptBaseChecks wired to it, the admission kept whole and the enrolment image (0129), and hosted_results_test.go; 47094/21522. Task 24 review round 1: the certification decision moved before any terminal checks report from a worker (done, failed, unsolicited cancelled, the early failure branches), the person's cancellation kept, and tests for those, a wrong step, a stopping job and each admission identity substitution; 47096/21714. Task 24 review round 2: hostedSettleCancel (under the person's cancellation or an ended task, an uncertified hosted runner's report settles only its termination, with no checks evidence, taint or retry) and TestHostedUncertifiedCancelRace; 47123/21758. Task 25: HostedUsage (a person's running jobs and this UTC day's and month's held or used figures, errors returned) and HostedLimitList (owner only, the roster in the transaction) in usage.go, with hostedCounted shared with hostedAdmit; 47210/21758. Task 25 review round 1: HostedMinLimits and ErrHostedLimitTooLow (SetHostedLimits refuses limits that could never admit one checks job) and hosted_limits_floor_test.go (the floor, and each limit chip's promise through admission); 47224/21852. Task 26: protocol_floor.go (Research placed and started only at ProtocolHostedRunners, runner_update_needed, rechecked at Authorize) and protocol_floor_test.go; 47304/21967. Task 26 review 1: the Research floor before the legacy protocol 13 check, and the reconnect fence's runner_update_needed for a step not started (a protocol 12 placement case, TestResearchFencedAtReconnect); 47301/21998. Task 27: checkpoint.go (AcknowledgeCheckpoint binds a hosted runner's checkpoint to its job's recorded task, repository, base, candidate, attempt and launch, needs the current primary's signed pack receipt, recomputes the notes digest and stores it immutably; RenderResume renders only from the acknowledgement's ID, each note JSON-quoted), Authority.RunnerMachineKey, the checkpoints model, and checkpoint_test.go; 47548/22421. Task 27 review 1: TestAckImmutable alters each digest-bound stored field separately; 47548/22440. Task 30 review 1: the feed-lost latch (decision S2-3): HostedFeedLost and feedLost, an enrolled job whose latest admission record is the feed's lifetime old takes no new record, renews nothing and fails hosted_unavailable, also when its result arrives first; hosted_feedlost_test.go; 47573/22524. |
| perf GET /api/v1/questions/{id} skip Thin v1 person API: bearer-only JSON for devices; the browser reads questions on /tasks/{id}. |
| perf GET /api/v1/steps/{id}/log skip Thin v1 person API: bearer-only JSON for devices; the browser shows the log tail on /tasks/{id}. |
| perf GET /api/v1/connections/preference skip Connections slice 1 person API: bearer-only JSON for devices; the browser shows the preference on /conversation/connections. |
diff --git a/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md b/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md| index 069ea00f..1cb1170d 100644 |
| --- a/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md |
| +++ b/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md |
| @@ -2809,7 +2809,9 @@ RED, the chain over the code as it stood (542acf39): |
| GREEN: `make hosted-chain-test`: ok 108.6s (8 tests; 128s under load 84 earlier). `go test ./internal/equipo/hostedrun -count=1` ok 24.8s; `go test ./internal/vminit` ok; `go test ./cmd/equipo-runner -run Hosted` ok; `make budget build vet lanes-check` ok. |
| -Mutation checks (each applied alone, the named test run, the file restored byte for byte; chain tests through `hcrun.sh`, a short TMPDIR under $HOME): |
| +Mutation checks (each applied alone, the named test run, the file restored byte for byte). Every chain test run, here and below, is exactly: |
| +`t=$(mktemp -d "$HOME/.hc.XXXXXX"); TMPDIR="$t" CGO_ENABLED=0 timeout 900 go test -tags hostedchain ./internal/hostedtest -run '^<TestName>$' -count=1; rm -rf "$t"` |
| +(the M1 to M8 runs used `mktemp -d /home/paulca/.hcXXXX` and `-run '<TestName>'` unanchored, the same tests; the scratch directory was removed after each run). Unit runs: `CGO_ENABLED=0 go test ./internal/<pkg> -run '^<TestName>$' -count=1`. |
| - M1 `cmd/equipo-runner/hosted.go`: containment `ScratchRoot: c.ScratchRoot` again. `TestChainHostedCheckPasses`: exit 1 | chain_test.go:169: step {State:done ... Reason:checks_unavailable Checks:cannot_run ...} | restored. |
| - M2 `hostedrun/dispatcher.go`: the FeedLost rule disabled (`if false && ...`). `TestControllerLostFailsEnrolledJob`: exit 1 | controller_test.go:200: the feed expired and the job is enrolled "" | restored. `TestChainKillControllerMidStep`: exit 1 | chain_test.go:308: the job failing hosted_unavailable: not within 30s | restored. |
| - M2b the rule's bound moved earlier (`FeedLost - 2*Every`). `TestControllerLostFailsEnrolledJob`: exit 1 | controller_test.go:195: failed 4m40s into the outage: stopping "hosted_unavailable" | restored. |
| @@ -2819,3 +2821,26 @@ Mutation checks (each applied alone, the named test run, the file restored byte |
| - M6 `chat/hosted_results.go`: hostedCertified ignores the job's and the record's CertValid. `TestChainCertWithdrawnMidStep`: exit 1 | chain_test.go:380: jobs [{... State:ended ...}] (the withdrawn VM's result kept) | restored. |
| - M7 `chat/hosted_results.go`: deps_new_module no longer presented as needs_network. `TestChainNewModule`: exit 1 | chain_test.go:228: the person sees "deps_new_module", not needs_network | restored. |
| - M8 `chat/hosted_results.go`: hostedCertified never certifies. `TestChainFailingCheck`: exit 1 | chain_test.go:193: step {State:done ... Reason:hosted_unavailable Checks:cannot_run ...} | restored. |
| + |
| +### Task 30 review round 1 |
| + |
| +Astra round 1 (`t30-r1.md`): four findings, all fixed. |
| + |
| +1. Latch (decision S2-3). `chat.HostedFeedLost` (5 min) and `feedLost(j, at)`: an enrolled job whose latest admission record is that old when the next record is asked for takes no record (`hostedAdmitted`) and moves to stopping `hosted_unavailable`, a durable latch: no later record or renewal revives it, its result is not kept, and the step retries once after the stop proof. A renewal that is the first record since (`HostedRenewAdmit`) is refused; a result arriving first stops the job `hosted_unavailable` too (`hostedUncertified`). `hostedrun.FeedLost` is `chat.HostedFeedLost`; the dispatcher's refresh-failure rule stays. The latch reads the job's own stored record time, so it needs no new column, and it catches a gap whether or not any pass saw the controller fail. |
| + RED (constant only, no behaviour): `CGO_ENABLED=0 go test ./internal/equipo/chat -run 'TestFeedLost' -count=1`: hosted_feedlost_test.go:41: the first record after the feed expired: job enrolled "", want stopping "hosted_unavailable"; hosted_feedlost_test.go:63: the result after the feed expired: job stopping "uncertified", want stopping "hosted_unavailable". Then `TestFeedLostRenewalRefused`: hosted_feedlost_test.go:81: a renewal after the feed expired was admitted. The latch also refused two Task 22 tests that moved the clock 20 and 30 minutes with no admission refresh (`TestHostedCredentialCappedAtDeadline`: hosted_enrol_test.go:713: renew: 403; `TestRenewThroughFullMiddleware`: hosted_enrol_test.go:608: challenge: 403); they now keep the record fresh as the dispatcher does (`hostedRig.pass`, a refresh a minute). Chain regression: `TestChainKillControllerMidStep` now holds the harness's passes from before the kill until after the controller is back, so the first fresh admission arrives after the feed expired with no failure seen. |
| +2. Barrier. The fixture gate, inside the running sandbox, touches `.gate-started` in its workspace and then waits for `.gate-release` for at most sleep.txt's seconds (60 in the drills). `midStep` waits (90 s bound) for that marker in the hosted runner's attempt tree (`<VM>/s/scratch/worker-steps/*/tree`) with the runner alive and the step running; each drill strikes, then releases the gates (`ReleaseGates`, and every later pass). The certificate drill releases only once the withdrawal is recorded on the job. |
| +3. Proof. `Chain.proven`: the stop proof names the job's attempt and VM, stopped; the controller's own record of the attempt names the job's launch and VM, stopped; the provider fake reports the VM stopped; the job's runner is revoked; the settled usage decodes, has every day and month positive, within the hold, and no more seconds than admission to end (rounded up, plus one). |
| +4. Commands, above and below, exact. |
| + |
| +GREEN: `make hosted-chain-test`: ok 74.3s. `CGO_ENABLED=0 go test ./internal/equipo ./internal/equipo/chat -count=1`: ok 98.3s, ok 35.3s. `CGO_ENABLED=0 go test ./internal/equipo/hostedrun ./internal/vminit -count=1`: ok 25.5s, ok. `make budget build vet lanes-check` ok (chat 47573/22524 and equipo 9338 test lines, records raised); `go vet -tags hostedchain ./internal/hostedtest ./internal/vminit` ok. |
| + |
| +Mutation checks (one at a time, restored byte for byte, each run as above): |
| +- R1 `chat/hosted_run.go` latch off (`if false && feedLost(j, at)`): `TestFeedLostLatched`: hosted_feedlost_test.go:41: the first record after the feed expired: job enrolled "", want stopping "hosted_unavailable"; `TestControllerBackAfterFeedLost` (hostedrun): controller_test.go:219: the controller came back after the feed expired and the job is enrolled ""; `TestChainKillControllerMidStep`: chain_test.go:376: jobs [{... State:ended ... VMRef:vm-0001 ...}] (the first VM's result certified, one job) | restored. |
| +- R2 `chat/hosted_results.go` result path off (`if false && feedLost(j, t.now())`): `TestFeedLostResultFirst`: hosted_feedlost_test.go:63: job stopping "uncertified", want stopping "hosted_unavailable" | restored. |
| +- R3 `chat/hosted_enrol.go` renewal latch ignored (`if err != nil || false && lost`): `TestFeedLostRenewalRefused`: hosted_feedlost_test.go:81: a renewal after the feed expired was admitted | restored. |
| +- R4 `chat/hosted_results.go` bound earlier (`HostedFeedLost - 2*time.Second`): `TestFeedLostLatched`: hosted_feedlost_test.go:37: a gap under the feed's lifetime failed the job: stopping "hosted_unavailable" | restored. |
| +- R5 gate never starts (`cmd/equipo-runner/hosted.go`, containment `ScratchRoot: c.ScratchRoot`): `TestChainStopVMMidStep`: chain_test.go:388: the gate started in the VM's sandbox: not within 1m30s (the drill stops, it does not strike) | restored. |
| +- R6 empty proof (`chat/hosted_run.go` HostedStopped records `&hostedwire.StopProof{}`): `TestChainHostedCheckPasses`: chain_test.go:217: the step ended and its VMs stopped with proof: not within 3m0s (the store's provenErr refuses to settle it, so the job never ends) | restored. |
| +- R6b proof for another VM (`chat/hosted_jobs.go` hostedEnd rewrites the proof's VMRef to `vm-elsewhere`): `TestChainHostedCheckPasses`: chain_test.go:217: not within 3m0s (refused by provenErr likewise) | restored. |
| +- R7 missing usage (`chat/hosted_jobs.go` settleHostedJob stores `{}` for both amounts): `TestChainHostedCheckPasses`: chain_test.go:227: job ... settled ... with usage {Seconds:map[] Micros:map[]}, hold {Seconds:map[2026-12-01:6000] Micros:map[2026-12:2066667]} | restored. |
| +- R8 runner not revoked (`chat/hosted_run.go` hostedFinish skips RevokeRunner): `TestChainHostedCheckPasses`: chain_test.go:227: job ...'s runner ... is not revoked | restored. |
diff --git a/internal/equipo/chat/hosted_enrol.go b/internal/equipo/chat/hosted_enrol.go| index c6d93ee2..32c33e93 100644 |
| --- a/internal/equipo/chat/hosted_enrol.go |
| +++ b/internal/equipo/chat/hosted_enrol.go |
| @@ -127,7 +127,7 @@ func (s *Store) HostedEnrolAdmit(tx *gorm.DB, attempt, launchID, vmRef string, a |
| // current deadline (the earliest is kept). It reports false when a was |
| // recorded and does not show the job's certified VM running; a record |
| // older than the one held leaves the held one to decide. A job not |
| -// enrolled is a refusal. |
| +// enrolled, or whose feed was lost (feedLost), is a refusal. |
| func (s *Store) HostedRenewAdmit(tx *gorm.DB, attempt string, a hostedwire.AdmissionView, asked time.Time) (bool, error) { |
| var j HostedJob |
| if err := tx.Where("attempt_id = ?", attempt).First(&j).Error; err != nil { |
| @@ -136,8 +136,9 @@ func (s *Store) HostedRenewAdmit(tx *gorm.DB, attempt string, a hostedwire.Admis |
| if j.State != HostedJobEnrolled { |
| return false, ErrForbidden |
| } |
| + lost := feedLost(j, asked) |
| valid, accepted, err := s.hostedTx(tx).hostedAdmitted(j, a, asked) |
| - if err != nil { |
| + if err != nil || lost { |
| return false, err |
| } |
| return !accepted || valid && a.State == hostedRunning, nil |
diff --git a/internal/equipo/chat/hosted_feedlost_test.go b/internal/equipo/chat/hosted_feedlost_test.go| new file mode 100644 |
| index 00000000..c9d05888 |
| --- /dev/null |
| +++ b/internal/equipo/chat/hosted_feedlost_test.go |
| @@ -0,0 +1,84 @@ |
| +package chat |
| + |
| +import ( |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/hostedwire" |
| + "amadan.net/oficina/equipo/internal/isolatedjob" |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// lostFeed fails unless j is stopping hosted_unavailable with nothing of |
| +// its result kept. |
| +func (r *hkRig) lostFeed(what string, j HostedJob) { |
| + r.t.Helper() |
| + if got := r.job(j.AttemptID); got.State != HostedJobStopping || got.StopReason != wire.ReasonHostedUnavailable { |
| + r.t.Fatalf("%s: job %s %q, want stopping %q", what, got.State, got.StopReason, wire.ReasonHostedUnavailable) |
| + } |
| + if s := r.step("s1"); wire.StepTerminal(s.State) || s.ChecksSandbox != "" || s.BaseChecksSHA != "" || s.Checks != "" { |
| + r.t.Fatalf("%s: s1 %s sandbox %q base %q checks %q, want nothing kept", what, s.State, s.ChecksSandbox, s.BaseChecksSHA, s.Checks) |
| + } |
| +} |
| + |
| +// TestFeedLostLatched (decision S2-3): the controller came back after the |
| +// proxies' feed expired, and the dispatcher's first refresh since then |
| +// succeeds. The record is not taken: the job fails hosted_unavailable |
| +// there and then, a later record does not revive it, its VM's result is |
| +// not kept, and after the stop proof the step is placed again once. A gap |
| +// shorter than the feed's lifetime changes nothing. |
| +func TestFeedLostLatched(t *testing.T) { |
| + r := hostedPlaceRig(t) |
| + r.checksStep("s1", "tkp") |
| + j := r.certifiedOnVM("vm-1", "H1") |
| + r.now = r.now.Add(HostedFeedLost - time.Second) |
| + r.must(r.s.HostedAdmitted(r.ctx, j.AttemptID, hrAdmission(j.AttemptID, "vm-1", true), r.now)) |
| + if got := r.job(j.AttemptID); got.State != HostedJobEnrolled { |
| + t.Fatalf("a gap under the feed's lifetime failed the job: %s %q", got.State, got.StopReason) |
| + } |
| + r.now = r.now.Add(HostedFeedLost) |
| + r.must(r.s.HostedAdmitted(r.ctx, j.AttemptID, hrAdmission(j.AttemptID, "vm-1", true), r.now)) |
| + r.lostFeed("the first record after the feed expired", j) |
| + r.now = r.now.Add(10 * time.Second) |
| + r.must(r.s.HostedAdmitted(r.ctx, j.AttemptID, hrAdmission(j.AttemptID, "vm-1", true), r.now)) |
| + r.reportAs("H1", passedReport("s1", 1, wire.SandboxBubblewrap)) |
| + r.lostFeed("a fresh record and the result after the latch", j) |
| + r.online(hpPrimary, wire.ProtocolHostedRunners) |
| + r.must(r.s.HostedStopped(r.ctx, j.AttemptID, hostedwire.StopProof{AttemptID: j.AttemptID, VMRef: "vm-1", State: isolatedjob.StateStopped}, r.now)) |
| + jobs := r.jobsOf("s1") |
| + if len(jobs) != 2 || jobs[0].State != HostedJobFailed || jobs[1].RetryOf != j.AttemptID { |
| + t.Fatalf("after the stop proof: jobs %+v", jobs) |
| + } |
| +} |
| + |
| +// TestFeedLostResultFirst: the VM's result arrives before any record |
| +// since the feed expired; it is not kept and the job fails |
| +// hosted_unavailable, not merely uncertified. |
| +func TestFeedLostResultFirst(t *testing.T) { |
| + r := hostedPlaceRig(t) |
| + r.checksStep("s1", "tkp") |
| + j := r.certifiedOnVM("vm-1", "H1") |
| + r.now = r.now.Add(HostedFeedLost) |
| + r.reportAs("H1", passedReport("s1", 1, wire.SandboxBubblewrap)) |
| + r.lostFeed("the result after the feed expired", j) |
| +} |
| + |
| +// TestFeedLostRenewalRefused: the VM's renewal is the first record asked |
| +// for since the feed expired; it is refused and the job fails |
| +// hosted_unavailable. |
| +func TestFeedLostRenewalRefused(t *testing.T) { |
| + r := hostedPlaceRig(t) |
| + r.checksStep("s1", "tkp") |
| + j := r.certifiedOnVM("vm-1", "H1") |
| + r.now = r.now.Add(HostedFeedLost) |
| + var ok bool |
| + r.must(r.tx(func(t *txn) error { |
| + var err error |
| + ok, err = r.s.HostedRenewAdmit(t.db, j.AttemptID, hrAdmission(j.AttemptID, "vm-1", true), r.now) |
| + return err |
| + })) |
| + if ok { |
| + t.Fatal("a renewal after the feed expired was admitted") |
| + } |
| + r.lostFeed("the renewal after the feed expired", j) |
| +} |
diff --git a/internal/equipo/chat/hosted_results.go b/internal/equipo/chat/hosted_results.go| index 121f5000..b0f7bf89 100644 |
| --- a/internal/equipo/chat/hosted_results.go |
| +++ b/internal/equipo/chat/hosted_results.go |
| @@ -20,6 +20,14 @@ import ( |
| // certified. The dispatcher refreshes it every pass (about 10 s). |
| const AdmissionFresh = 2 * time.Minute |
| +// HostedFeedLost is how long the proxies act on the controller's last |
| +// feed (ctlproxy.FeedLifetime, decision S2-3). An enrolled job whose |
| +// latest admission record is this old when the next one is asked for (or |
| +// when its result arrives) has had its VM's tunnels closed in between: it |
| +// fails hosted_unavailable, latched by its move to stopping, and no later |
| +// record revives it. |
| +const HostedFeedLost = 5 * time.Minute |
| + |
| // hostedStopUncertified is why a hosted job stops when its runner's |
| // checks result could not be certified: the job ends failed, and its |
| // step is placed again once (placeHosted's rule 2). |
| @@ -59,7 +67,7 @@ func (t *txn) hostedCertified(runnerID, stepID string, stepAttempt int64, now ti |
| } |
| // hostedUncertified stops j, whose runner's checks result could not be |
| -// certified. The runner is not tainted (it may have run them in its |
| +// certified: hosted_unavailable when its feed was lost (feedLost). The runner is not tainted (it may have run them in its |
| // sandbox; nothing certifies that it did) and the result is not kept: |
| // once the VM is proven stopped the step is placed again under the same |
| // attempt (hostedStepAgain), once. |
| @@ -67,9 +75,19 @@ func (t *txn) hostedUncertified(j HostedJob) error { |
| if !j.Live() || j.State == HostedJobStopping { |
| return nil |
| } |
| + if feedLost(j, t.now()) { |
| + return t.hostedStopping(j.AttemptID, wire.ReasonHostedUnavailable) |
| + } |
| return t.hostedStopping(j.AttemptID, hostedStopUncertified) |
| } |
| +// feedLost reports whether enrolled job j's latest admission record was |
| +// HostedFeedLost old or more at at: the proxies' feed has expired since, |
| +// and its VM's tunnels with it. |
| +func feedLost(j HostedJob, at time.Time) bool { |
| + return j.State == HostedJobEnrolled && j.CertCheckedAt != nil && !at.Before(j.CertCheckedAt.Add(HostedFeedLost)) |
| +} |
| + |
| // hostedSettleCancel takes only the termination of an uncertified hosted |
| // runner's terminal report while its task is being cancelled or has |
| // ended: with termination proof the step ends cancelled, terminated, with |
diff --git a/internal/equipo/chat/hosted_run.go b/internal/equipo/chat/hosted_run.go| index b0ba85c8..aa526971 100644 |
| --- a/internal/equipo/chat/hosted_run.go |
| +++ b/internal/equipo/chat/hosted_run.go |
| @@ -356,12 +356,18 @@ func (s *Store) HostedAdmitted(ctx context.Context, attempt string, a hostedwire |
| // hostedAdmitted records a for the live job j (HostedAdmitted) and |
| // reports whether it is valid for j, and whether it was recorded: a |
| // record older than the one held (a newer refusal among them) is |
| -// ignored, and accepted is false. |
| +// ignored, and accepted is false. An enrolled job whose feed was lost |
| +// (feedLost) takes no record: it fails hosted_unavailable instead. |
| func (t *txn) hostedAdmitted(j HostedJob, a hostedwire.AdmissionView, at time.Time) (valid, accepted bool, err error) { |
| attempt := j.AttemptID |
| if a.AttemptID != attempt || !j.Live() || j.VMRef == "" || at.IsZero() { |
| return false, false, fmt.Errorf("%w: admission for %s", ErrHostedTransition, attempt) |
| } |
| + if feedLost(j, at) { |
| + // The VM lost its tunnels while no record was taken: this one is |
| + // not, and the job fails before anything can be certified by it. |
| + return false, false, t.hostedStopping(attempt, wire.ReasonHostedUnavailable) |
| + } |
| if a.LaunchID == j.LaunchID && string(a.VMRef) == j.VMRef { |
| // The job's current deadline, whatever the record's age: the |
| // earliest is kept. |
diff --git a/internal/equipo/hosted_enrol_test.go b/internal/equipo/hosted_enrol_test.go| index 6f4a3fed..0da64d89 100644 |
| --- a/internal/equipo/hosted_enrol_test.go |
| +++ b/internal/equipo/hosted_enrol_test.go |
| @@ -178,6 +178,25 @@ func (r *hostedRig) vm(t *testing.T, n int, opts ...hostedJobOpts) *hostedRig { |
| } |
| // setView changes the controller's admission record for the rig's job. |
| +// pass advances the clock by d a minute at a time, recording each of vms' |
| +// admission records at every step as the dispatcher's refresh does: a |
| +// record chat.HostedFeedLost old loses its job (decision S2-3). |
| +func (r *hostedRig) pass(t *testing.T, d time.Duration, vms ...*hostedRig) { |
| + t.Helper() |
| + for left := d; left > 0; left -= time.Minute { |
| + r.clock.Advance(min(time.Minute, left)) |
| + for _, v := range vms { |
| + a, err := v.adm.Admission(context.Background(), v.job.AttemptID) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := r.s.Chat().HostedAdmitted(context.Background(), v.job.AttemptID, a, r.clock.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + } |
| +} |
| + |
| func (r *hostedRig) setView(fn func(*hostedwire.AdmissionView)) { |
| r.adm.mu.Lock() |
| defer r.adm.mu.Unlock() |
| @@ -584,7 +603,7 @@ func TestRenewThroughFullMiddleware(t *testing.T) { |
| if w := r.post("/api/runner/v2/hosted/challenge", "{}", tok, ""); w.Code != http.StatusUnprocessableEntity { |
| t.Fatalf("a challenge with a body: %d %s, want 422", w.Code, w.Body) |
| } |
| - r.clock.Advance(30 * time.Minute) |
| + r.pass(t, 30*time.Minute, r) |
| refused(t, "a challenge past its minute", r.post("/api/runner/v2/hosted/renew", r.renewBody(out.Credential.RunnerID, r.job.Epoch, ch.Nonce), tok, "")) |
| next := r.renew(t, out.Credential) |
| r.wantCredential(t, next, r.clock.Now().Add(time.Hour)) |
| @@ -709,7 +728,7 @@ func TestHostedCredentialCappedAtDeadline(t *testing.T) { |
| ctlOut := ctl.enrol(t) |
| ctl.wantCredential(t, ctlOut, ctlDeadline) |
| - r.clock.Advance(20 * time.Minute) |
| + r.pass(t, 20*time.Minute, r, ctl) |
| r.wantCredential(t, r.renew(t, out.Credential), deadline) |
| ctl.wantCredential(t, ctl.renew(t, ctlOut.Credential), ctlDeadline) |
| @@ -739,7 +758,7 @@ func TestHostedCredentialCappedAtDeadline(t *testing.T) { |
| t.Fatalf("kept deadline %v after the refreshes, want %v", j.Deadline, hostedNow.Add(25*time.Minute)) |
| } |
| ch := r.challenge(t, out.Credential.Token) |
| - r.clock.Advance(10 * time.Minute) |
| + r.pass(t, 10*time.Minute, r) |
| refused(t, "a renewal at the deadline", r.post("/api/runner/v2/hosted/renew", r.renewBody(out.Credential.RunnerID, r.job.Epoch, ch.Nonce), out.Credential.Token, "")) |
| } |
diff --git a/internal/equipo/hostedrun/controller_test.go b/internal/equipo/hostedrun/controller_test.go| index 76d755bb..5245cdd3 100644 |
| --- a/internal/equipo/hostedrun/controller_test.go |
| +++ b/internal/equipo/hostedrun/controller_test.go |
| @@ -200,3 +200,26 @@ func TestControllerLostFailsEnrolledJob(t *testing.T) { |
| t.Fatalf("the feed expired and the job is %s %q", got.State, got.StopReason) |
| } |
| } |
| + |
| +// TestControllerBackAfterFeedLost: the controller comes back after the |
| +// feed expired, before any pass saw it fail; the first refresh succeeds, |
| +// and still the job fails hosted_unavailable, and stays failed. |
| +func TestControllerBackAfterFeedLost(t *testing.T) { |
| + r := newRig(t, nil) |
| + j := r.enrolling() |
| + if !r.enrol(j.AttemptID, "H1") { |
| + t.Fatal("the VM did not enrol") |
| + } |
| + r.passes(Every) |
| + checked := r.job(j.AttemptID).CertCheckedAt |
| + r.now = checked.Add(FeedLost) |
| + r.online(primary) |
| + r.pass() |
| + if got := r.job(j.AttemptID); got.State != chat.HostedJobStopping || got.StopReason != wire.ReasonHostedUnavailable { |
| + t.Fatalf("the controller came back after the feed expired and the job is %s %q", got.State, got.StopReason) |
| + } |
| + r.passes(3 * Every) |
| + if got := r.job(j.AttemptID); got.State == chat.HostedJobEnrolled { |
| + t.Fatalf("a later record revived the job: %s", got.State) |
| + } |
| +} |
diff --git a/internal/equipo/hostedrun/dispatcher.go b/internal/equipo/hostedrun/dispatcher.go| index ba5b876c..a6fefc7a 100644 |
| --- a/internal/equipo/hostedrun/dispatcher.go |
| +++ b/internal/equipo/hostedrun/dispatcher.go |
| @@ -48,10 +48,11 @@ type Controller interface { |
| const Every = 10 * time.Second |
| // FeedLost is how long the proxies act on the controller's last feed |
| -// (ctlproxy.FeedLifetime, decision S2-3). An enrolled job whose latest |
| +// (chat.HostedFeedLost, decision S2-3). An enrolled job whose latest |
| // admission record is this old, the controller unreachable since, has |
| -// had its VM's tunnels closed: it fails hosted_unavailable. |
| -const FeedLost = 5 * time.Minute |
| +// had its VM's tunnels closed: it fails hosted_unavailable, here when the |
| +// refresh fails, in the store when the next record is taken. |
| +const FeedLost = chat.HostedFeedLost |
| // A launch the controller did not take, or an intent it has not yet |
| // given a VM (a throttle), is tried again after a wait that doubles from |
diff --git a/internal/hostedtest/chain.go b/internal/hostedtest/chain.go| index 0aea7c84..aedc06a0 100644 |
| --- a/internal/hostedtest/chain.go |
| +++ b/internal/hostedtest/chain.go |
| @@ -225,8 +225,9 @@ type Chain struct { |
| // The base and candidate commits of the repository's change. |
| Base, Candidate string |
| - loopMu sync.Mutex // held by each harness loop pass |
| - paused bool |
| + loopMu sync.Mutex // held by each harness loop pass |
| + paused bool |
| + releasing bool // ReleaseGates: each pass releases started gates |
| } |
| // Proxy is one egress proxy of the chain. |
| @@ -387,6 +388,11 @@ func (ch *Chain) loop() { |
| case <-tick.C: |
| } |
| ch.loopMu.Lock() |
| + if ch.releasing { |
| + for _, vm := range ch.Prov.VMs() { |
| + vm.release() |
| + } |
| + } |
| if !ch.paused { |
| ch.Prov.Tick() |
| for _, p := range ch.Proxies { |
| @@ -648,11 +654,49 @@ func (vm *VM) Run() (int, string) { |
| // RunnerPID is the VM's runner's pid while it runs. |
| func (vm *VM) RunnerPID() int { return vm.hooks.RunnerPID() } |
| -// Gating reports whether a checks gate has started in the VM: its |
| -// runner's containment manager has recorded a namespace. |
| -func (vm *VM) Gating() bool { |
| - entries, _ := os.ReadDir(filepath.Join(vm.Dir, "s", "ns")) |
| - return len(entries) > 0 |
| +// The start marker the fixture gate writes in its workspace from inside |
| +// the running sandbox, and the release file its barrier waits for. |
| +const ( |
| + GateStarted = ".gate-started" |
| + GateRelease = ".gate-release" |
| +) |
| + |
| +// trees are the checked trees of the VM's attempts (thin's worker-steps, |
| +// under the hosted runner's scratch root). |
| +func (vm *VM) trees() []string { |
| + trees, _ := filepath.Glob(filepath.Join(vm.Dir, "s", "scratch", "worker-steps", "*", "tree")) |
| + return trees |
| +} |
| + |
| +// GateStarted reports whether a gate has started in the VM's sandbox: an |
| +// attempt's tree holds its start marker. |
| +func (vm *VM) GateStarted() bool { |
| + for _, tree := range vm.trees() { |
| + if _, err := os.Stat(filepath.Join(tree, GateStarted)); err == nil { |
| + return true |
| + } |
| + } |
| + return false |
| +} |
| + |
| +// release lets every started gate in the VM go on past its barrier. |
| +func (vm *VM) release() { |
| + for _, tree := range vm.trees() { |
| + if _, err := os.Stat(filepath.Join(tree, GateStarted)); err == nil { |
| + _ = os.WriteFile(filepath.Join(tree, GateRelease), nil, 0o644) |
| + } |
| + } |
| +} |
| + |
| +// ReleaseGates lets every gate go on past its barrier, now and, through |
| +// the harness's loop, from now on. |
| +func (ch *Chain) ReleaseGates() { |
| + ch.loopMu.Lock() |
| + ch.releasing = true |
| + ch.loopMu.Unlock() |
| + for _, vm := range ch.Prov.VMs() { |
| + vm.release() |
| + } |
| } |
| // Log is everything the VM's root init and runner wrote. |
diff --git a/internal/hostedtest/chain_test.go b/internal/hostedtest/chain_test.go| index ff53dffd..08711971 100644 |
| --- a/internal/hostedtest/chain_test.go |
| +++ b/internal/hostedtest/chain_test.go |
| @@ -7,6 +7,7 @@ import ( |
| "encoding/json" |
| "fmt" |
| "io" |
| + "math" |
| "os" |
| "path/filepath" |
| "slices" |
| @@ -59,11 +60,15 @@ const contract = `{"version":1,"files":["budgets.txt"]}` |
| var dep = depsbundle.Module{Path: "example.com/m", Version: "v1.0.0"} |
| // gate is make ci: the module staged read-only from the bundle, the |
| -// candidate's budget, then sleep.txt's seconds (a drill's window). |
| +// candidate's budget, then, from inside the running sandbox, the start |
| +// marker (GateStarted) and a bounded barrier: it waits for the release |
| +// file (Chain.ReleaseGates) for at most sleep.txt's seconds (a drill's |
| +// window; 0 for no wait). |
| const gate = "ci:\n" + |
| "\t@test -f /opt/go-mod/example.com/m@v1.0.0/m.go && echo staged\n" + |
| "\t@test \"$$(cat size.txt)\" -le \"$$(cat budgets.txt)\" || { echo over budget; exit 3; }\n" + |
| - "\t@sleep \"$$(cat sleep.txt)\"\n" + |
| + "\t@touch " + GateStarted + "\n" + |
| + "\t@n=$$(( $$(cat sleep.txt) * 10 )); while [ $$n -gt 0 ] && [ ! -f " + GateRelease + " ]; do sleep 0.1; n=$$((n - 1)); done\n" + |
| "\t@echo gate done\n" |
| // moduleFixture puts dep in cache as the go command keeps it and returns |
| @@ -146,13 +151,53 @@ func (ch *Chain) ended(id string, d time.Duration) (Step, []chat.HostedJob) { |
| return ch.Step(id), ch.Jobs(id) |
| } |
| -// proven fails unless j ended with the controller's stop proof and its |
| -// usage settled. |
| -func proven(t *testing.T, j chat.HostedJob) { |
| +// proven fails unless j ended with the controller's stop proof for its |
| +// own attempt and VM, the controller's own record shows that launch's VM |
| +// stopped, the provider shows the VM stopped, the job's runner is |
| +// revoked, and its usage settled: at least a second and a cent's |
| +// fraction, no more than its hold, in every day and month charged. |
| +func (ch *Chain) proven(j chat.HostedJob) { |
| + t := ch.t |
| t.Helper() |
| var p chat.HostedEndProof |
| - if j.StopProofJSON == "" || json.Unmarshal([]byte(j.StopProofJSON), &p) != nil || j.SettledAt == nil { |
| - t.Fatalf("job %s ended %s without proof or settlement: proof %q settled %v", j.AttemptID, j.State, j.StopProofJSON, j.SettledAt) |
| + if err := json.Unmarshal([]byte(j.StopProofJSON), &p); err != nil || p.Stop == nil || j.VMRef == "" || j.LaunchID == "" || |
| + p.Stop.AttemptID != j.AttemptID || string(p.Stop.VMRef) != j.VMRef || p.Stop.State != isolatedjob.StateStopped { |
| + t.Fatalf("job %s (launch %s, VM %s) ended %s without its stop proof: %q", j.AttemptID, j.LaunchID, j.VMRef, j.State, j.StopProofJSON) |
| + } |
| + if c := ch.Controller(); c != nil { |
| + v, err := c.Get(t.Context(), instanceKey, j.AttemptID) |
| + if err != nil || v.LaunchID != j.LaunchID || string(v.VMRef) != j.VMRef || v.State != "stopped" { |
| + t.Fatalf("the controller's record of %s: %+v %v, want launch %s VM %s stopped", j.AttemptID, v, err, j.LaunchID, j.VMRef) |
| + } |
| + } |
| + if vm, err := ch.Fake.Get(t.Context(), isolatedjob.Ref(j.VMRef)); err != nil || vm.State != isolatedjob.StateStopped { |
| + t.Fatalf("the provider's VM %s: %+v %v, want stopped", j.VMRef, vm, err) |
| + } |
| + if j.RunnerID != "" { |
| + var revoked bool |
| + if err := ch.Inst.DB.Writer().QueryRow("SELECT revoked_at IS NOT NULL FROM runners WHERE id = ?", j.RunnerID).Scan(&revoked); err != nil || !revoked { |
| + t.Fatalf("job %s's runner %s is not revoked: %v", j.AttemptID, j.RunnerID, err) |
| + } |
| + } |
| + used, uerr := j.Used() |
| + hold, herr := j.Hold() |
| + if j.SettledAt == nil || uerr != nil || herr != nil || len(used.Seconds) == 0 || len(used.Micros) == 0 { |
| + t.Fatalf("job %s settled %v with usage %+v (%v), hold %+v (%v)", j.AttemptID, j.SettledAt, used, uerr, hold, herr) |
| + } |
| + var seconds int64 |
| + for day, n := range used.Seconds { |
| + seconds += n |
| + if n <= 0 || n > hold.Seconds[day] { |
| + t.Fatalf("job %s used %d s on %s, held %d", j.AttemptID, n, day, hold.Seconds[day]) |
| + } |
| + } |
| + for month, n := range used.Micros { |
| + if n <= 0 || n > hold.Micros[month] { |
| + t.Fatalf("job %s used %d micros in %s, held %d", j.AttemptID, n, month, hold.Micros[month]) |
| + } |
| + } |
| + if j.AdmittedAt == nil || j.EndedAt == nil || seconds > int64(math.Ceil(j.EndedAt.Sub(*j.AdmittedAt).Seconds()))+1 { |
| + t.Fatalf("job %s used %d s between admission %v and end %v", j.AttemptID, seconds, j.AdmittedAt, j.EndedAt) |
| } |
| } |
| @@ -179,7 +224,7 @@ func TestChainHostedCheckPasses(t *testing.T) { |
| if len(jobs) != 1 || jobs[0].State != chat.HostedJobEnded { |
| t.Fatalf("jobs %+v", jobs) |
| } |
| - proven(t, jobs[0]) |
| + ch.proven(jobs[0]) |
| } |
| // TestChainFailingCheck: a candidate over its budget fails the base's |
| @@ -198,7 +243,7 @@ func TestChainFailingCheck(t *testing.T) { |
| if len(jobs) != 1 || jobs[0].State != chat.HostedJobEnded { |
| t.Fatalf("jobs %+v", jobs) |
| } |
| - proven(t, jobs[0]) |
| + ch.proven(jobs[0]) |
| } |
| // TestChainNewModule: a candidate that pins a module the base does not |
| @@ -230,25 +275,31 @@ func TestChainNewModule(t *testing.T) { |
| if len(jobs) != 1 || jobs[0].State != chat.HostedJobEnded { |
| t.Fatalf("jobs %+v", jobs) |
| } |
| - proven(t, jobs[0]) |
| + ch.proven(jobs[0]) |
| } |
| -// slow is a candidate whose gate sleeps long enough for a drill. |
| -var slow = map[string]string{"NEWS": "news\n", "sleep.txt": "8\n"} |
| +// slow is a candidate whose gate waits at its barrier for up to 60 s: |
| +// long enough for a drill to strike while it runs. |
| +var slow = map[string]string{"NEWS": "news\n", "sleep.txt": "60\n"} |
| -// midStep waits until the step's checks run in its first VM (a |
| -// namespace recorded there) and returns that VM. |
| +// midStep waits, bounded, until the step's gate has started inside the |
| +// sandbox of its first VM (its start marker) and is still held at its |
| +// barrier, and returns that VM. From then on the harness releases every |
| +// gate it sees started: a drill strikes first. |
| func (ch *Chain) midStep(id string) *VM { |
| ch.t.Helper() |
| var vm *VM |
| - ch.Until(2*time.Minute, "the checks running in the VM", func() bool { |
| + ch.Until(90*time.Second, "the gate started in the VM's sandbox", func() bool { |
| vms := ch.Prov.VMs() |
| - if len(vms) == 0 || ch.Step(id).State != wire.StepRunning { |
| + if len(vms) == 0 { |
| return false |
| } |
| vm = vms[0] |
| - return vm.Gating() |
| + return vm.GateStarted() && vm.RunnerPID() > 0 |
| }) |
| + if s := ch.Step(id); s.State != wire.StepRunning { |
| + ch.t.Fatalf("the gate started and the step is %s", s.State) |
| + } |
| return vm |
| } |
| @@ -272,6 +323,7 @@ func TestChainKillProxyMidStep(t *testing.T) { |
| t.Fatalf("the VM reached the instance through the second proxy first:\n%s", ch.Proxies[1].Log.String()) |
| } |
| ch.Proxies[0].Kill() |
| + ch.ReleaseGates() |
| // A tunnel's line is written when it closes: the link's, now. |
| if !strings.Contains(ch.Proxies[0].Log.String(), `"status":101`) { |
| t.Fatalf("the killed proxy carried no link:\n%s", ch.Proxies[0].Log.String()) |
| @@ -281,20 +333,24 @@ func TestChainKillProxyMidStep(t *testing.T) { |
| if len(jobs) != 1 || jobs[0].State != chat.HostedJobEnded { |
| t.Fatalf("jobs %+v", jobs) |
| } |
| - proven(t, jobs[0]) |
| + ch.proven(jobs[0]) |
| // The VM stopped, its link through the second proxy closed. |
| ch.Until(30*time.Second, "the link through the other proxy", func() bool { return strings.Contains(ch.Proxies[1].Log.String(), `"status":101`) }) |
| } |
| // TestChainKillControllerMidStep: the controller dies mid-step. With no |
| // fresh feed the proxies close the VM's open sockets at the feed's |
| -// expiry and let nothing through; the step fails hosted_unavailable, |
| -// and once the controller is back the VM is stopped with proof and the |
| -// step retried once, on a new VM, where it passes. |
| +// expiry and let nothing through. The controller comes back before the |
| +// dispatcher has seen it gone (its passes held through the outage); its |
| +// first fresh admission record is not taken: the job fails |
| +// hosted_unavailable however the VM's reconnection, renewal or result |
| +// races it, the VM is stopped with proof and the step retried once, on a |
| +// new VM, where it passes. |
| func TestChainKillControllerMidStep(t *testing.T) { |
| ch := start(t, slow) |
| ch.AddChecks("s1", "tk1") |
| - ch.midStep("s1") |
| + first := ch.midStep("s1") |
| + resume := ch.Pause() |
| ch.KillController() |
| // The feed's lifetime passes, for the proxies and the instance alike. |
| ch.ProxyClock.Forward(hostedrun.FeedLost + time.Second) |
| @@ -307,23 +363,20 @@ func TestChainKillControllerMidStep(t *testing.T) { |
| } |
| return false |
| }) |
| - ch.Until(30*time.Second, "the job failing hosted_unavailable", func() bool { |
| - j := ch.Jobs("s1")[0] |
| - return j.State == chat.HostedJobStopping && j.StopReason == wire.ReasonHostedUnavailable |
| - }) |
| - // No proof without the controller: the step waits for it. |
| - time.Sleep(2 * time.Second) |
| - if jobs := ch.Jobs("s1"); len(jobs) != 1 || jobs[0].State != chat.HostedJobStopping { |
| - t.Fatalf("the job ended, or another began, with the controller down: %+v", jobs) |
| + if j := ch.Jobs("s1")[0]; j.State != chat.HostedJobEnrolled { |
| + t.Fatalf("the dispatcher saw the outage: %s %q", j.State, j.StopReason) |
| } |
| ch.StartController() |
| + ch.ReleaseGates() |
| + resume() |
| s, jobs := ch.ended("s1", 4*time.Minute) |
| passed(t, ch, s) |
| - if len(jobs) != 2 || jobs[0].State != chat.HostedJobFailed || jobs[0].StopReason != wire.ReasonHostedUnavailable || jobs[1].State != chat.HostedJobEnded || jobs[1].RetryOf != jobs[0].AttemptID { |
| + if len(jobs) != 2 || jobs[0].State != chat.HostedJobFailed || jobs[0].StopReason != wire.ReasonHostedUnavailable || jobs[0].VMRef != string(first.Ref) || |
| + jobs[1].State != chat.HostedJobEnded || jobs[1].RetryOf != jobs[0].AttemptID { |
| t.Fatalf("jobs %+v", jobs) |
| } |
| - proven(t, jobs[0]) |
| - proven(t, jobs[1]) |
| + ch.proven(jobs[0]) |
| + ch.proven(jobs[1]) |
| } |
| // TestChainStopVMMidStep: the provider stops the VM mid-step; the |
| @@ -336,13 +389,14 @@ func TestChainStopVMMidStep(t *testing.T) { |
| if err := ch.Prov.Stop(t.Context(), vm.Ref, "provider stopped it"); err != nil { |
| t.Fatal(err) |
| } |
| + ch.ReleaseGates() |
| s, jobs := ch.ended("s1", 2*time.Minute) |
| passed(t, ch, s) |
| if len(jobs) != 2 || jobs[0].State != chat.HostedJobFailed || jobs[0].StopReason != wire.ReasonHostedVMLost || jobs[1].State != chat.HostedJobEnded || jobs[1].RetryOf != jobs[0].AttemptID { |
| t.Fatalf("jobs %+v", jobs) |
| } |
| - proven(t, jobs[0]) |
| - proven(t, jobs[1]) |
| + ch.proven(jobs[0]) |
| + ch.proven(jobs[1]) |
| } |
| // TestChainOrphanVM: a VM no launch asked for runs on the provider; past |
| @@ -376,12 +430,16 @@ func TestChainCertWithdrawnMidStep(t *testing.T) { |
| if _, err := ch.Certs.Replace(ctlcerttest.Keys(), nil); err != nil { |
| t.Fatal(err) |
| } |
| + // The gate is held until the instance has the controller's word that |
| + // the certificate is gone: its result arrives after that record. |
| + ch.Until(30*time.Second, "the withdrawal recorded", func() bool { return !ch.Jobs("s1")[0].CertValid }) |
| + ch.ReleaseGates() |
| ch.Until(4*time.Minute, "the first job ended", func() bool { return !ch.Jobs("s1")[0].Live() }) |
| jobs := ch.Jobs("s1") |
| if jobs[0].State != chat.HostedJobFailed || jobs[0].StopReason != "uncertified" { |
| t.Fatalf("jobs %+v", jobs) |
| } |
| - proven(t, jobs[0]) |
| + ch.proven(jobs[0]) |
| if s := ch.Step("s1"); s.Checks == wire.ChecksPassed || s.ChecksSandbox != "" || s.BaseChecksSHA != "" { |
| t.Fatalf("an uncertified result was kept: %+v", s) |
| } |