Skip to content

feat(webui): realtime update channel for ingest events (#957) - #1128

Merged
Sinity merged 1 commit into
masterfrom
feature/feat/webui-realtime-updates
May 17, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/feat/webui-realtime-updates

Conversation

@Sinity

@Sinity Sinity commented May 17, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds a realtime update channel from the daemon to the web reader so the
conversation list, facets, and status chips refresh as the daemon
ingests new sessions, without a manual page reload. Closes #957.

Problem

The web reader (polylogue/daemon/web_shell.py) was strictly
request/response: opening the page pinned a snapshot of archive state
and only setInterval(loadStatus, 30000) polled — and only the status
chips, not the conversation list. New sessions landing in seconds
elsewhere in the system required an F5. The daemon already emits
operational events (ingestion_batch, ingest, reset, operation)
to a SQLite ledger at daemon_events.db (via
polylogue/daemon/events.py), but there was no surface that turned
those events into reader notifications.

Solution

Wire the existing daemon-event ledger to the reader as a streaming
channel, with an ETag-style fallback when SSE is not available.

  • polylogue/daemon/events.py — add query_events_since(last_id, kinds, limit) and get_latest_event_id(). These expose the ledger as
    a monotonic cursor and are the substrate for both the SSE stream and
    the polling fallback.
  • polylogue/daemon/events_http.py (new module to keep
    daemon/http.py under its file-size budget) — implements GET /api/events with two shapes: SSE stream (default) writing one frame
    per event with id:/event:/data: lines and a heartbeat comment
    between idle ticks, bounded by max_seconds so HTTP idle timeouts and
    tests cannot deadlock; and ?poll=1 returning a JSON snapshot of
    {events, last_event_id} for the ETag fallback. Honors
    Last-Event-ID for EventSource reconnect semantics and a kinds
    whitelist.
  • polylogue/daemon/http.py — routes /api/events to the new module;
    GET /api/status advertises last_event_id and a weak ETag, and
    returns 304 Not Modified when If-None-Match matches. _check_auth
    accepts ?access_token=... so EventSource (which cannot send custom
    headers) can authenticate when a daemon token is configured.
  • polylogue/daemon/web_shell.py — replaces the naive loadStatus
    poller with an EventSource subscription that debounce-refreshes the
    conversation list, facets, and status chips on relevant event kinds,
    falls back to a 5s ?poll=1 loop on persistent SSE failure, and
    drives a live: live | stale | polling | offline | connecting status
    chip with the last-seen event id.
  • Tests: tests/unit/daemon/test_daemon_events_endpoint.py — 9
    contract tests covering poll envelopes, kinds whitelist, strict-gt
    since semantics, SSE frame shape, Last-Event-ID resume, status ETag
    • 304, and the access_token query auth fallback. Existing daemon
      http contract tests extended with last_event_id as a required
      status key.
  • docs/plans/file-size-budgets.yaml, docs/plans/topology-target.yaml,
    docs/topology-status.md, CHANGELOG.md updated for the new module
    and the trimmed daemon/http.py budget headroom.

Alternative rejected: WebSocket. SSE is sufficient for the
server-to-client direction the reader actually needs, works over
HTTP/1.x without protocol upgrade, has built-in reconnect via
EventSource, and reuses the existing BaseHTTPRequestHandler without
introducing a WS stack.

Out of scope of this PR (the issue explicitly lists granular event
families — conversation.created, message.appended,
insights.refreshed, etc., and per-row animations). The substrate now
exists for those: emit a new event kind from the producer and the
reader will see it. Tracked here:

Verification

devtools verify --quick

exit_code: 0 after rendering topology/pages and adding the
daemon/http.py budget exception.

nix develop -c pytest tests/unit/daemon/test_daemon_events_endpoint.py \
  tests/unit/daemon/test_daemon_http_contracts.py \
  tests/unit/daemon/test_daemon_http.py \
  tests/unit/daemon/test_daemon_http_security.py

215 passed in 9.17s (9 new + 206 existing).

Pre-existing failures in tests/unit/cli/test_terminal_snapshots.py
reproduce on origin/master and are unrelated to this change.

Closes #957

Summary by CodeRabbit

Release Notes

  • New Features

    • Added real-time event streaming endpoint with Server-Sent Events, including JSON polling fallback for broader browser compatibility
    • Live status indicator in the web interface displaying connection state (connecting, live, polling, or offline)
    • Enhanced status endpoint with HTTP caching headers (ETag) and conditional response support
    • Automatic client-side fallback to polling when real-time streaming is unavailable
  • Tests

    • Added comprehensive test coverage for event streaming and status endpoints

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 17, 2026 •

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Sinity has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 55 minutes and 38 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5dedd4c6-a761-431a-a100-b077b4c3cbb7

📥 Commits

Reviewing files that changed from the base of the PR and between 5f4f307 and b6c63b3.

📒 Files selected for processing (11)
  • CHANGELOG.md
  • docs/plans/file-size-budgets.yaml
  • docs/plans/topology-target.yaml
  • docs/topology-status.md
  • polylogue/daemon/events.py
  • polylogue/daemon/events_http.py
  • polylogue/daemon/http.py
  • polylogue/daemon/web_shell.py
  • tests/unit/daemon/test_daemon_events_endpoint.py
  • tests/unit/daemon/test_daemon_http_contracts.py
  • tests/unit/daemon/test_daemon_http_security.py
📝 Walkthrough

Walkthrough

Implements a Server-Sent Events realtime notification channel (GET /api/events) for the daemon that streams ingestion, reset, and operation events, with JSON polling fallback (?poll=1). Updates /api/status to include last_event_id and weak ETags (304 Not Modified). Replaces client-side fixed-interval polling with SSE subscription, automatic fallback to polling on unavailability, and a live status chip.

Changes

Realtime Event Streaming

Layer / File(s) Summary
Events query interface
polylogue/daemon/events.py
query_events_since(last_id, kinds=None, limit=200) fetches events with id > last_id in ascending order, optionally filtered by allowlist of kinds; get_latest_event_id() returns maximum id or 0 when empty. Both added to __all__ exports.
HTTP events streaming handler
polylogue/daemon/events_http.py
New module implements handle_events supporting two /api/events modes: JSON polling mode with ?poll=1 returning events since cursor, and Server-Sent Events streaming with long-polling, event frames, and periodic heartbeat comments. Helper functions serialize SSE frames with orjson and manage response stream writes.
HTTP router and status updates
polylogue/daemon/http.py
Adds _handle_events method delegating to events module, routes GET /api/events with parsed query params, extends _send_json with optional extra_headers for HTTP caching. Replaces _handle_status to compute weak ETag from latest event id, return 304 NOT_MODIFIED on If-None-Match match, inject last_event_id into payload. Query-string access_token parsed as bearer token fallback when Authorization header absent.
Client-side realtime subscription
polylogue/daemon/web_shell.py
Adds status-live chip to display connection state and last-seen event id. Replaces fixed-interval status refresh with SSE subscription to /api/events?since=..., event handlers updating live chip and throttling UI refreshes on ingest, reset, operation events. Implements polling fallback (/api/events?poll=1) when SSE unavailable or timeout occurs.
Test contracts and validation
tests/unit/daemon/test_daemon_events_endpoint.py, tests/unit/daemon/test_daemon_http_contracts.py, tests/unit/daemon/test_daemon_http_security.py
Comprehensive contract tests for JSON polling (empty response, ordering, strict since, kind filtering), SSE streaming (headers, frame format, Last-Event-ID suppression), and /api/status ETag behavior with 304 conditional. Added last_event_id to required status fields. Updated mock signature to accept **kwargs for extra headers.
Documentation and topology updates
CHANGELOG.md, docs/plans/file-size-budgets.yaml, docs/plans/topology-target.yaml, docs/topology-status.md
Changelog documents SSE endpoint with polling fallback and status ETag behavior. File-size budget exception added for polylogue/daemon/http.py (1200 line ceiling). Topology metadata updated for affected modules; summary counts incremented by 2.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

🐰 A rabbit hops through streams of time,
where daemon heartbeats sync sublime.
No more the stale refresh delay—
live events dance and play all day!
SSE flows through realtime's grace, ✨
while fallback polls keep steady pace.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 36.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(webui): realtime update channel for ingest events (#957)' accurately summarizes the primary change - adding a realtime update mechanism to the web UI for daemon ingest events.
Description check ✅ Passed The PR description comprehensively covers all template sections: Summary (what changed), Problem (why needed), Solution (modules touched), Verification (commands run), Changelog (updated), and Risks (deferred work noted).
Linked Issues check ✅ Passed The PR implements the core technical requirements from #957: streaming channel (SSE), event emission/subscription, fallback polling, and status indicator. Granular event kinds and animations are explicitly deferred as out-of-scope.
Out of Scope Changes check ✅ Passed All changes directly support the realtime update objective: daemon event querying, HTTP endpoints, web shell subscription, tests, and documentation updates are within scope per #957 requirements.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/feat/webui-realtime-updates

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 and usage tips.

Add a Server-Sent Events channel from the daemon to the web reader so
new conversations and ingest activity surface without a manual refresh.

- polylogue/daemon/events.py: query_events_since() and
  get_latest_event_id() expose the daemon-event ledger as a monotonic
  cursor.
- polylogue/daemon/events_http.py (new): GET /api/events handler with
  two shapes — SSE stream (default) and JSON snapshot (poll=1) — plus
  Last-Event-ID resume semantics for EventSource reconnects.
- polylogue/daemon/http.py: routes /api/events; status payload gains
  last_event_id + weak ETag and returns 304 on If-None-Match; auth
  accepts access_token query param so EventSource can authenticate
  without a custom header.
- polylogue/daemon/web_shell.py: subscribes via EventSource, refreshes
  conversations/facets/status on relevant kinds, falls back to polling
  on persistent failure, and surfaces a live/stale/offline status chip.
- tests + budget/topology/CHANGELOG updates.

Closes #957

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@Sinity
Sinity force-pushed the feature/feat/webui-realtime-updates branch from 5f4f307 to b6c63b3 Compare May 17, 2026 00:34
@Sinity
Sinity merged commit 632ffe7 into master May 17, 2026
2 checks passed
@Sinity
Sinity deleted the feature/feat/webui-realtime-updates branch May 17, 2026 00:34

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5f4f30762c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread polylogue/daemon/web_shell.py Resolved
Comment thread polylogue/daemon/http.py Resolved
@Sinity

Sinity commented Sep 30, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

Only the rows listed above are dispositioned. Held findings remain open.

@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

  • 63.F073 / P2: fixed-already at the checked revision: The status ETag now hashes the stable status representation at polylogue/daemon/http.py:3329-3330 rather than only the latest event ID. The projection removes only clock-only age/evaluation fields at line 519, so health, disk and liveness changes alter conditional identity without requiring a daemon event.

Only the rows listed above are dispositioned. Held findings remain open.

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.

feat(webui): realtime — live, dynamic updates as the daemon ingests

1 participant