console analytics: Astra round 1 fixes
- P1: seedTime is the start of the current UTC hour, not midday, so the chart assertions hold before noon (future hours are not drawn). - P2: the Overview waits at most 250 ms past the rest of the page for the traffic card, then shows it as still loading (TestOverviewTrafficCardSlowRead). - P2: Dropped.Flush counts discarded batches, so the note says some counts are missing without a number. - P2: bots are excluded from page views and visitors, not data served. - P2: restart notes no longer promise a five-minute bound. Findings: docs/superpowers/reviews/CODEX-FINDINGS-console-analytics-ui-R1.md
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/superpowers/reviews/CODEX-FINDINGS-console-analytics-ui-R1.md+18 −0internal/console/analyticsdisplay.go+8 −7internal/console/analyticsdisplay_test.go+25 −0internal/console/analyticsview.go+9 −3internal/console/apianalytics_test.go+5 −2internal/console/server.go+15 −6internal/console/templates/app_analytics.html+2 −2internal/console/templates/app_overview.html+4 −2
CI cancelled — superseded by a newer push — run details
Intent
<task-notification> <task-id>b040yw1js</task-id> <tool-use-id>toolu_01CrYuSn2gVYpayfVsbHHu9X</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ce90495f-c7a7-490e-9b84-a6251050e87f/tasks/b040yw1js.output</output-file> <status>completed</status> <summary>Monitor "Astra branch review round 1" stream ended</summary> <event>review finished loss warnings must reflect retry and restart behavior. Twelve targeted arithmetic/cache tests passed. HTTP tests compiled but could not execute because listening sockets are prohibited. No full suites or cross-platform builds ran. No files were edited; the working tree remains clean. **NOT READY**</event> </task-notification>
diff --git a/docs/superpowers/reviews/CODEX-FINDINGS-console-analytics-ui-R1.md b/docs/superpowers/reviews/CODEX-FINDINGS-console-analytics-ui-R1.md| new file mode 100644 |
| index 000000000..3a69eaaad |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/CODEX-FINDINGS-console-analytics-ui-R1.md |
| @@ -0,0 +1,18 @@ |
| +1. **P1 — CI: chart tests fail before noon UTC.** |
| + [seedTime](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/console-analytics-ui/internal/console/apianalytics_test.go:124) seeds today’s traffic at noon. The new chart excludes future hours and returns nil when no past hour has traffic ([analyticsdisplay.go:113](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/console-analytics-ui/internal/console/analyticsdisplay.go:113)). Before noon, `TestAppAnalyticsPage` and `TestAnalyticsTabOffStateKeepsCountedData` therefore fail their chart assertions. **Fix:** seed an elapsed hour or inject a fixed clock shared by fixtures and handlers. **Fault family:** time-independent test fixtures. Verified by tracing the code; HTTP execution was blocked by sandbox socket restrictions. |
| + |
| +2. **P2 — Overview: the traffic card can delay the entire page by two seconds.** |
| + The handler unconditionally waits at [server.go:4243](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/console-analytics-ui/internal/console/server.go:4243), before rendering. If other reads finish quickly but analytics stalls, the page waits for its two-second timeout, exceeding the stated GET budgets. The comment that only the card is delayed is false. **Fix:** bound the wait within the page’s remaining latency budget and render the unavailable state on timeout. **Fault family:** optional data must respect page latency limits. |
| + |
| +3. **P2 — Missing-count message uses the wrong unit.** |
| + [app_analytics.html:97](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/console-analytics-ui/internal/console/templates/app_analytics.html:97) describes `Dropped.Flush` as missing page views. [Meter.Requeue](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/console-analytics-ui/internal/analytics/meter.go:265) increments it once per discarded delta batch. Losing a batch containing 1,000 views produces “1 page view … missing”; an events-only batch can produce the same message. **Fix:** describe discarded batches and leave the lost page-view count unspecified. **Fault family:** displayed units must match stored counters. |
| + |
| +4. **P2 — Bot exclusion message incorrectly includes data served.** |
| + [app_analytics.html:96](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/console-analytics-ui/internal/console/templates/app_analytics.html:96) says bot requests are excluded from “these numbers,” but [meter.go:178](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/console-analytics-ui/internal/analytics/meter.go:178) includes their bytes. For example, the existing fixture’s bot contributes 500 bytes to data served. **Fix:** scope the exclusion statement to page views and visitors. **Fault family:** displayed claims must match aggregation semantics. |
| + |
| +5. **P2 — Restart notes promise an unsupported five-minute loss bound.** |
| + [analyticsdisplay.go:452](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/console-analytics-ui/internal/console/analyticsdisplay.go:452) and the chart tooltip say at most about five minutes may be missing. A failed flush is retained for retry; restarting before that retry loses both that batch and newly accumulated traffic. Multiple restarts can lose further windows. **Fix:** describe unsaved counts without a five-minute upper bound, including in tooltips. **Fault family:** loss warnings must reflect retry and restart behavior. |
| + |
| +Twelve targeted arithmetic/cache tests passed. HTTP tests compiled but could not execute because listening sockets are prohibited. No full suites or cross-platform builds ran. No files were edited; the working tree remains clean. |
| + |
| +**NOT READY** |
| \ No newline at end of file |
diff --git a/internal/console/analyticsdisplay.go b/internal/console/analyticsdisplay.go| index f94e4e4db..d9f1c8a0e 100644 |
| --- a/internal/console/analyticsdisplay.go |
| +++ b/internal/console/analyticsdisplay.go |
| @@ -102,7 +102,7 @@ func buildTrafficChart(rng string, sum analytics.Summary, now time.Time) *traffi |
| } |
| col.Lines = []string{pv, plural(d.Visitors, "visitor", "visitors"), humanBytes(d.Bytes) + " served"} |
| if d.Restarted { |
| - col.Lines = append(col.Lines, "The edge restarted that day. Up to about five minutes may be missing.") |
| + col.Lines = append(col.Lines, "The edge restarted that day. Some counts may be missing.") |
| } |
| c.Cols = append(c.Cols, col) |
| } |
| @@ -436,8 +436,9 @@ func analyticsSpanText(rng string, now time.Time) string { |
| } |
| // restartNote is the note for the days an edge restarted: the counts it |
| -// had not yet saved (a flush runs every five minutes) were lost, so those |
| -// days may read a little low. Up to three days are named; more are counted. |
| +// had not yet saved were lost, so those days may read low. No bound is |
| +// given: a flush runs every five minutes, but a failed flush is held for |
| +// the next one, so a restart can lose more than one window. Up to three days are named; more are counted. |
| func restartNote(days []analytics.DaySummary) string { |
| var hit []string |
| for _, d := range days { |
| @@ -449,12 +450,12 @@ func restartNote(days []analytics.DaySummary) string { |
| case n == 0: |
| return "" |
| case n == 1 && len(days) == 1: |
| - return "The edge restarted today. Up to about five minutes of counts may be missing." |
| + return "The edge restarted today. Counts it had not saved yet may be missing." |
| case n == 1: |
| - return "The edge restarted on " + hit[0] + ". Up to about five minutes of counts may be missing that day." |
| + return "The edge restarted on " + hit[0] + ". Counts it had not saved yet may be missing for that day." |
| case n <= 3: |
| - return "The edge restarted on " + strings.Join(hit[:n-1], ", ") + " and " + hit[n-1] + ". Up to about five minutes of counts may be missing on each day." |
| + return "The edge restarted on " + strings.Join(hit[:n-1], ", ") + " and " + hit[n-1] + ". Counts it had not saved yet may be missing for those days." |
| default: |
| - return fmt.Sprintf("The edge restarted on %d of these days. Up to about five minutes of counts may be missing on each day. Those days are marked under the chart.", n) |
| + return fmt.Sprintf("The edge restarted on %d of these days. Counts it had not saved yet may be missing for each of them. Those days are marked under the chart.", n) |
| } |
| } |
diff --git a/internal/console/analyticsdisplay_test.go b/internal/console/analyticsdisplay_test.go| index 2e8448813..1f83d3775 100644 |
| --- a/internal/console/analyticsdisplay_test.go |
| +++ b/internal/console/analyticsdisplay_test.go |
| @@ -265,3 +265,28 @@ func TestOverviewTrafficCard(t *testing.T) { |
| t.Error("overview (on) still says off, or has no link to the tab") |
| } |
| } |
| + |
| +// A slow analytics read costs the card, not the page: the Overview renders |
| +// once the grace runs out, with the card saying it is still loading. |
| +func TestOverviewTrafficCardSlowRead(t *testing.T) { |
| + fx, _ := instanceFixture(t, "code-analytics-overview-slow") |
| + seedAnalytics(t, fx, seedTime()) |
| + release := make(chan struct{}) |
| + defer close(release) |
| + fx.srv.cfg.Releases = &hookStore{Store: fx.rel, onGet: func(key string) { |
| + if strings.Contains(key, "/analytics/") { |
| + <-release |
| + } |
| + }} |
| + fx.setUser("paul@keymail.dev") |
| + c := newBrowser(t) |
| + signUp(t, fx, c, "code-analytics-overview-slow-browser") |
| + start := time.Now() |
| + status, _, body := get(t, c, fx.u("/apps/titogo")) |
| + if took := time.Since(start); took > overviewTrafficTimeout { |
| + t.Fatalf("overview took %v: it waited for the traffic read", took) |
| + } |
| + if status != http.StatusOK || !strings.Contains(body, "Traffic is still loading.") { |
| + t.Fatalf("overview = %d, want the card's still-loading line:\n%s", status, body) |
| + } |
| +} |
diff --git a/internal/console/analyticsview.go b/internal/console/analyticsview.go| index f647f152d..73ef41457 100644 |
| --- a/internal/console/analyticsview.go |
| +++ b/internal/console/analyticsview.go |
| @@ -267,9 +267,15 @@ const ( |
| range30d = "30d" |
| ) |
| -// overviewTrafficTimeout bounds the Overview's traffic card read. Past it |
| -// the card says the numbers could not be read; the page is not held up. |
| -const overviewTrafficTimeout = 2 * time.Second |
| +// overviewTrafficTimeout bounds the Overview's traffic card read, and |
| +// overviewTrafficGrace is how much longer than the rest of the page the |
| +// Overview waits for it (handleApp). A warm read takes a few GETs, well |
| +// inside the grace; a cold one past it shows the card as still loading, |
| +// and its settled days are in the cache for the next view. |
| +const ( |
| + overviewTrafficTimeout = 2 * time.Second |
| + overviewTrafficGrace = 250 * time.Millisecond |
| +) |
| func validRange(s string) bool { return s == rangeToday || s == range7d || s == range30d } |
diff --git a/internal/console/apianalytics_test.go b/internal/console/apianalytics_test.go| index 2c7c7dbf1..6abcf5a42 100644 |
| --- a/internal/console/apianalytics_test.go |
| +++ b/internal/console/apianalytics_test.go |
| @@ -120,8 +120,11 @@ func seedAnalytics(t *testing.T, fx *consoleFixture, when time.Time) { |
| } |
| } |
| -// seedTime is the stamp seedAnalytics uses — midday of the current UTC day. |
| -func seedTime() time.Time { return time.Now().UTC().Truncate(24 * time.Hour).Add(12 * time.Hour) } |
| +// seedTime is the stamp seedAnalytics uses: the start of the current UTC |
| +// hour, which is always today and never in the future. (Midday was in the |
| +// future every morning, and the chart does not draw hours that have not |
| +// happened.) |
| +func seedTime() time.Time { return time.Now().UTC().Truncate(time.Hour) } |
| func TestAPIAnalyticsSummary(t *testing.T) { |
| fx, token := instanceFixture(t, "code-analytics-api") |
diff --git a/internal/console/server.go b/internal/console/server.go| index 63761c9d3..e9a42a8fe 100644 |
| --- a/internal/console/server.go |
| +++ b/internal/console/server.go |
| @@ -2513,9 +2513,10 @@ type page struct { |
| AnalyticsRange string // "today" | "7d" | "30d" |
| AnalyticsErr string |
| // Traffic is the Overview's traffic card: the Analytics tab's 7-day |
| - // window, read the same way. nil when the read failed or timed out, |
| - // which costs the card its numbers, never the page. |
| - Traffic *analyticsWindow |
| + // window, read the same way; nil when the read failed. TrafficSlow: it |
| + // had not finished when the rest of the page was ready. |
| + Traffic *analyticsWindow |
| + TrafficSlow bool |
| // Action confirm interstitial (confirm.go): what is about to happen, |
| // carried fields and all. Nil everywhere except the confirm page. |
| @@ -4183,8 +4184,12 @@ func (s *Server) handleApp(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| app := p.Detail.App |
| - // The traffic card reads beside everything else this page reads, under |
| - // its own deadline, so a slow bucket delays nothing but the card. |
| + // The traffic card reads beside everything else this page reads. Once |
| + // the rest is ready the page waits at most overviewTrafficGrace more, |
| + // then renders the card as still loading: a slow bucket costs the card |
| + // its numbers, never the page its budget. The read is under the |
| + // request's context, so it stops when the handler returns, and the |
| + // channel is buffered, so a late result is dropped, not leaked. |
| traffic := make(chan *analyticsWindow, 1) |
| go func() { |
| ctx, cancel := context.WithTimeout(r.Context(), overviewTrafficTimeout) |
| @@ -4240,7 +4245,11 @@ func (s *Server) handleApp(w http.ResponseWriter, r *http.Request) { |
| p.Pending = s.pendingChangeViews(pcs, p.Detail.Pipeline) |
| } |
| end = perf.Span(r, "s3") |
| - p.Traffic = <-traffic |
| + select { |
| + case p.Traffic = <-traffic: |
| + case <-time.After(overviewTrafficGrace): |
| + p.TrafficSlow = true |
| + } |
| end() |
| s.render(w, http.StatusOK, "app_overview", p) |
| } |
diff --git a/internal/console/templates/app_analytics.html b/internal/console/templates/app_analytics.html| index fcdaf69fc..36b71ab75 100644 |
| --- a/internal/console/templates/app_analytics.html |
| +++ b/internal/console/templates/app_analytics.html |
| @@ -93,8 +93,8 @@ When analytics is on, the edge counts HTML page views and daily visitors. No Jav |
| edge dropped, days an edge restarted before it flushed. Said once. */}} |
| {{define "trafficquality"}} |
| <p class="an-quality small"> |
| - {{if .Sum.Bots}}{{count .Sum.Bots}} bot request{{if ne .Sum.Bots 1}}s are{{else}} is{{end}} not included in these numbers.{{else}}No bots detected.{{end}} |
| - {{if .Sum.Dropped.Flush}} {{count .Sum.Dropped.Flush}} page view{{if ne .Sum.Dropped.Flush 1}}s are{{else}} is{{end}} missing because {{if ne .Sum.Dropped.Flush 1}}they{{else}}it{{end}} could not be saved.{{end}} |
| + {{if .Sum.Bots}}{{count .Sum.Bots}} bot request{{if ne .Sum.Bots 1}}s are{{else}} is{{end}} not included in page views or visitors.{{else}}No bots detected.{{end}} |
| + {{if .Sum.Dropped.Flush}} Some counts could not be saved and are missing.{{end}} |
| {{with .Restarts}} {{.}}{{end}} |
| </p> |
| {{end}} |
diff --git a/internal/console/templates/app_overview.html b/internal/console/templates/app_overview.html| index f5533f5c0..9429cf1f6 100644 |
| --- a/internal/console/templates/app_overview.html |
| +++ b/internal/console/templates/app_overview.html |
| @@ -71,7 +71,9 @@ |
| <h2 id="an-overview-head">Traffic, last 7 days</h2> |
| <a href="{{.Nav}}/apps/{{.AppName}}/analytics?range=7d">View analytics</a> |
| </div> |
| - {{with .Traffic}} |
| + {{if .TrafficSlow}} |
| + <p class="small">Traffic is still loading. Reload this page, or check the <a href="{{.Nav}}/apps/{{.AppName}}/analytics?range=7d">Analytics</a> tab.</p> |
| + {{else}}{{with .Traffic}} |
| {{if or .On .HasData}} |
| {{template "trafficfigures" .}} |
| {{if .Chart}}{{template "trafficchart" .Chart}}{{else}}<p class="an-empty">No page views in the last 7 days.</p>{{end}} |
| @@ -81,7 +83,7 @@ |
| {{end}} |
| {{else}} |
| <p class="small">Traffic could not be read just now. Check the <a href="{{.Nav}}/apps/{{.AppName}}/analytics?range=7d">Analytics</a> tab.</p> |
| - {{end}} |
| + {{end}}{{end}} |
| </section> |
| {{/* The legacy safety-delay flag: legacy-path-only, exactly as ladder.html |
| skips this same block in pipeline mode. A pipelined app's bake story is |