Stop demo logs and errors blocking demo admission (#527)
Squashed from agent-start-demo-log-skip into main. Co-Authored-By: codex <codex~paul@keymail.dev>
22 files changed,
+458
−130
docs/superpowers/notes/census-agent-start-demo-log-skip-claims.md+6 −0docs/superpowers/notes/census-proposal-agent-start-demo-log-skip.md+31 −0docs/superpowers/reviews/REVIEW-BRIEF-agent-start-demo-log-skip-R1.md+78 −0docs/superpowers/reviews/REVIEW-FINDINGS-agent-start-demo-log-skip-R1.md+18 −0internal/console/apidemo.go+1 −1internal/console/demo_analytics_test.go+144 −101internal/console/demo_expiry.go+8 −3internal/console/demo_expiry_test.go+8 −4internal/console/demo_store.go+1 −1internal/console/lifetimes_purge.go+1 −1internal/edge/analytics.go+21 −7internal/edge/edge.go+1 −1internal/edge/guard.go+1 −1internal/edge/reqrecords.go+1 −1internal/edge/reqrecords_test.go+60 −0internal/host/errship.go+5 −3internal/host/errship_test.go+23 −0internal/host/logship.go+7 −4internal/host/logship_test.go+21 −0internal/provision/plan9_b8_census_test.go+4 −2internal/provision/testdata/plan14-root-reads-agent-start-demo-log-skip.tsv+17 −0internal/provision/testdata/plan14-root-reads-chain.tsv+1 −0
CI passed — run details
diff --git a/docs/superpowers/notes/census-agent-start-demo-log-skip-claims.md b/docs/superpowers/notes/census-agent-start-demo-log-skip-claims.md| new file mode 100644 |
| index 000000000..f8c79c285 |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-agent-start-demo-log-skip-claims.md |
| @@ -0,0 +1,6 @@ |
| +internal/edge/analytics.go:Edge.analyticsEnabled the demo refusal moves into demoUnrecorded(rt, nil): same rt.IsDemo() and reserved rt.Host checks over already-loaded demo config; can only disable analytics; no new read, open or follow |
| +internal/edge/analytics.go:Edge.observeAnalytics the reserved r.Host refusal moves into demoUnrecorded(rt, r); same checks; only suppresses an observation; no new read |
| +internal/edge/analytics.go:Edge.demoUnrecorded new, replaces demoAnalyticsRefused: true for rt.IsDemo(), or a route or request Host that demoAuthority/demoReserved name as a reserved demo host, compared against already-loaded demo config; pure predicate, opens, runs or follows nothing; its only effect at every caller is to skip recording |
| +internal/edge/edge.go:Edge.emitEdgeError returns early when demoUnrecorded(rt, r): files no edge error record for a demo; only suppresses an in-memory record; no new read |
| +internal/edge/guard.go:Edge.noteBurst skips only the in-memory Trip record when demoUnrecorded(rt, r); cooling, the limiter and peer notices are unchanged; no new read |
| +internal/edge/reqrecords.go:Edge.observeRecords returns early when demoUnrecorded(rt, r): files no Response or Match for a demo; only suppresses an in-memory record; no new read |
diff --git a/docs/superpowers/notes/census-proposal-agent-start-demo-log-skip.md b/docs/superpowers/notes/census-proposal-agent-start-demo-log-skip.md| new file mode 100644 |
| index 000000000..b7ea4410e |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-agent-start-demo-log-skip.md |
| @@ -0,0 +1,31 @@ |
| +# Census approval: agent-start-demo-log-skip |
| + |
| +Ruling `census-ruling-agent-start-demo-log-skip`. The independent reviewer approves or rejects every change below, 1 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| + |
| +| unit | change | read sites | what changed | |
| +|---|---|---|---| |
| +| `internal/edge/analytics.go` `Edge.analyticsEnabled` | sites | -registry:Host, +whole:Route | the demo refusal moves into demoUnrecorded(rt, nil): same rt.IsDemo() and reserved rt.Host checks over already-loaded demo config; can only disable analytics; no new read, open or follow | |
| +| `internal/edge/analytics.go` `Edge.observeAnalytics` | sites | +whole:Route | the reserved r.Host refusal moves into demoUnrecorded(rt, r); same checks; only suppresses an observation; no new read | |
| +| `internal/edge/edge.go` `Edge.emitEdgeError` | sites | +whole:Route | returns early when demoUnrecorded(rt, r): files no edge error record for a demo; only suppresses an in-memory record; no new read | |
| +| `internal/edge/guard.go` `Edge.noteBurst` | sites | +whole:Route | skips only the in-memory Trip record when demoUnrecorded(rt, r); cooling, the limiter and peer notices are unchanged; no new read | |
| +| `internal/edge/reqrecords.go` `Edge.observeRecords` | sites | +whole:Route | returns early when demoUnrecorded(rt, r): files no Response or Match for a demo; only suppresses an in-memory record; no new read | |
| + |
| +Envelopes re-pinned: `internal/edge`, `internal/host`. |
| + |
| +Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner. |
| + |
| +Recorded dispositions, which each change must still satisfy: |
| + |
| +- `internal/edge/analytics.go` `Edge.analyticsEnabled`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=J1;basis=root-route;rev3=census-ruling-agent-start-demo-analytics-fix;basis=analytics.go:61-63 returns false for rt.IsDemo() or a reserved demo route Host (new read registry:Host, compared against already-loaded demo config); can only disable analytics, opens or follows nothing. |
| +- `internal/edge/analytics.go` `Edge.observeAnalytics`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=J1;basis=root-route;rev3=census-ruling-agent-start-demo-analytics-fix;basis=analytics.go:121 also refuses requests whose Host is a reserved demo name (demoAuthority/demoReserved over already-loaded demo config); only suppresses an observation, no new read, open or follow. |
| +- `internal/edge/edge.go` `Edge.emitEdgeError`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=J1;basis=root-route |
| +- `internal/edge/guard.go` `Edge.noteBurst`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-probe-burst-limit;basis=new: in the observer defer, counts a not-found (a 404, or a hard or probe match) from a non-browser client (no Sec-Fetch-Mode) toward the in-memory probe-burst limiter, keyed by the route's account/app; on a trip mints a reference code, files a Trip record into the in-memory recorder and queues notices to peer edges; the sites are the route value passed in; reads no file, store or registry; no new root read or write kind |
| +- `internal/edge/reqrecords.go` `Edge.observeRecords`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-edge-request-records;identity=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=new: called from ServeHTTP's observer defer after observeAnalytics, with the route the defer already holds; returns at once when no recorder is wired or the request arrived over a tunnel (the forwarding box records it); otherwise builds the Response through requestResponse from that route and the request and hands it to the in-memory recorder, which files it into the box's log sink; its one scanned site is the route value passed in; it reads no file, no store and no box state, writes nothing outside the log sink, and makes no serving or root decision; the class of Edge.observeAnalytics (J1 root-route);rev3=census-ruling-edge-protection-2;basis=files one reqrec.Match in place of the Response when the request's outcome carries a guard verdict (kind block or watch, the verdict's rule tier, id, fragment and reference code; a block woke nothing), and the plain Response otherwise; still in-memory, its one scanned site is the route value passed in; no read added;rev3=census-ruling-probe-burst-limit;basis=the Match it files also carries the verdict's cool-down start and end (CooldownFrom, CooldownUntil, set only for the burst rule); RequestRecorder gains Trip; still in-memory into the log sink, the same one route site; no new root read or write kind |
| + |
| +New dispositions, which census-propose wrote and the reviewer checks against the unit's reads and the diff: |
| + |
| +- new `internal/edge/analytics.go:Edge.demoUnrecorded`: reads +registry:Host; written legacy, accepted-legacy, frozen |
| + |
| +Seal: `89841c50d08090185e24cb03c6bb4878ab8a4ccb84b7d2f0113f88b617df8026` → `ed24b69243622fc702159e0b22c732f4f8297438b87f10c499887cd1a13f6fce`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-agent-start-demo-log-skip.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/docs/superpowers/reviews/REVIEW-BRIEF-agent-start-demo-log-skip-R1.md b/docs/superpowers/reviews/REVIEW-BRIEF-agent-start-demo-log-skip-R1.md| new file mode 100644 |
| index 000000000..801c13a9d |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/REVIEW-BRIEF-agent-start-demo-log-skip-R1.md |
| @@ -0,0 +1,78 @@ |
| +# Review brief: branch agent-start-demo-log-skip, round 1 of 3 |
| + |
| +Repo carlos/platform, branch `agent-start-demo-log-skip`, commit 3f542e3b760b371474df5815ef7174cf1cd35c71. |
| +Under review: the diff `ddbc0297..3f542e3b` (excluding this brief). |
| +Authorities: merged commit 7d0f26cb (the analytics version of this fix, |
| +"Stop demo analytics blocking demo admission"), AGENTS.md, |
| +docs/superpowers/notes/agent-start-demo-2-rulings.md. |
| + |
| +You are an independent reviewer. Read the diff, then the code it |
| +touches, and check every claim against that code. |
| + |
| +## The bug |
| + |
| +After a demo is purged, an ingress box can still ship request logs or |
| +edge error records under apps/<acct>/<app>/logs/ or errors/ (shipping |
| +retries every 10 s). The console's admission orphan check |
| +(internal/console/apidemo.go, validateDemoAdmissionState) then refuses |
| +every demo create. 7d0f26cb fixed this for analytics/; this branch does |
| +the same for logs/ and errors/. |
| + |
| +## Fixed: do not re-argue |
| + |
| +- Scope ruling: the edge records nothing for demo routes or reserved |
| + demo hosts; shippers drop tmp-demo- buckets like analytics UpsertDay; |
| + admission/purge/sweep treat logs/ and errors/ like analytics/. Live |
| + demos have no logs or errors view, so dropping them is intended. |
| +- Not in scope: a pre-roll DB query (ops, not code). |
| + |
| +## What to check |
| + |
| +1. demoUnrecorded (internal/edge/analytics.go): analytics behaviour is |
| + unchanged from 7d0f26cb, and it now also covers observeRecords, |
| + emitEdgeError and the burst Trip record in guard.go. Is any demo |
| + path still recording (other callers of the request recorder or error |
| + sink, e.g. activator, wake, tunnel, assetcatch)? Does the guard.go |
| + change leave burst protection itself intact? |
| +2. Shipper drops (internal/host/logship.go, errship.go): correct key |
| + (k.App), no ordinary app affected, no retry loop or leak. |
| +3. Console: demoStrayPath at all three sites; admission still refuses a |
| + real orphan (live app keys, non-purged demo, non-stray path); the |
| + resumed purge in retireDemoLocked still refuses (errNoMarker) any |
| + non-stray key; the sweep only deletes under the app lock, no apps row, |
| + purged demo. |
| +4. purgedDemoApp tombstone match by first host label |
| + (substr/instr in SQLite): correct for hosts without a dot, names that |
| + are prefixes of other names, and cannot mark a live or different |
| + demo purged in a way that lets admission or the sweep delete or |
| + ignore something it should not. |
| +5. Tests: do they prove the claims (a demo request yields no record and |
| + no error record; an ordinary app unchanged; logs/errors key shapes |
| + match the real shippers' keys)? |
| + |
| +## Severity |
| + |
| +- **P1**: unsafe, would not compile, a test fails, or it would not work. |
| + Blocks merge. |
| +- **P2**: wrong or missing. Fixed without reopening this review. |
| +- **P3**: clarity or polish. Goes on a follow-up list; never a reason for |
| + another round. |
| + |
| +A P1 states its failure scenario and the evidence (file:line). Do not |
| +raise a P2 to P1 to keep the review open. |
| + |
| +## Output |
| + |
| +Findings ranked P1, P2, P3. Each gives the problem, the evidence |
| +(file:line, verified), the failure scenario, a concrete fix and the |
| +invariant it breaks (its fault family). End with exactly one verdict: |
| + |
| +- **READY**: no P1 and no P2. |
| +- **READY AFTER FIXES**: no P1. The listed P2s are fixed without another |
| + round. |
| +- **NOT READY**: one or more P1s, listed. |
| + |
| +Do not edit files. Do not spawn reviewers or subagents of your own. Do |
| +not run the full test suites; targeted `go test ./internal/<pkg>/ -run` |
| +is fine, with TMPDIR=/home/paulca/.cache/tmp/claude-1001/asd-logskip and |
| +GOCACHE left at its default. |
diff --git a/docs/superpowers/reviews/REVIEW-FINDINGS-agent-start-demo-log-skip-R1.md b/docs/superpowers/reviews/REVIEW-FINDINGS-agent-start-demo-log-skip-R1.md| new file mode 100644 |
| index 000000000..53f8c165e |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/REVIEW-FINDINGS-agent-start-demo-log-skip-R1.md |
| @@ -0,0 +1,18 @@ |
| +# Review findings: agent-start-demo-log-skip, round 1 (Opus) |
| + |
| +Diff ddbc0297..3f542e3b. Verdict: **READY** (no P1, no P2). |
| + |
| +Checked: demoUnrecorded keeps 7d0f26cb's analytics behaviour and guards |
| +every request-record, trip and edge-error call site; the shipper drops key |
| +on k.App and the tmp-demo- prefix is reserved for every account; |
| +demoStrayPath at all three console sites; admission still refuses real |
| +orphans; the first-label tombstone match is exact. Three console tests |
| +that bind unix sockets could not run in the reviewer's sandbox (env, not |
| +the diff); CI covers them. |
| + |
| +P3s: |
| +1. purgedDemoApp's substr() match cannot use the tombstone index and runs |
| + per stray key. Left: the table is small today; follow-up. |
| +2. logship/errship KnownApps still listed demo apps for the hourly prune. |
| + FIXED in the follow-up commit (demo apps left off the worklist, tested). |
| +3. demoUnrecorded lost its doc comment. FIXED. |
diff --git a/internal/console/apidemo.go b/internal/console/apidemo.go| index ba7ec2067..edfffb3f0 100644 |
| --- a/internal/console/apidemo.go |
| +++ b/internal/console/apidemo.go |
| @@ -209,7 +209,7 @@ func validateDemoAdmissionState(ctx context.Context, cfg Config, st *Store) erro |
| return fmt.Errorf("orphan objects lifecycle: %w", err) |
| } |
| if life == nil || life.DemoID == "" { |
| - if life == nil && strings.HasPrefix(path, "analytics/") { |
| + if life == nil && demoStrayPath(path) { |
| purged, err := st.purgedDemoApp(ctx, cfg.Demo, app) |
| if err != nil { |
| return err |
diff --git a/internal/console/demo_analytics_test.go b/internal/console/demo_analytics_test.go| index f5c5f1b2a..61c2dbec7 100644 |
| --- a/internal/console/demo_analytics_test.go |
| +++ b/internal/console/demo_analytics_test.go |
| @@ -10,7 +10,13 @@ import ( |
| "github.com/carlosframework/platform/internal/release" |
| ) |
| -func demoAnalyticsFixture(t *testing.T) (*Server, DemoRow, string) { |
| +var demoStrayTestPaths = []string{ |
| + "analytics/box-1/days/2026-11-05.json", |
| + "logs/box-1/2026-11-05-10/0001793872800000-257.jsonl.gz", |
| + "errors/box-1/2026-11-05-10/0001793872800000-257.jsonl.gz", |
| +} |
| + |
| +func demoStrayFixture(t *testing.T, path string) (*Server, DemoRow, string) { |
| t.Helper() |
| s, _ := demoJobServer(t) |
| in := demoTestAdmission(t, s.cfg.Demo) |
| @@ -21,127 +27,164 @@ func demoAnalyticsFixture(t *testing.T) (*Server, DemoRow, string) { |
| if err != nil { |
| t.Fatal(err) |
| } |
| - return s, d, "apps/" + d.AccountSqid + "/tmp-demo-plucky-coral-60/analytics/box-1/days/2026-11-05.json" |
| + return s, d, release.AppPrefix(d.AccountSqid, d.App) + path |
| +} |
| + |
| +func TestDemoAdmissionPurgedStrays(t *testing.T) { |
| + for _, path := range demoStrayTestPaths { |
| + t.Run(strings.SplitN(path, "/", 2)[0], func(t *testing.T) { |
| + for _, state := range []string{"purged", "tombstoned", "history wiped", "no history", "unpurged", "other account", "other domain", "ordinary row"} { |
| + t.Run(state, func(t *testing.T) { |
| + s, d, key := demoStrayFixture(t, path) |
| + if _, err := s.store.db.Exec(`DELETE FROM apps WHERE demo_id=?`, d.ID); err != nil { |
| + t.Fatal(err) |
| + } |
| + now := time.Now() |
| + if state != "unpurged" { |
| + if _, err := s.store.db.Exec(`UPDATE demo_apps SET state='retired',purged_at=? WHERE demo_id=?`, now.Unix(), d.ID); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + if state == "tombstoned" || state == "history wiped" || state == "other domain" || state == "ordinary row" { |
| + host := d.Host |
| + if state == "other domain" { |
| + host = d.Name + ".elsewhere.example.com" |
| + } |
| + if _, err := s.store.db.Exec(`INSERT INTO demo_host_tombstones(host,demo_id,purged_at) VALUES(?,?,?)`, host, d.ID, now.Unix()); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + if state == "history wiped" { |
| + if err := s.store.WipeDemoAbuse(t.Context(), now.Add(8*24*time.Hour)); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + if state == "tombstoned" || state == "no history" || state == "other domain" { |
| + if _, err := s.store.db.Exec(`DELETE FROM demo_apps WHERE demo_id=?`, d.ID); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + if state == "other account" { |
| + if _, err := s.store.db.Exec(`UPDATE demo_apps SET account_sqid='elsewhere' WHERE demo_id=?`, d.ID); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + if state == "ordinary row" { |
| + if _, err := s.store.CreateTemporaryAppIn(d.AccountID, d.App, "test", now, now.Add(time.Hour)); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + if _, err := s.cfg.Releases.Put(t.Context(), key, []byte("{}"), ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + err := validateDemoAdmissionState(t.Context(), s.cfg, s.store) |
| + wantPass := state == "purged" || state == "tombstoned" || state == "history wiped" || state == "other domain" |
| + if wantPass && err != nil || !wantPass && (err == nil || !strings.Contains(err.Error(), "orphan objects")) { |
| + t.Fatalf("admission: %v, want pass=%v", err, wantPass) |
| + } |
| + if !wantPass { |
| + return |
| + } |
| + for _, path := range []string{"manifest.json", "analytics-other/box-1/days/2026-11-05.json", "logs-other/box-1/chunk.jsonl.gz", "errors-other/box-1/chunk.jsonl.gz"} { |
| + other := release.AppPrefix(d.AccountSqid, d.App) + path |
| + if _, err := s.cfg.Releases.Put(t.Context(), other, []byte("{}"), ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := validateDemoAdmissionState(t.Context(), s.cfg, s.store); err == nil || !strings.Contains(err.Error(), "orphan objects") { |
| + t.Fatalf("accepted %s: %v", path, err) |
| + } |
| + if err := s.cfg.Releases.Delete(t.Context(), other); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + }) |
| + } |
| + }) |
| + } |
| } |
| -func TestDemoAdmissionPurgedAnalytics(t *testing.T) { |
| - for _, state := range []string{"purged", "tombstoned", "history wiped", "no history", "unpurged", "other account", "other domain", "ordinary row"} { |
| - t.Run(state, func(t *testing.T) { |
| - s, d, key := demoAnalyticsFixture(t) |
| - if _, err := s.store.db.Exec(`DELETE FROM apps WHERE demo_id=?`, d.ID); err != nil { |
| +func TestDemoPurgeStraysAndLateFlush(t *testing.T) { |
| + for _, path := range demoStrayTestPaths { |
| + t.Run(strings.SplitN(path, "/", 2)[0], func(t *testing.T) { |
| + s, d, key := demoStrayFixture(t, path) |
| + now := time.Unix(d.CreatedAt+86400, 0) |
| + if _, err := s.cfg.Releases.Put(t.Context(), key, []byte("{}"), ""); err != nil { |
| t.Fatal(err) |
| } |
| - now := time.Now() |
| - if state != "unpurged" { |
| - if _, err := s.store.db.Exec(`UPDATE demo_apps SET state='retired',purged_at=? WHERE demo_id=?`, now.Unix(), d.ID); err != nil { |
| - t.Fatal(err) |
| - } |
| + if err := s.expireDemoLocked(t.Context(), d, now); err != nil { |
| + t.Fatal(err) |
| } |
| - if state == "tombstoned" || state == "history wiped" || state == "other domain" || state == "ordinary row" { |
| - host := d.Host |
| - if state == "other domain" { |
| - host = d.Name + ".elsewhere.example.com" |
| - } |
| - if _, err := s.store.db.Exec(`INSERT INTO demo_host_tombstones(host,demo_id,purged_at) VALUES(?,?,?)`, host, d.ID, now.Unix()); err != nil { |
| - t.Fatal(err) |
| - } |
| + if _, _, err := s.cfg.Releases.Get(t.Context(), key); !errors.Is(err, os.ErrNotExist) { |
| + t.Fatalf("main purge left %s: %v", key, err) |
| } |
| - if state == "history wiped" { |
| - if err := s.store.WipeDemoAbuse(t.Context(), now.Add(8*24*time.Hour)); err != nil { |
| - t.Fatal(err) |
| - } |
| + if err := s.store.WipeDemoAbuse(t.Context(), now.Add(8*24*time.Hour)); err != nil { |
| + t.Fatal(err) |
| } |
| - if state == "tombstoned" || state == "no history" || state == "other domain" { |
| - if _, err := s.store.db.Exec(`DELETE FROM demo_apps WHERE demo_id=?`, d.ID); err != nil { |
| - t.Fatal(err) |
| - } |
| + otherKeys := []string{ |
| + release.AppPrefix(d.AccountSqid, d.App) + "manifest.json", |
| + "apps/" + d.AccountSqid + "/tmp-demo-bright-otter-42/" + path, |
| + "apps/" + d.AccountSqid + "/shop/" + path, |
| } |
| - if state == "other account" { |
| - if _, err := s.store.db.Exec(`UPDATE demo_apps SET account_sqid='elsewhere' WHERE demo_id=?`, d.ID); err != nil { |
| + for _, k := range append(otherKeys, key) { |
| + if _, err := s.cfg.Releases.Put(t.Context(), k, []byte("{}"), ""); err != nil { |
| t.Fatal(err) |
| } |
| } |
| - if state == "ordinary row" { |
| - if _, err := s.store.CreateTemporaryAppIn(d.AccountID, d.App, "test", now, now.Add(time.Hour)); err != nil { |
| - t.Fatal(err) |
| + counted := &demoCountingListStore{Store: s.cfg.Releases} |
| + s.cfg.Releases = counted |
| + s.cfg.Demo.Enabled = false |
| + s.expiryPass(t.Context(), now.Add(8*24*time.Hour)) |
| + if _, _, err := s.cfg.Releases.Get(t.Context(), key); !errors.Is(err, os.ErrNotExist) { |
| + t.Fatalf("late flush survived expiry sweep: %v", err) |
| + } |
| + for _, k := range otherKeys { |
| + if _, _, err := s.cfg.Releases.Get(t.Context(), k); err != nil { |
| + t.Fatalf("sweep removed unrelated key %s: %v", k, err) |
| } |
| } |
| + if n := counted.calls.Load(); n != 2 { |
| + t.Fatalf("hourly pass made %d LISTs; want stray scan plus existing trash scan", n) |
| + } |
| if _, err := s.cfg.Releases.Put(t.Context(), key, []byte("{}"), ""); err != nil { |
| t.Fatal(err) |
| } |
| - err := validateDemoAdmissionState(t.Context(), s.cfg, s.store) |
| - wantPass := state == "purged" || state == "tombstoned" || state == "history wiped" |
| - if wantPass && err != nil || !wantPass && (err == nil || !strings.Contains(err.Error(), "orphan objects")) { |
| - t.Fatalf("admission: %v, want pass=%v", err, wantPass) |
| + s.expiryPass(t.Context(), now.Add(8*24*time.Hour+5*time.Minute)) |
| + if counted.calls.Load() != 2 { |
| + t.Fatal("stray cleanup polled before the hourly sweep") |
| } |
| - if !wantPass { |
| - return |
| - } |
| - for _, path := range []string{"manifest.json", "analytics-other/box-1/days/2026-11-05.json"} { |
| - other := release.AppPrefix(d.AccountSqid, d.App) + path |
| - if _, err := s.cfg.Releases.Put(t.Context(), other, []byte("{}"), ""); err != nil { |
| - t.Fatal(err) |
| - } |
| - if err := validateDemoAdmissionState(t.Context(), s.cfg, s.store); err == nil || !strings.Contains(err.Error(), "orphan objects") { |
| - t.Fatalf("accepted %s: %v", path, err) |
| - } |
| - if err := s.cfg.Releases.Delete(t.Context(), other); err != nil { |
| - t.Fatal(err) |
| - } |
| + s.expiryPass(t.Context(), now.Add(8*24*time.Hour+time.Hour)) |
| + if _, _, err := s.cfg.Releases.Get(t.Context(), key); !errors.Is(err, os.ErrNotExist) { |
| + t.Fatalf("next hourly sweep left %s: %v", key, err) |
| } |
| }) |
| } |
| } |
| -func TestDemoPurgeAnalyticsAndLateFlush(t *testing.T) { |
| - s, d, key := demoAnalyticsFixture(t) |
| - now := time.Unix(d.CreatedAt+86400, 0) |
| - if _, err := s.cfg.Releases.Put(t.Context(), key, []byte("{}"), ""); err != nil { |
| - t.Fatal(err) |
| - } |
| - if err := s.expireDemoLocked(t.Context(), d, now); err != nil { |
| - t.Fatal(err) |
| - } |
| - if _, _, err := s.cfg.Releases.Get(t.Context(), key); !errors.Is(err, os.ErrNotExist) { |
| - t.Fatalf("main purge left analytics: %v", err) |
| - } |
| - if err := s.store.WipeDemoAbuse(t.Context(), now.Add(8*24*time.Hour)); err != nil { |
| - t.Fatal(err) |
| - } |
| - otherKeys := []string{ |
| - release.AppPrefix(d.AccountSqid, d.App) + "manifest.json", |
| - "apps/" + d.AccountSqid + "/tmp-demo-bright-otter-42/analytics/box-1/days/2026-11-05.json", |
| - "apps/" + d.AccountSqid + "/shop/analytics/box-1/days/2026-11-05.json", |
| - } |
| - for _, k := range append(otherKeys, key) { |
| - if _, err := s.cfg.Releases.Put(t.Context(), k, []byte("{}"), ""); err != nil { |
| - t.Fatal(err) |
| - } |
| - } |
| - counted := &demoCountingListStore{Store: s.cfg.Releases} |
| - s.cfg.Releases = counted |
| - s.cfg.Demo.Enabled = false |
| - s.expiryPass(t.Context(), now.Add(8*24*time.Hour)) |
| - if _, _, err := s.cfg.Releases.Get(t.Context(), key); !errors.Is(err, os.ErrNotExist) { |
| - t.Fatalf("late flush survived expiry sweep: %v", err) |
| - } |
| - for _, k := range otherKeys { |
| - if _, _, err := s.cfg.Releases.Get(t.Context(), k); err != nil { |
| - t.Fatalf("sweep removed unrelated key %s: %v", k, err) |
| - } |
| - } |
| - if n := counted.calls.Load(); n != 2 { |
| - t.Fatalf("hourly pass made %d LISTs; want analytics scan plus existing trash scan", n) |
| - } |
| - if _, err := s.cfg.Releases.Put(t.Context(), key, []byte("{}"), ""); err != nil { |
| - t.Fatal(err) |
| - } |
| - s.expiryPass(t.Context(), now.Add(8*24*time.Hour+5*time.Minute)) |
| - if counted.calls.Load() != 2 { |
| - t.Fatal("analytics cleanup polled before the hourly sweep") |
| - } |
| - s.expiryPass(t.Context(), now.Add(8*24*time.Hour+time.Hour)) |
| - if _, _, err := s.cfg.Releases.Get(t.Context(), key); !errors.Is(err, os.ErrNotExist) { |
| - t.Fatalf("next hourly sweep left analytics: %v", err) |
| +func TestPurgedDemoAppTombstoneName(t *testing.T) { |
| + for _, tc := range []struct { |
| + host string |
| + purgedAt int64 |
| + want bool |
| + }{ |
| + {"plucky-coral-60.old.example.com", 1, true}, |
| + {"plucky-coral-60.old.example.com", 0, false}, |
| + {"plucky-coral-600.old.example.com", 1, false}, |
| + {"xplucky-coral-60.old.example.com", 1, false}, |
| + {"other.plucky-coral-60.old.example.com", 1, false}, |
| + {"plucky-coral-60", 1, false}, |
| + } { |
| + t.Run(tc.host+"/"+time.Unix(tc.purgedAt, 0).Format(time.RFC3339), func(t *testing.T) { |
| + s, d, _ := demoStrayFixture(t, demoStrayTestPaths[0]) |
| + if _, err := s.store.db.Exec(`DELETE FROM demo_apps WHERE demo_id=?`, d.ID); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := s.store.db.Exec(`INSERT INTO demo_host_tombstones(host,demo_id,purged_at) VALUES(?,?,?)`, tc.host, d.ID, tc.purgedAt); err != nil { |
| + t.Fatal(err) |
| + } |
| + got, err := s.store.purgedDemoApp(t.Context(), s.cfg.Demo, d.App) |
| + if err != nil || got != tc.want { |
| + t.Fatalf("purged = %v, err %v; want %v", got, err, tc.want) |
| + } |
| + }) |
| } |
| } |
diff --git a/internal/console/demo_expiry.go b/internal/console/demo_expiry.go| index 1e8d8af93..a048ffb7f 100644 |
| --- a/internal/console/demo_expiry.go |
| +++ b/internal/console/demo_expiry.go |
| @@ -211,7 +211,8 @@ func (s *Server) retireDemoLocked(ctx context.Context, d DemoRow, now time.Time, |
| return err |
| } |
| for _, key := range keys { |
| - if !strings.HasPrefix(key, release.AppPrefix(d.AccountSqid, d.App)+"analytics/") { |
| + path, ok := strings.CutPrefix(key, release.AppPrefix(d.AccountSqid, d.App)) |
| + if !ok || !demoStrayPath(path) { |
| return errNoMarker |
| } |
| } |
| @@ -321,7 +322,11 @@ func (s *Server) finishDemoPurge(ctx context.Context, d DemoRow, now time.Time) |
| return nil |
| } |
| -func (s *Server) sweepDemoAnalytics(ctx context.Context) error { |
| +func demoStrayPath(path string) bool { |
| + return strings.HasPrefix(path, "analytics/") || strings.HasPrefix(path, "logs/") || strings.HasPrefix(path, "errors/") |
| +} |
| + |
| +func (s *Server) sweepDemoStrays(ctx context.Context) error { |
| if s.cfg.HostClaim || s.cfg.Releases == nil || s.cfg.Demo.Account == "" { |
| return nil |
| } |
| @@ -341,7 +346,7 @@ func (s *Server) sweepDemoAnalytics(ctx context.Context) error { |
| continue |
| } |
| app, path, ok := strings.Cut(rest, "/") |
| - if ok && strings.HasPrefix(path, "analytics/") { |
| + if ok && demoStrayPath(path) { |
| byApp[app] = append(byApp[app], key) |
| } |
| } |
diff --git a/internal/console/demo_expiry_test.go b/internal/console/demo_expiry_test.go| index 06d4279a0..d702f189c 100644 |
| --- a/internal/console/demo_expiry_test.go |
| +++ b/internal/console/demo_expiry_test.go |
| @@ -223,7 +223,7 @@ func (f *demoExpiryFault) Get(ctx context.Context, k string) ([]byte, string, er |
| } |
| func TestDemoPurgeRecoveryInterruptedWrites(t *testing.T) { |
| - for _, fault := range []string{"marker before", "marker after", "row", "receipt", "purge marker after", "purge marker after analytics", "final row"} { |
| + for _, fault := range []string{"marker before", "marker after", "row", "receipt", "purge marker after", "purge marker after analytics", "purge marker after logs", "purge marker after errors", "final row"} { |
| t.Run(fault, func(t *testing.T) { |
| s, d, _, _ := demoPublishFixture(t) |
| life, _ := s.store.AppLife(d.AccountID, d.App) |
| @@ -266,7 +266,7 @@ func TestDemoPurgeRecoveryInterruptedWrites(t *testing.T) { |
| t.Fatal(err) |
| } |
| switch fault { |
| - case "purge marker after", "purge marker after analytics": |
| + case "purge marker after", "purge marker after analytics", "purge marker after logs", "purge marker after errors": |
| f.deleteKey = release.AppTombstoneKey(d.AccountSqid, d.App) |
| f.after = true |
| case "final row": |
| @@ -276,8 +276,12 @@ func TestDemoPurgeRecoveryInterruptedWrites(t *testing.T) { |
| } |
| s.expiryPass(t.Context(), now.Add(2*time.Minute)) |
| f.deleteKey = "" |
| - if fault == "purge marker after analytics" { |
| - key := release.AppPrefix(d.AccountSqid, d.App) + "analytics/box-1/days/2026-11-05.json" |
| + for _, path := range demoStrayTestPaths { |
| + family, _, _ := strings.Cut(path, "/") |
| + if fault != "purge marker after "+family { |
| + continue |
| + } |
| + key := release.AppPrefix(d.AccountSqid, d.App) + path |
| if _, err := original.Put(t.Context(), key, []byte("{}"), ""); err != nil { |
| t.Fatal(err) |
| } |
diff --git a/internal/console/demo_store.go b/internal/console/demo_store.go| index aa3db52a9..5a9117c09 100644 |
| --- a/internal/console/demo_store.go |
| +++ b/internal/console/demo_store.go |
| @@ -464,6 +464,6 @@ func (s *Store) purgedDemoApp(ctx context.Context, cfg demo.Config, app string) |
| } |
| var purged bool |
| err := s.db.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM demo_apps WHERE account_sqid=? AND app=? AND purged_at>0) |
| -OR EXISTS(SELECT 1 FROM demo_host_tombstones WHERE host=? AND purged_at>0)`, cfg.Account, app, name+"."+cfg.Domain).Scan(&purged) |
| +OR EXISTS(SELECT 1 FROM demo_host_tombstones WHERE substr(host,1,instr(host,'.')-1)=? AND purged_at>0)`, cfg.Account, app, name).Scan(&purged) |
| return purged, err |
| } |
diff --git a/internal/console/lifetimes_purge.go b/internal/console/lifetimes_purge.go| index 7856811cc..3489c02e5 100644 |
| --- a/internal/console/lifetimes_purge.go |
| +++ b/internal/console/lifetimes_purge.go |
| @@ -169,7 +169,7 @@ func (s *Server) trashSweep(ctx context.Context, now time.Time) { |
| if !due { |
| return |
| } |
| - if err := s.sweepDemoAnalytics(ctx); err != nil { |
| + if err := s.sweepDemoStrays(ctx); err != nil { |
| jobFailed(ctx, err) |
| } |
| apps, err := release.ExpiredTrashApps(ctx, s.cfg.Releases, now) |
diff --git a/internal/edge/analytics.go b/internal/edge/analytics.go| index 9b5a7635e..4618e28ac 100644 |
| --- a/internal/edge/analytics.go |
| +++ b/internal/edge/analytics.go |
| @@ -51,15 +51,29 @@ func (e *Edge) SetAnalyticsOn(on map[string]bool) { |
| e.analyticsOn.Store(&cp) |
| } |
| -// demoAnalyticsRefused reports whether host is a demo's reserved name. It |
| -// reads only the demo config, so no switch map or call site can undo it. |
| -func (e *Edge) demoAnalyticsRefused(host string) bool { |
| - name, _ := demoAuthority(host) |
| - return e.demoReserved(name) |
| +// demoUnrecorded reports whether a response is a demo's: a demo route, or a |
| +// route or request Host naming a reserved demo host. Analytics, request |
| +// records, burst trips and edge errors all skip it, so a demo leaves no keys |
| +// a late flush could ship after its purge (#527). It reads only the route and |
| +// the demo config, so no switch map or call site can undo it. r is nil when |
| +// only the route is known (analyticsEnabled). |
| +func (e *Edge) demoUnrecorded(rt registry.Route, r *http.Request) bool { |
| + if rt.IsDemo() { |
| + return true |
| + } |
| + host, _ := demoAuthority(rt.Host) |
| + if e.demoReserved(host) { |
| + return true |
| + } |
| + if r != nil { |
| + host, _ = demoAuthority(r.Host) |
| + return e.demoReserved(host) |
| + } |
| + return false |
| } |
| func (e *Edge) analyticsEnabled(rt registry.Route) bool { |
| - if rt.IsDemo() || e.demoAnalyticsRefused(rt.Host) { |
| + if e.demoUnrecorded(rt, nil) { |
| return false |
| } |
| m := e.analyticsOn.Load() |
| @@ -118,7 +132,7 @@ func isPrefetchPurpose(v string) bool { |
| // wrapper is added for it and no path here can wake an instance. |
| func (e *Edge) observeAnalytics(rt registry.Route, r *http.Request, ob *countingWriter, bytes int64) { |
| ref := e.analyticsMeter.Load() |
| - if ref == nil || !e.analyticsEnabled(rt) || e.demoAnalyticsRefused(r.Host) { |
| + if ref == nil || !e.analyticsEnabled(rt) || e.demoUnrecorded(rt, r) { |
| return |
| } |
| // One observation per served response (geoip spec §9, codex R4-1): the |
diff --git a/internal/edge/edge.go b/internal/edge/edge.go| index 886f21804..027ac4dd8 100644 |
| --- a/internal/edge/edge.go |
| +++ b/internal/edge/edge.go |
| @@ -689,7 +689,7 @@ func (e *Edge) EnableErrors(s ErrorSink) { |
| // from its socket (viaTunnel false) and files everything as usual. |
| func (e *Edge) emitEdgeError(rt registry.Route, viaTunnel bool, r *http.Request, status int, cause string) { |
| ref := e.errSink.Load() |
| - if ref == nil || cause == causeClientGone || (viaTunnel && cause == "") { |
| + if ref == nil || e.demoUnrecorded(rt, r) || cause == causeClientGone || (viaTunnel && cause == "") { |
| return |
| } |
| path := apperr.SanitizePath(r.URL.Path) |
diff --git a/internal/edge/guard.go b/internal/edge/guard.go| index 0f5148fe5..268ec02d7 100644 |
| --- a/internal/edge/guard.go |
| +++ b/internal/edge/guard.go |
| @@ -322,7 +322,7 @@ func (e *Edge) noteBurst(rt registry.Route, r *http.Request, status int, out *ou |
| return |
| } |
| ref := e.mintRef(reqrec.TierBurst, edgeguard.BurstRule.ID) |
| - if rec := e.requestRecords.Load(); rec != nil { |
| + if rec := e.requestRecords.Load(); rec != nil && !e.demoUnrecorded(rt, r) { |
| rec.Trip(reqrec.Trip{Response: requestResponse(rt, r, status), Until: until, Ref: ref}) |
| } |
| e.sendBurstNotices(client, until, ref) |
diff --git a/internal/edge/reqrecords.go b/internal/edge/reqrecords.go| index 456e79ebe..329897d98 100644 |
| --- a/internal/edge/reqrecords.go |
| +++ b/internal/edge/reqrecords.go |
| @@ -62,7 +62,7 @@ func requestResponse(rt registry.Route, r *http.Request, status int) reqrec.Resp |
| // to see (WokeKnown). |
| func (e *Edge) observeRecords(rt registry.Route, viaTunnel bool, r *http.Request, ob *countingWriter, out *outcome) { |
| ref := e.requestRecords.Load() |
| - if ref == nil { |
| + if ref == nil || e.demoUnrecorded(rt, r) { |
| return |
| } |
| // One record per served response, observeAnalytics's rule: the hub that |
diff --git a/internal/edge/reqrecords_test.go b/internal/edge/reqrecords_test.go| index 3a66a8ad2..239b466cf 100644 |
| --- a/internal/edge/reqrecords_test.go |
| +++ b/internal/edge/reqrecords_test.go |
| @@ -7,6 +7,7 @@ import ( |
| "net/http/httptest" |
| "testing" |
| + "github.com/carlosframework/platform/internal/demo" |
| "github.com/carlosframework/platform/internal/registry" |
| "github.com/carlosframework/platform/internal/reqrec" |
| "github.com/carlosframework/platform/internal/tunnelclient" |
| @@ -18,6 +19,65 @@ type memRecorder struct { |
| trips []reqrec.Trip |
| } |
| +func TestRecordsAndErrorsSkipServedDemo(t *testing.T) { |
| + e, rt, c := demoTrafficFixture(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + w.WriteHeader(http.StatusInternalServerError) |
| + })) |
| + rec, sink := &memRecorder{}, &memErrSink{} |
| + e.EnableRequestRecords(rec) |
| + e.EnableErrors(sink) |
| + w := httptest.NewRecorder() |
| + e.ServeHTTP(w, httptest.NewRequest("GET", "https://"+rt.Host+"/", nil)) |
| + if w.Code != 500 || c.requests != 1 { |
| + t.Fatalf("demo request was not served: %d, counted %d", w.Code, c.requests) |
| + } |
| + if len(rec.resp)+len(rec.match)+len(rec.trips) != 0 || len(sink.snap()) != 0 { |
| + t.Fatalf("demo recorded: %+v, errors %+v", rec, sink.snap()) |
| + } |
| +} |
| + |
| +func TestRecordsAndErrorsDemoGuards(t *testing.T) { |
| + e := &Edge{demo: demo.Config{Domain: "demo.example.com"}} |
| + ordinary := registry.Route{Host: "app.example.com", App: "web", Account: "shop"} |
| + check := func(rt registry.Route, host string, want int) { |
| + t.Helper() |
| + rec, sink := &memRecorder{}, &memErrSink{} |
| + e.EnableRequestRecords(rec) |
| + e.EnableErrors(sink) |
| + r := httptest.NewRequest("GET", "https://"+host+"/", nil) |
| + r.Host = host |
| + e.observeRecords(rt, false, r, &countingWriter{status: 500}, nil) |
| + e.emitEdgeError(rt, false, r, 500, "") |
| + if len(rec.resp) != want || len(rec.match)+len(rec.trips) != 0 || len(sink.snap()) != want { |
| + t.Fatalf("route %+v request host %q: records %+v, errors %+v; want %d each", rt, host, rec, sink.snap(), want) |
| + } |
| + e.burst, _ = burstTestLimiter() |
| + r.RemoteAddr = "203.0.113.7:12345" |
| + for i := 0; i < burstThreshold; i++ { |
| + e.noteBurst(rt, r, 404, &outcome{guard: e.newGuardState(rt)}) |
| + } |
| + if _, _, cooling := e.burst.cooling(burstClientA); !cooling || len(rec.trips) != want { |
| + t.Fatalf("host %q: cooling=%v, trips=%d; want cooling with %d trips", host, cooling, len(rec.trips), want) |
| + } |
| + } |
| + check(ordinary, ordinary.Host, 1) |
| + for _, rt := range []registry.Route{ |
| + {Host: ordinary.Host, App: "web", Account: "shop", DemoID: "x"}, |
| + {Host: ordinary.Host, App: "web", Account: "shop", DemoHost: "h"}, |
| + {Host: ordinary.Host, App: "web", Account: "shop", DemoLifetime: "l"}, |
| + {Host: ordinary.Host, App: "web", Account: "shop", DemoExpiresAt: 1}, |
| + } { |
| + check(rt, ordinary.Host, 0) |
| + } |
| + for _, host := range []string{"plucky-coral-60.demo.example.com", "Plucky-Coral-60.Demo.Example.com.", "plucky-coral-60.demo.example.com:443", "demo.example.com"} { |
| + rt := ordinary |
| + rt.Host = host |
| + check(rt, ordinary.Host, 0) |
| + check(ordinary, host, 0) |
| + } |
| + check(ordinary, ordinary.Host, 1) |
| +} |
| + |
| func (m *memRecorder) Response(x reqrec.Response) { m.resp = append(m.resp, x) } |
| func (m *memRecorder) Match(x reqrec.Match) { m.match = append(m.match, x) } |
diff --git a/internal/host/errship.go b/internal/host/errship.go| index 97932ab5c..2d2aede3d 100644 |
| --- a/internal/host/errship.go |
| +++ b/internal/host/errship.go |
| @@ -12,10 +12,12 @@ import ( |
| "errors" |
| "log" |
| "os" |
| + "strings" |
| "time" |
| "github.com/carlosframework/platform/internal/apperr" |
| "github.com/carlosframework/platform/internal/applog" |
| + "github.com/carlosframework/platform/internal/demo" |
| "github.com/carlosframework/platform/internal/release" |
| ) |
| @@ -71,7 +73,7 @@ func errshipGather(sink *apperr.Sink, pending map[applog.AppKey][]apperr.Record) |
| // what landed; a failed app keeps its records for the next round. |
| func errshipFlush(ctx context.Context, s release.Store, pending map[applog.AppKey][]apperr.Record) { |
| for k, recs := range pending { |
| - if len(recs) == 0 { |
| + if len(recs) == 0 || strings.HasPrefix(k.App, demo.AppPrefix) { |
| delete(pending, k) |
| continue |
| } |
| @@ -99,13 +101,13 @@ func errshipKnownApps(pending map[applog.AppKey][]apperr.Record, sink *apperr.Si |
| seen := make(map[applog.AppKey]bool) |
| var out []applog.AppKey |
| for k := range pending { |
| - if !seen[k] { |
| + if !seen[k] && !strings.HasPrefix(k.App, demo.AppPrefix) { |
| seen[k] = true |
| out = append(out, k) |
| } |
| } |
| for _, k := range sink.Known() { |
| - if !seen[k] { |
| + if !seen[k] && !strings.HasPrefix(k.App, demo.AppPrefix) { |
| seen[k] = true |
| out = append(out, k) |
| } |
diff --git a/internal/host/errship_test.go b/internal/host/errship_test.go| index 83a7e033e..3bd6ae8ad 100644 |
| --- a/internal/host/errship_test.go |
| +++ b/internal/host/errship_test.go |
| @@ -2,6 +2,7 @@ package host |
| import ( |
| "context" |
| + "strings" |
| "testing" |
| "time" |
| @@ -10,6 +11,28 @@ import ( |
| "github.com/carlosframework/platform/internal/release" |
| ) |
| +func TestErrshipFlushDropsDemoApps(t *testing.T) { |
| + s := release.NewDirStore(t.TempDir()) |
| + sink := apperr.NewSink("box1", time.Now) |
| + for _, app := range []string{"tmp-demo-plucky-coral-60", "tmp-demo-unknown", "web"} { |
| + sink.Add("bab", app, apperr.Record{Source: apperr.SourceEdge, Kind: apperr.KindHTTP, Name: "500 GET /", Host: "app.example.com"}) |
| + } |
| + pending := make(map[applog.AppKey][]apperr.Record) |
| + errshipGather(sink, pending) |
| + if known := errshipKnownApps(pending, sink); len(known) != 1 || known[0].App != "web" { |
| + t.Fatalf("prune worklist should hold only the ordinary app: %v", known) |
| + } |
| + errshipFlush(t.Context(), failingStore{}, pending) |
| + if len(pending) != 1 || len(pending[applog.AppKey{Acct: "bab", App: "web"}]) != 1 { |
| + t.Fatalf("only ordinary app should remain pending: %v", pending) |
| + } |
| + errshipFlush(t.Context(), s, pending) |
| + keys, err := s.List(t.Context(), "apps/") |
| + if err != nil || len(keys) != 1 || !strings.HasPrefix(keys[0], "apps/bab/web/errors/") || len(pending) != 0 { |
| + t.Fatalf("flush: keys %v, pending %v, err %v", keys, pending, err) |
| + } |
| +} |
| + |
| func TestErrshipFlushWritesOneChunkPerApp(t *testing.T) { |
| s := release.NewDirStore(t.TempDir()) |
| now := time.Date(2026, 9, 7, 10, 0, 0, 0, time.UTC) |
diff --git a/internal/host/logship.go b/internal/host/logship.go| index c876cf621..7fa53a2df 100644 |
| --- a/internal/host/logship.go |
| +++ b/internal/host/logship.go |
| @@ -17,10 +17,12 @@ import ( |
| "errors" |
| "log" |
| "os" |
| + "strings" |
| "sync" |
| "time" |
| "github.com/carlosframework/platform/internal/applog" |
| + "github.com/carlosframework/platform/internal/demo" |
| "github.com/carlosframework/platform/internal/release" |
| ) |
| @@ -115,7 +117,7 @@ func logshipGather(sink *applog.Sink, pending map[applog.AppKey][]applog.Record) |
| // round; other apps' flushes proceed regardless. |
| func logshipFlush(ctx context.Context, s release.Store, pending map[applog.AppKey][]applog.Record) { |
| for k, recs := range pending { |
| - if len(recs) == 0 { |
| + if len(recs) == 0 || strings.HasPrefix(k.App, demo.AppPrefix) { |
| delete(pending, k) |
| continue |
| } |
| @@ -140,18 +142,19 @@ func logshipFlush(ctx context.Context, s release.Store, pending map[applog.AppKe |
| } |
| // logshipKnownApps is the union of apps with pending records and apps the |
| -// sink has ever buffered for — the prune worklist. |
| +// sink has ever buffered for — the prune worklist. A demo app is left off: |
| +// its chunks are never shipped, so listing them would cost requests for nothing. |
| func logshipKnownApps(pending map[applog.AppKey][]applog.Record, sink *applog.Sink) []applog.AppKey { |
| seen := make(map[applog.AppKey]bool) |
| var out []applog.AppKey |
| for k := range pending { |
| - if !seen[k] { |
| + if !seen[k] && !strings.HasPrefix(k.App, demo.AppPrefix) { |
| seen[k] = true |
| out = append(out, k) |
| } |
| } |
| for _, k := range sink.Known() { |
| - if !seen[k] { |
| + if !seen[k] && !strings.HasPrefix(k.App, demo.AppPrefix) { |
| seen[k] = true |
| out = append(out, k) |
| } |
diff --git a/internal/host/logship_test.go b/internal/host/logship_test.go| index 03e566ecd..9f47e7889 100644 |
| --- a/internal/host/logship_test.go |
| +++ b/internal/host/logship_test.go |
| @@ -17,6 +17,27 @@ func logshipFixture(t *testing.T) (release.Store, *applog.Sink) { |
| return s, applog.NewSink("box1", func() time.Time { return now }) |
| } |
| +func TestLogshipFlushDropsDemoApps(t *testing.T) { |
| + s, sink := logshipFixture(t) |
| + for _, app := range []string{"tmp-demo-plucky-coral-60", "tmp-demo-unknown", "web"} { |
| + sink.Edge("bab", app, "app.example.com", "warn", "not found", nil) |
| + } |
| + pending := make(map[applog.AppKey][]applog.Record) |
| + logshipGather(sink, pending) |
| + if known := logshipKnownApps(pending, sink); len(known) != 1 || known[0].App != "web" { |
| + t.Fatalf("prune worklist should hold only the ordinary app: %v", known) |
| + } |
| + logshipFlush(t.Context(), failingStore{}, pending) |
| + if len(pending) != 1 || len(pending[applog.AppKey{Acct: "bab", App: "web"}]) != 1 { |
| + t.Fatalf("only ordinary app should remain pending: %v", pending) |
| + } |
| + logshipFlush(t.Context(), s, pending) |
| + keys, err := s.List(t.Context(), "apps/") |
| + if err != nil || len(keys) != 1 || !strings.HasPrefix(keys[0], "apps/bab/web/logs/") || len(pending) != 0 { |
| + t.Fatalf("flush: keys %v, pending %v, err %v", keys, pending, err) |
| + } |
| +} |
| + |
| // TestLogshipFlushWritesOneChunkPerApp: a drain with two apps lands as two |
| // immutable chunks, each under its own app prefix, decodable and complete. |
| func TestLogshipFlushWritesOneChunkPerApp(t *testing.T) { |
diff --git a/internal/provision/plan9_b8_census_test.go b/internal/provision/plan9_b8_census_test.go| index a490b7d24..48aad3a63 100644 |
| --- a/internal/provision/plan9_b8_census_test.go |
| +++ b/internal/provision/plan9_b8_census_test.go |
| @@ -777,10 +777,12 @@ var plan9B8CensusInventory = []censusEntry{ |
| // D1 compares the retained registration's record key to the fresh claim; no record write. |
| {"internal/host/rootexecution_authority.go", "ClaimRootHTTP.executionAuthority", "key-site", "key:RecordKey", "107989f561409fd8c11c2666d0672b8dbeb368842fe00ad6a7b84fece2150438"}, |
| // Re-digested for fix-empty-app-key (census-ruling-fix-empty-app-key, platform-1e 2026-10-16): a chunk key the errors builder refuses (empty or invalid account or app) drops that app's records and logs once; no Put happens for it. Same single Put of the errors chunk; no record key. |
| - {"internal/host/errship.go", "errshipFlush", "nonrecord", "sel:Put", "b340b3dede6d5cab08a13a2ee8dbef5bb6dfb4943264e9835489292c479a379d"}, |
| + // Re-digested for agent-start-demo-log-skip (Opus review, 2026-11-05): a tmp-demo- app's pending records are dropped before any Put, as UpsertDay drops demo analytics. One fewer write; same single Put of the errors chunk otherwise; no record key. |
| + {"internal/host/errship.go", "errshipFlush", "nonrecord", "sel:Put", "cbd28ca322e52f3d0ee67e483c04911f635223963fba9e306d5148e54439585c"}, |
| {"internal/host/fleetbind.go", "WriteFleetBinding", "nonrecord", "sel:Put", "44ab984c2c9b30abcc938132118f61a6922ccc0cd40ed2b6cb61c7654aa0a1c3"}, |
| // Re-digested for fix-empty-app-key (census-ruling-fix-empty-app-key, platform-1e 2026-10-16): as errshipFlush, for the logs family. Same single Put of the log chunk; no record key. |
| - {"internal/host/logship.go", "logshipFlush", "nonrecord", "sel:Put", "214a52ecc3bef193b8edcd6998cdaa75da182d552f4e605f68a5dededa4ffb68"}, |
| + // Re-digested for agent-start-demo-log-skip (Opus review, 2026-11-05): as errshipFlush, for the logs family. Same single Put of the log chunk otherwise; no record key. |
| + {"internal/host/logship.go", "logshipFlush", "nonrecord", "sel:Put", "6458f1225c8f079c5ecab6635f154e53fb5c5d643de9451854d75ab976a840d7"}, |
| {"internal/host/metrics_loop.go", "putAlertState", "nonrecord", "sel:Put", "d5b6e8b34dc5a731d6bbafeac0b7d0c5c20706d6f413dff38088b3321b35a26c"}, |
| // Clears an aborting record through SetRecordMove (MoveGuardedAbortComplete) once nothing is owed under the op, then ReleaseAbort: record first, ruling M4. |
| {"internal/host/movesabort.go", "movesWorker.abortSource", "record-writer", "key:SetRecordMove", "51bafe02fe16f07c1f1e08cfbc224ba21c8277ec065fff1142349afe0dde675b"}, |
diff --git a/internal/provision/testdata/plan14-root-reads-agent-start-demo-log-skip.tsv b/internal/provision/testdata/plan14-root-reads-agent-start-demo-log-skip.tsv| new file mode 100644 |
| index 000000000..48ea392c5 |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-agent-start-demo-log-skip.tsv |
| @@ -0,0 +1,17 @@ |
| +# Census overlay agent-start-demo-log-skip, written by census-propose (#369). census-ruling-agent-start-demo-log-skip, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-agent-start-demo-log-skip.md. |
| +# 0 body, 5 sites, 2 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +# 1 new dispositions: 0 reads re-frozen at their disposition with the claim, 1 new units frozen accepted-legacy, 0 quiet units retired while they read nothing, 0 other. |
| +@legacy fbd5a95444ad7bd39f5593e35adb5df5850f952810743fad833727cb9b9733ed internal/edge/analytics.go Edge.demoUnrecorded legacy accepted-legacy accepted-legacy;rev3=census-ruling-agent-start-demo-log-skip;basis=new, replaces demoAnalyticsRefused: true for rt.IsDemo(), or a route or request Host that demoAuthority/demoReserved name as a reserved demo host, compared against already-loaded demo config; pure predicate, opens, runs or follows nothing; its only effect at every caller is to skip recording registry:Host@134 3200dcd9e2e2ed30df1c0d841ace2ed6856e32f98bf77b3ddc2e3e498bb01f33 |
| +@legacy cedb006e7a396ea0a4b84a106c364fb40c994054ee0a2a605df0c3dd7c93a080 internal/edge/analytics.go Edge.analyticsEnabled legacy accepted-legacy accepted-legacy;rev3=J1;basis=root-route;rev3=census-ruling-agent-start-demo-analytics-fix;basis=analytics.go:61-63 returns false for rt.IsDemo() or a reserved demo route Host (new read registry:Host, compared against already-loaded demo config); can only disable analytics, opens or follows nothing.;rev3=census-ruling-agent-start-demo-log-skip;basis=the demo refusal moves into demoUnrecorded(rt, nil): same rt.IsDemo() and reserved rt.Host checks over already-loaded demo config; can only disable analytics; no new read, open or follow registry:App@210,whole:Route@202,whole:Route@79 ed60707f5b608d9cf2439f5513e1407571bf5feb7107ac9944511405a192f87a |
| +@legacy 7acf89be63e802cfc65506cd07982fae5932f556f2dd806991954b30cbda15b4 internal/edge/analytics.go Edge.observeAnalytics legacy accepted-legacy accepted-legacy;rev3=J1;basis=root-route;rev3=census-ruling-agent-start-demo-analytics-fix;basis=analytics.go:121 also refuses requests whose Host is a reserved demo name (demoAuthority/demoReserved over already-loaded demo config); only suppresses an observation, no new read, open or follow.;rev3=census-ruling-agent-start-demo-log-skip;basis=the reserved r.Host refusal moves into demoUnrecorded(rt, r); same checks; only suppresses an observation; no new read registry:App@769,registry:Host@783,whole:Route@173,whole:Route@197,whole:Route@759 02ce2d28d86ab307ebc608e04e869147d4941210c250e92ebf68e5b4fbf9274d |
| +@legacy f763fb6fb31d7ef58ef46d48dc1f563f5ed5591a1048e33d18c4ea0b1fed0897 internal/edge/edge.go Edge.emitEdgeError legacy accepted-legacy accepted-legacy;rev3=J1;basis=root-route;rev3=census-ruling-agent-start-demo-log-skip;basis=returns early when demoUnrecorded(rt, r): files no edge error record for a demo; only suppresses an in-memory record; no new read registry:App@748,registry:Host@323,registry:Version@497,whole:Route@169,whole:Route@743 47278262d96c349af5439b2665995ece77327ae5eed6621f5c9ec0f01e285c23 |
| +@legacy b53f0c7ee96d2a09c6dff62344d0df0b9fd5927119b7b603790323c228131a27 internal/edge/guard.go Edge.noteBurst legacy accepted-legacy accepted-legacy;rev3=census-ruling-probe-burst-limit;basis=new: in the observer defer, counts a not-found (a 404, or a hard or probe match) from a non-browser client (no Sec-Fetch-Mode) toward the in-memory probe-burst limiter, keyed by the route's account/app; on a trip mints a reference code, files a Trip record into the in-memory recorder and queues notices to peer edges; the sites are the route value passed in; reads no file, store or registry; no new root read or write kind;rev3=census-ruling-agent-start-demo-log-skip;basis=skips only the in-memory Trip record when demoUnrecorded(rt, r); cooling, the limiter and peer notices are unchanged; no new read whole:Route@502,whole:Route@670,whole:Route@728 e0d899364656df07bd1e5c80f33036cdcbfcf0cbf377f2cf4b9f815592c1fb2f |
| +@legacy 50f0008ea391521c63e6633fe2a8d0339e844e3542a6b8251f3477a37d35a5ae internal/edge/reqrecords.go Edge.observeRecords legacy accepted-legacy accepted-legacy;rev3=census-ruling-edge-request-records;identity=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=new: called from ServeHTTP's observer defer after observeAnalytics, with the route the defer already holds; returns at once when no recorder is wired or the request arrived over a tunnel (the forwarding box records it); otherwise builds the Response through requestResponse from that route and the request and hands it to the in-memory recorder, which files it into the box's log sink; its one scanned site is the route value passed in; it reads no file, no store and no box state, writes nothing outside the log sink, and makes no serving or root decision; the class of Edge.observeAnalytics (J1 root-route);rev3=census-ruling-edge-protection-2;basis=files one reqrec.Match in place of the Response when the request's outcome carries a guard verdict (kind block or watch, the verdict's rule tier, id, fragment and reference code; a block woke nothing), and the plain Response otherwise; still in-memory, its one scanned site is the route value passed in; no read added;rev3=census-ruling-probe-burst-limit;basis=the Match it files also carries the verdict's cool-down start and end (CooldownFrom, CooldownUntil, set only for the burst rule); RequestRecorder gains Trip; still in-memory into the log sink, the same one route site; no new root read or write kind;rev3=census-ruling-agent-start-demo-log-skip;basis=returns early when demoUnrecorded(rt, r): files no Response or Match for a demo; only suppresses an in-memory record; no new read whole:Route@185,whole:Route@518 227945c07eff2dfbbf03f5304cd492723ecd2082f238482ac35403e194cbc0fa |
| +internal/edge/analytics.go Edge.demoUnrecorded legacy accepted-legacy accepted-legacy;rev3=census-ruling-agent-start-demo-log-skip;basis=new, replaces demoAnalyticsRefused: true for rt.IsDemo(), or a route or request Host that demoAuthority/demoReserved name as a reserved demo host, compared against already-loaded demo config; pure predicate, opens, runs or follows nothing; its only effect at every caller is to skip recording registry:Host@134 3200dcd9e2e2ed30df1c0d841ace2ed6856e32f98bf77b3ddc2e3e498bb01f33 |
| +internal/edge/analytics.go Edge.analyticsEnabled legacy accepted-legacy accepted-legacy;rev3=J1;basis=root-route;rev3=census-ruling-agent-start-demo-analytics-fix;basis=analytics.go:61-63 returns false for rt.IsDemo() or a reserved demo route Host (new read registry:Host, compared against already-loaded demo config); can only disable analytics, opens or follows nothing.;rev3=census-ruling-agent-start-demo-log-skip;basis=the demo refusal moves into demoUnrecorded(rt, nil): same rt.IsDemo() and reserved rt.Host checks over already-loaded demo config; can only disable analytics; no new read, open or follow registry:App@210,whole:Route@202,whole:Route@79 ed60707f5b608d9cf2439f5513e1407571bf5feb7107ac9944511405a192f87a |
| +internal/edge/analytics.go Edge.observeAnalytics legacy accepted-legacy accepted-legacy;rev3=J1;basis=root-route;rev3=census-ruling-agent-start-demo-analytics-fix;basis=analytics.go:121 also refuses requests whose Host is a reserved demo name (demoAuthority/demoReserved over already-loaded demo config); only suppresses an observation, no new read, open or follow.;rev3=census-ruling-agent-start-demo-log-skip;basis=the reserved r.Host refusal moves into demoUnrecorded(rt, r); same checks; only suppresses an observation; no new read registry:App@769,registry:Host@783,whole:Route@173,whole:Route@197,whole:Route@759 02ce2d28d86ab307ebc608e04e869147d4941210c250e92ebf68e5b4fbf9274d |
| +internal/edge/edge.go Edge.emitEdgeError legacy accepted-legacy accepted-legacy;rev3=J1;basis=root-route;rev3=census-ruling-agent-start-demo-log-skip;basis=returns early when demoUnrecorded(rt, r): files no edge error record for a demo; only suppresses an in-memory record; no new read registry:App@748,registry:Host@323,registry:Version@497,whole:Route@169,whole:Route@743 47278262d96c349af5439b2665995ece77327ae5eed6621f5c9ec0f01e285c23 |
| +internal/edge/guard.go Edge.noteBurst legacy accepted-legacy accepted-legacy;rev3=census-ruling-probe-burst-limit;basis=new: in the observer defer, counts a not-found (a 404, or a hard or probe match) from a non-browser client (no Sec-Fetch-Mode) toward the in-memory probe-burst limiter, keyed by the route's account/app; on a trip mints a reference code, files a Trip record into the in-memory recorder and queues notices to peer edges; the sites are the route value passed in; reads no file, store or registry; no new root read or write kind;rev3=census-ruling-agent-start-demo-log-skip;basis=skips only the in-memory Trip record when demoUnrecorded(rt, r); cooling, the limiter and peer notices are unchanged; no new read whole:Route@502,whole:Route@670,whole:Route@728 e0d899364656df07bd1e5c80f33036cdcbfcf0cbf377f2cf4b9f815592c1fb2f |
| +internal/edge/reqrecords.go Edge.observeRecords legacy accepted-legacy accepted-legacy;rev3=census-ruling-edge-request-records;identity=the edge inside the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=new: called from ServeHTTP's observer defer after observeAnalytics, with the route the defer already holds; returns at once when no recorder is wired or the request arrived over a tunnel (the forwarding box records it); otherwise builds the Response through requestResponse from that route and the request and hands it to the in-memory recorder, which files it into the box's log sink; its one scanned site is the route value passed in; it reads no file, no store and no box state, writes nothing outside the log sink, and makes no serving or root decision; the class of Edge.observeAnalytics (J1 root-route);rev3=census-ruling-edge-protection-2;basis=files one reqrec.Match in place of the Response when the request's outcome carries a guard verdict (kind block or watch, the verdict's rule tier, id, fragment and reference code; a block woke nothing), and the plain Response otherwise; still in-memory, its one scanned site is the route value passed in; no read added;rev3=census-ruling-probe-burst-limit;basis=the Match it files also carries the verdict's cool-down start and end (CooldownFrom, CooldownUntil, set only for the burst rule); RequestRecorder gains Trip; still in-memory into the log sink, the same one route site; no new root read or write kind;rev3=census-ruling-agent-start-demo-log-skip;basis=returns early when demoUnrecorded(rt, r): files no Response or Match for a demo; only suppresses an in-memory record; no new read whole:Route@185,whole:Route@518 227945c07eff2dfbbf03f5304cd492723ecd2082f238482ac35403e194cbc0fa |
| +@coverage internal/edge 1e9811add3eed53ba482fa3b1df10835593ed251bdb36adf97ee38dc30fc167e |
| +@coverage internal/host ec2bc0ece41c9692d83cf9a0c57bc32b978438f14854de8fa56f2dc3f3768cb0 |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index 7614e4702..480300f00 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -100,3 +100,4 @@ plan14-root-reads-region-ha-g2-t8.tsv 05f08edeb46837a18f1abca302ad21d8c7782edef8 |
| plan14-root-reads-region-ha-g2-t3.tsv 6462853d58331c23d0b2f9ee3b52ccec5198b061d864cc97ba6e7b931017f02a |
| plan14-root-reads-region-ha-p3b2-ops.tsv f9a2c93d8237229de3623f097004da568ab0cb70a499bb3526b7249efde0f3cd |
| plan14-root-reads-agent-start-demo-analytics-fix.tsv 89841c50d08090185e24cb03c6bb4878ab8a4ccb84b7d2f0113f88b617df8026 |
| +plan14-root-reads-agent-start-demo-log-skip.tsv ed24b69243622fc702159e0b22c732f4f8297438b87f10c499887cd1a13f6fce |