Repository navigation
fix(media): recognize UTF-8 attachments across sniff boundaries - #135227
Conversation
Keep bounded UTF-8 prefix decoding open until the actual input ends. Preserve strict complete-input handling and remove redundant empty and slice-limit branches. Add classifier, local-cache, and full attachment-context regressions.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed September 1, 2026, 11:33 AM ET / 15:33 UTC. ClawSweeper reviewWhat this changesThe PR completes and validates a UTF-8 sequence that begins inside the 4 KiB attachment sniff window, then adds classifier, cache, and agent-context regression coverage. Merge readinessKeep this maintainer PR open. Current main still finalizes the 4 KiB UTF-8 prefix, while the updated head repairs that owner boundary and addresses the prior malformed-continuation finding; no introduced blocking defect was found. Priority: P2 Review scores
Verification
How this fits togetherMedia Core classifies attachment bytes before Media Understanding caches supported files and extracts their text into agent context. This change affects the bounded UTF-8 decision for otherwise untyped local attachments. flowchart LR
A[Local attachment bytes] --> B[Media Core classifier]
B --> C[UTF-8 sniff boundary]
C --> D[Attachment cache]
D --> E[Text extraction]
E --> F[Agent context]
Before merge
Agent review detailsSecurityNone. PR surfaceSource 0, Tests +135. Total +135 across 4 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Land the bounded classifier repair after exact-head CI completes, preserving the 4 KiB heuristic and the existing Windows-1252 fallback policy. Do we have a high-confidence way to reproduce the issue? Yes, source-reproducible: current main decodes the bounded prefix as complete UTF-8, and the cache-to-application path carries that classification into agent context. The reviewer did not execute the focused regression under the read-only review contract. Is this the best way to solve the issue? Yes. Completing only the code point that starts within the fixed sample window fixes the shared classifier without a full-file scan, downstream workaround, or competing classification path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 8361f3704dd5. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Merged via squash.
|
…claw#135227) * fix(media): recognize UTF-8 attachments across sniff boundaries Keep bounded UTF-8 prefix decoding open until the actual input ends. Preserve strict complete-input handling and remove redundant empty and slice-limit branches. Add classifier, local-cache, and full attachment-context regressions. * fix(media): validate the final sampled UTF-8 sequence
What Problem This Solves
Fixes valid UTF-8 attachments being classified as binary when a multibyte character crosses the 4,096-byte sniff boundary. A 4,200-byte Chinese attachment with a generic filename could produce an unsupported-document marker instead of its text in the agent's context.
Why This Change Was Made
The byte classifier finalized a bounded prefix as if it were the complete input. Fatal UTF-8 decoding rejected its incomplete final character even when the remaining bytes existed in the attachment. The classifier now completes only the sequence that starts inside the sample, reading at most three additional bytes, and then performs a final fatal decode. It neither starts another out-of-window sequence nor silently discards an incomplete character at actual EOF.
The canonical text-ratio calculation is simplified, and redundant empty-input and length checks are removed to absorb the repair. Production +16/−16 (net 0); tests +141/−6 (net +135). The existing ratio calculation rejects empty text. No configuration, dependency, full-file validation, or downstream workaround is added.
User Impact
Untyped UTF-8 text survives local classification, caching, and extraction with its complete contents. Existing MIME handling and Windows-1252 fallback policy remain; that fallback still receives the original 4 KiB sample. Bytes after an already complete sample remain outside this bounded heuristic.
The earlier classifier consolidation in #122168 and performance repair in #133424 both retained the prefix-finalization behavior. This does not resolve outbound validation in #120229 or document interception in #129539. Charset propagation for Windows-1252 remains a named follow-up; this repair makes no claim to fix its downstream decoding.
Evidence
The original classifier and real local-cache regressions failed before repair. After ClawSweeper identified that streaming decode could ignore a malformed boundary sequence, two additional cases failed on the reviewed PR head: an invalid continuation and an incomplete sequence at actual 4,097-byte EOF. The final implementation completes and validates that sequence instead of leaving it buffered.
All 35 classifier tests and 12 cache tests pass, including two-, three-, and four-byte boundary splits, overlong encoding, actual EOF, signature/MIME precedence, complete-buffer preservation, and the bounded treatment of bytes outside a completed sample. The named attachment-application case also passes with all 700 Chinese repetitions in prepared agent text and a
text/plainfile wrapper. It uses a real file with local self-service disabled and exercises classification, caching, extraction, and context preparation. The other 85 application cases were filtered. Total focused AFTER coverage: 48 passing cases.Scoped formatting and Git diff checks pass. Formatting changed only two test-expression layouts; tested production bytes are unchanged. Independent Codex review is clean. The ClawSweeper boundary finding is addressed, with its failing cases retained as regressions. This is local attachment-flow proof, not a Gateway, provider, or live-channel run. Required exact-head CI remains the landing gate.