carlos / platform Public

agent-start-demo-analytics-fix

Written by claude agent, operated by paul@keymail.dev — this branch has no commits of its own to compare against, so how current this is cannot be said

Where it stands

MERGED 7d0f26c (squash), not released. Dev restored 2026-11-05: orphan key deleted (evidence copy kept), demo serving ON since 13:52:42Z, create-to-live checked, then the check demo was taken down cleanly; no demos are live. The race can recur on dev at a takedown or expiry until a release with the fix lands there. P3 follow-ups are on #527.

Next

Paul to choose on #527: dev-only release with 7d0f26c, or wait for the next release. After a release reaches dev, the race is closed.

Blocked on

No release cut (not authorised).

Already decided

Merged 7d0f26c; dev orphan key deleted, serving on, create-to-live 21 s, check demo taken down cleanly, apps/bad empty.

Recently

Human

<task-notification> <task-id>b0vv02o3u</task-id> <tool-use-id>toolu_01B15ZmuZUPcfeV3X4RQzN9X</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/6bd32d2d-ae23-41f7-b6a2-b09daa00e055/tasks/b0vv02o3u.output</output-file> <status>completed</status> <summary>Background command "for i in $(seq 1 40); do o=$(carlos system demos takedown-status --host serene-orchid-33.dev.trycarlos.com --console https://platform.dev.carlosframework.com 2&gt;&amp;1); echo "$o" | grep -q "Cleanup: Complete" &amp;&amp; break; sleep 30; done; echo "$(date -u +%H:%M:%SZ) $o"; curl -sS -o /dev/null -w "host GET %{http_code}\n" https://serene-orchid-33.dev.trycarlos.com/; aws --profile kass s3 ls s3://carlos-dev-640012953448/apps/bad/ --recursive; echo "list1 done"; sleep 420; date -u +%H:%M:%SZ; aws --profile kass s3 ls s3://carlos-dev-640012953448/apps/bad/ --recursive; echo "list2 done"" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>bkczqfafl</task-id> <tool-use-id>toolu_01Vc2B3tgXKxwPGnDFKaaGqz</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/6bd32d2d-ae23-41f7-b6a2-b09daa00e055/tasks/bkczqfafl.output</output-file> <status>completed</status> <summary>Background command "sleep 60; until s=$(amadan ci status -branch agent-start-demo-analytics-fix 2&gt;&amp;1 | head -1); echo "$s" | grep -q "f95407e80" &amp;&amp; echo "$s" | grep -qi "passed\|failed"; do sleep 60; done; echo "$s"" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>bhzqzgjz8</task-id> <tool-use-id>toolu_01GxJLfy7mLQjhFghsMP3Pvu</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/6bd32d2d-ae23-41f7-b6a2-b09daa00e055/tasks/bhzqzgjz8.output</output-file> <status>completed</status> <summary>Background command "amadan task set 581 -status Done &gt;/dev/null; amadan task advance 582 &gt;/dev/null; until s=$(amadan ci status -branch agent-start-demo-analytics-fix 2&gt;&amp;1 | head -1); echo "$s" | grep -q "d1fa80575" &amp;&amp; ! echo "$s" | grep -qi "running\|pending\|queued"; do sleep 60; done; echo "$s"" completed (exit code 0)</summary> </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>

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>b2jbq0seo</task-id> <tool-use-id>toolu_01Tu2t988Rcf9PEvBpzmZq9o</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/6bd32d2d-ae23-41f7-b6a2-b09daa00e055/tasks/b2jbq0seo.output</output-file> <status>completed</status> <summary>Background command "D=/home/paulca/.cache/tmp/claude-1001/afix; until [ -f $D/impl.done ]; do sleep 30; done; tail -40 $D/impl.log" completed (exit code 0)</summary> </task-notification>

Human

<paseo-system version="1" kind="agent-message" source-agent-id="5091b1c1-8f89-4a10-bf62-f18243c7edb8" message-id="91aa2b7f-81fe-4d9f-82cd-7b064ab669d6" source-agent-title="agent-start-demo analytics fix"> CRITICAL: Paseo output reports wrong cwd. ALL reads/edits/commands must explicitly use /home/paulca/amadan.net/carlos/platform/.claude/worktrees/agent-start-demo-analytics-fix as workdir. Do not edit main checkout /home/paulca/amadan.net/carlos/platform. Confirm pwd and git branch agent-start-demo-analytics-fix before work. If any edits happened outside the requested worktree, report and revert only your own exact edits there. </paseo-system>

Human

<paseo-system version="1" kind="agent-message" source-agent-id="5091b1c1-8f89-4a10-bf62-f18243c7edb8" message-id="a96d6303-e43d-4b3e-8016-bbf5b4e351ce" source-agent-title="agent-start-demo analytics fix"> CRITICAL: Paseo output reports wrong cwd. ALL reads/edits/commands must explicitly use /home/paulca/amadan.net/carlos/platform/.claude/worktrees/agent-start-demo-analytics-fix as workdir. Do not edit main checkout /home/paulca/amadan.net/carlos/platform. Confirm pwd and git branch agent-start-demo-analytics-fix before work. If any edits happened outside the requested worktree, report and revert only your own exact edits there. </paseo-system>