Skip to content

Restore automatic usage tracking for default accounts - #6240

Merged
brennanb2025 merged 1 commit into
mainfrom
brennanb2025/issue-5690-usage-tracking-default-accounts
Jun 26, 2026
Merged

brennanb2025 merged 1 commit into
mainfrom
brennanb2025/issue-5690-usage-tracking-default-accounts

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #5690

Summary

  • Register the renderer rate-limit push listener before the initial startup snapshot request.
  • Treat the initial rateLimits.get() response as a fallback so a live startup push for system-default Claude/Codex accounts cannot be overwritten by an older empty snapshot.
  • Add a deterministic regression test for the startup race where a fresh push lands before the stale get() promise resolves.

Design and Review

  • Design approach: preserve IPC/store contracts and change only renderer event ordering/guarding in useIpcEvents. No UI, schema, provider, SSH/runtime target, or copy changes.
  • Design review: clean after adding alternatives, interaction states, architecture/data-flow coverage, and internal consistency notes to the ignored scratch design doc.
  • Implementation deviations: none.
  • Completeness verification: COMPLETE; implementation matches the design and edge cases.

Perf Audit

  • Result: PERF CLEAN.
  • Hot paths checked: renderer startup IPC hydration, main rate-limit service polling/push path, store subscriber/render churn, startup latency, and listener cleanup.
  • Evidence: no new polling, subprocesses, timers, IPC calls, or long-lived listeners; the raced path now avoids a redundant stale store write. Existing deterministic hook coverage is sufficient for this race.
  • Accepted gap: the regression asserts final behavior, not explicit call count; non-blocking because perf audit found no actionable churn.

Code Review

  • Review round 1: two independent reviewers reported no issues found.
  • Additional reviewer checks included focused Vitest, touched-file oxlint, and git diff --check.

Validation

  • Reproduction before fix: GITHUB_TOKEN=${GITHUB_TOKEN:-dummy} pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/hooks/useIpcEvents.test.ts -t "rate-limit hydration" failed with claude: null / codex: null overwriting fresh snapshots.
  • Focused test after fix: GITHUB_TOKEN=${GITHUB_TOKEN:-dummy} pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/hooks/useIpcEvents.test.ts -t "rate-limit hydration" passed.
  • Full touched hook suite: pnpm vitest run --config config/vitest.config.ts src/renderer/src/hooks/useIpcEvents.test.ts passed, 64 tests.
  • Static checks: pnpm run typecheck passed; pnpm run lint passed; git diff --check passed.
  • Electron validation: launched this exact worktree on CDP port 9337, verified window.api.app.getIdentity() branch/root, inspected window.api.rateLimits.get() and window.__store.getState().rateLimits, and confirmed renderer console had 0 errors.
  • Screenshot evidence: captured locally at .playwright-cli/page-2026-06-24T06-17-00-350Z.png; live Claude/Codex default accounts were unavailable in this profile, so visible usage chips could not be captured.
  • demo-project: not exercised because the change is global renderer startup hydration with no workspace-specific user action.

Post-PR Stabilization

  • Completed initial 8-minute wait and stabilization sweep.
  • CodeRabbit: no actionable comments generated.
  • PR checks: track-community-pr passed; verify passed (lint, typecheck, tests, build, packaged CLI smoke).

Risks

  • Live provider-account UI could not be observed in this local profile because rate-limit providers were all null; deterministic race coverage and live API/store inspection cover the startup hydration behavior.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

useIpcEvents previously subscribed to rateLimits.onUpdate after awaiting rateLimits.get(), creating a window where a pushed update could be missed and overwritten by the stale initial snapshot. The fix reorders the operations: onUpdate is subscribed first, a boolean flag records whether any push arrived before get() resolves, and the get() result is discarded if the flag is set. A new test suite reproduces the race by immediately invoking the captured listener with fresh state while get() returns stale state, asserting that setRateLimitsFromPush ends up called with the fresh value.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: fixing startup usage tracking hydration for default accounts.
Linked Issues check ✅ Passed The hook change and regression test address #5690 by preferring fresh startup pushes over stale initial snapshots.
Out of Scope Changes check ✅ Passed Changes stay within renderer IPC hydration and test coverage; no unrelated functionality appears to be added.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The description covers summary, testing, review, validation, and risks, but it does not follow the template exactly with explicit Screenshots and Security Audit sections.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

Comment @coderabbitai help to get the list of available commands.

@brennanb2025
brennanb2025 merged commit cdda9fd into main Jun 26, 2026
2 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
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.

[Bug]: Usage Tracking Doesn't PickUp Agents Automatically

1 participant