analytics-agents: Astra round 1 P2s and Luna's copy
- Every bot BotName names is a bot to IsBot (ChatGPT-User, Claude-User, Google-InspectionTool and Meta's agent matched a name but no generic marker, so they were counted as people). TestNamedBotsAreBots. - The pace hold runs from the latest view: an out-of-order timestamp no longer shortens it. TestPaceHoldRunsFromTheLatestView. - The overflow-row fix landed on analytics-pages (964d9bdd), merged here. - Bots note (Luna): "An unnamed crawler sent a normal browser user agent but read 20 or more pages within a minute." - Census: internal/analytics envelope resealed (approved by Astra in R1).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
internal/analytics/agents_test.go+37 −0internal/analytics/bots.go+8 −0internal/analytics/pace.go+6 −2internal/console/templates/app_analytics.html+1 −1internal/provision/testdata/plan14-root-reads-analytics-agents.tsv+1 −1
CI failed — run details
Intent
<task-notification> <task-id>b078ri6mu</task-id> <tool-use-id>toolu_011aMgWG9Ndv5g9JiXPkVWCZ</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ce90495f-c7a7-490e-9b84-a6251050e87f/tasks/b078ri6mu.output</output-file> <status>completed</status> <summary>Background command "/home/paulca/.cache/tmp/agents-review/luna.sh" completed (exit code 0)</summary> </task-notification>
<task-notification> <task-id>bw3w5xhjt</task-id> <tool-use-id>toolu_0163PK1usZ5Caxq1vzUjWmx2</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ce90495f-c7a7-490e-9b84-a6251050e87f/tasks/bw3w5xhjt.output</output-file> <status>completed</status> <summary>Background command "/home/paulca/.cache/tmp/agents-review/run.sh" completed (exit code 0)</summary> </task-notification>
Attributed to this commit: 47.7 g CO₂e (6,253,278 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on analytics-agents, 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/analytics/agents_test.go b/internal/analytics/agents_test.go| index d07ea2bdb..87639e807 100644 |
| --- a/internal/analytics/agents_test.go |
| +++ b/internal/analytics/agents_test.go |
| @@ -161,3 +161,40 @@ func drainOne(t *testing.T, m *Meter) Delta { |
| t.Fatal("nothing drained") |
| return Delta{} |
| } |
| + |
| +// Every bot BotName names is a bot to IsPageview, so it is counted under its |
| +// name and never as a page view. |
| +func TestNamedBotsAreBots(t *testing.T) { |
| + for _, b := range botNames { |
| + ua := "Mozilla/5.0 (compatible; " + b.marker + "/1.0)" |
| + if !IsBot(ua) { |
| + t.Errorf("%s names %q but IsBot says person", b.marker, b.name) |
| + } |
| + } |
| + t0 := time.Date(2026, 10, 28, 9, 0, 0, 0, time.UTC) |
| + m := NewMeter(t.TempDir(), "box1", func() time.Time { return t0 }) |
| + o := pageObs("/", t0, "203.0.113.1") |
| + o.UA = "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko); compatible; ChatGPT-User/1.0; +https://openai.com/bot" |
| + m.Observe(o) |
| + d := drainOne(t, m) |
| + if d.BotNames["ChatGPT"] != 1 || d.Hours["09"].PV != 0 { |
| + t.Fatalf("ChatGPT-User: bot names %v, page views %d", d.BotNames, d.Hours["09"].PV) |
| + } |
| +} |
| + |
| +// A view stamped earlier than the latest one does not shorten the hold. |
| +func TestPaceHoldRunsFromTheLatestView(t *testing.T) { |
| + noon := time.Date(2026, 10, 28, 12, 0, 0, 0, time.UTC) |
| + m := &Meter{} |
| + k := AppKey{App: "a"} |
| + for i := 0; i < paceLimit; i++ { |
| + m.tooFast(k, 1, noon) |
| + } |
| + m.tooFast(k, 1, noon.Add(-time.Hour)) // out of order |
| + if !m.tooFast(k, 1, noon.Add(time.Second)) { |
| + t.Fatal("an out-of-order view released a flagged crawler") |
| + } |
| + if m.tooFast(k, 1, noon.Add(paceHold+2*time.Second)) { |
| + t.Fatal("still flagged past the hold after the latest view") |
| + } |
| +} |
diff --git a/internal/analytics/bots.go b/internal/analytics/bots.go| index 195bfca0c..3ca63e7af 100644 |
| --- a/internal/analytics/bots.go |
| +++ b/internal/analytics/bots.go |
| @@ -28,5 +28,13 @@ func IsBot(ua string) bool { |
| return true |
| } |
| } |
| + // A bot BotName names is a bot, even when no generic marker matches |
| + // it (ChatGPT-User, Claude-User, Google-InspectionTool): naming and |
| + // counting must agree. |
| + for _, b := range botNames { |
| + if strings.Contains(l, b.marker) { |
| + return true |
| + } |
| + } |
| return false |
| } |
diff --git a/internal/analytics/pace.go b/internal/analytics/pace.go| index 08ff1e741..c7a29f37e 100644 |
| --- a/internal/analytics/pace.go |
| +++ b/internal/analytics/pace.go |
| @@ -54,14 +54,18 @@ func (m *Meter) tooFast(app AppKey, visitor uint64, when time.Time) bool { |
| p = &paceState{start: when} |
| m.paces[k] = p |
| } |
| - if p.flagged && when.Sub(p.last) > paceHold { |
| + if p.flagged && when.After(p.last) && when.Sub(p.last) > paceHold { |
| p.flagged = false |
| } |
| if when.Sub(p.start) >= paceWindow || when.Before(p.start) { |
| p.start, p.n = when, 0 |
| } |
| p.n++ |
| - p.last = when |
| + // The hold runs from the latest view, so a request stamped earlier |
| + // (another box's clock, a slow writer) cannot shorten it. |
| + if when.After(p.last) { |
| + p.last = when |
| + } |
| if p.n >= paceLimit { |
| p.flagged = true |
| } |
diff --git a/internal/console/templates/app_analytics.html b/internal/console/templates/app_analytics.html| index 296a13cd2..6acc6316a 100644 |
| --- a/internal/console/templates/app_analytics.html |
| +++ b/internal/console/templates/app_analytics.html |
| @@ -90,7 +90,7 @@ When analytics is on, the edge counts HTML page views and daily visitors. No Jav |
| <section class="an-card" aria-labelledby="an-bots"> |
| <h3 id="an-bots">Bots</h3> |
| {{template "sharelist" .Bots}} |
| - <p class="small">Requests from bots and crawlers. They are not counted as page views or visitors. An unnamed crawler is a browser that read pages faster than a person does.</p> |
| + <p class="small">Requests from bots and crawlers. They are not counted as page views or visitors. An unnamed crawler sent a normal browser user agent but read 20 or more pages within a minute.</p> |
| </section> |
| {{end}} |
| </div>{{end}} |
diff --git a/internal/provision/testdata/plan14-root-reads-analytics-agents.tsv b/internal/provision/testdata/plan14-root-reads-analytics-agents.tsv| index d469d8464..a0526344f 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-analytics-agents.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-analytics-agents.tsv |
| @@ -1,3 +1,3 @@ |
| # Census overlay analytics-agents, written by census-propose (#369). census-ruling-analytics-agents, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-analytics-agents.md. |
| # 0 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| -@coverage internal/analytics 41eb38537fc642645ad815127b7da63bb420de95d68763d5e17138d54c961219 |
| +@coverage internal/analytics e246685497e4db7d774b9397fb22a62ebcde876854b3c8eb891187661fc73e27 |