Repository navigation
fix(telegram): cancel unread response body on media fetch error - #110039
Monkey-wusky wants to merge 1 commit into
Conversation
|
Codex review: needs maintainer review before merge. Reviewed July 31, 2026, 1:51 PM ET / 17:51 UTC. ClawSweeper reviewWhat this changesThe branch cancels an unread response body before the Telegram media e2e harness throws for a failed download, with a regression test that observes the cancellation. Merge readinessThis PR remains necessary: current main's Telegram media e2e harness still throws on a non-OK media response without releasing its unread body. The proposed change fixes that exact harness-owned path, follows the repository’s established cancellation pattern, and does not introduce a code-level review finding; it needs a current-head CI refresh before merge. Priority: P3 Review scores
Verification
How this fits togetherTelegram media tests route a mocked remote media download through a harness reader before media resolution continues. The reader either buffers successful media or reports a failed HTTP response, so its error path owns cleanup of an unread stream. flowchart LR
A[Telegram media test] --> B[Media resolver]
B --> C[Harness media reader]
C --> D{HTTP response OK?}
D -->|Yes| E[Buffer media]
D -->|No| F[Cancel unread body]
F --> G[Report HTTP error]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +1, Tests +22. Total +23 across 2 files. View PR surface stats
Review metricsNone. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the harness-local cancellation and regression assertion, then refresh the branch against current main and merge once the exact-head compact check is understood and green. Do we have a high-confidence way to reproduce the issue? Yes, from source: return a non-OK Is this the best way to solve the issue? Yes. The non-OK branch that owns the unread response is the narrowest cleanup boundary, and the awaited cancellation matches established OpenClaw response-body cleanup without changing the existing error contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 8a4da1d19fad. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (6 earlier review cycles)
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
b48e8fa to
170dd43
Compare
170dd43 to
c809580
Compare
|
Thanks, @Monkey-wusky, for following up on response-body cleanup. I checked this against current main, the actual production Telegram media path, and a real HTTP server. This change only reaches the Vitest E2E harness; no production media download imports it. Real Telegram downloads use For the harness itself, the existing tests use finite in-memory mocked responses or mocked errors. Running the unchanged harness against a real finite HTTP 404 showed that the next healthy request reused the exact same TCP connection, so the existing scenario does not leak a socket. The indefinitely streaming response used to motivate this PR is not produced by these tests. The proposed awaited Since there is no user-facing bug, the real production owner already handles errors correctly, and the change adds suite-hang risk to a mocked-only path, I’m closing this rather than landing it. The failing CI is secondary to that behavioral concern. Thank you again for the cleanup work. |
What Problem This Solves
When
defaultReadRemoteMediaBufferin the Telegram e2e harness receives a non-OK response (e.g. 404, 503), it throws immediately without canceling the response body. The unconsumed stream holds a connection open until garbage collection.Why This Change Was Made
Follows the same pattern as #109519 (Google Chat), #109508 (docs search), #109677 (Chutes), #109701 (MSTeams consent upload), and #109728 (APNs relay) — cancel the response body before throwing so that upstream streams are drained and connections released.
User Impact
No user-facing change. This is test harness infrastructure used by the Telegram bot media e2e tests. Prevents resource leaks from unconsumed response bodies.
Evidence
Real HTTP server proof
The proof script starts a real HTTP server returning 503 with a slow stream, then exercises the exact cancel-before-throw pattern from this PR. The server confirms the client canceled the stream (
client canceled stream ✓), demonstrating thatbody?.cancel()reaches the server and releases the connection. The error message is preserved after cancel.Unit test
New test ("cancels response body on non-ok status before throwing") in
bot.media.stickers-and-fragments.e2e.test.tsverifies:Responsewith status 404 is returned by the fetch mockresponse.body.cancel()is called exactly once before the error is thrownReadableStream({ cancel })spy pattern as in fix(msteams): cancel non-OK consent upload response body before throwing #109701