fix(usage): usage no longer misses custom provider-instance homes #5806
main fromrefs/pull/5806/head·opened View on GitHubWhat Changed#
The usage scan now enumerates every configured provider instance instead of only the legacy settings.providers.<kind> blobs:
- A new
usageHomes.tslists each instance's config with the same precedence the provider registry uses (deriveProviderInstanceConfigMap): explicitproviderInstancesentries win, and the legacy blob only fills the default slot while no entry claims that id. - Each instance's home resolves with the runtime's exact rules: a configured
homePathwins; otherwise the provider's home variable from the instance's spawn environment applies (server environment as base, per-instance entries overriding, absolute paths only); never for shadowed homes, where the server always sets the variable itself. - Resolved directories are canonicalised (
realPath) and de-duplicated, so instances sharing a home — shadow overlays symlinksessionsinto the shared home — are scanned exactly once.
Server-only. No contract change (sources already carries several directories per provider) and no UI code change.
Why#
Configuring Codex through providerInstances (e.g. work + personal instances, each with its own CODEX_HOME) leaves the legacy providers.codex blob empty, so the scan read ~/.codex/sessions — a directory those instances never write to — and the usage page reported no Codex usage at all.
Closes #5805.
One known edge is left for a follow-up (#5738): buckets are still keyed per provider kind, so two environments whose partially overlapping directory sets get de-duplicated client-side can still over-count in the overlap. Fixing that needs per-directory bucket attribution, which is a contract change and deliberately out of scope here.
UI Changes#
No UI code changes, but the visible effect on an instance-based setup (four Codex instances across two homes):
| Before | After |
|---|---|
| Codex missing entirely | Codex usage reported |
![]() | ![]() |
Testing#
- New unit tests for the instance enumeration (legacy fallback, default-slot precedence including cross-driver claims, spawn-environment inheritance/override, absolute-path gating) and the home-path precedence.
vp test run src/usage/: 40 passed;tsgo --noEmitandvp lintclean.- Verified live against a real four-instance setup (two homes, two shadow overlays, legacy blob empty): both screenshots above are from the same state directory and transcripts, before/after only differing by this change on top of current
main.
Checklist#
- This PR is small and focused
- I explained what changed and why
- I included before/after screenshots for any UI changes
- I included a video for animation/interaction changes — not applicable
Note
Medium Risk Changes which transcript directories are scanned and aggregated usage totals for multi-instance setups; logic is server-only with tests but mis-resolved paths could still skew reported usage.
Overview
Usage scanning no longer relies only on legacy settings.providers blobs. It walks every Claude/Codex provider instance, resolves each home with the same rules as spawn (homePath, CODEX_HOME / CLAUDE_CONFIG_DIR, shadow homes), and dedupes transcript dirs via realPath so shared/shadow homes are counted once.
Adds usageHomes.ts (listProviderHomeCandidates, scanHomePath) aligned with provider registry precedence, plus unit tests. resolveTranscriptDirs in UsageService loops instances, skips invalid configs, and can return multiple dirs per provider (fixes missing Codex usage when instances live only under providerInstances).
Note
Fix resolveTranscriptDirs to scan transcript homes for every configured provider instance#
- Previously,
resolveTranscriptDirsresolved a single transcript directory per provider. It now enumerates all configured Claude and Codex instances via the newlistProviderHomeCandidatesutility in usageHomes.ts. - For each instance, the home path is derived using
scanHomePath, which mirrors runtime precedence between configuredhomePathand environment-variable-provided home paths. - Instances with undecodable configs are skipped; results are de-duplicated by provider and canonical real path to avoid counting the same transcripts twice.
- A legacy provider blob fallback is included when no instance claims the default slot, preserving backward compatibility.
- Behavioral Change:
resolveTranscriptDirsnow returns zero or more entries per provider (instead of exactly one), so usage counts may change for users with multiple configured instances or non-default home paths.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
Approvability#
Verdict: Needs human review
This PR expands the usage scanning system to cover multiple provider instances rather than just the default configuration. While labeled as a 'fix', it introduces new capability with ~300 lines of new code and changes what usage data gets collected - warranting human review for the behavioral change.
You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).zenDevNomad(GitHub profile, opens in a new tab) changed the title
zenDevNomad(GitHub profile, opens in a new tab) changed the title
Is this still alive? It's been open a while, and #8470 has since arrived at the same fix from a different direction, so it would be good to know which one to get behind.
Related question about scope: as written, every instance's transcripts pool into one series per provider. #6920 asks for the instances to be shown as separate, labelled series, which is the half your own #5738 implements —
homePath+homeLabelonUsageBucket,labelonUsageSource, one series per home named after the configured instance. Since #5738 is parked waiting on this PR, is the plan still to land them in sequence, or would you rather fold the labelling into this one so the feature arrives whole?Note
🤖 GPT-6 Astra (preview) responding on behalf of Theo
This was closed as part of an automated cleanup pass. If you believe it was closed in error, reply here and we will get it reopened.
Closing in favor of #8470. It uses the provider registry's environment rules for usage scans and already carries this branch's server and instance home precedence. Review continues there. The physical-path deduplication case is recorded on the retained PR so two configured paths to the same transcript directory do not count it twice.
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
9adb6d03-fab4-4f12-9c56-836af154da8fYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
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