Skip to content

fix(mcpx): tell a live /v1/events subscriber what it missed (#1914) - #2564

Merged
dezren39 merged 1 commit into
mainfrom
queue/3192-1914-events-live-drop
Oct 30, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/3192-1914-events-live-drop

Conversation

@dezren39

@dezren39 dezren39 commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Closes the remainder of #1914 left by the triage verdict (queue task 2809): a subscriber that falls behind live was still losing events silently.

What changed

pkgs/mcpx/internal/daemon/server.go — handleEvents now tracks the last sequence it delivered (lastSeq) and the drop count it has already reported (toldDrops), and emits the gap in band:

event: gap
data: {"since":<last delivered>,"latest":<bus latest>,"dropped":<this stream's losses>}
  • before the next delivered event, so the client learns why the sequence jumps before it reads the jump;
  • on the keep-alive tick as well, because a stall long enough to drop events can also be followed by silence;
  • once per stall, not once per delivered event.

This is the same event: gap shape the stream already emits at subscribe time, so clients that resynchronise on it need no new code. The subscribe-time replay path is untouched (it was fixed in #193).

Tests

  • internal/events: TestAFullRetainedHistoryReplaysAtSinceZero — 1024 events (the full retained history, not the 300 the existing regression test used), replayed at since=0: no gap, no drops, every sequence delivered.
  • internal/daemon: TestEventsTellsAStalledSubscriberWhatItMissed — the stall is produced deterministically by blocking the writer's first Flush, so the drops are real subscription drops rather than a timing race; asserts the gap line carries dropped and latest and precedes the event that follows the hole.

Verification

  • go vet ./internal/daemon/ ./internal/events/ — clean
  • go test ./internal/events/ -run 'FullRetainedHistory|ReplayLarger' — pass
  • go test ./internal/daemon/ -run 'StalledSubscriber|EventsRefuses' — pass
  • Full ./internal/daemon package on this laptop cannot complete: the daemon takeover/restart tests send SIGTERM to the process group and kill the test binary (signal: terminated). Reproduced identically on clean origin/main (TestACallInFlightAtTheHandoverIsAnsweredByTheOldDaemon), so it is a local-environment limitation, not this change. CI runs the full suite.

No overlap with #1679: the since=0-on-trimmed-history gap condition and malformed-since handling are untouched.

Refs #1914


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

Subscribe-time replay already reports its gap in band, but a subscriber
that fell behind LIVE still lost events silently: Subscription.Dropped
counted them and nothing read the counter, so the documented "you got
everything, or you were told you did not" promise held only up to the
subscribe.

handleEvents now tracks the last sequence it delivered and the drop count
it has already reported, and emits an in-band `event: gap` with
{since, latest, dropped} before the next delivered event (and on the
keep-alive tick, so a stall followed by silence still reports). One stall
produces one notice, not one per event.

Tests: a full retained history (1024 events) replays at since=0 with no
gap and no drops, and a stalled subscriber -- produced deterministically
by blocking the writer's first flush, not by timing -- is told what it
missed before the event that follows the hole.

Refs #1914 (remainder of the triage verdict; #1679 keeps the
trimmed-history and malformed-since cases).
@dezren39
dezren39 requested a review from a team as a code owner October 30, 2026 04:53
@coderabbitai

coderabbitai Bot commented Oct 30, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 48 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bb64253b-5686-4a85-9c20-4a2edfa4355c
Commits

Reviewing files that changed from the base of the PR and between 86b7d01 and 5b47280.

Files selected for processing: 3
  • pkgs/mcpx/internal/daemon/events_gap_test.go
  • pkgs/mcpx/internal/daemon/server.go
  • pkgs/mcpx/internal/events/events_history_test.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T04:55:37.248573Z 5b47280 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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