oficina / equipo Public

equipo: Task 21 review 2, guard HostedReplaces on invalid evidence

TestHostedReplacesNeedsProof: a retry's predecessor whose never-launched
evidence parses but does not hold is refused, valid evidence names none,
stop proof names it. Mutation 316 recorded.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev c9144cd614d8692b56700c3258bea605f512700c parent b58bdd9
3 files changed, +50 −2
  • .rastrillo/budgets.txt +1 −1
  • docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md +15 −1
  • internal/equipo/chat/hosted_place_test.go +34 −0
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt
index 2850b570..8753c704 100644
--- a/.rastrillo/budgets.txt
+++ b/.rastrillo/budgets.txt
@@ -60,7 +60,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 46709 20937 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.
+size internal/equipo/chat 46709 20971 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.
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 0972396d..e8f8b001 100644
--- a/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md
+++ b/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md
@@ -1677,4 +1677,18 @@ Mutations (same method, a script under `mktemp -d`; each file restored from a co
- **314** `hj_` attempt IDs. `-run TestDispatcherLostLaunchReply`: exit 1, `controller_test.go:96: the lost launch made no VM: map[]; ... controller answered 400 "invalid"`. Restored.
- **315** a retry never names its stop-proven predecessor (`if false && p.Stop != nil`). `-run TestEnrolTimeoutRetriesOnce`: exit 1, `dispatcher_test.go:630: retry launches [... Replaces: ...], want one for hj-... replacing hj-...`. Restored.
-Not mutation-checked: `HostedReplaces`'s error for a predecessor with no proof. `newHostedJob` already refuses such a retry, so no path reaches it.
+`HostedReplaces`'s error for a predecessor with no proof that holds is reached by no normal path, since `newHostedJob` refuses such a retry; it is now guarded directly (review round 2, below).
+
+### Task 21 review round 2 (t21-r2.md: round 1 all addressed; one Minor)
+
+`TestHostedReplacesNeedsProof` (chat, matched by the brief's regex) builds the retry and its predecessor rows directly. Three cases:
+- The predecessor's evidence parses but does not hold (an abandoned intent read at launch-by + 2m): `ErrHostedNoProof` and no name.
+- Its evidence holds (absent): no name and no error.
+- It holds stop proof: the predecessor is named.
+
+It passed at once, as a guard test.
+
+Mutation:
+- **316** the proof check removed from `HostedReplaces` (the `prior.provenErr()` block deleted). `CGO_ENABLED=0 go test ./internal/equipo/chat -run TestHostedReplacesNeedsProof -count=1`: exit 1, `hosted_place_test.go:653: predecessor with evidence that does not hold: "" <nil>, want ErrHostedNoProof`. Restored from a copy; `cmp` identical.
+
+Green: the brief's command passes, as does the whole chat package. `make migration-check budget build vet` exits 0.
diff --git a/internal/equipo/chat/hosted_place_test.go b/internal/equipo/chat/hosted_place_test.go
index d41c4f0a..6a864ee6 100644
--- a/internal/equipo/chat/hosted_place_test.go
+++ b/internal/equipo/chat/hosted_place_test.go
@@ -627,3 +627,37 @@ func TestHostedLaunchedWhileStopping(t *testing.T) {
t.Fatalf("after its VM's proof: %s", j.State)
}
}
+
+// TestHostedReplacesNeedsProof: a retry's launch names its predecessor
+// when that one ended with stop proof, names none when it ended with
+// never-launched evidence that holds, and is refused when its evidence
+// parses but does not hold (an abandoned intent read at launch-by + 2m),
+// rather than launched without naming the attempt it replaces.
+func TestHostedReplacesNeedsProof(t *testing.T) {
+ r := hostedPlaceRig(t)
+ r.checksStep("s1", "tkp")
+ first := r.jobsOf("s1")[0]
+ by := first.AdmittedAt.Add(HostedLaunchWindow)
+ end := func(p HostedEndProof) {
+ t.Helper()
+ raw, err := json.Marshal(p)
+ r.must(err)
+ r.exec("UPDATE hosted_jobs SET state = ?, launch_by = ?, stop_proof_json = ?, ended_at = ? WHERE attempt_id = ?", HostedJobFailed, by, string(raw), p.ObservedAt, first.AttemptID)
+ }
+ r.exec("INSERT INTO hosted_jobs(attempt_id, step_id, step_attempt, person, state, retry_of, retries, revision) VALUES ('hj-retry', 'other', 1, ?, ?, ?, 1, 1)", hkOwner, HostedJobPending, first.AttemptID)
+ evidence := func(state string, at time.Time) HostedEndProof {
+ return HostedEndProof{NeverLaunched: &HostedNeverLaunched{AttemptID: first.AttemptID, ObservedAt: at, LaunchBy: by, ControllerState: state, Signed: true}, ObservedAt: at}
+ }
+ end(evidence(HostedControllerAbandoned, by.Add(HostedNeverLaunchedAfter)))
+ if got, err := r.s.HostedReplaces(r.ctx, "hj-retry"); !errors.Is(err, ErrHostedNoProof) || got != "" {
+ t.Fatalf("predecessor with evidence that does not hold: %q %v, want ErrHostedNoProof", got, err)
+ }
+ end(evidence(HostedControllerAbsent, by.Add(HostedNeverLaunchedAfter)))
+ if got, err := r.s.HostedReplaces(r.ctx, "hj-retry"); err != nil || got != "" {
+ t.Fatalf("predecessor never launched: %q %v, want none named", got, err)
+ }
+ end(HostedEndProof{Stop: &hostedwire.StopProof{AttemptID: first.AttemptID, State: isolatedjob.StateStopped}, ObservedAt: by})
+ if got, err := r.s.HostedReplaces(r.ctx, "hj-retry"); err != nil || got != first.AttemptID {
+ t.Fatalf("predecessor with stop proof: %q %v, want %s", got, err, first.AttemptID)
+ }
+}