Skip to content

fix(protect): don't buffer live streams (SSE) in response screening - #108

Merged
patchstackdave merged 1 commit into
mainfrom
feat/streaming-aware-response-screening
Aug 12, 2026
Merged

fix(protect): don't buffer live streams (SSE) in response screening#108
patchstackdave merged 1 commit into
mainfrom
feat/streaming-aware-response-screening

Conversation

@patchstackdave

Copy link
Copy Markdown
Contributor

Why

Response screening buffers the whole body before deciding (redact/block). For a live streamtext/event-stream, the standard shape for LLM token streaming, which AI-built apps lean on heavily — readTextResponse reads the body until done, i.e. until the entire stream ends. So the client sees nothing until generation completes: incremental streaming is broken. Flagged in the output-filtering review as the blocker to enabling response screening by default on Node/Express.

What

Exclude text/event-stream from screening on both paths:

  • fetch path: readTextResponse returns null (skip) for an event-stream → screenResp hands back the original response untouched.
  • node/express path: the isTextCT gate returns false for event-stream → the buffered-response wrapper passes chunks straight through.

A live stream now passes through unbuffered and unscreened — the same fail-open tradeoff already used when a body exceeds the screen cap. (Non-stream text responses are screened exactly as before.)

Tests

tests/protect/response-streaming.test.ts — a never-closing SSE stream returns promptly (<500ms) and as the original object (before the fix it would await the stream forever), and a normal text response is still screened. 628 pass; typecheck clean.

🤖 Generated with Claude Code

Response screening buffers the whole body before deciding, so a Server-Sent-Events / token
stream — the common shape for LLM output in AI-built apps — was withheld from the client until
the stream *ended* (readTextResponse awaits the reader to `done`). Exclude `text/event-stream`
from screening on both paths (the fetch `readTextResponse` and the node `isTextCT` gate): a live
stream passes through unbuffered and streams normally, unscreened.

This removes the last blocker to enabling response screening by default on streaming stacks.
+2 tests (a never-closing SSE stream returns promptly & untouched; a normal text response is
still screened); 628 pass; typecheck clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderbuds

coderbuds Bot commented Aug 12, 2026

Copy link
Copy Markdown

Adds event-stream checks to skip buffering live SSE responses.

🎯 Quality: 100% Elite · 📦 Size: Small

📈 This month: Your 49th PR — above team average · Averaging Elite

See how your team is trending →

@patchstackdave

Copy link
Copy Markdown
Contributor Author

/review

@patchstackdave
patchstackdave merged commit 2797318 into main Aug 12, 2026
4 checks passed
@patchstackdave
patchstackdave deleted the feat/streaming-aware-response-screening branch August 12, 2026 11:30
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.

2 participants