Skip to content

fix(stats): count agent sessions from hook transitions, not OSC titles (STA-2445) - #14657

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/stats-canonical-transitions-10201
Aug 18, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/stats-canonical-transitions-10201

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​296 $\color{#cf222e}{\Huge{\mathbf{−}}}$​308 $\color{#cf222e}{\Huge{\mathbf{−}}}$​12
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​201 $\color{#cf222e}{\Huge{\mathbf{−}}}$​319 $\color{#cf222e}{\Huge{\mathbf{−}}}$​118

ELI5

Orca's stats page said you'd spawned almost no agents and they'd worked almost no time. That's because the counter wasn't watching agents — it was watching the text in the terminal's title bar and guessing. Agents that report their status properly (over hooks) but don't paint a fancy title were invisible to it. Meanwhile a spinning ⠋ from npm run build looked exactly like an agent, so it got counted as one.

Now the counter listens to the same agent status stream the sidebar and dashboard already use. It counts changes ("this agent just started working", "this agent just finished"), not reports — so when Orca reconnects and the host re-sends everything it remembers, nothing gets counted twice.

What Changed

New: src/main/stats/agent-session-transition-recorder.ts — mirrors the last hook state per pane and forwards start/stop edges to StatsCollector. Two guards carry the whole contract:

  • Same state = snapshot, not a transition. Mid-turn tool-progress events, disk hydration, and reconnect replay all re-emit the current state. Counting those is what makes every reconnect inflate the totals.
  • Only a live event may open a session. A replayed or restoredUnconfirmed working describes work that began in an earlier runtime, so crediting it would mint a phantom spawn. A replayed terminating state still closes a session — that is how a client learns about a completion it missed while disconnected, and refusing it would strand the session open until quit.

Also ignores providerSessionOnly events: they carry a state field but are identity-only resume-metadata refreshes with no turn-state transition.

Wired in main/index.ts beside the StatsCollector construction, to subscribeEnrichedStatus + subscribePaneStatusClear (pane teardown and the SSH transient-disconnect batch close out open sessions rather than leaking their duration to the quit flush).

Deleted: src/main/stats/agent-detector.ts (295 lines) and its raw-PTY invocation in orca-runtime.ts (onData on every chunk, plus onExit). Stats no longer parse a single byte of terminal output.

StatsCollector now keys sessions on a stable pane key instead of a per-spawn ptyId; the event meta field is renamed ptyId → sessionKey (internal log, no readers outside the stats module).

Why

AgentDetector read raw PTY bytes, pulled ordinary OSC titles out of them, and called detectAgentStatusFromTitle. Hook-only transitions never entered that path at all — so the near-zero counters weren't a missing subscription, they were a second, separate truth store.

The detector was provably wrong in both directions:

  • Misses: agent-detector.ts:141-144 returned early whenever the title didn't classify. An agent reporting cleanly over hooks in a pane showing an ordinary shell title contributed nothing.
  • Phantoms: detectAgentStatusFromTitle returns 'working' for any braille or quarter-circle spinner glyph, with no agent-name requirement (agent-title-status.ts:192-194). Every spinner TUI was an "agent spawned".

Dual-record comparison (the measured delta)

Per the review recommendation this landed in two commits: the first adds the recorder alongside the detector with a side-by-side harness feeding both into a real StatsCollector, and changes no behavior. The second switches over and deletes. The measured aggregates:

scenario title detector canonical
hook-only agent 0 1
braille-spinner non-agent TUI (⠋ npm run build) 1 0
one agent across one reconnect 2 1
totals 3 2

The detector's higher total is not better coverage. Two of its three are wrong — one phantom TUI and one duplicate — and the one real agent is the one it never saw. The reconnect row is structural: ptyIds are per-spawn UUIDs that are never reused (agent-detector.ts:78), so restoring buffered output into a fresh PTY re-runs the whole UNKNOWN → AGENT first-classification. Pane keys are stable across reconnect.

Shipped as one PR because the comparison came out clean and unambiguous in every direction. The comparison harness is deleted in commit 2 along with the detector it measures, so it is reviewable in bc0503b9 rather than in the squashed diff.

On idempotency

Counting transitions, not snapshots is the design constraint, and the prior art is why. #14610 fixed a replayed status re-arming a live staleness timer; STA-3524 covers cached replays re-firing task-complete notifications. Both are the same shape: a re-delivered snapshot treated as news. A snapshot-counting stats path would inflate on every WSL relay reconnect and every host-side relay restart. Both guards are mutation-tested below.

Linked Issue

Fixes #10201
Refs STA-2445

Visual Proof

N/A — main-process metric accounting with no rendered surface of its own. The Stats view reads StatsCollector.getSummary() unchanged; only the numbers flowing into it change, and a meaningful before/after would need weeks of real usage rather than a screenshot. The measured delta table above is the evidence.

Testing

src/main/stats/agent-session-transition-recorder.test.ts and stats-title-detection-independence.test.ts drive real StatsCollector aggregates against a temp userData dir. Required coverage:

  • a hook-only agent is counted (it was not before)
  • a braille-spinner non-agent TUI is not counted (it was before) — enforced as an import-graph guard, since the false positive can only return by rewiring title detection into the stats pipeline
  • a replayed/reconnected status does not double-count — both the warm case (pane already mirrored) and the cold case (replay is the first event this recorder sees, where only the live gate can help)

Plus: repeated working/done cycles count one session per turn; waiting/blocked are boundaries, not agent work; providerSessionOnly refreshes are inert; pane teardown and SSH batch clears close open sessions; the mirror is bounded and closes what it evicts.

Proven non-vacuous — each guard was mutated and a test killed it:

mutation caught by
remove the same-state snapshot guard does not double-count a re-emitted live status mid-turn, treats an unchanged state as a snapshot
let a replay open a session (live = true) never opens a session from a replayed or disk-restored working status, opens only on a live working edge
remove both providerSessionOnly guards ignores identity-only provider-session refreshes
re-import title detection into a stats source no stats source imports a title-based agent detector

Scoped checks run (full typecheck skipped — OOM risk; all changes are in src/main, covered by the node project):

  • tsc --noEmit -p config/tsconfig.node.json — clean

  • vitest src/main/stats src/main/agent-hooks — 635 passed

  • vitest src/main/runtime — 4135 passed

  • check-changed-code-quality.mjs — 0 new findings across 6 files (native, type-aware, React Doctor)

  • check-max-lines-ratchet.mjs — OK, no new bypasses

  • oxlint verified live by injecting a violation (it prints nothing when clean)

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Review

  • Security: no new inputs; strictly removes a parser that consumed raw PTY bytes.
  • Cross-platform: no platform-dependent behavior; no paths, shells, or accelerators touched.
  • Remote SSH: no wire change — this subscribes to an existing main-process listener, and nothing new crosses a client/host boundary. SSH panes are covered: the transient-disconnect batch clear closes sessions on the dropped connection at its stamped clearedAt rather than leaving them open. A remote agent still working through a blip is under-counted rather than credited an unbounded idle span, which is the safe direction for "time agents worked".
  • Folder workspaces: keyed on pane key, not worktree; folder workspaces behave identically.
  • Mobile: unaffected — no renderer or mobile surface reads these events.
  • Backwards compatibility: orca-stats.json schema version and aggregate fields are unchanged, so existing totals carry forward. Only the meta key on newly appended events changes (ptyId → sessionKey); nothing reads that field back.
  • Performance: strictly a win. Removes a per-chunk raw-byte scan (OSC extraction + a meaningful-content pass with two per-PTY tail buffers) from the hot onPtyData path, and replaces it with a Map lookup on an event that already fires.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • 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)

Author

  • X / Twitter: @BrennanKB5

@coderabbitai

coderabbitai Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change replaces PTY-based agent detection with hook-status session tracking. A new recorder classifies live and terminal states, handles pane and connection cleanup, and limits stored mirrors. StatsCollector now pairs lifecycle events by sessionKey. Runtime wiring forwards enriched status and pane-clear events to the recorder. PTY detector integration and its regression coverage were removed. Tests verify recorder behavior and prevent title-based detection imports.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The implementation satisfies issue [#10201] by connecting hook transitions to statistics and using stable pane keys instead of OSC-title detection.
Out of Scope Changes check ✅ Passed The changes remain focused on hook-based agent-session statistics, legacy detector removal, stable session identity, and related regression tests.
Title check ✅ Passed The title clearly and concisely describes the switch from OSC title parsing to hook-based agent-session transitions.
Description check ✅ Passed The description explains the change, motivation, testing, compatibility, performance, linked issue, and visual-proof status in substantial detail.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 09fc892e-b271-43bc-acf1-81b6ca462530

📥 Commits

Reviewing files that changed from the base of the PR and between 78d5920 and f0cfcd7.

📒 Files selected for processing (10)
  • src/main/index.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/stats/agent-detector-resurrection-leak.test.ts
  • src/main/stats/agent-detector.test.ts
  • src/main/stats/agent-detector.ts
  • src/main/stats/agent-session-transition-recorder.test.ts
  • src/main/stats/agent-session-transition-recorder.ts
  • src/main/stats/collector.ts
  • src/main/stats/stats-title-detection-independence.test.ts
  • src/main/stats/types.ts
💤 Files with no reviewable changes (4)
  • src/main/stats/agent-detector.test.ts
  • src/main/stats/agent-detector-resurrection-leak.test.ts
  • src/main/stats/agent-detector.ts
  • src/main/runtime/orca-runtime.ts

Comment on lines +102 to +106
if (transition === 'none' && previous?.state === event.payload.state) {
// Refresh recency without touching session state so a long-running pane
// isn't evicted ahead of an idle one.
this.touch(event.paneKey, previous)
return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Refresh connectionId when the state is unchanged.

A working pane can move to a new connection without a state transition. This path preserves the old connectionId. A clear for the new connection then cannot close the active session, so its duration continues until a later status or quit flush.

Proposed fix
     if (transition === 'none' && previous?.state === event.payload.state) {
-      this.touch(event.paneKey, previous)
+      this.touch(event.paneKey, {
+        ...previous,
+        connectionId: event.connectionId
+      })
       return
     }

Add a test that changes connectionId on an unchanged working event, then clears the new connection.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (transition === 'none' && previous?.state === event.payload.state) {
// Refresh recency without touching session state so a long-running pane
// isn't evicted ahead of an idle one.
this.touch(event.paneKey, previous)
return
if (transition === 'none' && previous?.state === event.payload.state) {
// Refresh recency without touching session state so a long-running pane
// isn't evicted ahead of an idle one.
this.touch(event.paneKey, {
...previous,
connectionId: event.connectionId
})
return

import { join } from 'node:path'
import { describe, expect, it } from 'vitest'

const STATS_DIR = join(__dirname)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Check the runtime integration source and multiline imports.

statsSourceFiles() only scans src/main/stats. It does not inspect src/main/index.ts, where the stats pipeline subscribes to agent status. Also, splitting the source before matching misses multiline imports.

A title detector can be wired into the runtime path with a multiline import and this test will pass. Scan complete source text and include the runtime stats entry point in the checked file set.

Also applies to: 29-45

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status

State: MERGEABLE / CLEAN against main. CI green — 44 successful checks, 1 skipped, 0 failing. 10 files, +497/-627 (net -130).

What the review loop established. The stats counters were near-zero not because a subscription was missing, but because AgentDetector was a second, separate truth store: it read raw PTY bytes, pulled ordinary OSC titles out of them, and called detectAgentStatusFromTitle. It was provably wrong in both directions — it returned early whenever a title didn't classify, so a hook-reporting agent in a pane showing an ordinary shell title contributed nothing; and detectAgentStatusFromTitle returns 'working' for any braille or quarter-circle spinner glyph with no agent-name requirement, so every spinner TUI counted as an agent spawn.

The replacement (src/main/stats/agent-session-transition-recorder.ts) mirrors the last hook state per pane and forwards start/stop edges, wired to subscribeEnrichedStatus + subscribePaneStatusClear. Two guards carry the contract: same state is a snapshot rather than a transition (mid-turn tool progress, disk hydration, and reconnect replay all re-emit the current state), and only a live event may open a session — a replayed or restoredUnconfirmed working describes work from an earlier runtime and would mint a phantom spawn. A replayed terminating state still closes a session, deliberately: that is how a client learns about a completion it missed while disconnected. providerSessionOnly events are ignored — they carry a state field but are identity-only resume-metadata refreshes.

agent-detector.ts (295 lines) and its raw-PTY invocation in orca-runtime.ts are deleted. Stats no longer parse a byte of terminal output. StatsCollector now keys sessions on a stable pane key rather than a per-spawn ptyId.

Validation — what was and was not done.

Done, and this is the substantive part: a dual-record comparison before switchover. The work landed in two commits — bc0503b9 adds the recorder alongside the detector with a side-by-side harness feeding both into a real StatsCollector and changes no behaviour; f0cfcd7a switches over and deletes. Measured aggregates:

scenario title detector canonical
hook-only agent 0 1
braille-spinner non-agent TUI (⠋ npm run build) 1 0
one agent across one reconnect 2 1
totals 3 2

The detector's higher total is not better coverage — two of its three are wrong (one phantom TUI, one duplicate) and the one real agent is the one it never saw. The reconnect row is structural: ptyIds are per-spawn UUIDs that are never reused, so restoring buffered output into a fresh PTY re-runs the whole first-classification; pane keys are stable.

Note the harness is deleted in commit 2 along with the detector it measures, so it is reviewable in bc0503b9 and not in the squashed diff. If you want to check the comparison, read that commit.

Tests were proven non-vacuous by mutation: removing the same-state snapshot guard, letting a replay open a session, removing both providerSessionOnly guards, and re-importing title detection into a stats source were each mutated in turn and each killed by a named test. The false-positive guard is enforced as an import-graph assertion, since a spinner phantom can only return by rewiring title detection back into the stats pipeline. Both the warm double-count case (pane already mirrored) and the cold case (replay is the first event the recorder sees, where only the live gate helps) are covered. oxlint was verified live by injecting a violation, since it prints nothing when clean.

Scoped checks: tsc --noEmit -p config/tsconfig.node.json clean, vitest src/main/stats src/main/agent-hooks 635 passed, vitest src/main/runtime 4135 passed, check-changed-code-quality.mjs 0 new findings across 6 files, max-lines ratchet OK.

Not done — read before merging:

  • No real-usage before/after. The stats surface has no rendered proof here, and by the PR's own reasoning a meaningful one would need weeks of real usage rather than a screenshot. The delta table is a harness measurement over synthetic scenarios, not observed production counts. Whether the absolute numbers a user sees become correct is not demonstrated; what is demonstrated is that three specific known-wrong behaviours are fixed.
  • No platform matrix was run; the change has no platform-dependent behaviour and no paths, shells, or accelerators.
  • Full pnpm typecheck skipped (OOM risk); all changes are in src/main, covered by the node project typecheck above.

Known limit worth carrying: on an SSH transient disconnect, the batch clear closes sessions at its stamped clearedAt. A remote agent still working through a blip is therefore under-counted rather than credited an unbounded idle span. That is the deliberate and safer direction for "time agents worked", but it does mean remote durations can read low.

Wire / compat: no wire change; this subscribes to an existing main-process listener. orca-stats.json schema version and aggregate fields are unchanged, so existing totals carry forward. The only format change is the meta key on newly appended events (ptyId → sessionKey), which nothing reads back.

Supersedes: nothing.

…k transitions

Adds an AgentSessionTransitionRecorder that derives agent-session start/stop
boundaries from agent-hook status transitions, and a side-by-side comparison
that feeds both pipelines into a real StatsCollector.

Nothing is rewired yet — this commit only measures the delta:

                                 title detector   canonical
  hook-only agent                       0             1
  braille-spinner non-agent TUI         1             0
  one agent, one reconnect              2             1
  totals                                3             2

Refs #10201, STA-2445.
… title detector

Switches StatsCollector off AgentDetector and onto the canonical agent-hook
status stream, then removes the detector and its raw-PTY invocation.

- main/index.ts subscribes the recorder to subscribeEnrichedStatus and
  subscribePaneStatusClear, next to where StatsCollector is constructed.
- orca-runtime.ts no longer feeds raw PTY bytes to a stats detector.
- StatsCollector keys sessions on a stable pane key, not a per-spawn ptyId.

Fixes #10201, refs STA-2445.
@brennanb2025
brennanb2025 force-pushed the brennanb2025/stats-canonical-transitions-10201 branch from f0cfcd7 to 5c4d084 Compare August 18, 2026 00:04
@coderabbitai

coderabbitai Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/main/stats/stats-title-detection-independence.test.ts (1)

1-10: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Shorten the file header comment.

Lines 1-10 use ten lines for one regression rationale. Keep one concise comment that states the OSC-title spinner false-positive risk.

Proposed change
-// Regression guard for the second half of `#10201`.
-//
-// The deleted AgentDetector read OSC titles, and detectAgentStatusFromTitle
-// classifies ANY braille/quarter-circle spinner glyph as `working` with no
-// agent-name requirement (agent-title-status.ts). That made every spinner TUI —
-// `⠋ npm run build`, a progress bar, a REPL — a counted "agent spawned".
-//
-// Stats now derive sessions from agent-hook transitions only. This test fails if
-// title detection is ever wired back into the stats pipeline, which is the only
-// way that false positive can return.
+// Guard statistics against OSC-title spinner false positives.

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: bc3a0a34-a17a-44f4-a5b3-23286419ec0a

📥 Commits

Reviewing files that changed from the base of the PR and between 24e662a and 5c4d084.

📒 Files selected for processing (10)
  • src/main/index.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/stats/agent-detector-resurrection-leak.test.ts
  • src/main/stats/agent-detector.test.ts
  • src/main/stats/agent-detector.ts
  • src/main/stats/agent-session-transition-recorder.test.ts
  • src/main/stats/agent-session-transition-recorder.ts
  • src/main/stats/collector.ts
  • src/main/stats/stats-title-detection-independence.test.ts
  • src/main/stats/types.ts
💤 Files with no reviewable changes (4)
  • src/main/stats/agent-detector.ts
  • src/main/stats/agent-detector-resurrection-leak.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/stats/agent-detector.test.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/main/stats/types.ts
  • src/main/stats/collector.ts
  • src/main/stats/agent-session-transition-recorder.ts
  • src/main/stats/agent-session-transition-recorder.test.ts
  • src/main/index.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 3 remain after this review.

@brennanb2025
brennanb2025 merged commit 8e13485 into main Aug 18, 2026
45 checks passed
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 21, 2026
…s (STA-2445) (stablyai#14657)

* test(stats): dual-record the OSC-title detector against canonical hook transitions

Adds an AgentSessionTransitionRecorder that derives agent-session start/stop
boundaries from agent-hook status transitions, and a side-by-side comparison
that feeds both pipelines into a real StatsCollector.

Nothing is rewired yet — this commit only measures the delta:

                                 title detector   canonical
  hook-only agent                       0             1
  braille-spinner non-agent TUI         1             0
  one agent, one reconnect              2             1
  totals                                3             2

Refs stablyai#10201, STA-2445.

* fix(stats): count agent sessions from hook transitions and delete the title detector

Switches StatsCollector off AgentDetector and onto the canonical agent-hook
status stream, then removes the detector and its raw-PTY invocation.

- main/index.ts subscribes the recorder to subscribeEnrichedStatus and
  subscribePaneStatusClear, next to where StatsCollector is constructed.
- orca-runtime.ts no longer feeds raw PTY bytes to a stats detector.
- StatsCollector keys sessions on a stable pane key, not a per-spawn ptyId.

Fixes stablyai#10201, refs STA-2445.
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
…s (STA-2445) (stablyai#14657)

* test(stats): dual-record the OSC-title detector against canonical hook transitions

Adds an AgentSessionTransitionRecorder that derives agent-session start/stop
boundaries from agent-hook status transitions, and a side-by-side comparison
that feeds both pipelines into a real StatsCollector.

Nothing is rewired yet — this commit only measures the delta:

                                 title detector   canonical
  hook-only agent                       0             1
  braille-spinner non-agent TUI         1             0
  one agent, one reconnect              2             1
  totals                                3             2

Refs stablyai#10201, STA-2445.

* fix(stats): count agent sessions from hook transitions and delete the title detector

Switches StatsCollector off AgentDetector and onto the canonical agent-hook
status stream, then removes the detector and its raw-PTY invocation.

- main/index.ts subscribes the recorder to subscribeEnrichedStatus and
  subscribePaneStatusClear, next to where StatsCollector is constructed.
- orca-runtime.ts no longer feeds raw PTY bytes to a stats detector.
- StatsCollector keys sessions on a stable pane key, not a per-spawn ptyId.

Fixes stablyai#10201, refs STA-2445.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…s (STA-2445) (stablyai#14657)

* test(stats): dual-record the OSC-title detector against canonical hook transitions

Adds an AgentSessionTransitionRecorder that derives agent-session start/stop
boundaries from agent-hook status transitions, and a side-by-side comparison
that feeds both pipelines into a real StatsCollector.

Nothing is rewired yet — this commit only measures the delta:

                                 title detector   canonical
  hook-only agent                       0             1
  braille-spinner non-agent TUI         1             0
  one agent, one reconnect              2             1
  totals                                3             2

Refs stablyai#10201, STA-2445.

* fix(stats): count agent sessions from hook transitions and delete the title detector

Switches StatsCollector off AgentDetector and onto the canonical agent-hook
status stream, then removes the detector and its raw-PTY invocation.

- main/index.ts subscribes the recorder to subscribeEnrichedStatus and
  subscribePaneStatusClear, next to where StatsCollector is constructed.
- orca-runtime.ts no longer feeds raw PTY bytes to a stats detector.
- StatsCollector keys sessions on a stable pane key, not a per-spawn ptyId.

Fixes stablyai#10201, refs STA-2445.
nwparker added a commit that referenced this pull request Oct 29, 2026
…5852)

* perf(stats): stop retaining and rewriting the raw stats event log (#35544)

The collector kept up to 10K raw events (~203 B each since #14657 switched
meta to pane keys and added worktree ids) and re-serialized the whole ~2 MB
file every 5 s. No consumer reads events; persist aggregates only, keep the
v1 file shape with an empty events array, and compact legacy files on load.

* test(stats): use a small event burst for the retained-size bound
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]: "Agents spawned" / "Time agents worked" stay near-zero — StatsCollector never sees hook-based agent status, only the legacy OSC-title detector

1 participant