awsjob: a Get without a MicroVM ID is an error
Ruling R38 (code review round 3). Get used to substitute the asked-for ref when the reply's microvmId was empty or absent, so a malformed reply naming no VM could still become stop proof. It now validates the reply's ID unconditionally; missing or malformed is a fixed error. TestMalformedIDsRefused adds empty and nil IDs; TestGetWithoutRefNeverProof shows a terminal Get naming no VM yields no proof in the controller. The hostedctl budget record moves to 8516 test lines.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+64
−7
.rastrillo/budgets.txt+1 −1docs/superpowers/plans/HOSTED-SLICE1-PROGRESS.md+17 −0internal/hostedctl/logs_test.go+27 −0internal/isolatedjob/awsjob/ids_test.go+13 −0internal/isolatedjob/awsjob/runner.go+6 −6
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt| index c5808990..68200169 100644 |
| --- a/.rastrillo/budgets.txt |
| +++ b/.rastrillo/budgets.txt |
| @@ -76,4 +76,4 @@ size internal/thintest - 33399 Fable follow-up gates, preview isolation and prov |
| perf GET /api/v1/projects/{id}/merge-policy skip Merge authority person API: bearer-only JSON for devices; the browser reads the policy on /projects/{id}. |
| perf GET /api/v1/usage skip Thin v1 person API: bearer-only JSON for devices; the browser reads usage through /usage. |
| perf GET /api/v1/advice skip Thin v1 person API: bearer-only JSON for devices; the browser reads advice through /usage and /conversation. |
| -size internal/hostedctl 5313 8489 Hosted controller core plus its lifecycle simulation; split planned for slice 1b; measured 5313/8489 source/test lines after the Task 17 pre-flight review rounds (R36 ref checks). |
| +size internal/hostedctl 5313 8516 Hosted controller core plus its lifecycle simulation; split planned for slice 1b; measured 5313/8516 source/test lines after the Task 17 pre-flight review rounds (R36, R38 ref checks). |
diff --git a/docs/superpowers/plans/HOSTED-SLICE1-PROGRESS.md b/docs/superpowers/plans/HOSTED-SLICE1-PROGRESS.md| index 3ca5230d..0400a980 100644 |
| --- a/docs/superpowers/plans/HOSTED-SLICE1-PROGRESS.md |
| +++ b/docs/superpowers/plans/HOSTED-SLICE1-PROGRESS.md |
| @@ -1172,3 +1172,20 @@ Offline preparation for the live check; no AWS call was made. The live pieces co |
| | awsjob checks only for an empty ID again (no validation) | `go test ./internal/isolatedjob/awsjob -run TestMalformedIDsRefused -count=1` | `ids_test.go:36: Launch with id "vm-1 SENTINEL-secret=hunter2" = ("vm-1 SENTINEL-secret=hunter2", <nil>), want an error and no ref` (and the Get and List rows) | yes, passes | |
| | hostedctl boundary checks only for an empty Ref | `go test ./internal/hostedctl -run TestMalformedRefsNeverStoredOrLogged -count=1` | `logs_test.go:94: Launch answered with a malformed ref = nil error, want a provider failure` | yes, passes | |
| | `seen_before_restart` back to `now-firstSeen < OrphanGrace` | `go test ./internal/hostedctl -run TestControllerLogs -count=1` | `logs_test.go:160: no log line holds [... "seen_before_restart=true"]` | yes, passes | |
| + |
| +### R38 (code review round 3): a Get without a MicroVM ID is an error |
| + |
| +- `awsjob.Runner.Get` used to substitute the asked-for ref when the reply's `microvmId` was empty or |
| + absent. It now always validates the reply's ID; missing or malformed is a fixed error. Run and |
| + List already required a valid ID; no other reply ID is optional. |
| +- `TestMalformedIDsRefused` adds Get replies with an empty and a nil ID (state TERMINATED). |
| + `TestGetWithoutRefNeverProof` (hostedctl): a Get that answers stopped but names no VM yields no |
| + proof through Stop, Refresh or a reaper pass. |
| +- Budget: hostedctl test lines record moved to 8516. |
| +- Runs: awsjob and isolatedjob ok; hostedctl ok (6.8 s); tagged vets; `make build vet`; |
| + `make budget`; the Task 7 guard. |
| + |
| +| Mutation | Command | Observed failure | Restored | |
| +| --- | --- | --- | --- | |
| +| Get substitutes the asked-for ref for an empty ID again | `go test ./internal/isolatedjob/awsjob -run TestMalformedIDsRefused -count=1` | `ids_test.go:73: Get answered with a nil id = ({Ref:vm-1 State:stopped ...}, <nil>), want an error and no job` (and the empty row) | yes, passes | |
| +| hostedctl boundary skips the Get check | `go test ./internal/hostedctl -run TestGetWithoutRefNeverProof -count=1` | `logs_test.go:147: Stop with a Get naming no VM = proof {AttemptID:att-1 VMRef:vm-0001 State:stopped ObservedAt:0}, want none` | yes, passes | |
diff --git a/internal/hostedctl/logs_test.go b/internal/hostedctl/logs_test.go| index cb8cff5a..cb59ff46 100644 |
| --- a/internal/hostedctl/logs_test.go |
| +++ b/internal/hostedctl/logs_test.go |
| @@ -51,6 +51,7 @@ func (e *launchEnv) wantLog(parts ...string) { |
| type badRefs struct { |
| *isolatedjob.Fake |
| launch, get, list bool |
| + emptyGet bool // Get answers stopped with no Ref (R38) |
| } |
| const badRef = isolatedjob.Ref("vm-1 SENTINEL-secret=hunter2") |
| @@ -68,6 +69,9 @@ func (b *badRefs) Get(ctx context.Context, ref isolatedjob.Ref) (isolatedjob.Job |
| if b.get && err == nil { |
| j.Ref = badRef |
| } |
| + if b.emptyGet && err == nil { |
| + j = isolatedjob.Job{State: isolatedjob.StateStopped} // terminal, naming no VM |
| + } |
| return j, err |
| } |
| @@ -126,6 +130,29 @@ func TestMalformedRefsNeverStoredOrLogged(t *testing.T) { |
| } |
| } |
| +// TestGetWithoutRefNeverProof (ruling R38): a Get that reports a terminal |
| +// state but names no VM is refused, so no stop, refresh or reaper pass |
| +// takes it as stop proof. |
| +func TestGetWithoutRefNeverProof(t *testing.T) { |
| + t.Parallel() |
| + e := newLaunchEnv(t) |
| + bad := &badRefs{Fake: e.fake} |
| + e.run = bad |
| + e.newController() |
| + e.audit() |
| + e.launchWith("att-1", 2*time.Hour) |
| + e.fake.Tick() |
| + bad.emptyGet = true |
| + if p, err := e.c.Stop(e.ctx, "inst-1", instKey, "att-1", "done"); err == nil { |
| + t.Fatalf("Stop with a Get naming no VM = proof %+v, want none", p) |
| + } |
| + _ = e.c.Refresh(e.ctx) |
| + _, _ = e.c.Reap(e.ctx) |
| + if s := e.stopCols("att-1"); s.proof.Valid { |
| + t.Fatalf("stop proof %s recorded from a Get naming no VM", s.proof.String) |
| + } |
| +} |
| + |
| // TestControllerLogs: the records the Task 17 live check reads (round 1 of |
| // its code review) appear, at info, with fixed messages and no provider text. |
| func TestControllerLogs(t *testing.T) { |
diff --git a/internal/isolatedjob/awsjob/ids_test.go b/internal/isolatedjob/awsjob/ids_test.go| index 0ce12dea..18499a80 100644 |
| --- a/internal/isolatedjob/awsjob/ids_test.go |
| +++ b/internal/isolatedjob/awsjob/ids_test.go |
| @@ -61,6 +61,19 @@ func TestMalformedIDsRefused(t *testing.T) { |
| quoted(t, err) |
| }) |
| } |
| + // R38: a Get reply with no ID, empty or absent, is an error, never the |
| + // asked-for ref (a stopped state in it must not become stop proof). |
| + for name, id := range map[string]*string{"empty": aws.String(""), "nil": nil} { |
| + t.Run("get "+name+" id", func(t *testing.T) { |
| + s := &stub{get: func(*vms.GetMicrovmInput) (*vms.GetMicrovmOutput, error) { |
| + return &vms.GetMicrovmOutput{MicrovmId: id, State: types.MicrovmStateTerminated}, nil |
| + }} |
| + job, err := newTestRunner(t, s).Get(context.Background(), "vm-1") |
| + if err == nil || job.Ref != "" || job.State != "" { |
| + t.Fatalf("Get answered with a %s id = (%+v, %v), want an error and no job", name, job, err) |
| + } |
| + }) |
| + } |
| // A malformed ref handed in is refused before any provider call. |
| s := &stub{} |
| r := newTestRunner(t, s) |
diff --git a/internal/isolatedjob/awsjob/runner.go b/internal/isolatedjob/awsjob/runner.go| index 052b5bdb..a8c638dd 100644 |
| --- a/internal/isolatedjob/awsjob/runner.go |
| +++ b/internal/isolatedjob/awsjob/runner.go |
| @@ -321,13 +321,13 @@ func (r *Runner) Get(ctx context.Context, ref isolatedjob.Ref) (isolatedjob.Job, |
| if err != nil { |
| return isolatedjob.Job{}, mapErr("get", err) |
| } |
| - if id := isolatedjob.Ref(aws.ToString(out.MicrovmId)); id != "" { |
| - if !id.Valid() { |
| - return isolatedjob.Job{}, errors.New("awsjob: get: the reply's microvm id is malformed") |
| - } |
| - ref = id |
| + // The reply must name a valid ID (R36, R38): a missing one is an error, |
| + // never the asked-for ref, so a malformed reply cannot become stop proof. |
| + id := isolatedjob.Ref(aws.ToString(out.MicrovmId)) |
| + if !id.Valid() { |
| + return isolatedjob.Job{}, errors.New("awsjob: get: the reply's microvm id is missing or malformed") |
| } |
| - return job(ref, out.State, out.StateReason, out.StartedAt, out.ResultMetadata), nil |
| + return job(id, out.State, out.StateReason, out.StartedAt, out.ResultMetadata), nil |
| } |
| // Suspend asks AWS to suspend the VM. |