registry: Upsert keeps a runtime row's region unless the tenant changed
Task 13 round 3 (Astra), Paul's ruling: the conflict arm sets region from the stored row when it has a runtime and the incoming row names the same tenant (tenantChangedSQL, as the hibernate arm does), so a domains apex mint that copies a sibling's region cannot move a rootfs row. A new life on the hostname takes the incoming region; binary rows are as on main.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
internal/registry/registry.go+6 −2internal/registry/runtime_test.go+44 −0
CI failed — run details
Intent
<task-notification> <task-id>af8fb77773e290938</task-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/723ae101-0fd7-40c3-a758-6adf1597efb2/tasks/af8fb77773e290938.output</output-file> <status>completed</status> <summary>Agent "Plan 3 Task 12 implementer" 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_WITH_CONCERNS Commits: - bba9a52d Revert Task 12 (carlos run on rootfs rows, --version): Paul cut it from this slice. It is one `git revert` commit covering 56cc06aa and 6c6f8607, with no history rewritten. - The 39921f17 change that sends Task 8's resident start through `putEntryLocked` is kept. Main's `TestEntriesEnterThroughPutEntryLocked` passes. What now holds: - **Rootfs runs:** `carlos run` on a rootfs row is refused as before. StartCmd's nestedGate gives `errRootfsBinaryLaunch`, and it never reaches a binary exec. Every Task 12 file is byte-identical to the pre-Task-12 tip d57fb8a0. - **Binary runs:** unchanged. The binary StartCmd golden test passes, and so do the StartCmd and RunCmd tests. - **Copy gate:** no extra revert was needed. RUN-C47 is back in `run.go` and the RFS-3 run strings are out of the built list. Tests: - The activator, runs and host packages pass, and so does the root package in full (copy gates included). - The invariant guards pass, the darwin and windows builds pass, and `TestEntriesEnterThroughPutEntryLocked` passes. - The console package has one failure: `TestPlan9SQLBatchSealsRetainedWriteQueuedAcrossCommit`. It times out under full-package load, and it failed the same way before the revert. Alone, it passes 5 runs out of 5, and its file has not changed in a long time. I'm treating it as a timing flake, not something this branch caused. Concerns: only that console flake. The Task 12 concerns are carried in the report for whoever picks the task up again. Report: `.superpowers/sdd/2026-10-24-rootfs-apps-3-lifecycle/task-12-report.md`, with a "Task 12 reverted (Paul cut)" section added. It is not committed, because `.superpowers/` is git-excluded.</result> <usage><subagent_tokens>467146</subagent_tokens><tool_uses>12</tool_uses><duration_ms>1183410</duration_ms></usage> </task-notification>
diff --git a/internal/registry/registry.go b/internal/registry/registry.go| index c88e62d28..74173d8cd 100644 |
| --- a/internal/registry/registry.go |
| +++ b/internal/registry/registry.go |
| @@ -1329,7 +1329,10 @@ func (r *Registry) UpsertUnlessRootfs(t Route) error { |
| // upsert is Upsert's statement. guard, when not "", is ANDed onto the |
| // conflict arm's WHERE; a conflict it refuses writes nothing and reads as |
| -// ErrClaimOwnership here. |
| +// ErrClaimOwnership here. A stored row with a runtime keeps its hibernation |
| +// and its region unless the incoming row names another tenant (a new life |
| +// on the hostname): an instance with a runtime never moves, whichever |
| +// writer upserts over it (a domains apex mint copies a sibling's region). |
| func (r *Registry) upsert(t Route, guard string) error { |
| res, err := r.sql.Exec(` |
| INSERT INTO routes (`+routeCols+`) |
| @@ -1341,7 +1344,8 @@ ON CONFLICT(host) DO UPDATE SET |
| last_error=excluded.last_error, |
| db_path=excluded.db_path, version=excluded.version, |
| prev_version=excluded.prev_version, app=excluded.app, pool=excluded.pool, |
| - region=excluded.region, channel=excluded.channel, |
| + region=CASE WHEN routes.runtime != '' AND NOT (`+tenantChangedSQL+`) THEN routes.region ELSE excluded.region END, |
| + channel=excluded.channel, |
| hibernate=CASE WHEN routes.runtime != '' AND NOT (`+tenantChangedSQL+`) THEN routes.hibernate ELSE excluded.hibernate END, |
| canary=excluded.canary, |
| next_due=excluded.next_due, |
diff --git a/internal/registry/runtime_test.go b/internal/registry/runtime_test.go| index e561930aa..fd4998298 100644 |
| --- a/internal/registry/runtime_test.go |
| +++ b/internal/registry/runtime_test.go |
| @@ -452,3 +452,47 @@ func TestSetPlacementRefusesARuntimeRow(t *testing.T) { |
| t.Fatalf("a missing row: err = %v", err) |
| } |
| } |
| + |
| +// Round 3 (Paul's ruling): Upsert keeps a runtime row's region unless the |
| +// tenant changed. The interleaving: provision mints the apex host as a |
| +// rootfs row from its record (region ie), then a domains apex mint that |
| +// listed the host as absent upserts it with a sibling's region (uk). The |
| +// rootfs row, rootfs-v1 or an unknown runtime, keeps ie and its runtime. A |
| +// re-tenanted row (another app: a new life on the hostname) takes the |
| +// incoming region, and a binary row takes it exactly as on main. |
| +func TestUpsertKeepsARuntimeRowsRegion(t *testing.T) { |
| + const host = "shop.bab.example.com" |
| + domainMint := func(region string) Route { |
| + // domains.mintedRoute's shape: copied from a ready sibling route. |
| + return Route{Host: host, Kind: "instance", App: "shop", Account: "bab", Status: "ready", Platform: true, Region: region} |
| + } |
| + for _, runtime := range []string{RuntimeRootfsV1, "rootfs-v9"} { |
| + reg := openRuntimeTestRegistry(t) |
| + if err := reg.Upsert(Route{Host: host, Kind: "instance", App: "shop", Account: "bab", Runtime: runtime, Region: "ie"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := reg.Upsert(domainMint("uk")); err != nil { |
| + t.Fatal(err) |
| + } |
| + if got := mustGet(t, reg, host); got.Region != "ie" || got.Runtime != runtime { |
| + t.Fatalf("%s: after the domain mint: region %q runtime %q, want ie %q", runtime, got.Region, got.Runtime, runtime) |
| + } |
| + // A new life on the hostname (another app) takes the incoming row. |
| + if err := reg.Upsert(Route{Host: host, Kind: "instance", App: "blog", Account: "bab", Region: "uk"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if got := mustGet(t, reg, host); got.Region != "uk" || got.Runtime != "" || got.App != "blog" { |
| + t.Fatalf("%s: re-tenanted: region %q runtime %q app %q, want uk \"\" blog", runtime, got.Region, got.Runtime, got.App) |
| + } |
| + } |
| + reg := openRuntimeTestRegistry(t) |
| + if err := reg.Upsert(Route{Host: host, Kind: "instance", App: "shop", Account: "bab", Region: "ie"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := reg.Upsert(domainMint("uk")); err != nil { |
| + t.Fatal(err) |
| + } |
| + if got := mustGet(t, reg, host); got.Region != "uk" { |
| + t.Fatalf("binary row: region %q, want uk as on main", got.Region) |
| + } |
| +} |