Repository navigation
Studio: fall back when a page declares a charset we do not know - #10221
Conversation
90d070b to
080dd85
Compare
Review + GitHub Actions reproductionReproduced on GitHub Actions against fresh upstream
Tests: 11 new cases in No screenshot: the change has no visible UI element — the user-visible effect is the tool result text quoted above, which is what the table reports. Conclusion: the defect and the fix are both verified on Actions; the one finding I raised against the first commit is fixed and covered by a regression test. |
|
@codex review Please review head The whole change is one guard in
Actions evidence for the before/after is in the comment above. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cf1e744fbb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| except UnicodeError: | ||
| # A real text codec that simply cannot decode this probe (utf-16 and | ||
| # other wide codecs reject a lone byte). Keep it. | ||
| pass |
There was a problem hiding this comment.
Reject the always-failing
undefined codec
When a page declares charset=undefined, Python's registered encodings.undefined codec makes the probe raise UnicodeError, so this arm preserves both declared and declared_codec; that codec deliberately raises UnicodeError for every decode, causing the real decode below to escape to the outer handler as Failed to fetch URL: undefined encoding instead of falling back. Distinguish the truncated-input errors from wide text codecs from codecs such as undefined that cannot decode any input.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed and fixed in ba5f63a7.
codecs.lookup("undefined") succeeds and encodings.undefined raises UnicodeError on every decode, so the probe landed in the except UnicodeError arm that was meant for wide codecs and the label was kept — then the real decode raised and the fetch was lost. Reproduced exactly as described.
Rather than enumerate which UnicodeErrors mean "truncated input" and which mean "unusable codec", I dropped the separate probe: the real raw_bytes.decode(...) is now the guard, so anything that cannot decode this page falls back. charset=undefined is a case in test_unusable_codec_charset_falls_back.
| declared_codec = codecs.lookup(declared).name | ||
| # base64/hex/zlib and friends pass lookup but are not text codecs, | ||
| # so they raise only here, where the decode below would fail the fetch. | ||
| b"a".decode(declared) |
There was a problem hiding this comment.
Probe codecs with the downstream error mode
When a page declares charset=idna, this strict-mode probe succeeds, but the actual decode below supplies errors="replace", which Python's idna codec rejects with UnicodeError: Unsupported error handling: replace; the fetch therefore still returns a failure instead of treating this unusable page charset as absent. Probe with the same error mode used by the real decode, or otherwise reject codecs that cannot accept it.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed and fixed in ba5f63a7 — this one was the more useful half of the pair, because it says the probe was the wrong shape rather than the wrong arm.
Verified: b"a".decode("idna") succeeds in strict mode, while body.decode("idna", errors = "replace") raises UnicodeError: Unsupported error handling: replace, so a strict probe could never have predicted the real call.
Taking your suggestion literally: the decode below is now itself wrapped, so the probe and the downstream call are the same call and cannot disagree about error mode. charset=idna is a case in test_unusable_codec_charset_falls_back.
Actions reproduction, round 2 — after the Codex findingsBoth Codex P2s reproduced exactly as described, so the approach changed rather than the arm: the separate probe is gone and the real Same fresh base (
Tests: Upstream CI: the two red checks — "Repo tests (CPU)" and "workflow-trigger lint" — are |
|
@codex review Both of your P2s were right and are fixed in Please confirm the new shape, in particular that |
Studio UI evidence — before/afterTwo isolated The pages are
The assistant bubble is written mechanically from the tool results alone, so it is the backend's own output quoted back rather than a stand-in's opinion: "1 returned the page (utf-8) and 3 failed to fetch (unicode, base64, idna)" becomes "4 returned the page (unicode, base64, idna, utf-8)". Both sides are comparable, not just different: each issued the same four URLs, rendered One detail the table does not show: BEFORE, each failing result also carried Photographed at |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Confirmed this still hits |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
This makes Guarding the decode itself rather than testing the label first is the right shape, and it catches |
…lothai#10284) `(Python 3.13)` is red on `main` at `a12162ab5`, on one test out of 37,035, failing on `[entry] = monitor.snapshot()` while its status code and message assertions pass. Two sites in `produce_openai_chat_completions` reject a `confirm_tool_calls` plus `stream=false` request, and `_should_validate_before_switch()` decides which one runs. The early site runs ahead of the model switch, so an invalid request cannot evict the resident model, and it returns before the API monitor row is opened. The later site goes through `_reject`, which fails a row that is already open. That predicate is `_automatic_model_load_may_run() or _preview_slot_is_owned()`, both process-wide state, and the test never pinned it, so it asserted whichever site the rest of the xdist worker happened to leave reachable. unslothai#10221 is not at fault. Its change is confined to charset handling in `_fetch_url_raw` and cannot affect whether a monitor row exists. It added 17 parametrized cases, which changed how xdist packs its four workers and shook loose a latent ordering flake. The twelve `main` commits before it are green on this check, it is red exactly at it, and the test passes alone, passes with its file serially, and passes with its file under `-n 4`. The predicate is now pinned and parametrized over both values, so each rejection site is asserted deliberately rather than by accident. That also adds coverage, since the early site was previously reached only by luck. Pinning it is what the rest of the suite already does, five times in `test_active_generations.py` and again in `test_openai_auto_switch.py`. A second test had the same fragility, `test_confirm_tool_calls_requires_streaming_for_safetensors_tools`. A regex scan missed it; running the file with the predicate forced found it. Both are fixed. Verified by forcing the predicate, which reproduces the CI failure exactly at the same line. The file is 360 passed both with the predicate as the environment leaves it and with it forced, up from 358. Before the change the forced column was 1 failed. Sweeping the whole backend suite the same way found no other test resting on this predicate. Left alone deliberately: the two sites disagree about whether a rejected request is recorded at all, so the same 400 is logged or not depending on whether an automatic load could have run. That predates unslothai#10221, and recording a row at the early site changes what the monitor shows, so it wants its own PR rather than being folded into an unblock.

web_searchhands the charset from the response header straight to the decoder. If Python cannot decode with that name the whole fetch fails and the model gets an error instead of the page, even though the bytes are already downloaded. Pages labelledunicodeorutf8mb4load fine in a browser.Several classes of label hit this, all with the same user-visible result:
unicode,utf8mb4,x-user-definedcodecs.lookup→LookupErrorFailed to fetch URL: unknown encoding: unicodebase64,hex,zlib,quopri,rot13,uu,bz2lookup, thenbytes.decode→LookupErrorFailed to fetch URL: 'base64' is not a text encodingundefinedlookup, raisesUnicodeErroron every decode by designFailed to fetch URL: undefined encodingidnalookupand a strict decode, but rejectserrors = "replace"Failed to fetch URL: Unsupported error handling: replacecodecs.lookup→ValueErrorFailed to fetch URL: embedded null characterRather than enumerate those, the decode we already perform is now the guard: if decoding with the declared label fails for any reason, the label is treated as if it had never been sent and the existing BOM/UTF-8 fallback runs. The fallback only ever uses
_UNICODE_BOM_CODECSentries or UTF-8 witherrors = "replace", so it cannot itself raise.A label that is real and decodes the page normally is untouched, including wide codecs such as
utf-16andutf-32.