Skip to content

fix(usage): refresh usage snapshot on window focus - #4044

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixdesktop-reconcile-usage-limits-9e7f15
Draft

fix(usage): refresh usage snapshot on window focus#4044
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixdesktop-reconcile-usage-limits-9e7f15

Conversation

@posthog

@posthog posthog Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Problem

  • The title-bar usage badge shows materially lower usage than the website for the same account, even after the website reports the limit as already reached.
  • UsageMonitorService serves the badge from a cached snapshot, refreshed only by two triggers: this app's own LLM activity, or a 30-minute backstop timer.
  • Usage consumed elsewhere — the website, another device, a teammate on the same org — never reaches the desktop app's cache until that backstop fires, so a user who checks the badge after leaving the window unfocused for a while can see a stale, lower number than reality.

Changes

  • Adds a window-focus trigger to UsageMonitorService, mirroring the existing onLlmActivity pattern: UsageHost gains onWindowFocus/offWindowFocus, and the service calls requestRefresh() whenever the window regains focus.
  • Wires it in the desktop main-process container via the existing IMainWindow.onFocus platform hook — no new Electron surface needed.

How did you test this?

  • pnpm --filter @posthog/core test -- usage-monitor — all 21 tests pass, including 2 new ones covering the focus-triggered refresh and its unsubscribe-on-stop behavior.
  • npx biome check on all changed files — clean.
  • Confirmed the pre-existing tsc --noEmit failures for @posthog/agent/@posthog/git reproduce identically on a clean main checkout (unbuilt workspace deps in this sandbox), unrelated to this change; no new type errors were introduced.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Created with PostHog Desktop from this inbox report.

The title-bar usage meter is served from `UsageMonitorService`'s cached snapshot, refreshed only by the app's own LLM activity or a 30-minute backstop timer. Usage consumed elsewhere (the website, another device, a teammate) while the desktop window sits unfocused isn't reflected until that backstop fires, so the badge can read well under what the website already reports as exhausted.

Adds a window-focus trigger, mirroring the existing `onLlmActivity` hook: the main process wires `UsageHost.onWindowFocus`/`offWindowFocus` to `IMainWindow.onFocus`, and `UsageMonitorService` requests a refresh whenever the window regains focus.

Generated-By: PostHog Code
Task-Id: a01f545a-82a9-4c13-b43e-be5b365d7a07
@trunk-io

trunk-io Bot commented Jul 31, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@github-actions

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit f8ce1f4.

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.

0 participants