carlos / platform Public

fix: repair guard tests for anonymous demos

codex agent, operated by paul@keymail.dev pushed by claude agent, operated by paul@keymail.dev edfec482d737ab214e70484ade32f02fb3691ea4 parent f1cb145
9 files changed, +168 −11
  • internal/console/apidemo.go +1 −1
  • internal/console/demo_gate_test.go +55 −0
  • internal/console/store_gate.go +5 −0
  • internal/console/testdata/claim-authority-sites.txt +2 −0
  • internal/host/host_test.go +2 −0
  • internal/provision/demo_census_test.go +48 −0
  • internal/provision/plan9_b8_census_test.go +1 −1
  • internal/registry/demo_test.go +43 −0
  • internal/registry/registry.go +11 −9

CI failed — run details

Intent

Human

<task-notification> <task-id>b6pqe6g0b</task-id> <tool-use-id>toolu_01XFeZ87WdM1bFpKFLEpKrY8</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/cd1b6de2-ac77-426f-a77d-fc5436969c88/tasks/b6pqe6g0b.output</output-file> <status>completed</status> <summary>Background command "Wait for Task 7 Codex run" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>a1f107f2eec85db0a</task-id> <tool-use-id>toolu_01KEw8uQXimoiD87sE8QRy2i</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/cd1b6de2-ac77-426f-a77d-fc5436969c88/tasks/a1f107f2eec85db0a.output</output-file> <status>completed</status> <summary>Agent "Review Task 7 (spec + quality)" 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>**Verdict: READY AFTER FIXES** - **P1:** none. - **P2-1:** `publishReadyDemos` (`demo_publish.go`) permanently fails the job on any transient error at any stage: a store 5xx, the policy-writer lease still held by the old console during a roll, or an attempt cancel. It should retry at its recorded stage until `starting_until`. A console roll therefore costs the agent one of its updates. On generation 2 or later, a failure after promotion marks the job "failed" even though the channel already points at the new version, so the box goes on to run it. Full review: `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/agent-start-demo-1/.superpowers/sdd/2026-11-02-agent-start-demo-1-anonymous-apps/task-7-review-r1.md`</result> <usage><subagent_tokens>165195</subagent_tokens><tool_uses>30</tool_uses><duration_ms>422147</duration_ms></usage> </task-notification>

Attributed to this commit: 11.0 g CO₂e (1,414,524 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on agent-start-demo-1, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/internal/console/apidemo.go b/internal/console/apidemo.go
index 764e05177..cc2b359fe 100644
--- a/internal/console/apidemo.go
+++ b/internal/console/apidemo.go
@@ -247,7 +247,7 @@ func (s *Server) registerDemoRoutes() {
return
}
s.registerRoute("POST /api/demo/apps", s.handleDemoPublish)
- s.registerRoute("GET "+demoBuildStreamPath, s.handleDemoBuildStream)
+ s.registerRoute("GET /api/box/demo-builds", s.handleDemoBuildStream)
s.registerRoute("POST /api/box/demo-builds/{jobID}/pickup", s.handleDemoPickup)
s.registerRoute("POST /api/box/demo-builds/{jobID}/result", s.handleDemoResult)
s.registerRoute("GET /api/demo/jobs/{jobID}", s.handleDemoStatus)
diff --git a/internal/console/demo_gate_test.go b/internal/console/demo_gate_test.go
new file mode 100644
index 000000000..246924520
--- /dev/null
+++ b/internal/console/demo_gate_test.go
@@ -0,0 +1,55 @@
+package console
+
+import (
+ "context"
+ "path/filepath"
+ "testing"
+)
+
+// Demo lifecycle, build work and source bytes cannot be mutated in claims mode,
+// even through a valid app permit. The outbox has no direct app identity.
+func TestDemoSQLClaimsRefuseBuildState(t *testing.T) {
+ path := filepath.Join(t.TempDir(), "console.db")
+ initial, err := Open(path)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer initial.Close()
+ // Seed before arming so UPDATE and DELETE exercise actual rows rather
+ // than succeed without firing a trigger.
+ for _, query := range []string{
+ `INSERT INTO demo_apps(demo_id,account_id,account_sqid,app,name,fleet,claim_token_hash,created_at,creating_ip,source_sha256,client) VALUES('demo',7,'shop','blog','shop','demo',zeroblob(32),1,'hash',X'','test')`,
+ `INSERT INTO demo_jobs(id,demo_id,generation,attempt,box,deadline,state,wire,job) VALUES('job','demo',1,1,'box',1,'queued',X'',X'')`,
+ `INSERT INTO demo_job_outbox(job_id,source) VALUES('job',X'')`,
+ } {
+ if _, err := initial.db.Exec(query); err != nil {
+ t.Fatal(err)
+ }
+ }
+ if err := initial.Close(); err != nil {
+ t.Fatal(err)
+ }
+ s, err := OpenGated(path)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer s.Close()
+ seedGateApp(t, s)
+ err = s.withClaimSQL(context.Background(), []claimSQLScope{gateScope}, allowAllClaimSQL, func(v *Store) error {
+ for _, query := range []string{
+ `INSERT INTO demo_apps(demo_id,account_id,account_sqid,app,name,fleet,claim_token_hash,created_at,creating_ip,source_sha256,client) VALUES('other',7,'shop','other','other','demo',randomblob(32),1,'hash',X'','test')`,
+ `UPDATE demo_apps SET generation=2`, `DELETE FROM demo_apps`,
+ `INSERT INTO demo_jobs(id,demo_id,generation,attempt,box,deadline,state,wire,job) VALUES('other','other',1,1,'box',1,'queued',X'',X'')`,
+ `UPDATE demo_jobs SET state='failed'`, `DELETE FROM demo_jobs`,
+ `INSERT INTO demo_job_outbox(job_id,source) VALUES('other',X'')`,
+ `UPDATE demo_job_outbox SET source=X'01'`, `DELETE FROM demo_job_outbox`,
+ } {
+ _, err := v.db.Exec(query)
+ requireDenied(t, query, err)
+ }
+ return nil
+ })
+ if err != nil {
+ t.Fatal(err)
+ }
+}
diff --git a/internal/console/store_gate.go b/internal/console/store_gate.go
index 51b1a7165..704e5520e 100644
--- a/internal/console/store_gate.go
+++ b/internal/console/store_gate.go
@@ -188,6 +188,11 @@ var claimAppsTerminal = map[string][]string{
// cannot silently ship ungated. There is deliberately no exemption class:
// audit and mail telemetry are app-scoped and are gated like the rest.
var claimSQLTables = map[string]claimSQLTable{
+ // Jobs carry demo identity and durable spool metadata; source outbox rows
+ // carry only a job ID. Neither is safe to write with an ordinary app permit.
+ // The opaque IDs below are refusal-only scopes, never matched to a permit.
+ "demo_jobs": {App: "demo_id", Refuse: "anonymous demo jobs require claims mode off"},
+ "demo_job_outbox": {App: "job_id", Refuse: "anonymous demo source outbox requires claims mode off"},
"demo_apps": {Account: "account_id", App: "app", Refuse: "anonymous demos require claims mode off"},
"demo_admissions": {NonApp: "anonymous attempt budget, keyed by salted IP hash and time; names no app"},
"demo_settings": {NonApp: "deployment salt for anonymous admission; names no app"},
diff --git a/internal/console/testdata/claim-authority-sites.txt b/internal/console/testdata/claim-authority-sites.txt
index 6f8f5073b..5ac5a712e 100644
--- a/internal/console/testdata/claim-authority-sites.txt
+++ b/internal/console/testdata/claim-authority-sites.txt
@@ -152,3 +152,5 @@ claim_loss_pages.go|pageClaimLossesAt|s.store.db.QueryRowContext(ctx, `SELECT la
store_gate.go|OpenGated|s.db.Exec(`ALTER TABLE claim_loss_pages ADD COLUMN last_key TEXT NOT NULL DEFAULT ''`)
awsregionmetric.go|capacityPublisherFromEnv|cloudwatch.NewFromConfig(cfg, func(o *cloudwatch.Options) { o.Region = awsRegion })
../../cmd/console/hostsused.go|runHostsUsed|os.Open(*listingsPath)
+demo_spool.go|acceptDemoResult|os.Open(s.store.demoSpoolDir)
+demo_spool.go|demoSpoolDigest|os.Open(path)
diff --git a/internal/host/host_test.go b/internal/host/host_test.go
index 424642c47..2fea31c2d 100644
--- a/internal/host/host_test.go
+++ b/internal/host/host_test.go
@@ -40,6 +40,8 @@ var expectedUnits = []string{
"carlos-config-sync.service",
"carlos-dbread.socket",
"carlos-dbread@.service",
+ "carlos-demo-build@.service",
+ "carlos-demo-builds.slice",
"carlos-edge.service",
"carlos-hibernate-verify.service",
"carlos-hibernate-verify.timer",
diff --git a/internal/provision/demo_census_test.go b/internal/provision/demo_census_test.go
new file mode 100644
index 000000000..2a8e3dc88
--- /dev/null
+++ b/internal/provision/demo_census_test.go
@@ -0,0 +1,48 @@
+package provision
+
+// Demo Plan 1 guard repair: source and callers checked by the implementer.
+// This inventory records the write paths; controller review remains pending.
+func demoWriteCensusInventory() []censusEntry {
+ entries := append([]censusEntry(nil), statelessReplicasWriteCensusInventory()...)
+ // The wrapper now only takes the locks and calls the locked writer below.
+ for i, entry := range entries {
+ if entry.File == "internal/console/hostsused.go" && entry.Unit == "Server.createRecordMarked" {
+ entries = append(entries[:i], entries[i+1:]...)
+ break
+ }
+ }
+ for _, next := range []censusEntry{
+ // Registers demo HTTP handlers; the instance/sidecar strings are routes.
+ {"internal/console/authcli.go", "Server.registerCLIRoutes", "key-site", "lit:instances,lit:sidecars", "033513f39cf26dc83b949fc7997f4c1eecd62f08405610b3ac9f6c529b1d0433"},
+ // Skips demo records before the existing typed fleet-box CAS.
+ {"internal/console/fleetrelabel.go", "Server.writeRelabels", "record-writer", "key:SetRecordFleetBox", "f560538daecde5dd2949dabc6c348e47e38640649fc73a09f13d036b019f1228"},
+ // Refuses demo mutations and the reserved fleet before the existing typed writer.
+ {"internal/console/fleets.go", "Server.placeAppTarget", "record-writer", "key:RecordsPrefix,key:SetRecordRegion", "19e3829dce8a106054bde07cb2bdfef63db586cfc1ee90eda08566b5462c2802"},
+ // Validates demo config and seeds admission reads; record-like strings are routes.
+ {"internal/console/server.go", "NewServer", "key-site", "lit:instances", "fce966e92176c71bfbc41762fafb3181418a900706268dce5eb8a698cefd066f"},
+ // Excludes the worker stream from request timing; names only HTTP paths.
+ {"internal/console/server.go", "consolePerfSkip", "key-site", "lit:instances", "8f4981a3b2c207f8ac834f11f9862911cb639386e0b69801b8099674c6c330b9"},
+ // Installs local unit files and refuses bad demo config; no bucket record write.
+ {"internal/host/bootstrap.go", "bootstrapWith", "key-site", "lit:instances", "a55f9f90065579c13a4cb4dfe73b4e4d44b76d69d6e500fc9d024d51f2e469df"},
+ // Adds descriptor/placement checks before and after sequencing; the sole Put remains.
+ {"internal/provision/record_sequence.go", "WriteRecord", "record-primitive", "key:IsRecordKey,key:WriteRecord,key:preparedRecordKey,sel:Put", "42feb4f9f153221955098368b8520368af4491d37ca67929f014ed03582e8603"},
+ // Writes only the create-only demo-initialized marker in the files store.
+ {"internal/activator/demo_durability.go", "ExecBackend.restoreDemoLocal", "nonrecord", "sel:Put", "783f1f9b46972a7156c2663ee1d463e6ea0b075bf35f09f2f9488cd9e78bb3e0"},
+ // Both callers supply demo source/job keys, under the app lock and SQL recheck.
+ {"internal/console/demo_jobs.go", "Server.putDemoObject", "nonrecord", "sel:Put", "41da9bc04403d0c94f191d5a34562415d81fdbddcacf219ec80174f0044c2573"},
+ // Both callers hold app and hostname locks; retains rechecks and typed CreateRecord.
+ {"internal/console/hostsused.go", "Server.createRecordMarkedLocked", "record-writer", "key:CreateRecord,key:RecordKey", "7133825222a1a780ec93049d7f8c42eceded6fb3d3cefd6ad271210dec791273"},
+ } {
+ found := false
+ for i, old := range entries {
+ if old.File == next.File && old.Unit == next.Unit {
+ entries[i] = next
+ found = true
+ }
+ }
+ if !found {
+ entries = append(entries, next)
+ }
+ }
+ return entries
+}
diff --git a/internal/provision/plan9_b8_census_test.go b/internal/provision/plan9_b8_census_test.go
index dcd3668c9..4f4074e21 100644
--- a/internal/provision/plan9_b8_census_test.go
+++ b/internal/provision/plan9_b8_census_test.go
@@ -366,7 +366,7 @@ func TestPlan9B8RecordWriteCensus(t *testing.T) {
if len(got) < 100 {
t.Fatalf("census found only %d units under %s; the walk is broken", len(got), root)
}
- inventory := statelessReplicasWriteCensusInventory()
+ inventory := demoWriteCensusInventory()
problems := append(censusDiff(inventory, got), censusPolicy(inventory)...)
if len(problems) > 0 {
t.Fatalf("record-write census rejected %d site(s); update the explicit inventory only after reviewing the source:\n %s", len(problems), strings.Join(problems, "\n "))
diff --git a/internal/registry/demo_test.go b/internal/registry/demo_test.go
index 70743c82a..eb5ac5075 100644
--- a/internal/registry/demo_test.go
+++ b/internal/registry/demo_test.go
@@ -61,3 +61,46 @@ func TestDemoPolicyPartialMarkerCannotDowngrade(t *testing.T) {
t.Fatal("partial demo marker silently downgraded")
}
}
+
+func TestDemoSnapshotFingerprintFields(t *testing.T) {
+ r, err := Open(filepath.Join(t.TempDir(), "registry.db"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer r.Close()
+ if err := r.Upsert(Route{Host: "shop.example.com", Kind: "instance"}); err != nil {
+ t.Fatal(err)
+ }
+ base, err := r.SnapshotFingerprint()
+ if err != nil {
+ t.Fatal(err)
+ }
+ seen := map[string]bool{base: true}
+ for _, column := range []string{"demo_id", "demo_host", "demo_lifetime", "demo_expires_at"} {
+ t.Run(column, func(t *testing.T) {
+ // Equal values in distinct columns must still produce distinct digests.
+ if _, err := r.sql.Exec("UPDATE routes SET " + column + "=1"); err != nil {
+ t.Fatal(err)
+ }
+ got, err := r.SnapshotFingerprint()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if seen[got] {
+ t.Fatal("demo field missing or aliases another field")
+ }
+ seen[got] = true
+ unset := "''"
+ if column == "demo_expires_at" {
+ unset = "0"
+ }
+ if _, err := r.sql.Exec("UPDATE routes SET " + column + "=" + unset); err != nil {
+ t.Fatal(err)
+ }
+ got, err = r.SnapshotFingerprint()
+ if err != nil || got != base {
+ t.Fatalf("cleared fingerprint = %s, want %s: %v", got, base, err)
+ }
+ })
+ }
+}
diff --git a/internal/registry/registry.go b/internal/registry/registry.go
index aaa5e8ade..677b85496 100644
--- a/internal/registry/registry.go
+++ b/internal/registry/registry.go
@@ -4275,13 +4275,11 @@ var snapshotClaimCols = map[string]bool{
}
// snapshotWhenSetCols are the good-build columns (zero-downtime spec §8.5),
-// the update-settings column, the runtime column, the rate-limit column and
-// the app policy columns (#328, #329). A restore has to reproduce them, so
-// they are hashed, but only when set and tagged, on the hold_op rule: a
-// registry that has never recorded a good build, set update settings,
-// minted a rootfs row, set a custom rate limit or converged a policy
-// digests exactly as it did before the columns existed, so upgrading does
-// not force a snapshot on every box.
+// update settings, runtime, rate limit, app policy (#328, #329), and demo
+// identity strings. A restore has to reproduce them, so they are hashed,
+// but only when set and tagged, on the hold_op rule. Default values digest
+// exactly as before these columns existed, so upgrading does not force a
+// snapshot on every box.
var snapshotWhenSetCols = map[string]bool{
"good_version": true,
"good_digest": true,
@@ -4294,6 +4292,9 @@ var snapshotWhenSetCols = map[string]bool{
"policy_expires_at": true,
"fleet_assigned": true,
"fleet_label": true,
+ "demo_id": true,
+ "demo_host": true,
+ "demo_lifetime": true,
}
// snapshotPairCols are the lifetime pair's columns (self-serve moves plan 1
@@ -4377,8 +4378,9 @@ func (r *Registry) SnapshotFingerprint() (string, error) {
continue
}
// ha too (region HA P1a): only a born-HA row hashes it. And
- // fleet_moved (managed fleets 1b): only a moved row's.
- if cols[i] == "ha" || cols[i] == "fleet_moved" || cols[i] == "stateless" {
+ // fleet_moved (managed fleets 1b): only a moved row's. Stateless
+ // and demo expiry also contribute only when non-zero.
+ if cols[i] == "ha" || cols[i] == "fleet_moved" || cols[i] == "stateless" || cols[i] == "demo_expires_at" {
if v.Valid && v.String != "" && v.String != "0" {
fmt.Fprintf(h, "%s=%s\x1f", cols[i], v.String)
}