Repository navigation
Conversation
…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
There was a problem hiding this comment.
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
commit_feed_handlers.ts(new catch): the message fromdata.subscribe's projection (dataChangesOfwith the resolver) is now sent to the client throughsanitizeErrorForClient. That function removes paths but not data content. For example, V8'sJSON.parsemessages 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 returnsanitizeErrorForClient(error)for generic failures, so it is not a new pattern. If you want to be strict, send a fixed message plusexceptionTypeForClient(error)and keep the full error in the server log, which already gets it.serve_feed_client.ts:178: the warn interpolatesString(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.
Summary
When a member's commit-feed or data-feed subscription failed on an unexpected error (a
changesSinceor projection failure other thanCommitsCompactedError), the handler rethrew toconnection.ts's generic catch. That catch only logs "Unhandled request error", so no frame was sent and the socket stayed open. The member'swatchServeFeedwaited for frames that never came. The member saw a stall, not an error, until the socket dropped.The fix:
followCommitFeed, shared bycommits.subscribeanddata.subscribeand 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 codedcommit_feed_failederror frame. The frame carries a sanitized message and{cursor}, the last cursor sent, so the subscriber resubscribes from there. It never rethrows.CommitsCompactedErrorkeeps itscommits_compactedframe.watchServeFeedlogs the error frame's code and message at warn, then closes and resubscribes on its existing capped backoff.FollowerFeedalready fails and restores on an error frame; a test now pins that.connection.tsandchangesSinceare untouched.Test Plan
commit_feed_handlers_test.ts, 8 tests, 4 for each handler:commit_feed_failedon the request id with the last cursor, and the handler resolves;CommitsCompactedErrorstill sendscommits_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_failedfails theFollowerFeed.Red-checked on a Linux VM. Each mutation turned its tests red:
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