Skip to content

Usage: fold linked-machine accounts into the original usage bars (#1553) - #1558

Merged
scuttletoby merged 4 commits into
mainfrom
fix/usage-one-fleet-list
Dec 1, 2026
Merged

scuttletoby merged 4 commits into
mainfrom
fix/usage-one-fleet-list

Conversation

@scuttletoby

Copy link
Copy Markdown
Owner

Closes #1553. Stacked on #1557 (which announces the 4 seam lines added to apps/web/src/components/usage/UsageLimitsPooled.tsx); merge #1557 first, then update this branch from main.

What the owner sees

  • Before: Opening the Usage tab with linked machines showed a separate "Across linked machines" card with its own thin bars above upstream's per-provider usage bars, duplicating accounts visible locally.
  • After: The separate card is gone. The original per-provider pooled usage bars cover every account across all linked machines, deduped to one entry per account using the freshest reading (preserving local account details, email redaction, accent color, and reset-credit controls), with a quiet note beneath each provider section showing where and how long ago each account was read (e.g. Read on <machine>, 3 min ago). Unreachable or stale (>30 min) remote-only accounts never show bars or stale numbers; their reason appears in upstream's limit notices instead. With no linked machines, the tab renders identically to upstream.

How it works

  • apps/web/src/components/fork/fleetUsage/fleetUsage.logic.ts (mergeFleetPresentations) folds the aged fork.fleetUsage answer into upstream's LimitPresentations (matching direct native and hub accounts by the server's snapshot key, with a safe 1-to-1 per-host/driver fallback for workspace-less vs workspace-ful reports, and attaching linked machines to shared accounts so the popover's "Signed in" list covers every machine). Respects environment and provider filters and keeps asLimitAccounts intact for the work panel.
  • apps/web/src/components/fork/fleetUsage/ForkFleetUsage.tsx exposes useFleetUsage and ReadingNotes, replacing the separate card.
  • apps/web/src/components/usage/UsageLimitsPooled.tsx drops the 2 old separate-card seam lines and adds the 4 announced merge/notes seam lines. No other upstream files are modified.

General vs project

General: T3 fork UI change for linked-machine usage presentation, keeping the #1153 data plumbing as-is and containing no project-specific facts.

Verification

  • vp fmt and vp lint clean on all 6 changed TS/TSX files (0 warnings, 0 errors).
  • vp run @t3tools/web#typecheck (effect-tsgo) passes with 0 errors.
  • Focused unit & browser tests pass:
    • apps/web/src/components/fork/fleetUsage/fleetUsage.logic.test.ts (5/5)
    • apps/web/src/components/fork/fleetUsage/ForkFleetUsage.browser.test.tsx (3/3)
    • apps/web/src/components/usage/UsageLimitsPooled.browser.test.tsx (2/2)
  • fork-seam-check.cjs --no-upstream --config-ref fix/usage-one-fleet-list-seam, fork-seam-check.test.cjs ("every listed seam line is in its file"), fork-schema-check.cjs, and fork-test-names-check.cjs all pass.

@scuttletoby
scuttletoby force-pushed the fix/usage-one-fleet-list branch from ad2accc to 643f206 Compare December 1, 2026 10:49
@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: code · reviewer: GPT-6.2 Sol (high) · read at: 643f206
blocker: none
major: The one-candidate fallback in fleetUsage.logic.ts:346–368 can merge two different logins. After a login switch, the direct config can already report the new email while the cached fleet round still lists the old email on that host. One unmatched entry on each side passes the host/driver check, so the old account's windows go on the new account's bar with the new account's reset control. Require a proven account match, including compatible workspace identity, before overlaying windows.
major: The winner comparison in fleetUsage.logic.ts:425–433, 521–529 compares a raw direct server timestamp against a browser-relative fleet timestamp. A server clock eight minutes ahead can keep an older direct reading over the fleet's newer reading and label it “just now.” An unparseable direct timestamp also gets now, and line 76 turns a missing fleet age into zero. Compare valid ages in a common clock frame, preserve the age of a cached round across rereads, and treat unknown ages as unknown in the winner comparison.
major: Overwriting usageLimits.checkedAt while retaining each direct report's credit balance in fleetUsage.logic.ts:434–442, 530–538 changes the reset-credit winner selected by usageLimits.ts:357–364. With two direct reports for one account (older with one credit, newer with zero) and a fresher fleet reading, both reports get the same synthetic timestamp. The first report can then resurrect the stale credit and its redemption target. Keep the original timestamps for credit and redemption selection when choosing fleet windows.
minor: A fleet-only account can lose its reading note at fleetUsage.logic.ts:626–650. If a non-source machine already appears earlier in the presentations map, upstream uses its synthetic provider key while the note is stored under the source machine's key. Attach the note to the final pooled account key.
minor: Offline or older-version machines with no remembered accounts disappear from Limits. The merge only consumes answer.accounts, so the machine-level reason previously shown by the card is dropped. Surface the reason through the existing notices when it has no account row.

State check. An empty or unlinked answer leaves the original bars intact. A kept remote-only reading past 30 minutes becomes a notice, and an empty window list cannot create a remote bar. Equal comparable timestamps keep the first reading. A refresh split between direct config and fleet cache exposes the account-switch and reset-credit failures above. The four announced seam lines match the pooled component, and the rest of the seam manifest matches the base.

A capacity-gated source check reproduced the login switch, skew, credit selection and missing note using the merge and upstream collector. Extend the existing merge tests with table rows for those cases. Keep the browser coverage for removing the card and the live age transition. The pure no-op test already covers the unlinked merge.

@scuttletoby

Copy link
Copy Markdown
Owner Author

Fix round 1 at 69781abffcf8984616d5434eb438b2e075a739c2 addressing all findings from the round-1 review:

  • Major (unproven 1-to-1 login/workspace match): Removed the host/driver one-candidate fallback in fleetUsage.logic.ts. Added optional base hash to ForkFleetUsageAccount (packages/contracts/src/forkFleetUsage.ts, populated by fleetMerge.ts for shared non-ambiguous accounts) and required either an exact key match or a proven single-workspace base match before overlaying fleet windows. Login switches and incompatible workspaces no longer merge.
  • Major (clock skew, unknown ages, cached round age): Compared direct and fleet reading ages in a common clock frame (answer.answeredAt + elapsed for the primary host, toServerClock via UsageScope.serverNow for other directly-connected hosts). Treated unparseable direct timestamps and missing fleet ageMs as unknown (null / undefined) rather than now / 0, and stopped fabricating "just now" when age is unknown. Advanced cached fleet rounds on reread both on the server (ageFleetAnswer in fleetMerge.ts/fleetUsage.ts) and client (receiveFleetUsage preserving the earliest arrival time per answeredAt in fleetUsageAtom.ts).
  • Major (stale reset-credit resurrection): Decided fleet vs direct window winners per pooled account row while preserving original usageLimits.checkedAt on direct native and hub reports (and pinning synthetic peer entries to 1970-01-01T00:00:00.000Z), so upstream collectLimitAccounts keeps the newest direct report for reset credits, plan, and redemption target.
  • Minor (lost fleet-only reading note): Resolved reading notes in a final pass over merged matching collectLimitAccounts iteration order, so notes attach to the final pooled LimitAccount.key even when a non-source machine appears earlier in presentations.
  • Minor (account-less offline / older-version machines dropped): Surfaced unknown linked machines with no account row as synthetic error usageLimitSources entries so their reasons render in upstream's existing LimitNotices without adding seam lines.

Verification:

  • Failing-first tests added in fleetUsage.logic.test.ts, fleetUsage.test.ts, and fleetMerge.test.ts; targeted unit & browser suites green (4 files, 31 tests).
  • vp fmt + vp lint clean on all changed files; typecheck clean on @t3tools/contracts, @t3tools/web, and t3.
  • Local fork-checks clean (fork-schema-check, fork-upstream-files-check, fork-seam-check --no-upstream, fork-test-names-check, plus check script tests: 201 passed).

@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: code · reviewer: GPT-6.2 Sol (high) · read at: 69781ab
blocker: none
major: fleetMerge.ts:71–78,107–117 still turns an unparseable fleet timestamp into a zero-age reading. IsoDateTime accepts strings without validating the date. I reproduced a malformed peer reading winning over a one-minute-old valid direct reading and replacing its windows. Preserve the unknown age at the source and exclude it from freshness selection.
major: fleetUsage.logic.ts:485–510,550–573,635–659 picks the newest direct reading in the corrected clock frame for the note, but only writes winning windows through when fleet wins. With direct readings one and three minutes old, an eight-minute clock lead on the older host, and a five-minute-old fleet reading, the bar shows the older direct windows and the note credits the newer host. Carry the selected windows through for both kinds of winner while preserving direct timestamps for credit and redemption selection.
major: fleetUsage.logic.ts:370–376,401–407,435–440 treats an environment and provider slot as an exact account match when the login supplies neither an email nor a fingerprint. I reproduced cached fleet windows replacing the direct windows using only this slot key. A cached round from before an anonymous login switch can therefore fill the new login's row. Require a proven account identity for the overlay, including when a workspace is ambiguous.
minor: fleetUsage.logic.ts:776–788 treats any configured usage source as an account. An older-version machine with a directly connected, empty hub source gets the generic empty-hub notice and loses the machine's version reason. Count actual account rows when deciding whether to show the machine notice.

round 1, fixed: The host/driver one-candidate fallback is gone. Different reported logins and explicitly different workspaces stay separate, and the shared base can bridge the single-workspace case.
round 1, fixed: Cached replies advance known ages on the server and repeated replies with the same timestamp keep their original client arrival time. A missing age received by the client cannot beat a valid direct reading.
round 1, fixed: A winning fleet reading keeps the original direct timestamps, so the newer zero-credit report keeps the reset-credit and redemption selection in the original repro.
round 1, fixed: Fleet-only notes follow the final pooled key even when a non-source machine comes first.
round 1, fixed: An account-less unknown machine with no direct usage configuration reaches the existing notices.

State check. With no linked answer, the merge returns the original bars. Cached rereads age known windows, and a failed refresh keeps aging the last answer until a remote-only row becomes a notice. An empty window list cannot create a remote bar. If direct config refreshes before the fleet cache, identity-less slot matches can still overlay a prior login, and two direct hosts with skewed clocks can disagree about which reading the note and bar represent. Older answers without the optional base still decode.

A capacity-gated source check reproduced the three open findings. Extend the existing merge cases with an invalid peer timestamp, two skewed direct hosts and a cached slot without a stable login. Keep the existing browser coverage for removing the separate card and aging a kept reading.

@scuttletoby

Copy link
Copy Markdown
Owner Author

Fix round 2 at 0e63f0d43a64d3240358c7492a6fb59c23014f2a (addressing all findings from round-2 review):

  1. Invalid peer timestamps (apps/server/src/fork/fleetUsage/fleetMerge.ts, usageSnapshot.ts): ageOf now returns null when checkedAt is unparseable instead of 0. Unknown-age readings sort after valid ages, are excluded from freshness selection, and surface as state: "unknown" with empty windows if no valid fresh reading exists. Local same-machine dedupe in usageSnapshot.ts also prefers finite timestamps over unparseable ones.
  2. Skewed direct hosts (apps/web/src/components/fork/fleetUsage/fleetUsage.logic.ts): decisionByRowKey now carries winningWindows for both fleet winners and direct winners (selected in the clock-corrected frame) across native and hub rows, so the rendered bars always match the reading note while leaving original direct checkedAt timestamps untouched for upstream reset-credit, plan, and redemption selection.
  3. Proven identity required for fleet overlay (fleetUsage.logic.ts): Fleet overlays now require a proven resolved account identity (resolvedIdentity !== null and unambiguous workspace). Anonymous provider/hub slots and ambiguous-workspace rows never inherit cached fleet windows, while local-only cached echoes from the same directly connected host are suppressed from Pass 3 so they do not duplicate the direct bar.
  4. Empty configured hub on older-version machine (fleetUsage.logic.ts): Pass 4 now checks for actual hub account rows (source.accounts.length > 0 or http quotaAccounts.length > 0) instead of usageLimitSources.length > 0, so an older-version machine with an empty hub still surfaces its version notice.

Verified failing-first tests for all four cases before fixing, then passed fleetMerge.test.ts, fleetUsage.test.ts, usageSnapshot.test.ts, fleetUsage.logic.test.ts, ForkFleetUsage.browser.test.tsx, vp fmt / vp lint, typecheck on t3 and @t3tools/web, and the local fork-checks scripts.

@scuttletoby scuttletoby added the fork:merge-ready Merge conveyor: lenses done, merge when green (PRs) label Dec 1, 2026
@scuttletoby
scuttletoby merged commit 8edcc99 into main Dec 1, 2026
61 checks passed
@scuttletoby
scuttletoby deleted the fix/usage-one-fleet-list branch December 1, 2026 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork:merge-ready Merge conveyor: lenses done, merge when green (PRs)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Usage: one list in the original T3 design, covering accounts on all linked machines

1 participant