Skip to content

perf(daemon): make droppable stream tracking constant-time - #10121

Merged
nwparker merged 1 commit into
mainfrom
nwparker/perf-daemon-droppable-membership
Jul 24, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/perf-daemon-droppable-membership

Conversation

@nwparker

Copy link
Copy Markdown
Contributor

Description

  • Track queued droppable daemon sessions with one per-client-batch membership Set instead of
    recounting every queued session on every hidden-output chunk.
  • Discover membership when queued data first becomes positive, and reconcile it across every
    pending client batch on background changes, attach completion, and exit.
  • Preserve the existing rare Map-order re-trim when the evaluated membership count grows, including
    transformed empty spans, gap/query salvage ordering, and the legacy last-evaluated-count timing.
  • Remove membership on final drain and targeted flush; whole-batch clear/disconnect continues to
    discard all state.
  • Add deterministic operation budgets and lifecycle coverage for background toggles, reattach,
    cross-client held batches, and exit output held behind socket backpressure.

ELI5

Orca used to ask every waiting hidden terminal, “Are you hidden?” whenever one hidden terminal
produced another piece of output. Now each delivery batch keeps a small attendance list and updates it
only when a terminal joins, leaves, hides, reveals, attaches, or exits. The existing rules for which
old output is kept are unchanged.

Proof of zero regression

  • Three independent final reviews—correctness, performance, and platform/integration—report no
    remaining findings after tracing every membership mutation and lifecycle boundary.
  • Full suite: 3,270 files and 34,812 tests passed; 8 files and 60 tests skipped by the existing suite.
  • Focused batcher/server slice: 71/71 tests passed.
  • Full daemon slice: 1,011 tests passed; 5 existing skips.
  • Full Node/CLI/web TypeScript check passed.
  • Touched-file oxlint and oxfmt, reliability gates, max-lines ratchet, and git diff --check passed.
  • Full pnpm run lint passes oxlint, switch exhaustiveness, styled-scrollbar, reliability,
    max-lines, and bundled-guide stages before the pre-existing released orca-cli revision-9
    manifest blocker. This diff changes no skill or manifest files.
  • Tests preserve Map-order gap/salvage behavior, transformed empty spans, control-only entries,
    delayed count updates after shrink/regrow, foreground/background marker order, attach routing,
    partial/final drain, targeted flush, cross-client refresh, and exit-held tails.
  • The code is platform-neutral. macOS, Linux, native Windows/ConPTY, and WSL daemon sessions use the
    same batcher. Direct SSH/relay PTY delivery uses its separate existing batching path and is
    unchanged.

Proof of performance improvement

  • Deterministic pre-change state: 100 positive queued droppable sessions, then 1,000 one-character
    chunks to one already-queued hidden producer.
  • Before: every chunk made 1 producer predicate call plus 100 queued-session predicate calls and
    visits: exactly 101,000 isSessionDroppable calls and 100,000 Map-entry visits.
  • After: the production-path test records 0 droppability predicate calls and 0 Map iterator,
    entries, values, or forEach calls. It performs exactly 1,000 keyed Map reads, 1,000 keyed Map
    writes, and 1,000 Set membership checks while preserving exactly 1,400 total queued characters.
  • Steady-state membership work changes from O(P × N) to O(N), where P is queued producers and N is
    chunks. A newly queued session and a cross-client lifecycle refresh each make exactly one
    droppability predicate call.
  • The intentional O(P) re-trim remains only when the evaluated droppable-session count grows, so the
    aggregate keep-tail budget and reveal-latency protection are unchanged.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b8a08ffc-967c-4db6-8e0f-d6bfe5f12549

📥 Commits

Reviewing files that changed from the base of the PR and between a29c487 and 08c88e9.

📒 Files selected for processing (7)
  • src/main/daemon/daemon-server.ts
  • src/main/daemon/daemon-stream-data-batcher.ts
  • src/main/daemon/daemon-stream-data-entry.ts
  • src/main/daemon/daemon-stream-droppability-lifecycle.test.ts
  • src/main/daemon/daemon-stream-droppable-membership.test.ts
  • src/main/daemon/daemon-stream-droppable-membership.ts
  • src/main/daemon/daemon-stream-keep-tail-drop.ts

📝 Walkthrough

Walkthrough

The change centralizes daemon stream droppability evaluation in shared helpers and tracks droppable sessions with per-batch sets. Queue append operations now return updated session totals, while enqueue, flush, and session flush paths synchronize membership. The daemon refreshes droppability during session attachment, background-state changes, and subprocess exits. New tests cover membership evaluation, trimming, draining, control entries, and lifecycle ordering.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description omits the required template sections and most required details, so it is largely incomplete. Add the required Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes sections, and fill in the cross-platform review details.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: daemon droppable stream tracking is now constant-time.
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.
✨ Finishing Touches
📝 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.

@nwparker
nwparker merged commit 943f9a0 into main Jul 24, 2026
9 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
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.

1 participant