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.devc4258467c5cd63774db5bd4319e791bf27e2dc94parent afab0c5
<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 >= ?||'.' AND host < ?||'/'`, 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>