Skip to content

fix(serve): a commit-feed subscription that fails on an unexpected error sends a coded error frame instead of going silent, so a member resubscribes (swamp-club#5204) - #4037

Merged
stack72 merged 1 commit into
mainfrom
5204
Nov 29, 2026

Conversation

@stack72

@stack72 stack72 commented Nov 29, 2026

Copy link
Copy Markdown
Member

Summary

When a member's commit-feed or data-feed subscription failed on an unexpected error (a changesSince or projection failure other than CommitsCompactedError), the handler rethrew to connection.ts's generic catch. That catch only logs "Unhandled request error", so no frame was sent and the socket stayed open. The member's watchServeFeed waited for frames that never came. The member saw a stall, not an error, until the socket dropped.

The fix:

  • Serve: followCommitFeed, shared by commits.subscribe and data.subscribe and the only place holding the last cursor, catches an unexpected error. Unless the caller cancelled or the socket is already closed, it logs at error and sends a coded commit_feed_failed error frame. The frame carries a sanitized message and {cursor}, the last cursor sent, so the subscriber resubscribes from there. It never rethrows. CommitsCompactedError keeps its commits_compacted frame.
  • Member: watchServeFeed logs the error frame's code and message at warn, then closes and resubscribes on its existing capped backoff.
  • Follower: the serve FollowerFeed already fails and restores on an error frame; a test now pins that.

connection.ts and changesSince are untouched.

Test Plan

  • commit_feed_handlers_test.ts, 8 tests, 4 for each handler:

    • an unexpected failure sends commit_feed_failed on the request id with the last cursor, and the handler resolves;
    • a path in the error is not echoed;
    • an aborted signal or a closed socket sends nothing;
    • CommitsCompactedError still sends commits_compacted.
  • serve_feed_client_test.ts: the error frame closes the socket, warns once with the code, and resubscribes after the backoff.

  • follower_feed_test.ts: commit_feed_failed fails the FollowerFeed.

  • Red-checked on a Linux VM. Each mutation turned its tests red:

    Mutation Tests failing
    catch removed 6
    rethrow after sending 4
    client warn dropped 1
    abort or closed guard removed 2
  • verify-build passed (44,757 tests), as did verify-reviews and verify-skills; the attestation is posted.

🤖 Generated with Claude Code

https://claude.ai/code/session_012GowZUrsU4hvwF8CqN6Afu

…ror sends a coded error frame instead of going silent, so a member resubscribes (swamp-club#5204)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012GowZUrsU4hvwF8CqN6Afu

@github-actions github-actions 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.

Attestation Approved

Verified commit 456fd714 — attestation gate passed (12/17 steps).

@github-actions github-actions 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.

Adversarial Review

I traced followCommitFeed (src/serve/handlers/commit_feed_handlers.ts), both callers (handleCommitsSubscribe and handleDataSubscribe), the client in watchServeFeed, and the generic catch in connection.ts.

Critical / High

None.

Cursor correctness. cursor changes only after changesSince and follow.project both succeed. Its new value is then sent unless the signal has aborted, and in that case the new guard sends nothing. So details.cursor in commit_feed_failed is always a cursor the subscriber has already received. A resubscribe from it skips nothing and repeats nothing. The one gap is a throw from send itself, after cursor was assigned but before the frame left. That only happens when the socket is no longer OPEN, and the guard then returns without sending anything.

Cleanup. off(), offSteppingDown() and the per-socket subscription counters still run in finally and in the callers' own finally blocks, because the catch no longer rethrows. CommitsCompactedError is still handled in the inner catch before it can reach the new outer one.

Retry loop. A deterministic failure (say, a corrupt commit at cursor N) makes the member resubscribe at N over and over. watchServeFeed's existing capped backoff and the follower's fail/restore path limit that, so it is not a hot loop.

Medium

None.

Low

  1. commit_feed_handlers.ts (new catch): the message from data.subscribe's projection (dataChangesOf with the resolver) is now sent to the client through sanitizeErrorForClient. That function removes paths but not data content. For example, V8's JSON.parse messages quote part of the input (Unexpected token 'x', "..." is not valid JSON), and a resolver error could name a data item. If a projection error ever includes content from a resource the caller cannot read, the frame would expose it. Before this PR that error was only logged. This matches how other handlers already return sanitizeErrorForClient(error) for generic failures, so it is not a new pattern. If you want to be strict, send a fixed message plus exceptionTypeForClient(error) and keep the full error in the server log, which already gets it.
  2. serve_feed_client.ts:178: the warn interpolates String(frame.error?.message). That text is controlled by the server and has no length limit on the client side. A misbehaving or hostile serve could put a very long string into member logs. This is cosmetic and the server is already trusted for the feed.

Verdict

PASS: the fix is correct and limited to followCommitFeed. The cursor it reports is safe to resubscribe from, cleanup paths are unchanged, and the tests cover the abort and closed-socket guards.

@stack72
stack72 merged commit 704ce99 into main Nov 29, 2026
6 checks passed
@stack72
stack72 deleted the 5204 branch November 29, 2026 16:57
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