Skip to content

FIX: MessageBus reconnect reliability#8

Merged
merefield merged 10 commits intomasterfrom
fix/messagebus-reconnect-reliability
Mar 19, 2026
Merged

FIX: MessageBus reconnect reliability#8
merefield merged 10 commits intomasterfrom
fix/messagebus-reconnect-reliability

Conversation

@merefield
Copy link
Owner

@merefield merefield commented Mar 19, 2026

  • Reworked live status updates to be MessageBus-first, with notification and PM badges seeded from Discourse’s notification_channel_position instead of relying on steady-state HTTP polling.
  • Replaced constant healthy-state badge polling with reconnect-triggered one-shot HTTP resync, while keeping HTTP fallback when live counts are still unseeded or MessageBus is unavailable.
  • Added per-channel MessageBus cursor tracking for /latest, /new, /unread, /unread/:user_id, /notification/:user_id, and active /topic/:id subscriptions.
  • Added a MessageBus watchdog that runs every 30s, detects stale clients after 240s without successful polls, and rebuilds the client cleanly.
  • Added reconnect recovery that restores subscriptions from saved channel positions and requests list/topic refreshes when resume state is not trustworthy.
  • Introduced a timeout-configured MessageBusHTTPClient wrapper with explicit open, read, and write timeouts.
  • Fixed reconnect edge cases so badge seeding keeps retrying until live values are populated, and default -1 cursors are treated as non-resumable rather than trusted.
  • Added live topic subscriptions for /topic/:id, so termcourse can react while you are inside a topic instead of only at the list level.
  • Added live in-topic handling for new posts, including tail-follow behavior when you are already on the last loaded post.
  • Added live in-topic handling for post edits, likes/unlikes, delete/recover-style updates via targeted single-post refreshes.
  • Added topic refresh fallback for reload-style and stats-style topic events when incremental updates are not sufficient.
  • Fixed topic reconnect behavior so revisiting a topic updates the stored topic cursor and failed topic refreshes stay pending until they succeed.
  • Improved topic-view responsiveness by removing constant idle rerenders, rendering only the needed visible post blocks, caching rendered post blocks, and reducing debug I/O churn.
  • Tightened temporary debug instrumentation so it is only active when TERMCOURSE_DEBUG=1.
  • Clarified auth behavior in the README: realtime MessageBus features require login auth with a session cookie; API-key auth is HTTP-only and does not support live PM/topic updates.
  • Added focused regression coverage for reconnect reliability, resumable cursors, topic refresh behavior, healthy-state no-poll behavior, and the custom MessageBus HTTP client wrapper.

@merefield merefield requested a review from Copilot March 19, 2026 10:05
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR reworks Termcourse’s live status updates to be MessageBus-first, improving reconnect behavior and reducing steady-state HTTP polling by seeding counts from the server and resyncing on reconnect.

Changes:

  • Added watchdog-driven MessageBus reconnect logic with per-channel resume positions and explicit resync/refresh requests.
  • Made notification + PM badge counts primarily driven by MessageBus, with HTTP seeding/resync and reduced periodic polling.
  • Introduced a timeout-configured MessageBus HTTP client wrapper and expanded test coverage for the new behaviors.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
lib/termcourse/live_updates.rb Adds watchdog/restart logic, per-channel positions, resync + topic list refresh requests, and PM count tracking.
lib/termcourse/message_bus_http_client.rb New MessageBus HTTP client subclass to apply explicit Net::HTTP timeouts for long-polling.
lib/termcourse/ui.rb Switches UI loops to maybe_refresh_status_counts, adds server seeding/resync hooks, and integrates PM unread via live updates.
lib/termcourse/cli.rb Passes notification_channel_position from Discourse session/current-user data into the UI.
lib/termcourse.rb Requires the new message_bus_http_client file.
test/live_updates_test.rb Adds tests for resume positions, channel position tracking, watchdog restarts, and refresh requests.
test/ui_caching_test.rb Updates caching/polling tests to reflect “live healthy => no poll” and reconnect resync behavior; adds PM totals coverage.
test/ui_renderer_test.rb Extends notification state tests to cover PM unread count behavior when live values are zero.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@merefield merefield requested a review from Copilot March 19, 2026 13:31
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR shifts termcourse’s realtime model to be MessageBus-first (instead of steady-state polling), improves reconnect reliability, and extends realtime behavior into topic view with live post updates plus fallback resync/refresh paths.

Changes:

  • Reworks status counts (notifications + PMs) to prefer MessageBus values, with one-shot HTTP reseeding on reconnect and reduced background polling.
  • Adds MessageBus reliability features: per-channel positions, watchdog-based stale detection/restart, and a timeout-configured MessageBus HTTP client wrapper.
  • Adds topic-view live-update plumbing (watching topic channels, merging post deltas, and cache invalidation) plus README clarification about realtime requiring cookie-based login auth.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
test/ui_renderer_test.rb Updates UI notification-state tests for PM unread counts and new refresh return shape.
test/ui_caching_test.rb Updates caching/status-count tests for MessageBus-first behavior, reseed retry, and reconnect resync.
test/live_updates_test.rb Expands LiveUpdates tests for channel positions, watchdog restarts, and reseed triggers.
lib/termcourse/ui.rb Implements MessageBus-first status counts, reconnect resync hooks, topic live-update loop, and post-block caching/invalidation.
lib/termcourse/message_bus_http_client.rb Introduces a timeout-configured MessageBus HTTP client with streaming long-poll handling.
lib/termcourse/live_updates.rb Adds watchdog/restart logic, per-channel cursor tracking, PM unread tracking, and reconnect resync signaling.
lib/termcourse/cli.rb Passes Discourse’s notification_channel_position into UI/LiveUpdates setup.
lib/termcourse.rb Wires in the new MessageBus HTTP client wrapper.
README.md Documents realtime limitations of API-key auth and clarifies status badge behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@merefield merefield merged commit 4e24952 into master Mar 19, 2026
2 checks passed
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.

2 participants