carlos / platform Public

census 9B8: re-digest UpsertDay after the demo analytics guard

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev d1fa805750ecd486752c59a78d527586d01ac54f parent a76f053
1 file changed, +2 −1
  • internal/provision/plan9_b8_census_test.go +2 −1

CI passed — run details

Intent

Human

<task-notification> <task-id>af069ffdeab69da8e</task-id> <tool-use-id>toolu_01SUkkyqQFiRM3QsKEGUt4jC</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/6bd32d2d-ae23-41f7-b6a2-b09daa00e055/tasks/af069ffdeab69da8e.output</output-file> <status>completed</status> <summary>Agent "Opus review analytics fix R1" 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.** I found no P1 or P2 problems. The fix does what the brief asks, the new tests fail without it, and the census needs no card. **Tests** - `go test ./internal/analytics/ ./internal/edge/ -run 'Analytics|Demo|Observ|UpsertDay'` passes. - The four new or changed console tests passed three runs in a row with `-count=3`: `TestDemoAdmissionPurgedAnalytics`, `TestDemoPurgeAnalyticsAndLateFlush`, `TestDemoPurgeRecoveryInterruptedWrites` and `TestDemoReport*`. - The wider `./internal/console -run Demo` run had three failures, all from the sandbox: `TestDemoSourceToLiveAndUpdate`, `TestDemoUsesRealReleasePathGET` and `TestDemoProtectionsSourceToLimitAndTakedown` failed with "listen unix …sock: socket: operation not permitted". ## Checks 1. **Edge guard.** Only two places record analytics: `edge.go:2380` and `demo_traffic.go:214`. Both go through `observeAnalytics`, and so through `analyticsEnabled`. - Every demo route is caught. Resident, forwarded and tunnelled demo routes all carry the demo marks, so `rt.IsDemo()` refuses them. - The request-host check covers an unmarked route reached through a demo host. - Ordinary apps are unaffected. `demoReserved` is false when the demo domain is empty (`demo.go:138-141`). When the domain is set, `demoRouteOK` already refuses ordinary routes on demo hosts, so no real app is served from that domain. 2. **`UpsertDay` guard.** It is the only writer of analytics day files (`usage_loop.go:33`). The `tmp-demo-` prefix is refused for every account at create and rename (`server.go:5295`, `appsettings.go:878`). `internal/demo` imports no other platform package, so there is no import cycle or cross-compile concern. 3. **Admission.** The skip applies only when the key path starts with `analytics/`, the app has no row (`life == nil`), and either a purged `demo_apps` row matches the demo account and app, or a purged host tombstone matches. Any error refuses admission. - The host match is right: `ReserveDemo` requires the host to be name + "." + domain (`demo_store.go:210`), and `finishDemoPurge` stores `d.Host` (`demo_expiry.go:307`). - Names are never reused: reserving counts existing tombstones for the host (`demo_store.go:241`). - The test covers `analytics-other/` and `manifest.json`, which are still refused. 4. **Purge paths.** - The resumed-purge branch runs under the app lock already held, and deletes only `analytics/` keys. - The hourly sweep: - skips HostClaim consoles, as the trash sweep does; - makes one paginated LIST of the demo account per hour; - deletes only listed `analytics/` keys, under `lockApp`, after re-checking that the app has no row and its demo was purged. - The sweep runs from a deferred `trashSweep`, so no other lock is held while it takes the app lock. - When the seven-day history is wiped, the permanent host tombstone still matches. The "history wiped" test covers this. 5. **Tests.** They use the exact key from the incident, and each would fail without its part of the fix: the admission test expects a pass where the old code refused, the late-flush test expects the key deleted, and the edge and `UpsertDay` tests check for zero observations and zero store calls. The test that asserts exactly two LISTs held across three runs. 6. **Report form.** `maxlength="1000"` matches the server's `len(details) &gt; 1000` check (`demo_reports.go:113`), and the test checks it. **Census.** `make census-card` reports "Nothing to approve: the census is clean (seal `82c82c7f…`)". No card is needed. ## P3 (follow-up only) - **Logs and errors can cause the same refusal.** Edge logs, request records and error records are written under `apps/&lt;acct&gt;/&lt;app&gt;/logs/` and `errors/` (`applog/chunk.go`, `apperr/read.go`). They ship every 10 seconds and keep pending records through failed uploads (`host/logship.go`). A retry that lands after the purge would block admission the same way, and the skip only covers `analytics/`. It fails safe (admission refuses), but it is the same kind of outage. Fix: skip demo routes in `observeRecords` and `emitEdgeError`, or widen the skip to those families if this ever happens. - **Possible older apps named `tmp-demo-*`.** That prefix has been refused only since 11dadb7a (2026-11-03), but users could name temporary apps from 2026-10-24. An app named `tmp-demo-*` created in that window would now silently lose analytics. Fix: before the roll, query the console database for app names starting with `tmp-demo-` that have no `demo_id`. - **The tombstone match depends on today's demo domain.** If `CARLOS_DEMO_DOMAIN` changes and a demo's seven-day history has been wiped, its leftover analytics keys are no longer recognised. Admission then refuses, which fails safe. Fix: a comment is enough. - **Character count versus bytes.** `maxlength` counts characters (UTF-16 units) but the server counts bytes, so 1,000 non-ASCII characters can still be refused. The server error path handles it; this only matters if the error copy reads as "too long" when the counter shows room. Files: `internal/edge/analytics.go`, `internal/analytics/day.go`, `internal/console/apidemo.go`, `internal/console/demo_store.go`, `internal/console/demo_expiry.go`, `internal/console/lifetimes_purge.go`, `internal/console/templates/demo_report.html` (all under `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/agent-start-demo-analytics-fix/`). **READY**</result> <usage><subagent_tokens>93777</subagent_tokens><tool_uses>35</tool_uses><duration_ms>684687</duration_ms></usage> </task-notification>

