feat(usage): split usage per provider instance home #5738
ClosedzenDevNomad(GitHub profile, opens in a new tab)wants to merge 2 commits into
main fromrefs/pull/5738/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
- apps/server/src/usage/usageHomes.ts line 104Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +40,21 @@40+ * Callers decode each through the driver's settings schema; blobs that fail to41+ * decode belong to instances the registry already surfaces as unavailable and42+ * are simply skipped by the scan.43+ */44+export function listProviderHomeCandidates(45+ settings: ServerSettings,46+ provider: UsageProviderKind,47+): ReadonlyArray<UsageHomeCandidate> {48+ const driver = DRIVER_BY_PROVIDER[provider];49+ const candidates: UsageHomeCandidate[] = [];50+ let defaultSlotClaimed = false;51+52+ for (const [instanceId, envelope] of Object.entries(settings.providerInstances)) {53+ // Any entry occupying the default slot claims it, even one for another54+ // driver: the registry suppresses the legacy blob in that case too.55+ if (instanceId === driver) defaultSlotClaimed = true;56+ if (envelope.driver !== driver) continue;57+ candidates.push({58+ // An envelope without a config payload is an instance running on driver59+ // defaults; the settings schemas fill those in when the blob decodes.60+ config: envelope.config ?? {},
- packages/contracts/src/usage.ts line 86OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -78,3 +78,9 @@7878 export const UsageBucket = Schema.Struct({7979 day: UsageDay,8080 provider: UsageProviderKind,81+ /**82+ * Resolved transcript directory the records came from. Matches the83+ * `resolvedHomePath` of exactly one of the summary's source fingerprints, so84+ * clients can attribute buckets to the sources they decided to count.85+ */86+ homePath: TrimmedNonEmptyString,
- @@ -214,6 +229,13 @@214229 ),215230 );216231217- const claudeHome = yield* resolveClaudeHomePath(settings.providers.claudeAgent);218- const claudeDir = yield* resolveClaudeTranscriptDir(claudeHome);219- const codexLayout = yield* resolveCodexHomeLayout(settings.providers.codex);232+ const homes: ResolvedUsageHome[] = [];233+234+ for (const candidate of listProviderHomeCandidates(settings, "claude")) {235+ // A blob that fails to decode belongs to an instance the registry236+ // already reports as unavailable; the scan skips it.237+ const config = yield* decodeClaudeSettings(candidate.config).pipe(238+ Effect.catchCause(() => Effect.succeed(null)),239+ );240+ if (config === null) continue;241+ const claudeHome = yield* resolveClaudeHomePath({
- apps/server/src/usage/usageHomes.ts lines 75 to 75OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +55,21 @@55+ * Candidate configs for every configured instance of the given provider.56+ * Callers decode each through the driver's settings schema; blobs that fail to57+ * decode belong to instances the registry already surfaces as unavailable and58+ * are simply skipped by the scan.59+ */60+export function listProviderHomeCandidates(61+ settings: ServerSettings,62+ provider: UsageProviderKind,63+): ReadonlyArray<UsageHomeCandidate> {64+ const driver = DRIVER_BY_PROVIDER[provider];65+ const homeVariable = HOME_VARIABLE_BY_PROVIDER[provider];66+ const candidates: UsageHomeCandidate[] = [];67+ let defaultSlotClaimed = false;68+69+ for (const [instanceId, envelope] of Object.entries(settings.providerInstances)) {70+ // Any entry occupying the default slot claims it, even one for another71+ // driver: the registry suppresses the legacy blob in that case too.72+ if (instanceId === driver) defaultSlotClaimed = true;73+ if (envelope.driver !== driver) continue;74+75+ let homeEnvValue: string | null = null;
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- @@ -0,0 +147,21 @@147+ readonly isDirect: boolean;148+ readonly isDefault: boolean;149+}150+151+export interface UsageTranscriptDir {152+ readonly provider: UsageProviderKind;153+ readonly dir: string;154+ readonly label: string | null;155+}156+157+/**158+ * Collapses candidates that resolved to the same directory into one scan159+ * entry, keeping input order.160+ *161+ * Label precedence when several instances share a directory: a direct162+ * instance beats a shadow overlay (overlays share another instance's home),163+ * and the default slot beats named extras — a config-less extra instance164+ * resolves to the same home as the default, and that home's usage should165+ * render under the plain provider name, not the extra's.166+ */167+export function dedupeUsageHomes(
zenDevNomad(GitHub profile, opens in a new tab) changed the title
zenDevNomad(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:
272ac504-dc4a-4b62-a66e-8b897f7f38fcYou 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