Skip to content

feat: detect events dropped by sql-tapd and treat reports with drops as incomplete - #45

Merged
mickamy merged 8 commits into
mainfrom
feat/drop-detection
Nov 23, 2026
Merged

mickamy merged 8 commits into
mainfrom
feat/drop-detection

Conversation

@mickamy

@mickamy mickamy commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

sql-tapd's broker drops events for a subscriber whose buffer is full, so that a slow client never blocks the proxy. Until now this was silent: a run or -ci report could miss events and still look complete, and diff would read the missing statements as an improvement. This PR counts the drops per subscription, sends the count to clients, and makes reports with drops incomplete.

Changes

feat(broker): count dropped events per subscription

  • Broker.Subscribe returns a Subscription (Events, Dropped(), Close()) instead of a channel and an unsubscribe function. Each subscription counts its own drops with an atomic.Uint64.
  • server and web are updated; their behavior is unchanged.

build: pin buf remote plugin versions

  • buf.gen.yaml pins protocolbuffers/go:v1.36.11 and grpc/go:v1.6.1, the versions the checked-in code was generated with, so regenerating does not churn gen/. Regenerating without proto changes produces no diff.

feat(proto): report dropped events in WatchResponse

  • uint64 dropped_events = 2: the cumulative number of events dropped for this subscription.

feat(server): send the subscription's dropped count with each event

  • Each WatchResponse carries sub.Dropped() at send time.
  • On its own this misses the last drop: Watch can drain the queue between Publish seeing a full buffer and incrementing the count, so no later event carries it. See the fix below.

feat(ci): report dropped events and refuse them in diff

  • Result.DroppedEvents / JSON dropped_events (omitted when zero) keep the latest cumulative count, in both ci.Run (-ci) and Watcher.Collect (run). The text report shows a Dropped: line.
  • diff refuses a report with dropped events like an incomplete one (exit 2). This also covers -ci reports, which are not marked incomplete.

feat: mark run reports with dropped events incomplete and warn in -ci

  • run marks the report incomplete and exits 2 when events were dropped. The command's own failure still takes priority.
  • -ci prints a warning but keeps its exit code, as with the zero-statement warning, so existing CI jobs are not affected.
  • README updated.

fix: report drops to clients as they happen instead of with the next event

  • The broker signals a per-subscription Drops channel after incrementing the count, so a reader of the signal always sees the new count.
  • New WatchRequest.report_drops: when set, the server sends an event-less WatchResponse{dropped_events} as soon as a drop happens. ci (run and -ci) sets it and skips event-less responses when counting. TUI and Web do not set it, so every response they receive still carries an event.
  • The server test publishes 10,000 events into a broker with a buffer of 1 and waits until delivered + dropped equals the number published (thousands are actually dropped). A second test checks that a client without report_drops never receives an event-less response.

fix(broker): make the zero Subscription safe to use

  • Dropped() and Close() on a zero Subscription no longer panic.

Older sql-tapd does not send dropped_events, which reads as zero, i.e. the previous behavior. See the review comment for the local review that found these issues.

Verification

  • go test -race ./... passes
  • golangci-lint run ./...: 0 issues
  • buf lint passes; buf generate with the pinned plugins only adds the new fields
  • Each intermediate commit builds and passes the tests on its own

Copilot AI balanced review requested due to automatic review settings November 23, 2026 01:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@mickamy

mickamy commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

Copilot could not review this PR (insufficient quota), so it was reviewed locally with Claude Code's /code-review. Findings and how they were handled:

Fixed in 13bdbf8 (fix: report drops to clients as they happen instead of with the next event)

  • Important: there was a window between Publish seeing a full buffer and dropped.Add(1). Watch could drain the queue in that window, so the last drop was never reported and a run that lost an event could still look complete. The PR description's claim that "events are always queued behind a drop" did not hold.
  • -ci could miss drops near shutdown, since the count only travelled with delivered events.
  • The new server test leaked its receiver goroutine and depended on a fixed 500ms idle window.

The broker now signals a per-subscription Drops channel after incrementing the count. A client that sets the new WatchRequest.report_drops gets an event-less WatchResponse{dropped_events} as soon as a drop happens. ci (run and -ci) sets it and skips event-less responses when counting statements. TUI and Web do not set it, so every response they receive still carries an event. The server test now waits until delivered + dropped equals the number published (10s cap), and its receiver exits with the test context. There is also a test that a client without report_drops never sees an event-less response.

Fixed in db8bd23 (fix(broker): make the zero Subscription safe to use)

  • Dropped() and Close() on a zero Subscription panicked. Both are now nil-safe.

Not addressed

  • Suggested bumping SchemaVersion so that an older diff rejects reports with dropped_events. Neither the JSON report nor diff has been released yet (latest release is v0.4.0), so no older reader exists.

Copilot AI balanced review requested due to automatic review settings November 23, 2026 03:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@mickamy
mickamy merged commit 7e8e7b3 into main Nov 23, 2026
4 checks passed
@mickamy
mickamy deleted the feat/drop-detection branch November 23, 2026 03:22
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