Skip to content

fix(usage): guard web client against undefined usage scan state - #10073

Merged
nwparker merged 1 commit into
stablyai:mainfrom
scokeepa:fix/web-client-usage-scan-state-crash
Jul 24, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
scokeepa:fix/web-client-usage-scan-state-crash

Conversation

@scokeepa

@scokeepa scokeepa commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Enabling an agent's usage tracking in Settings → Stats & Usage no longer crashes when Orca runs as a web client (a paired orca serve runtime).

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 *Usage IPC namespaces (claudeUsage, codexUsage, openCodeUsage) are desktop-only and are never bridged in the web preload, so the fallback proxy resolves every call to undefined. The slices cast that result to a non-optional scan state and read scanState.enabled, throwing Cannot read properties of undefined (reading 'enabled'). The fix adds | undefined to the casts and bails out with a no-op when the scan state is absent — on both the enable* (setEnabled) and fetch* (getScanState) paths — across all three providers. Desktop behavior is unchanged since a real ScanState is always truthy there.

Evidence

Validated & rebased onto latest main during a bug-bash triage on 2026-07-23.

  • Test file: src/renderer/src/store/slices/usage-web-client-fallback.test.ts (3 tests, one per provider), which stubs the web-client fallback so every window.api.*Usage.* resolves to undefined.
  • On branch (fix present): 3 passed. Fix reverted to origin/main: 3 failed with the assertion below — proving the test guards the fix.
  • Lint: oxlint on the three changed source files is clean.
On branch:        Test Files 1 passed (1) | Tests 3 passed (3)
Fix reverted:     Test Files 1 failed (1) | Tests 3 failed (3)
  AssertionError: expected undefined to be null
  (claudeUsageScanState / codexUsageScanState / openCodeUsageScanState received undefined)

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.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Claude, 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)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and accurately summarizes the main fix: guarding web client usage tracking against an undefined scan state.
Description check ✅ Passed The description covers the summary, root cause/fix, evidence, trade-offs, and regression risk; only template sections like screenshots and audit are omitted.

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.

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.
@nwparker
nwparker force-pushed the fix/web-client-usage-scan-state-crash branch from 88a69f5 to 168503e Compare July 23, 2026 11:49
@nwparker
nwparker merged commit 6997bc4 into stablyai:main Jul 24, 2026
@nwparker

Copy link
Copy Markdown
Contributor

Thanks @scokeepa — great catch on the web-client usage-scan crash. Verified the fix (fail-on-main/pass-on-branch: 3 tests fail on main, pass with the guards) and merged. 🙏 (Follow-up idea, non-blocking: the root cause is that the three *Usage namespaces aren't registered in createWebPreloadApi(), so they hit the generic fallback proxy — a small web-side registration would fix it at the source; happy to do that separately.)

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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]>
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.

3 participants