Skip to content

feat(daemon): scope live-ingest SSE events to real session identity - #3361

Merged
Sinity merged 1 commit into
masterfrom
feature/daemon/sse-session-identity
Jul 27, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/daemon/sse-session-identity

Conversation

@Sinity

@Sinity Sinity commented Jul 27, 2026

Copy link
Copy Markdown
Owner

Summary

Live-ingest SSE events (session.appended / message.appended) now carry
the real session id they describe instead of firing once per batch with
session_id: null. Added a real production emitter for session.updated.
Retired three advertised-but-unwired topics (insight.updated,
progress.update, progress.complete) that had zero production callers.

Problem

polylogue-20d.13 names an evidence-identity defect: the daemon emitted one
aggregate session.appended/message.appended event per live-ingest batch
with session_id=None. The web reader's live-tail handler already had
correct session-scoping logic (if (convId && convId !== selectedId) return;
in web_shell_realtime.py), but since the producer never sent a real
session_id, the guard never fired — every successful ingest batch
refreshed whichever session the browser happened to have open, regardless
of which session actually changed.

Separately, session.updated was advertised in GRANULAR_EVENT_KINDS and
subscribed to by the client, but had no emitter at all. Grepping the whole
codebase for emit_insight_updated/emit_progress_update/
emit_progress_complete turned up zero production callers — only their own
unit tests — and the docstring's claimed CLI consumer
(status --convergence --watch) does not exist.

