feat(newtab): one leader row with machine, direct-report attention and linear aggregation

Draft
TE
3d ago
+152-22

Brief 18 — one leader row with machine and attention, even at thousands of sessions

Source-backed follow-up to HQ #6236 brief 18 and the already merged Leads #32103 / duplicate-group cleanup #32107. Original base: feat-cmux-next@6c3fe3648ba4b44e7bf38c4982a665ec2d5d5712.

Problem / why this is a bounded change

The New Tab All view repeated a working leader in both Leads and Active. Leads displayed only a report count, leaving its machine and direct reports awaiting human input invisible. The TypeScript leaders() builder copied the entire accumulated report array for every new report, O(k²) for one large reporting group. HQ #4878 documents a real census of 3,055 sessions, including 38 streaming, so fan-out costs deserve attention.

Change

  • Keep the leader in Leads once and remove its same-machine duplicate from Active, while retaining other local/remote sessions with a coincidentally equal bare ID. Other filters still show active sessions.
  • Show the leader's known host/peer and Needs input (N) for itself plus direct reporters explicitly marked indicator: input. Preserve existing translations for report count and input label.
  • Keep peer on live-chat cards for identity-safe React keys and list deduplication.
  • Replace repeated report-array spreading with in-place append; row order stays stable.
  • Add targeted pure-model tests for host collisions, direct-report input, archived/closed exclusion, and a 3,000-report fan-out; add a DOM test for one lead row, location, attention and a same-bare-ID local chat.

Validation and evidence tier

Source change + authored tests; app test execution pending. This connector session has GitHub write access but no Bun/React app environment or approved live machine, so I did not claim a full web suite, signed build, or runtime capture. Run:

cd webviews
bun test src/agent-session/acpmux/leads.test.ts src/agent-session/acpmux/newtab/leaderCards.test.ts src/agent-session/acpmux/newtab/leadsList.test.tsx
bun run typecheck
../scripts/web-lint.sh

An isolated Node 22 synthetic 3,000-report fan-out benchmark (9 trials, median) improved from 5.617 ms with repeated spreads to 0.025 ms with appended arrays. This is a focused algorithm measurement, not a NEXT app CPU or wall-clock improvement claim. The meaningful verification is the web suite and a New Tab gallery/capture on the merged app head.

Boundaries / review requests

  • #32218 remains the native opening identity problem: onOpenSession calls chat.select({sessionId}) with the bare ID. Distinct React keys and deduplication prevent visual collisions here but do not solve wrong-chat opening between peers. Address with peer-qualified selection all the way through the host before promising safe cross-machine navigation.
  • lane.reportsTo derives local-daemon direct reporting only; remote-to-remote delegation, nested leadership and stale/disconnected peer status still need explicit coverage. Current Needs input count deliberately excludes errors and ambiguous offline signals.
  • This work does not touch group tidy, mutate live sidebar groups, change machine/account permissions or create Cloud VMs.
  • New Tab Leads appearance changed; request gallery before/after plus peer-collision and filtered-view review. Draft until checks and owner review.

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.


Summary by cubic

Fixes the New Tab All view so each working leader appears once, in Leads, showing its machine and how many direct reports need input — previously leaders were duplicated in Leads and Active, and Leads showed only a report count. Also removes the O(k²) cost of accumulating large report groups in the leader builder.

Refactors

  • Leader rows are deduplicated by the owning machine; a chat with the same bare session ID on another machine stays visible in Active.
  • The leads builder appends to its report groups in place, preserving row order.