Human

<task-notification> <task-id>af069ffdeab69da8e</task-id> <tool-use-id>toolu_01XNvaan6gg5gWZRLoCMjzm9</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/6bd32d2d-ae23-41f7-b6a2-b09daa00e055/tasks/af069ffdeab69da8e.output</output-file> <status>completed</status> <summary>Agent "Opus review analytics fix R1" 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>**APPROVE** on all four: both units and both re-pinned envelopes. I read the card at a76f053d, its overlay, and the diff from d6551338. The criteria I checked against are AGENTS.md lines 342-350 and the card's "Reject if" paragraph. None of the four changes lets root open, run, query or follow anything new, and none weakens a check. - **`Edge.observeAnalytics`: APPROVE.** The only change is one extra early-return condition, `|| e.demoAnalyticsRefused(r.Host)` at `internal/edge/analytics.go:121`. - `demoAnalyticsRefused` (`analytics.go:56-59`) calls two helpers that only work on strings. `demoAuthority` (`demo.go:20-52`) uses `net.SplitHostPort`, lowercasing and trimming, and `demo.ValidDomain`. `demoReserved` (`demo.go:138-141`) compares the host against `e.demo.Domain`. - `e.demo` comes from the process environment, set once when the edge is built (`edge.go:576` → `demoEdgeConfig`, `demo.go:129-131`). A tenant, app or box agent cannot write it. - The request host was already in hand at this point and was already an input. Using it here can only skip an observation. Nothing new is opened, read from a file, queried or followed. - The disposition stays accepted-legacy with basis root-route (J1), and the change does not conflict with it. - **`Edge.analyticsEnabled` (new reads disposition `+registry:Host`): APPROVE.** - The added lines 62-64 return false when `rt.IsDemo()` is true (`registry/demo.go:5-7`, which only compares fields) or when `demoAnalyticsRefused(rt.Host)` is true. - The new read is `rt.Host`, a field of a route the function already receives. The overlay records exactly that as `registry:Host@100`, so the disposition matches the unit's reads. - The change can only turn analytics off. It loosens no check. - **Envelope `internal/analytics`: APPROVE.** - The only changed function outside tests is `UpsertDay` (`day.go:186-190`). It adds a prefix check on the app name that returns nil before any store `Get` or `Put`. That removes a write and adds no read. - The new import, `internal/demo`, only brings in a string constant. `go list -deps ./internal/demo` shows it pulls in no other platform package and no cgo. - **Envelope `internal/edge`: APPROVE.** Outside tests, the only changes in the package are in `analytics.go`: the new `demoAnalyticsRefused` and the two units above. What they call (`demoAuthority`, `demoReserved`, `IsDemo`) is pure string work over configuration loaded at startup. The overlay rows match the card. The chain line moves the seal from `6462853d…` to `82c82c7f…`, and `make census-card` reports the census clean at that seal. **Overall review verdict (unchanged): READY**</result> <usage><subagent_tokens>99811</subagent_tokens><tool_uses>37</tool_uses><duration_ms>714651</duration_ms></usage> </task-notification>

Attributed to this commit: 16.6 g CO₂e (1,923,023 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-analytics-fix, 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/provision/plan9_b8_census_test.go b/internal/provision/plan9_b8_census_test.go
index 5e26c812d..a490b7d24 100644
--- a/internal/provision/plan9_b8_census_test.go
+++ b/internal/provision/plan9_b8_census_test.go
@@ -661,7 +661,8 @@ var plan9B8CensusInventory = []censusEntry{
{"internal/registry/aliassocket.go", "LayoutSibling", "key-site", "lit:instances", "675ab91403b73f0ce0a492d1ae09067d62e41ab202c20714b236501860d8435c"},
{"internal/activator/paths.go", "ExecBackend.pathsFor", "key-site", "lit:instances", "cbc01865e27934cb38baab9329a0867b899149531b4706a533a6956afc7c71b3"},
// Re-digested for fix-empty-app-key (census-ruling-fix-empty-app-key, platform-1e 2026-10-16): DayKey now returns an error for an empty or invalid account, app, box or date, and UpsertDay returns it before any Get or Put. Same single Put of the app-day file; no record key.
- {"internal/analytics/day.go", "UpsertDay", "nonrecord", "sel:Put", "ab892656cdbce1c80f0c33441341cf9c94dd22f06716ffffbd6c025100adb1b8"},
+ // Re-digested for agent-start-demo-analytics-fix (Opus review, 2026-11-05): UpsertDay returns nil for a tmp-demo- app before any Get or Put, so demo buckets are dropped. One fewer write; same single Put otherwise; no record key.
+ {"internal/analytics/day.go", "UpsertDay", "nonrecord", "sel:Put", "07ba80aec076d8449b1ac3c698fd755cc88eb993bd21f7f28f4e353dc595355c"},
{"internal/appconfig/configack.go", "WriteConfigAck", "nonrecord", "sel:Put", "211c8417bdbd6c6721fc503db085e9df073adeba623d9daa1e226554760ef5d1"},
{"internal/appconfig/generation.go", "claimRawTouchGeneration", "nonrecord", "sel:Put", "313a5de17aee1b9ed6a344f6b785637c6978b60552a2243ef208c28eb8401a02"},
{"internal/appconfig/store.go", "applyAt", "nonrecord", "sel:Put", "d234e359f44951240e6c052d87a17587845fb263ef9499dae39dae6c5c763e47"},