fix(mitm): spinner + retry for body load instead of premature "failed" - #389
Merged
Conversation
Expanding a flow fetched its body once and, on any non-2xx, showed
"failed to load body" with no retry. But mitmweb serves content.data only
after it finalizes the message, so a body fetched the instant a flow is
expanded can error while the response is still arriving — especially a
streaming/SSE response. It "failed", then loaded fine a second later on a
manual re-expand. That's "not ready yet", not a failure.
BodySlot now tracks a loading/ready/error state:
- A spinner ("loading body…") shows while fetching, replacing the plain
"loading…" text.
- On error OR an empty body while the response is still in flight
(no timestamp_end), it retries a few times with a short delay before
giving up — so a not-yet-captured / streaming body resolves on its own.
- Only after retries are exhausted does it show an honest
"couldn't load body: …".
Verified with Playwright (content endpoint 502s twice then returns the
body): spinner shows, no error flash, body renders on the 3rd attempt.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Expanding a flow fetched its body once and, on any non-2xx, showed "failed to load body" with no retry. But mitmweb serves
content.dataonly after it finalizes the message — so a body fetched the instant a flow is expanded can error while the response is still arriving, especially a streaming/SSE response. It "failed", then loaded fine a second later on a manual re-expand. That's "not ready yet", not a failure.Fix
BodySlotnow tracks a loading/ready/error state:timestamp_end), it retries a few times (6× / 700ms) before giving up — so a not-yet-captured / streaming body resolves on its own.Verified
Playwright with the content endpoint returning 502 twice then the body: spinner shows, no error flash, body renders (pretty-printed JSON) on the 3rd attempt (
hits=3,hasBody=true). Screenshots confirmed both states. Typecheck + build pass.🤖 Generated with Claude Code