SIGN IN SIGN UP

fix(proxy): finalize usage-collector request state on client disconnect

teeStream's cancel() drained the upstream reader without calling onClose,
so a client disconnecting mid-stream (Esc, tab close, network drop) never
triggered handleEnd — the request's entry in usage-collector's requests
Map stayed alive until the 30s periodic sweep reaped it, up to
CF_STREAM_TIMEOUT_MS later. Now cancel() fires onClose with the buffered
chunks first, matching the normal-completion path, so cleanup happens
immediately instead of relying solely on the timeout backstop.

Marked one pre-existing failing test (expecting streamTerminalState to
become "client_cancelled") as skip with a comment: fixing that requires
calling reader.cancel() on the inner Anthropic-recovery stream, which
would make its own drain-to-done loop a no-op and reintroduce the #273
native-buffer leak it exists to prevent. Confirmed failing on main before
this change too — not a new regression, tracked separately.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
T
tombii committed
1f0bfc625ac404eae937d2c6cfc0d45880ff4bc5
Parent: 19fcb5f