Repository navigation
fix: binary attachments are pasted into the prompt as text - #198309
Conversation
A magic-detected binary such as SQLite stays binary. Text recovery remains for bytes with no recognized type. Co-authored-by: fangyun1008 <[email protected]>
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesPreserve signature-identified binary attachments instead of reclassifying their bytes as text. Example: Send a 20 KB SQLite database as an application/octet-stream attachment.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a current attachment-classification bug with a focused shared-owner change; no actionable defects were found, and current-head CI is still running. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe shared media-core classifier turns attachment bytes and MIME hints into one classification consumed by attachment admission, text extraction, and model-context rendering. flowchart TD
A[Attachment bytes and MIME hints] --> B[Shared media-core classifier]
B --> C[Attachment cache]
C --> D[Document context owner]
D --> E[Text extraction or unsupported marker]
E --> F[Model request]
Technical reviewBest possible solution: Land the shared-classifier fix after current-head required checks pass. Do we have a high-confidence way to reproduce the issue? Current-main source establishes the failure path, and the supplied Gateway comparison demonstrates it with a real SQLite attachment; this read-only review ran no target code. Is this the best way to solve the issue? The fix preserves authoritative byte signatures in the existing classifier while retaining text recovery for unrecognized bytes and malformed MIME hints. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 01e1612c3992. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +6, Tests -1. Total +5 across 2 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReviewed November 13, 2026, 10:28 AM ET / 15:28 UTC (Revision 3). |
|
Maintainer proof for c66a81f. Fixes #198289; thanks @mulderp82 for the report and @Yun-0000 for the fix. I folded the two SQLite cases into the existing byte-detected classifier table (net -1 test line; the PNG fixture is now its signature bytes). Both rows fail on main and pass here. End to end: built Gateway in a secretless node:24.22.1 container, The |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Maintainer override: the only red check is
|
|
Landed in afa871c. Thanks @Yun-0000, and @mulderp82 for the report. |
…198309) fix(media): keep signature-detected binaries binary instead of guessing UTF-16 The attachment classifier guessed BOM-less UTF-16 text whenever enough of the first bytes were zero, without checking what the bytes actually were, so binaries such as SQLite databases were retyped as text/plain and up to 60,000 characters of decoded garbage were pasted into the user's message to the model. The classifier now re-sniffs the bytes and keeps the attachment binary when the MIME type detected from its magic bytes matches the resolved type. The BOM, file-extension and text-hint paths are unchanged, and files with no known signature behave as before. No new text. Evidence: a built Gateway in a secretless node:24.22.1 container, sending files with chat.send to a stand-in model and recording what it received. With a real SQLite database made by the sqlite3 CLI, main logged a MIME override from application/x-sqlite3 to text/plain and the model received 13,230 characters of decoded garbage; with this change the file stays application/x-sqlite3 with the existing unsupported-format marker. A NUL-heavy file with no known signature named blob.txt, UTF-16LE text with and without a BOM, UTF-8 text and a PNG behave the same on both. Two SQLite rows in the existing byte-detected table fail on main, at -1 net test lines. Details: openclaw#198309 (comment). Fixes openclaw#198289. Thanks @Yun-0000, and @mulderp82 for the report. Co-authored-by: Ayaan Zaidi <[email protected]>
fix(media): keep signature-detected binaries binary instead of guessing UTF-16 The attachment classifier guessed BOM-less UTF-16 text whenever enough of the first bytes were zero, without checking what the bytes actually were, so binaries such as SQLite databases were retyped as text/plain and up to 60,000 characters of decoded garbage were pasted into the user's message to the model. The classifier now re-sniffs the bytes and keeps the attachment binary when the MIME type detected from its magic bytes matches the resolved type. The BOM, file-extension and text-hint paths are unchanged, and files with no known signature behave as before. No new text. Evidence: a built Gateway in a secretless node:24.22.1 container, sending files with chat.send to a stand-in model and recording what it received. With a real SQLite database made by the sqlite3 CLI, main logged a MIME override from application/x-sqlite3 to text/plain and the model received 13,230 characters of decoded garbage; with this change the file stays application/x-sqlite3 with the existing unsupported-format marker. A NUL-heavy file with no known signature named blob.txt, UTF-16LE text with and without a BOM, UTF-8 text and a PNG behave the same on both. Two SQLite rows in the existing byte-detected table fail on main, at -1 net test lines. Details: #198309 (comment). Fixes #198289. Thanks @Yun-0000, and @mulderp82 for the report. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit afa871c) Release adaptation: keep the release classifier tests and add the two source SQLite signature regressions without importing main's unrelated table consolidation. Production guard is unchanged. Companion audit: no later same-path or PR-number follow-ups through 7bccde6. Existing detectMime signature sniffing and extraction consumers already honor binary classification; no storage internals are imported. Proof: git diff --check passed; source path traced through detectMime and file extraction. Targeted Vitest/typecheck/lint unavailable because this isolated worktree has no node_modules; dependencies left untouched. Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]> (cherry picked from commit 7bbf8c1477902194477dff695c477819c1960ca6)
Preserve the existing 2026.11.5 beta line and its pending test repairs. Repair transcript admission, terminal SQLite iterators, binary attachment classification, detached lifecycle calls, cron late wakes and reload handover. Carry the explicitly requested Bonjour package-integrity fix and release guidance. Selected backports: #188055, #198309, #190242, #198860, #198011, #197658, #197484, #197606. #198011 is the operator-required open PR head, not a merged-main claim. Cron tests are adapted to the existing beta runtime. (cherry picked from commit e3064bf) (cherry picked from commit afa871c) (cherry picked from commit 2c0ab86) (cherry picked from commit fee19a9) (cherry picked from commit dbb6f39) (cherry picked from commit 4d9f782) (cherry picked from commit 87c10f5) (cherry picked from commit ce76ed2) Proof: frozen parent suite passed all 7 shards (265 tests) in 274.45s. Separate unchanged-production baseline reproduced transcript/lifecycle, late-wake and live-receipt failures. SQLite already passed on Node 26.12.1. Independent review found no actionable P0/P1 defects in this snapshot. The complete beta.4 candidate and stable-profile FRV remain pending. Co-authored-by: jalehman <[email protected]> Co-authored-by: vincentkoc <[email protected]> Co-authored-by: Yun. <[email protected]> Co-authored-by: ava-perry <[email protected]> Co-authored-by: Alfred J Berchtold <[email protected]> Co-authored-by: Stronggenetics <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]> Co-authored-by: RomneyDa <[email protected]>
Closes #198289
What Problem This Solves
Fixes: a SQLite database, ELF file, or PE executable sent as a document is classified as UTF-16 text, so decoded bytes are inlined into the model prompt.
User Impact
A file with a recognized binary signature stays binary. The prompt gets the unsupported-document marker instead of the decoded bytes, and the attachment remains available to tools. Ordinary text, including BOM-less UTF-16 and a malformed
plainMIME, is unchanged.Why This Change Was Made
Magic detection already returns a specific binary type such as
application/x-sqlite3. Classification then guessed a charset from NUL bytes and replaced that type withtext/plain. A binary type that came from the file bytes now stays binary. Bytes with no magic type still go through text recovery.Evidence
Node v24.22.2, pnpm 12.15.0, Vitest 5.0.5. Package
2026.11.3. Base3577724c727. Head24de01d39a9.The production entry is
classifyAttachmentBytes. Document extraction uses it before inlining text, and file context skips extraction when the class is nottext.Red, before the guard:
pnpm test packages/media-core/src/attachment-classify.test.ts --maxWorkers=1 -t "keeps a SQLite database binary"{ mime: "text/plain", class: "text", charset: "utf-16le" }.{ mime: "text/plain", class: "text" }.application/octet-stream, returnedtext/plainwithutf-16be. ELF and PE headers returnedtext/plainwithutf-16le.Green, head
24de01d39a9:packages/media-core/src/attachment-classify.test.tsandsrc/media/input-files.extract.test.ts: 62 passed. Vitest duration 6.71s. Shard wall 9.37s. The malformedplain; charset=windows-1252recovery still decodes text.application/x-sqlite3/binary. ELF isapplication/x-elf/binary. PE isapplication/x-msdownload/binary. BOM-less UTF-16notes.txtand unnamed UTF-8 staytext/plain.pnpm exec oxfmt --checkon the two files passed.node scripts/run-oxlint.mjson the two files passed.git diff --checkpassed.pnpm check:test-lines-ratchet --base upstream/main --no-merge-base:Test lines OK. Net test lines: +15; allowance: 400; allocation credit: 0.pnpm check:line-cap-ratchet --base upstream/main --no-merge-base:Line-cap ratchet OK: 2 changed source files; no new violations or over-cap growth.Not run: a live channel send, full
pnpm test, andpnpm check. CI has not finished.Release note: sending a SQLite database or another recognized binary no longer pastes decoded bytes into the prompt.
Maintainer proof
Built Gateway end to end (main vs this PR, plus controls): #198309 (comment)