carlos / platform Public

Skip demo apps in the log/error prune; doc demoUnrecorded

Review R1 (Opus, READY) P3s 2 and 3: the hourly chunk prune no longer
lists demo apps whose chunks are never shipped, and demoUnrecorded gets
its doc comment back. R1 findings recorded.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev c4258467c5cd63774db5bd4319e791bf27e2dc94 parent afab0c5
6 files changed, +36 −5
  • docs/superpowers/reviews/REVIEW-FINDINGS-agent-start-demo-log-skip-R1.md +18 −0
  • internal/edge/analytics.go +6 −0
  • internal/host/errship.go +2 −2
  • internal/host/errship_test.go +3 −0
  • internal/host/logship.go +4 −3
  • internal/host/logship_test.go +3 −0

Intent

Human

<task-notification> <task-id>a7318eba4d0e439bc</task-id> <tool-use-id>toolu_018cFWkLHjRcDm7qkWeVCh2n</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/6875c1aa-b47e-417d-b474-a1a48165ae5e/tasks/a7318eba4d0e439bc.output</output-file> <status>completed</status> <summary>Agent "Opus review R1 log-skip" 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># Review R1: agent-start-demo-log-skip (diff ddbc0297..3f542e3b) I read the diff and the code around it, and checked every claim in the brief against the code. I edited nothing. My scratch directory is deleted. Files already in `asd-logskip/` belong to someone else and I left them alone. ## Verification - **`go vet`** on edge, host and console: clean. - **edge** (`-run 'TestRecordsAndErrors|Analytics|Demo'`): passed. - **host** (`-run 'Logship|Errship'`): passed. - **console** (`-run Demo`): every test in the changed files passed. These are `TestDemoAdmissionPurgedStrays`, `TestDemoPurgeStraysAndLateFlush`, `TestPurgedDemoAppTombstoneName` and `TestDemoPurgeRecoveryInterruptedWrites`, including the new "purge marker after logs/errors" cases. - Three tests failed: `TestDemoSourceToLiveAndUpdate`, `TestDemoUsesRealReleasePathGET` and `TestDemoProtectionsSourceToLimitAndTakedown`. Each failed while its fixture was starting, with `listen unix ...sock: socket: operation not permitted`. The sandbox refuses Unix sockets under my scratch TMPDIR, so the cause is the environment, not this diff. - I did not rerun them under `/tmp/g`, which is where they normally run, because the brief limits scratch to my own directory. CI should confirm them. ## Checks against the brief **1. Edge (`demoUnrecorded`)** - Analytics behaviour is unchanged from 7d0f26cb: - `analyticsEnabled` still refuses `rt.IsDemo()` or a reserved `rt.Host`. - `observeAnalytics` still adds the reserved `r.Host` check. - Every request record and error record goes through a guarded function: - `observeRecords` is called from `edge.go:2381`, `demo_traffic.go:215` and `assetcatch.go:1163`. - `emitEdgeError` is called from `edge.go:2378` and `demo_traffic.go:212`. - The only direct `Trip` call is `guard.go:326`, which is now guarded. - No path in activator, wake or tunnel bypasses these guards. - In `guard.go`, only the `Trip` record is skipped. The cooling state and `sendBurstNotices` still run, and the test asserts that cooling still happens for demo routes. - `r` is never nil at the `emitEdgeError` and `noteBurst` call sites. **2. Shippers** - Both drop on `k.App` with the `tmp-demo-` prefix (`logship.go:120`, `errship.go:76`). - That prefix is reserved for every account (`reservedAppName`, `server.go:5296`), so no ordinary app is affected. - Records are dropped at flush, not kept for retry, so nothing loops or builds up beyond the existing pending cap. - The only writers of `logs/` and `errors/` chunks are these two shippers, via `applog.ChunkKey` and `apperr.ChunkKey`. **3. Console** - `demoStrayPath` is used at all three sites: admission `apidemo.go:212`, resumed purge `demo_expiry.go:214`, and the sweep `demo_expiry.go:349`. - Admission still refuses a real orphan: - Any key with an apps row that is not a demo is refused. - So is any key that is not a stray family; the test covers `manifest.json`, `logs-other/` and `errors-other/`. - Strays are refused when no purge evidence exists (the "unpurged", "no history" and "other account" states). - The resumed purge still returns `errNoMarker` for any key outside the stray families. - The sweep only deletes when it holds `lockApp`, the app has no apps row, and `purgedDemoApp` is true. **4. Tombstone match by first label** - `substr(host,1,instr(host,'.')-1)` compares the whole first label exactly: - Names that are prefixes or suffixes of other names don't match. - A host with no dot gives an empty string, which never equals a valid name. - Tests cover all of these cases. - The one behaviour change is that the "other domain" state now passes admission. That is safe because live demos insert their apps row in the same transaction as `demo_apps` (`demo_store.go:254-269`). Admission and the sweep only reach this check when there is no apps row, and then only for stray families. - The worst case is that admission ignores, or the sweep deletes, analytics, logs or errors under a demo name that was once purged. Those are exactly the families the scope ruling says to drop. **5. Tests** - The edge tests prove a demo request produces no response, match, trip or error record. They cover all four demo route fields and the reserved host forms (mixed case, trailing dot, port, apex). - An ordinary app still produces one record of each kind, before and after the demo checks. - The shipper tests use the real gather and flush. Only `apps/bab/web/logs/` and `apps/bab/web/errors/` land, and demo buckets drop even when the store is failing. - The console paths match the real key shapes, and `demoStrayPath` only checks the family prefix anyway. ## Findings **P1:** none. **P2:** none. **P3** (follow-up list): 1. **Tombstone query can't use the index.** - Evidence: `demo_store.go:467` applies `substr(...)` to every row of `demo_host_tombstones`. That table only grows: one row per demo ever made, never pruned. Admission calls `purgedDemoApp` once per stray key, not once per app (`apidemo.go:213`), inside a 10 s timeout. - Scenario: a large tombstone table combined with a backlog of stray keys left from before the roll could push admission toward its deadline. Today this is small. - Fix: use a range on the primary key, `host &gt;= ?||'.' AND host &lt; ?||'/'`, and/or cache the answer per app inside `validateDemoAdmissionState`. - Fault family: per-key work against an unbounded table. 2. **Hourly prune still LISTs for demo apps.** - Evidence: `logshipKnownApps` / `errshipKnownApps` (`logship.go:146`, `errship.go:100`) still return `tmp-demo-` apps from `sink.Known()`. So `chunkPrune` does a ListDirs for each demo app, on each box, each hour, for both families, even though these boxes now never write chunks for them. - Scenario: wasted S3 requests, which cost money. - Fix: skip the `demo.AppPrefix` prefix in both functions. - Fault family: per-box polling that does nothing. 3. **`demoUnrecorded` has no doc comment.** - Evidence: `analytics.go:54`. The old comment ("reads only the demo config, so no switch map or call site can undo it") was dropped. - Fix: restore it, and add that the function now also covers request records, burst trips and edge errors, and why `r` may be nil. - Fault family: clarity. **Verdict: READY**</result> <usage><subagent_tokens>87229</subagent_tokens><tool_uses>24</tool_uses><duration_ms>579692</duration_ms></usage> </task-notification>

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/edge/analytics.go b/internal/edge/analytics.go
index 49cd8ad56..4618e28ac 100644
--- a/internal/edge/analytics.go
+++ b/internal/edge/analytics.go
@@ -51,6 +51,12 @@ func (e *Edge) SetAnalyticsOn(on map[string]bool) {
e.analyticsOn.Store(&cp)
}
+// 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
diff --git a/internal/host/errship.go b/internal/host/errship.go
index 4bf39aa48..2d2aede3d 100644
--- a/internal/host/errship.go
+++ b/internal/host/errship.go
@@ -101,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 ef3966536..3bd6ae8ad 100644
--- a/internal/host/errship_test.go
+++ b/internal/host/errship_test.go
@@ -19,6 +19,9 @@ func TestErrshipFlushDropsDemoApps(t *testing.T) {
}
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)
diff --git a/internal/host/logship.go b/internal/host/logship.go
index 8dcb494fa..7fa53a2df 100644
--- a/internal/host/logship.go
+++ b/internal/host/logship.go
@@ -142,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 5e0d670d2..9f47e7889 100644
--- a/internal/host/logship_test.go
+++ b/internal/host/logship_test.go
@@ -24,6 +24,9 @@ func TestLogshipFlushDropsDemoApps(t *testing.T) {
}
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)