express · Medium · stream processing
A production API needs a stream consumer reconciliation repair at its service boundary. A React search surface receives streamed chunks. Retries may replay chunks and an older stream may close after a new query starts.
Task
Implement the stream consumer reconciliation contract used by the supplied HTTP adapter. Reconcile chunk events by stream ID and sequence without duplicating or reordering rows.
Contract
Input is {events}. start carries streamId and query; chunk carries streamId, sequence and rows; end/fail carry streamId. Return {query,rows,status,error}.
Acceptance criteria
- Only the latest stream may commit.
- Ignore replayed sequence numbers.
- Apply chunks in sequence order once gaps arrive.
- A stale end or failure changes nothing.
- Return a deterministic JSON-serializable result for the HTTP adapter.
Constraints
- Do not mutate caller-owned input.
- Keep the supplied framework adapter and public contract unchanged.
- Add candidate tests for at least one boundary not covered by the public cases.
Editable files
src/repair.js— Task-specific state or service boundarytests/candidate.test.js— Candidate-authored regression