--- id: review-001-sse-parser name: Incremental byte-level SSE parser (FWD-06) status: pending depends_on: [] scope: narrow risk: high impact: component level: implementation tags: [adapters, review-001] --- ## Description Review 001 finding FWD-06 — silent subscription data loss, empirically verified: `parse_sse_frames` (`src/adapters/forward.rs:409-417`) keeps only the *last* line of each TCP chunk and discards any pending multi-line `data_buffer`, so a chunk ending exactly at `data: …\n` (blank line not yet arrived) silently loses the event. Verified: chunks `"data: {\"n\":1}\n"` + `"\ndata: {\"n\":2}\n\n"` yield only event 2. Single-chunk delivery (as in the tests) works, which is why the suite passes. Additional defects in the same parser: per-chunk `String::from_utf8_lossy` (`:357`) corrupts multi-byte characters split at a chunk boundary (JSON parse failure → event degraded to raw string); the trailing partial line has no length cap (unbounded buffering); an event pending at EOF is dropped (SSE says dispatch at EOF). For a subscription forwarder this is silent data loss with no error signal. Fix: an incremental **byte-level** parser carrying buffer state across chunks (decode UTF-8 once over the reassembled buffer, not per chunk). ## Acceptance Criteria - [ ] Multi-chunk test: event split across two TCP chunks is delivered (the review's empirically-verified case — the acceptance gate) - [ ] Split multi-byte UTF-8 across chunks parses (test) - [ ] Pending event dispatched at EOF; trailing partial line length-capped (tests) - [ ] Existing single-chunk SSE tests unchanged and green - [ ] `cargo test` and `cargo clippy --all-targets -- -D warnings` pass ## References - docs/reviews/001-initial-implementation-review.md (Part D, FWD-06; Part I, COV-01) ## Notes > Agent fills during implementation. Parser rewrite is isolated > from the response-decode fixes (content-type, size caps, error bodies) > in review-001-response-decoding so the delicate stateful rewrite lands > alone. Same file — sequence or coordinate. ## Summary > Filled on completion.