Repository navigation
fix(usage): guard web client against undefined usage scan state - #10073
Conversation
📝 WalkthroughWalkthroughClaude, Codex, and OpenCode usage slices now treat missing IPC scan states as unavailable, returning early during enable and fetch operations. A new Vitest suite stubs the web-client fallback APIs to return undefined and verifies that usage operations do not throw while scan state and summary fields remain null. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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. Comment |
The claude/codex/openCode usage store slices read `scanState.enabled` directly off `window.api.<provider>Usage.getScanState()`. In the web client that usage IPC is not bridged, so the preload fallback proxy resolves those calls to `undefined`, and enabling usage tracking from Settings -> Stats & Usage throws `TypeError: Cannot read properties of undefined (reading 'enabled')` (reproduced live against `orca serve` v1.4.150; present on main too). Guard the getScanState()/setEnabled() seams in all three slices so an absent scan state degrades to a graceful no-op instead of crashing. Desktop behavior is unchanged (a real ScanState is always truthy). Adds a regression test that stubs the web-client fallback (every call -> undefined) and asserts fetch*/enable* no-op without throwing for all three providers.
88a69f5 to
168503e
Compare
|
Thanks @scokeepa — great catch on the web-client usage-scan crash. Verified the fix (fail-on-main/pass-on-branch: 3 tests fail on |
…lyai#10073) The claude/codex/openCode usage store slices read `scanState.enabled` directly off `window.api.<provider>Usage.getScanState()`. In the web client that usage IPC is not bridged, so the preload fallback proxy resolves those calls to `undefined`, and enabling usage tracking from Settings -> Stats & Usage throws `TypeError: Cannot read properties of undefined (reading 'enabled')` (reproduced live against `orca serve` v1.4.150; present on main too). Guard the getScanState()/setEnabled() seams in all three slices so an absent scan state degrades to a graceful no-op instead of crashing. Desktop behavior is unchanged (a real ScanState is always truthy). Adds a regression test that stubs the web-client fallback (every call -> undefined) and asserts fetch*/enable* no-op without throwing for all three providers. Co-authored-by: ECO2G Migration <[email protected]>
Summary
Enabling an agent's usage tracking in Settings → Stats & Usage no longer crashes when Orca runs as a web client (a paired
orca serveruntime).ELI5
In the browser version of Orca, clicking "enable" for usage stats used to hit an error because that feature only exists on the desktop app. Now it just quietly does nothing instead of breaking.
Root cause & fix
The
*UsageIPC namespaces (claudeUsage,codexUsage,openCodeUsage) are desktop-only and are never bridged in the web preload, so the fallback proxy resolves every call toundefined. The slices cast that result to a non-optional scan state and readscanState.enabled, throwingCannot read properties of undefined (reading 'enabled'). The fix adds| undefinedto the casts and bails out with a no-op when the scan state is absent — on both theenable*(setEnabled) andfetch*(getScanState) paths — across all three providers. Desktop behavior is unchanged since a realScanStateis always truthy there.Evidence
Validated & rebased onto latest main during a bug-bash triage on 2026-07-23.
src/renderer/src/store/slices/usage-web-client-fallback.test.ts(3 tests, one per provider), which stubs the web-client fallback so everywindow.api.*Usage.*resolves toundefined.origin/main: 3 failed with the assertion below — proving the test guards the fix.oxlinton the three changed source files is clean.Trade-offs
None — pure fix. The Settings navigation gating is intentionally unchanged; the web client now treats usage tracking as unavailable (its actual state) rather than crashing.
Regression risk
Zero-regression: only the previously-crashing branch changes — when the scan state is present (always the case on desktop) every path is byte-identical, so desktop behavior is untouched. The passing test covers all three providers on both the enable and fetch seams.
Credit to original author @scokeepa. Validated, rebased, and (where applicable) hardened via automated bug-bash review; original fix design preserved.