Repository navigation
feat(daemon): scope live-ingest SSE events to real session identity - #3361
Conversation
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]>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reached
Next review available in: 53 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (11)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Summary
Live-ingest SSE events (
session.appended/message.appended) now carrythe real session id they describe instead of firing once per batch with
session_id: null. Added a real production emitter forsession.updated.Retired three advertised-but-unwired topics (
insight.updated,progress.update,progress.complete) that had zero production callers.Problem
polylogue-20d.13names an evidence-identity defect: the daemon emitted oneaggregate
session.appended/message.appendedevent per live-ingest batchwith
session_id=None. The web reader's live-tail handler already hadcorrect session-scoping logic (
if (convId && convId !== selectedId) return;in
web_shell_realtime.py), but since the producer never sent a realsession_id, the guard never fired — every successful ingest batchrefreshed whichever session the browser happened to have open, regardless
of which session actually changed.
Separately,
session.updatedwas advertised inGRANULAR_EVENT_KINDSandsubscribed to by the client, but had no emitter at all. Grepping the whole
codebase for
emit_insight_updated/emit_progress_update/emit_progress_completeturned up zero production callers — only their ownunit tests — and the docstring's claimed CLI consumer
(
status --convergence --watch) does not exist.Solution
polylogue/sources/live/append_ingest.py: capture thesession_idthatarchive.apply_raw_revision_replayalready returns (previouslydiscarded) 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 onlyever reduced to a count).
polylogue/sources/live/batch.py: accumulate(source_name, session_id)touches from both routes during
ingest_filesand attach them toLiveBatchMetricsasnew_sessions(full-ingest route — firstmaterialization) and
updated_sessions(append route — the append pathonly ever grows a file whose session already exists, by construction).
polylogue/sources/live/metrics.py: serialize the two new fields into_payload().polylogue/daemon/cli.py:_emit_live_batch_eventnow fans out onesession.appended/session.updated/message.appendedevent perdistinct touched session, each carrying its real
session_id, insteadof 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: addedemit_session_updated(the first realproducer for
session.updated); addedsession_idtoemit_session_appended. RemovedEVENT_INSIGHT_UPDATED,EVENT_PROGRESS_UPDATE,EVENT_PROGRESS_COMPLETEand 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 thematching client-side subscriptions/handlers and doc references.
Not done (honest residual):
EventSpecregistry (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.
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.appendedrather thansession.updated. Documented, not silently claimed solved.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).
were already in place before this change (bounded replay ring,
Last- Event-ID, subscriber controls inevents_http.py) and are untouched bythis PR.
Verification
Anti-vacuity: reverted the
session_ids_by_pathassignment inappend_ingest.pyand confirmedtest_live_ingest_metrics_carry_real_session_identityfails(
assert () == (('claude-code', ...),)), then restored it — proving thetest exercises the real production wiring, not a self-authorized mock.
Ref polylogue-20d.13