Claude/vibrant wozniak 284617#413
Merged
Merged
Conversation
Python html.parser exhibits quadratic behaviour inside <script> and <style> bodies because it rescans the accumulated rawdata buffer for the closing tag on every feed() call. With descend enabled, a single large SSR/hydration blob (tens of MB of inline <script>) is enough to block the event loop past the systemd watchdog timeout and have the process killed. Stop feeding the parser once a response has contributed more than 2 MB of body, which keeps the worst case well under the watchdog limit while still covering the head and early body where the relevant link tags live.
The HTML link parser was registered on response_content_processors, which receives raw network bytes. For any gzip- or brotli-encoded response the parser saw compressed bytes, decoded them as UTF-8 with errors=ignore (producing near-empty output), and silently extracted no links. Descend was effectively broken on most of the modern web. Register feed_bytes on response.decoded.processors instead, mirroring how sample_decoded is already wired, so the parser sees the decompressed stream. Adds a regression test that exercises the wiring end-to-end with a gzip body.
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.
Summary
html.parsergoing quadratic inside large inline<script>/<style>bodies — e.g. SPA SSR/hydration blobs.response_content_processors(raw network bytes), so for gzip/brotli responses it received compressed bytes, decoded them as UTF-8 witherrors=ignore, and silently extracted no links. Moved toresponse.decoded.processorsso it sees the decompressed stream.Test plan
make typecheckmake lint.venv/bin/python -m pytest test/test_link_parse.py(3 passed, including the new gzip regression test)