Skip to content

fix(orcad): mobile home stats on orca serve hosts, and a parity test that sees every way a host wires a service - #31197

Merged
nwparker merged 2 commits into
mainfrom
nwparker/orcad-stats-collector
Oct 20, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/orcad-stats-collector

Conversation

@nwparker

@nwparker nwparker commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​247 $\color{#cf222e}{\Huge{\mathbf{−}}}$​14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​233
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​59 $\color{#cf222e}{\Huge{\mathbf{−}}}$​16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​43

ELI5

When you run Orca headless with orca serve, the server that answers your phone has been a separate Node program (orcad) since 1.4.229. That program never got the piece that counts agent sessions, so the phone's home screen showed 0 agents and 0 agent time. This PR gives orcad that counter. It reads the same orca-stats.json file, so your old totals come back. It also fixes the test that should have caught this.

What Changed

Before: on an orca serve host from 1.4.229 on, Orca Mobile's home screen shows 0 agents spawned and 0 agent time, and orca-stats.json stops changing.
After: the home screen shows the host's totals again, including everything counted before the upgrade, and new agent sessions keep being counted.

How it works:

  • src/main/stats/collector.ts no longer imports Electron. It finds the profile directory through the app environment port, which both the desktop and orcad install, so plain Node can load it.

  • src/main/stats/agent-session-stats-feed.ts is one function that counts sessions from agent-hook status, the same signal the sidebar uses. The desktop now calls it instead of wiring the recorder inline.

  • src/main/orcad/orcad-stats.ts creates the collector before the hook server starts and passes it to OrcaRuntimeService. On shutdown it stops the feed, then writes the file, all before the profile lock is released.

  • The test fix (the bug class): runtime-composition-parity.test.ts exists to fail when the desktop and orcad build the runtime differently. It missed this for two reasons:

    It now records separate constructor arguments, records every service setter called in those startup files, and fails when such a setter is called from a startup file it doesn't read. It ignores teardown resets like set…(null), and it checks that every constructor option is wired by at least one host. Services orcad deliberately leaves out stay listed with a reason. Speech is listed as a known gap for now; a follow-up PR wires it.

Why

A collector belongs on the host that runs the agents, because that host's hook server is what sees them. That holds for a local desktop, orca serve, and SSH or WSL hosts alike. I reused the existing collector and session recorder instead of writing a headless version, so the desktop and orcad count sessions the same way.

For the test, I extended the existing parity check rather than adding a second one. That way there is one place that lists what orcad deliberately leaves out, and each entry needs a reason.

Alternatives I rejected:

  • Making the stats parameter required. Hundreds of tests construct the runtime without stats.
  • Booting both hosts in a unit test to compare them. Too slow and too heavy for the unit suite.

Linked Issue

Fixes #31112

Thanks to @fergusmolloy for the report and the precise pointer to orcad-entry.ts.

Related: #31174 (speech, same gap in the parity test; separate PR). #30160 was already fixed by #29209; see the comments there.

Visual Proof

N/A. This is a data fix with no UI change. The mobile home screen just shows real numbers again. The live check below shows the RPC answer the screen renders.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated

Verified live (macOS arm64): I built the real orcad slot (pnpm build:orcad) and started it with its own HOME and ORCA_USER_DATA under /tmp, seeded with an orca-stats.json holding 42 agents, 3 PRs and 2 hours of agent time.

Tests only:

  • Counting a new live session on orcad: agent-session-stats-feed.test.ts records a session on a Node app environment with no Electron, and the totals survive a reload.
  • The parity test fails on main with orcad lacks ctor-arg:stats and passes here.

I also ran the full static job locally: lint, format, anti-slop, the focused and type-aware code-quality checks, changed-code quality, pnpm tc, every ratchet including focus-read, and the generated-catalog checks.

Review

  • Codex (gpt-6.1-sol, high): no findings.
  • Independent Opus review: nothing blocking. I adopted all five suggestions:
    • start the stats feed before the hook server, so early turns are counted
    • ignore teardown resets in the parity check
    • flag startup files that install a service but aren't listed
    • fix a comment
    • use the existing fake app-environment helper instead of a cast

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • SSH and WSL hosts: each host counts its own sessions in its own profile, and mobile reads the paired host's totals. The desktop and orcad never share a stats file.
  • Folder workspaces: not affected, since counting is keyed by pane.
  • Wire: no change. stats.summary keeps its shape and simply stops answering {}.
  • Cross-platform: paths go through path.join, and no new processes are started.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…parity test see positional and host-port wiring

Mobile home on an orca serve host showed 0 agents and 0 agent time since
1.4.229: orcad built the runtime with no stats collector, so stats.summary
answered {}. orcad now loads the profile's orca-stats.json and counts hook
sessions through the same feed the desktop uses.

The runtime composition parity test only compared constructor options and
runtime/rpc setters in four files, so a positional constructor argument
(stats) and process-wide host ports installed at preflight (speech) were
invisible to it. It now records both, and checks every declared
construction option is accounted for.

Reported-by: Fergus Molloy (@fergusmolloy)
…eardown resets and finds unlisted host-port files
@coderabbitai

coderabbitai Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b36501ef-cf2e-41af-adea-882c5a4e283b
📥 Commits

Reviewing files that changed from the base of the PR and between 2fc2f92 and e651a37.

📒 Files selected for processing: 9
  • src/main/orcad/orcad-entry.ts
  • src/main/orcad/orcad-stats.ts
  • src/main/quit-path-durable-write-blocking.test.ts
  • src/main/runtime/construction/runtime-composition-parity.test.ts
  • src/main/startup/main-process-observers.ts
  • src/main/stats/agent-session-stats-feed.test.ts
  • src/main/stats/agent-session-stats-feed.ts
  • src/main/stats/collector-async-save.test.ts
  • src/main/stats/collector.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

📝 Walkthrough

Orcad startup now initializes a stats collector, records agent sessions from status and pane-clear events, and passes the collector to OrcaRuntimeService. Stats path initialization uses the app environment by default and accepts an explicit user-data path. Tests cover session totals, listener cleanup, persistence, and runtime composition wiring.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to e651a

No identified issue blocks merging the restored host statistics behavior.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 56.25% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 9 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the main changes: restoring mobile home statistics for orcad hosts and improving runtime wiring parity coverage. It is specific and related to the changeset.
Description check Passed The description includes all required sections, explains the user impact and implementation, links issue #31112, documents testing and platform coverage, records the separate speech gap, and completes…
Linked Issues check Passed Issue #31112 requires orca serve to return existing host totals and count new agent sessions. The PR initializes the stats path in startOrcadStats, creates and passes StatsCollector to the orcad…
Out of Scope Changes check Passed The changes stay within issue #31112. The collector path refactor enables the orcad runtime to load the shared stats implementation. The shared feed, desktop wiring change, and related tests support c…
Full details: Description check

Explanation

The description includes all required sections, explains the user impact and implementation, links issue #31112, documents testing and platform coverage, records the separate speech gap, and completes the checklist.

Full details: Linked Issues check

Explanation

Issue #31112 requires orca serve to return existing host totals and count new agent sessions. The PR initializes the stats path in startOrcadStats, creates and passes StatsCollector to the orcad runtime, and feeds the collector from agent status and pane-clear events. Cleanup stops the feed before the final asynchronous flush. The added feed tests cover Node-only execution, session totals, listener cleanup, and persistence. The reported live check also returned seeded totals and rewrote the stats file on shutdown.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue #31112. The collector path refactor enables the orcad runtime to load the shared stats implementation. The shared feed, desktop wiring change, and related tests support consistent session counting. The parity-test expansion checks the constructor and startup-service wiring that allowed this regression. The PR documents speech as a separate gap for #31174 and does not implement speech changes.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

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.

[Bug]: Mobile home stats show 0 on an orca serve host since 1.4.229 (orcad runtime has no stats collector)

1 participant