Skip to content

refactor(core): centralize session indexing#124

Merged
xingkaixin merged 3 commits into
mainfrom
feat/cs-43-session-index
Jul 11, 2026
Merged

refactor(core): centralize session indexing#124
xingkaixin merged 3 commits into
mainfrom
feat/cs-43-session-index

Conversation

@xingkaixin

Copy link
Copy Markdown
Owner

Summary

  • add a browser-safe canonical session index module for activity, route, agent, project, and project-agent lookups
  • centralize route-keyed change/removal merging and stable activity ordering
  • make the Web live-update and derived-index adapters reuse the canonical implementation
  • keep CLI sorting on the same comparator and sorted-input fast path
  • add characterization, deterministic incremental/full equivalence tests, and a reproducible benchmark

Why

Session ordering and lookup semantics were independently implemented in core orchestration, Web live updates, and Web indexes. That duplication made first-match route behavior, project identity keys, and SSE replacement semantics vulnerable to drift.

The new contract seam is pure and browser-safe, so both Node and Web adapters share behavior without sharing runtime-dependent instances.

Complexity note

The original O(K log N) target is not achievable end to end while CLI and React callers require complete array snapshots: materializing a snapshot has an O(N) lower bound. This change avoids sorting already ordered snapshots and centralizes the work, but does not claim a benchmark speedup. At 25,000 sessions and 100 changes, the median comparison was 27.46 ms for the canonical path versus 26.80 ms for the repeated-sort model.

A balanced incremental structure should only be introduced if callers can consume lazy ordered views; otherwise it adds implementation complexity without removing snapshot cost.

Validation

  • pnpm lint
  • pnpm format:check
  • pnpm build
  • pnpm test (654 passed)
  • pnpm test:e2e (6 passed)
  • pnpm bench:session-index

Closes CS-43

@xingkaixin xingkaixin marked this pull request as ready for review July 11, 2026 11:54
@xingkaixin xingkaixin merged commit 59d3bfb into main Jul 11, 2026
7 checks passed
@xingkaixin xingkaixin deleted the feat/cs-43-session-index branch July 11, 2026 11:55
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