Solution

  • polylogue/sources/live/append_ingest.py: capture the session_id that
    archive.apply_raw_revision_replay already returns (previously
    discarded) into a new _AppendResult.session_ids_by_path.
  • polylogue/sources/live/batch_support.py: add
    _FullIngestResult.changed_session_ids (threaded from
    _IngestBatchSummary.changed_session_ids, which existed but was only
    ever reduced to a count).
  • polylogue/sources/live/batch.py: accumulate (source_name, session_id)
    touches from both routes during ingest_files and attach them to
    LiveBatchMetrics as new_sessions (full-ingest route — first
    materialization) and updated_sessions (append route — the append path
    only ever grows a file whose session already exists, by construction).
  • polylogue/sources/live/metrics.py: serialize the two new fields in
    to_payload().
  • polylogue/daemon/cli.py: _emit_live_batch_event now fans out one
    session.appended/session.updated/message.appended event per
    distinct touched session
    , each carrying its real session_id, instead
    of one aggregate event. Falls back to the old unscoped emission only when
    no identity was resolved for a succeeded batch (an explicit, logged
    degrade rather than silent loss — covers source families this pass
    doesn't thread identity through yet).
  • polylogue/daemon/events.py: added emit_session_updated (the first real
    producer for session.updated); added session_id to
    emit_session_appended. Removed EVENT_INSIGHT_UPDATED,
    EVENT_PROGRESS_UPDATE, EVENT_PROGRESS_COMPLETE and their emitters —
    per this bead's own design text ("remove topics with no production
    semantics or wire their actual producers"), zero-producer advertised
    topics are a completeness defect, not a feature worth preserving.
  • polylogue/daemon/web_shell_realtime.py / events_http.py: dropped the
    matching client-side subscriptions/handlers and doc references.

Not done (honest residual):

  • No formal per-topic EventSpec registry (design section 1 of this bead)
    — that's a larger structural addition (ids, refs, cursor/frame, phase,
    authorization contract per topic) beyond identity-scoping the two
    existing wired topics.
  • New-vs-updated classification uses the ingestion route (full vs
    append) as a proxy for new-vs-existing session. This is accurate for the
    common case (a brand-new file vs. an already-cursor-tracked file growing)
    but a full reparse of an already-existing session id (e.g. a rewritten
    file) would still surface as session.appended rather than
    session.updated. Documented, not silently claimed solved.
  • Multi-session bundle raws (browser-capture snapshots, ChatGPT exports)
    get correct per-session identity for every touched session, but no
    per-session message-count split (the underlying membership-census
    application only returns an aggregate message count across all sessions
    in one raw).
  • Ring-gap resync, subscriber cap, and privacy/auth policy (AC refactor: split CLI into command modules and add HTML preview output #4 and Conversation data is scattered across four providers with no unified archive path #5)
    were already in place before this change (bounded replay ring, Last- Event-ID, subscriber controls in events_http.py) and are untouched by
    this PR.

Verification

devtools test tests/unit/sources/test_live_watcher.py \
  tests/unit/sources/test_live_metrics.py \
  tests/unit/daemon/test_daemon_events_endpoint.py \
  tests/unit/sources/test_live_batch_support.py
# 193 passed, 1 pre-existing failure unrelated to this change
# (test_live_full_ingest_over_ambiguous_membership_fails_closed_with_diagnostic,
# reproduced identically against master before this branch existed)

uv run mypy polylogue          # Success: no issues found in 1087 source files
uv run ruff check . / format --check .   # all clean
devtools render all --check    # exit 0
devtools verify --quick        # exit_code 0

Anti-vacuity: reverted the session_ids_by_path assignment in
append_ingest.py and confirmed
test_live_ingest_metrics_carry_real_session_identity fails
(assert () == (('claude-code', ...),)), then restored it — proving the
test exercises the real production wiring, not a self-authorized mock.

Ref polylogue-20d.13

Problem: session.appended/message.appended fired once per batch with
session_id=None regardless of which session actually changed, so a
browser with session A open was refreshed by an event that only ever
touched session B. session.updated had no production emitter at all,
and emit_insight_updated/emit_progress_update/emit_progress_complete
were tests-only (no caller anywhere in the codebase, despite being
advertised SSE topics).

What changed:
- Thread real session identity from the live-ingest full/append routes
  into LiveBatchMetrics (new_sessions/updated_sessions, (source_name,
  session_id) pairs) via _FullIngestResult.changed_session_ids and a
  new _AppendResult.session_ids_by_path (captured from the session_id
  apply_raw_revision_replay already returns but previously discarded).
- daemon/cli.py's _emit_live_batch_event now fans out one
  session.appended/session.updated/message.appended event per distinct
  touched session, each carrying its real session_id, instead of one
  aggregate event with session_id=None. Falls back to the prior
  unscoped emission only when no identity was resolved (an explicitly
  logged, honest degrade, not silent loss).
- Added emit_session_updated (daemon/events.py) as the first real
  producer for session.updated, fired from the append route (which
  only ever grows an already-tracked file -- an existing session, by
  construction).
- Retired insight.updated/progress.update/progress.complete: grepped
  the whole codebase and found no production caller for
  emit_insight_updated/emit_progress_update/emit_progress_complete,
  and the docstring's claimed CLI consumer does not exist. Per this
  bead's design ("remove topics with no production semantics or wire
  their actual producers"), an advertised topic with zero real
  producers is a completeness defect, not a feature worth preserving.
  Removed the constants, emitters, GRANULAR_EVENT_KINDS entries, and
  the matching client-side subscriptions/handlers in
  web_shell_realtime.py.

Verification:
- devtools test tests/unit/sources/test_live_watcher.py
  tests/unit/sources/test_live_metrics.py
  tests/unit/daemon/test_daemon_events_endpoint.py
  tests/unit/sources/test_live_batch_support.py
  -> 192 passed, 1 pre-existing failure unrelated to this change
  (test_live_full_ingest_over_ambiguous_membership_fails_closed_with_diagnostic,
  reproduced identically on master before this branch).
- Anti-vacuity: reverted the session_ids_by_path assignment in
  append_ingest.py and confirmed
  test_live_ingest_metrics_carry_real_session_identity fails
  (assert () == (('claude-code', ...),)), then restored it.
- mypy --strict polylogue -> Success: no issues found in 1086 source files.
- ruff check . / ruff format --check . -> all clean.
- devtools render all --check -> exit 0, no surfaces out of sync.
- devtools verify --quick -> exit_code 0.

Not done (honest residual, left for follow-up): no formal EventSpec
registry per topic (design section 1 of this bead); full/append-path
classification uses ingestion route as a proxy for new-vs-existing
session (a full reparse of an already-existing session id would still
surface as session.appended -- documented, not silently claimed
solved); multi-session bundle raws (browser-capture, ChatGPT exports)
get identity for every touched session but no per-session message-count
split; ring-gap resync/backpressure/subscriber-cap semantics were
already in place before this change and are untouched.

Ref polylogue-20d.13

Co-Authored-By: Claude <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 53 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f6df1466-9009-44cf-b8b5-2b7651a3f2cd

📥 Commits

Reviewing files that changed from the base of the PR and between ac108e4 and 7d13fde.

📒 Files selected for processing (11)
  • polylogue/daemon/cli.py
  • polylogue/daemon/events.py
  • polylogue/daemon/events_http.py
  • polylogue/daemon/web_shell_realtime.py
  • polylogue/sources/live/append_ingest.py
  • polylogue/sources/live/batch.py
  • polylogue/sources/live/batch_support.py
  • polylogue/sources/live/metrics.py
  • tests/unit/daemon/test_daemon_events_endpoint.py
  • tests/unit/sources/test_live_metrics.py
  • tests/unit/sources/test_live_watcher.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/daemon/sse-session-identity

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.

@Sinity
Sinity merged commit 1ccecd5 into master Jul 27, 2026
3 checks passed
@Sinity
Sinity deleted the feature/daemon/sse-session-identity branch July 27, 2026 21:13
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