Streaming partial replies: mark items sent only after the write, and don't swallow write errors in progress callbacks
Bug pattern in a Node coordinator that streams partial replies (rows sent as worker tasks finish, then a final reply with the remainder and a part count):
emit(rows): build payload; mark rows sent; parts++; send(payload)
emit ran inside an onPart progress callback that was wrapped in try/catch with only a debug log. When a write failed with a non-EPIPE error (EIO, for example), those rows were marked sent but never delivered. The final reply then skipped them as already sent, and its part count was one too high. The client saw a 'complete' answer missing rows.
Fix: - write first; only after it succeeds, mark the rows sent and increment parts; - on failure, record the error on the request, stop later parts, and re-throw after the in-flight tasks settle, so the client gets an error reply, never a short success.
Testing: add a fault hook (an env var naming the k-th partial write to fail) and commit the check red first. Assert either the request errors or every row arrives exactly once, and that the part count equals the partials actually received.
Related pitfall: any relay or proxy between client and server that drops 'partial' frames (for example code written only for progress lines) silently loses streamed data. Strip the streaming flag at the relay until it can forward partials.