console: an exhausted label CAS stays unknown, 502 C38 (M2 rereview A)
A CAS conflict that outlasts updateRecord's retry may hide a write that landed (a retried Put losing to itself), so it is no longer "changed". Only ErrRecordMigrating, refused before any Put, stays C35. The witness lands the second Put, then answers it with a conflict.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
internal/console/instancelabel.go+5 −4internal/console/instancelabel_test.go+34 −12
Intent
<task-notification> <task-id>a2bee0384e8178390</task-id> <tool-use-id>toolu_01YcM2TF3oR9GnBwWyciG1QL</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ac77363b-5830-422c-9f38-d7f2540dd398/tasks/a2bee0384e8178390.output</output-file> <status>completed</status> <summary>Agent "Implement Task 8 m2: census" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>- **Status:** Done. I reviewed the 3 changed units against the fix wave and re-pinned them with class and kinds unchanged. The writer still only refuses, or sets the three label fields inside the CAS. The root-read overlay is re-proposed, with the `.` and `internal/provision` envelopes changed; the seal is unchanged at 5603979d. - **Commit:** bcf13dbe `census: fleet record labels m2 after the review fix wave`. Not pushed. - **Tests:** `go test ./internal/provision -run 'TestPlan14RootReadCensus|TestPlan9B8|TestCensusScopeIsTheRootBinary|TestFirstLabel' -count=1` passes (10.5 s). - **Concerns:** None new. Astra's #280 verdict is still owed and should cover the fix wave too; the updated claims are in task-8-m2-report.md under "After the fix wave".</result> <usage><subagent_tokens>135047</subagent_tokens><tool_uses>11</tool_uses><duration_ms>103223</duration_ms></usage> </task-notification>
diff --git a/internal/console/instancelabel.go b/internal/console/instancelabel.go| index 00de62983..3c82d3b2d 100644 |
| --- a/internal/console/instancelabel.go |
| +++ b/internal/console/instancelabel.go |
| @@ -274,11 +274,12 @@ func (s *Server) handleAPIInstanceLabel(w http.ResponseWriter, r *http.Request) |
| if errors.As(err, &ce) { |
| ans.CoordinatorBox = ce.Box |
| } |
| - // A CAS lost on updateRecord's retry too, and a record a migration |
| - // has marked (ErrRecordMigrating is a CAS conflict), are definite |
| - // non-writes: the record changed under the write (M2 review P3-2). |
| + // A record a migration has marked refuses before any Put, a definite |
| + // non-write (M2 review P3-2). Any other CAS conflict that outlasts |
| + // updateRecord's retry falls to the unknown outcome below: a retried |
| + // Put can land and then lose to itself (M2 re-review A). |
| case errors.Is(err, provision.ErrFleetBoxMoved), errors.Is(err, os.ErrNotExist), |
| - errors.Is(err, release.ErrCASConflict), errors.Is(err, provision.ErrRecordMigrating): |
| + errors.Is(err, provision.ErrRecordMigrating): |
| refuseLabel(&ans, labelWhyChanged) |
| case err != nil: |
| log.Printf("console: api instance label %s/%s/%s: write: %v", acct.Sqid, app, host, err) |
diff --git a/internal/console/instancelabel_test.go b/internal/console/instancelabel_test.go| index 06f24ad24..3022db4a6 100644 |
| --- a/internal/console/instancelabel_test.go |
| +++ b/internal/console/instancelabel_test.go |
| @@ -736,28 +736,50 @@ func TestLabelDoorReadFailureIs503(t *testing.T) { |
| } |
| } |
| -// casLosingStore loses every compare-and-swap Put of key. |
| -type casLosingStore struct { |
| +// landedConflictStore loses the first Put of key without writing (a real |
| +// CAS loss), then writes the second and answers it with ErrCASConflict, as |
| +// an SDK retry of a landed conditional put does against its own write. |
| +type landedConflictStore struct { |
| release.Store |
| - key string |
| + key string |
| + mu sync.Mutex |
| + puts int |
| } |
| -func (c casLosingStore) Put(ctx context.Context, key string, body []byte, ifMatch string) (string, error) { |
| - if key == c.key { |
| +func (c *landedConflictStore) Put(ctx context.Context, key string, body []byte, ifMatch string) (string, error) { |
| + if key != c.key { |
| + return c.Store.Put(ctx, key, body, ifMatch) |
| + } |
| + c.mu.Lock() |
| + c.puts++ |
| + n := c.puts |
| + c.mu.Unlock() |
| + if n == 1 { |
| return "", release.ErrCASConflict |
| } |
| - return c.Store.Put(ctx, key, body, ifMatch) |
| + if _, err := c.Store.Put(ctx, key, body, ifMatch); err != nil { |
| + return "", err |
| + } |
| + return "", release.ErrCASConflict |
| } |
| -// M2 review P3-2 (Fable): the writer's definite non-writes are "changed" |
| -// (C35), not 502 and C38: a CAS lost on the retry too, and a record a |
| -// migration has marked past the wait. |
| +// M2 review P3-2 (Fable) and re-review A (Astra): a record a migration has |
| +// marked refuses before any Put, so it is "changed" (C35). A CAS conflict |
| +// that outlasts updateRecord's retry may hide a write that landed, so it |
| +// stays an unknown outcome: 502 with C38, not applied. |
| func TestLabelDoorDefiniteNonWritesAreChanged(t *testing.T) { |
| - t.Run("cas conflict", func(t *testing.T) { |
| + t.Run("cas conflict after a landed write", func(t *testing.T) { |
| fx, token, reg, created := labelWorld(t, "code-ld-cas", "pi-1", "pi-2") |
| servingEvidence(t, fx, reg, created, "pi-1") |
| - fx.srv.cfg.Releases = casLosingStore{Store: fx.srv.cfg.Releases, key: provision.RecordKey(fx.sqid, "shop", labelHost)} |
| - wantRefused(t, fx, labelPost(t, fx, token, "pi-1", false), "changed") |
| + fx.srv.cfg.Releases = &landedConflictStore{Store: fx.srv.cfg.Releases, key: provision.RecordKey(fx.sqid, "shop", labelHost)} |
| + code, _, raw := rawReq(t, http.MethodPost, labelURL(fx, labelHost), token, labelBody("pi-1", false)) |
| + want := fmt.Sprintf("the result is unknown: it may or may not be tied. to see which, run carlos instances label --app shop %s", labelHost) |
| + if code != http.StatusBadGateway || errorOf(t, raw) != want || strings.Contains(raw, `"applied":true`) { |
| + t.Fatalf("an exhausted CAS = %d %s; want 502 with C38, not applied", code, raw) |
| + } |
| + if r := shopRec(t, fx, labelHost); r.FleetBox != "pi-1" { |
| + t.Fatalf("record %+v; the witness needs the second write to land", r) |
| + } |
| }) |
| t.Run("migrating", func(t *testing.T) { |
| fx, token, reg, created := labelWorld(t, "code-ld-migrating", "pi-1", "pi-2") |