Skip to content

Reduce background analytics volume - #47137

Merged
brennanb2025 merged 10 commits into
mainfrom
brennanb2025/posthog-pare
Nov 23, 2026
Merged

brennanb2025 merged 10 commits into
mainfrom
brennanb2025/posthog-pare

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Orca sends fewer background analytics messages. Two kinds of messages that used to go out very often are now combined into a small daily summary or sent only occasionally. Nothing new is collected, and nothing changes in the app.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​104 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​104
Prod 18 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​328 $\color{#cf222e}{\Huge{\mathbf{−}}}$​271 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​57

What Changed

The events go out for the first send of each day on each device, then for about 1 in 10, tagged with its sampling rate, and as one total per provider per day.

Linked Issue

N/A (maintainer change)

Visual Proof

N/A: no UI change.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below
  • Every added test fails without this change and avoids the test anti-patterns

agent-token-usage-reporter.test.ts covers the saved-state rules: a finished day is sent under the day it was used, earlier history is never sent, only later growth is sent after a restart, and the start day after upgrading from an older build. Ran locally on macOS; CI covers Linux and Windows.

Performance

None, because chat sends add one in-memory comparison in the existing track() path, and the token reporter sums the scan's existing daily rows once per scan (the same order of work as before) while sending far fewer events.

Risk

Riskiest part: the token reporter's saved state. If it went wrong, daily token totals would stop arriving; nothing in the app changes. An unreadable state file is logged and reporting restarts from that day; a newer build's state file is left untouched.

Reading the data: totals for the chat event now need to be weighted by sample_rate; per-install and per-day views are unaffected. Daily token rows for the same install, provider and day add up. Combined with the older per-session event, use that event for an install only before its first daily row. Known limits: a time-zone change followed by a full usage rescan can count tokens near midnight once more, and days spent on an older build that is never upgraded again aren't covered.

Backing out is a plain revert: the older build still reads its own untouched file.

Level: Low

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@brennanb2025
brennanb2025 marked this pull request as ready for review November 22, 2026 22:02
@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review
Walkthrough

Agent token usage is now aggregated by UTC day and sent through a daily telemetry event. The reporter tracks reported daily totals and sends positive growth for completed days. Provider stores select daily aggregates, and the analytics session ID store is removed. Native chat message sampling uses per-client UTC-day cursors persisted in telemetry settings. The tracking path passes event details and a shared timestamp to sampling.

Merge Risk: Low · up to ea649

This change moves token telemetry to daily totals. Dashboards could show slightly inconsistent per-day figures: the date contract is unclear, usage from the first partial day is included, and a rare state-write failure plus restart can double-count a day. These are telemetry accuracy issues, not user-facing failures. Reconcile the usage_day definition before or soon after merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title "Reduce background analytics volume" matches the main change. The PR reduces telemetry volume by sampling per-day chat-send events and replacing per-session token-usage snapshots with daily …
Description check Passed The description is mostly complete. It gives a clear ELI5, a What Changed section, a Testing section with checkboxes and test coverage details, a Performance line, a Risk section with level, rollback,…
Full details: Title check

Explanation

The title "Reduce background analytics volume" matches the main change. The PR reduces telemetry volume by sampling per-day chat-send events and replacing per-session token-usage snapshots with daily totals. The title is short and specific enough for a teammate to understand the primary change, though it does not name the two mechanisms.

Full details: Description check

Explanation

The description is mostly complete. It gives a clear ELI5, a What Changed section, a Testing section with checkboxes and test coverage details, a Performance line, a Risk section with level, rollback, and data-reading notes, and the Agent skill boundary and checklist are filled in. The Linked Issue section says N/A (maintainer change), which the template permits for maintainers. The Visual Proof section says N/A with a reason. The 'What Changed' section is thin: it gives one sentence about sampling and daily totals but does not describe the before/after behavior or the mechanism (for example the UTC-day cursor persisted in telemetry settings, or the move from per-session snapshots to daily totals with schema version 2). The Why section is missing entirely; the template asks why this approach beats alternatives. The AI Disclosure section is blank, and the pnpm lint/typecheck/test/build checklist item is unchecked without a note saying CI will cover it. These gaps are non-critical, so the description is mostly complete.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Minor comments: 1

src/main/usage/reporting/token-usage/agent-token-usage-reporter.ts: 1

84-84: Minor · Functional Correctness · Poor tradeoff

Growth is attributed to the scan day, not the day it occurred.

The reporter receives only cumulative session counts, so it cannot use source usage dates. Growth accrued after one scan is added to the day of the next scan. A day's total therefore omits usage accrued after its last scan and includes that usage on the next day. Totals across days stay correct.

Either pass per-day usage to the reporter through the selectSessions contract, or document that usage_day records the scan day. Keep first-scan history suppression in either case.

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8601e0fb-ff8b-47b4-8b21-86209d6946a8
Commits

Reviewing files that changed from the base of the PR and between 096a87b and 7b95313.

Files selected for processing: 13

  • docs/site/content/docs/telemetry.mdx
  • src/main/backend-desktop/backend-desktop-capabilities.ts
  • src/main/backend/backend-entry.ts
  • src/main/ipc/telemetry.ts
  • src/main/telemetry/client.ts
  • src/main/telemetry/event-sampling.ts
  • src/main/usage/provider-lifecycle/usage-provider-store-lifecycle.ts
  • src/main/usage/reporting/token-usage/agent-token-usage-reporter.test.ts
  • src/main/usage/reporting/token-usage/agent-token-usage-reporter.ts
  • src/main/usage/usage-store-host.ts
  • src/shared/telemetry/schemas/telemetry-agent-token-usage-schema.ts
  • src/shared/telemetry/telemetry-event-registry.ts
  • src/shared/telemetry/telemetry-settings-types.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@brennanb2025

brennanb2025 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Addressed the review at 68e635d: old pending rows now expire by age, a failed save is retried on the next scan, and the schema comment clarifies which day a row belongs to.

@brennanb2025
brennanb2025 force-pushed the brennanb2025/posthog-pare branch from 68e635d to e07ec78 Compare November 22, 2026 22:26
@brennanb2025

brennanb2025 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Perf scan at e07ec78f7ff

No findings. The change adds no timers, polling or idle wakeups, and it does less background work than before: fewer analytics events are queued and sent.

@brennanb2025

brennanb2025 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Perf scan at 83f7efd584c

No findings. The change adds no timers, polling or idle wakeups, and it does less background work than before: fewer analytics events are queued and sent.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b76c4cb8-63a4-4035-b68e-069641267233
Commits

Reviewing files that changed from the base of the PR and between e07ec78 and 83f7efd.

Files selected for processing: 4

  • docs/site/content/docs/telemetry.mdx
  • src/main/usage/reporting/token-usage/agent-token-usage-reporter.test.ts
  • src/main/usage/reporting/token-usage/agent-token-usage-reporter.ts
  • src/shared/telemetry/schemas/telemetry-agent-token-usage-schema.ts
Files skipped from review as they are similar to previous changes: 2

  • docs/site/content/docs/telemetry.mdx
  • src/shared/telemetry/schemas/telemetry-agent-token-usage-schema.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

@brennanb2025
brennanb2025 force-pushed the brennanb2025/posthog-pare branch from 83f7efd to ea6493f Compare November 22, 2026 22:54
@brennanb2025

brennanb2025 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Perf scan at ea6493f5ddf

No findings. The change adds no timers, polling or idle wakeups, and it does less background work than before: fewer analytics events are queued and sent, and two local state files that grew over time are replaced by a small bounded one.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Minor comments: 1

src/main/usage/reporting/token-usage/agent-token-usage-reporter.ts: 1

119-123: Minor · Data Integrity & Integration · Poor tradeoff

Accepted daily growth can be sent again after a restart.

publish records growth in state.reported after capture returns true, and it saves state only at the end of the scan. If that save fails, the file on disk does not include the accepted growth. unsaved retries the save only within the same process. After a restart, the reporter loads the stale file, computes the same growth, and sends it again. Daily rows are additive, so that day's total is counted twice.

If capture throws instead of returning false, the save after the loop is skipped. Progress from earlier days in that scan then exists only in memory. The declared capture contract returns Promise<boolean>, so this path depends on the production implementation.

Changing the save order does not fix this. Saving before capture loses growth whenever capture returns false. Full protection needs a stable delivery identifier with receiver-side deduplication. Otherwise, accept at-least-once delivery and document it. Choose one of these explicitly.

Nitpick comments: 1

src/main/usage/reporting/token-usage/agent-token-usage-reporter.test.ts: 1

69-72: Trivial · Maintainability & Code Quality · Quick win

Cover two eligible completed days with independent baselines.

The current assertions never compare two eligible completed days. The first test starts on 2026-11-20, so 2026-11-19 is excluded as history. The second test captures no rows after the downgrade. A reported-count baseline shared across dates would pass these assertions.

Add a case that starts the reporter on 2026-11-19. At 2026-11-21, report both completed days with different totals, such as 500 and 130 tokens. Assert that both initial rows are captured. Then raise only the 2026-11-20 total to 150 tokens and report again. Assert that the second scan captures only the 20-token growth for 2026-11-20.

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3a1f1716-1c0a-44d2-b637-26405c452657
Commits

Reviewing files that changed from the base of the PR and between 83f7efd and ea6493f.

Files selected for processing: 10

  • src/main/claude-usage/store.ts
  • src/main/codex-usage/store.ts
  • src/main/opencode-usage/store.ts
  • src/main/usage/provider-lifecycle/usage-provider-store-contract.ts
  • src/main/usage/provider-lifecycle/usage-provider-store-lifecycle.ts
  • src/main/usage/reporting/token-usage/agent-token-usage-reporter.test.ts
  • src/main/usage/reporting/token-usage/agent-token-usage-reporter.ts
  • src/main/usage/reporting/token-usage/agent-token-usage.ts
  • src/main/usage/reporting/token-usage/analytics-session-id-store.ts
  • src/shared/telemetry/schemas/telemetry-agent-token-usage-schema.ts
Files with no reviewable changes: 1

  • src/main/usage/reporting/token-usage/analytics-session-id-store.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

@brennanb2025

brennanb2025 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Perf scan at a36a87a15e4

No findings. The change adds no timers, polling or idle wakeups, and it does less background work than before: fewer analytics events are queued and sent, and two local state files that grew over time are replaced by a small bounded one.

@brennanb2025

brennanb2025 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Perf scan at ca33cac8d60

No findings. The change adds no timers, polling or idle wakeups, and it does less background work than before: fewer analytics events are queued and sent, and two local state files that grew over time are replaced by a small bounded one.

@brennanb2025
brennanb2025 force-pushed the brennanb2025/posthog-pare branch from ca33cac to d4517dc Compare November 22, 2026 23:26
@brennanb2025

brennanb2025 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Perf scan at d4517dcde59

No findings. The change adds no timers, polling or idle wakeups, and it does less background work than before: fewer analytics events are queued and sent, and two local state files that grew over time are replaced by a small bounded one.

@brennanb2025 brennanb2025 mentioned this pull request Nov 23, 2026
10 of 11 tasks
@brennanb2025

brennanb2025 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Review status

Change. Two high-frequency analytics events are reduced: one is sent for the first occurrence each day per device and then sampled, the other becomes a small daily total. Nothing in the app changes.

Fixed during review. Sampling state survives restarts. Upgrade and downgrade keep their own state files and never overwrite each other's. Daily totals are dated by the day they belong to. Saved state is written before sending, so a crash never sends a row twice, and a failed save is retried. Unreadable or newer state files are handled safely. Unused code was removed, and the PR text was corrected.

Refuted. A suspected over-count after a worktree is removed: Orca keeps removed worktrees attributed, so it doesn't happen.

Deferred (agreed by the reviewer who raised it). A row can be lost if the app crashes right after queueing it. That's the same best-effort delivery as all other analytics. Known limits are listed in the PR's Risk section.

Verified. CI green at d4517dc. Reporter test (2 cases) passes and fails if the start-day or downgrade logic is reverted. Main and renderer typecheck and lint pass locally. Fresh repair review: clean. Perf scan at this head: clean. Blinded regression audit: its only must-fix was refuted. QA by tests: no UI.

@brennanb2025 brennanb2025 changed the title Send fewer usage events: daily token totals and sampled chat sends Reduce background analytics volume Nov 23, 2026
@brennanb2025
brennanb2025 merged commit b7d9614 into main Nov 23, 2026
40 of 41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant