Repository navigation
refactor(media): collapse attachment byte classification into media-core - #122168
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
22be6d1 to
ab25cd6
Compare
|
Codex review: needs maintainer review before merge. Reviewed August 11, 2026, 3:03 PM ET / 19:03 UTC. ClawSweeper reviewWhat this changesThe PR moves attachment byte classification into media-core so cache policy checks and file extraction share one MIME, class, and charset result. Merge readinessKeep this PR open: the revised head resolves the prior MIME-precedence and YAML/XML allowlist findings, but the protected maintainer path still needs compatibility confirmation and after-fix real-behavior evidence before merge. Priority: P2 Review scores
Verification
How this fits togetherInbound attachments are fetched or read locally by media-understanding, then MIME-gated and extracted into agent context. This changes the shared classification step between byte acquisition and those downstream decisions. flowchart LR
A[Inbound attachment] --> B[Attachment cache]
B --> C[Shared byte classification]
C --> D[Configured MIME gate]
C --> E[File extraction]
D --> F[Agent context]
E --> F
Decision needed
Why: The PR intentionally changes the shared normalizer and updates a Gateway session-file expectation, so maintainers must confirm that existing consumers may observe the new canonical value. Before merge
Agent review detailsSecurityNone. PR surfaceSource -114, Tests +170, Config +11, Generated 0, Other +4. Total +71 across 36 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain one cache-owned classification flow, prove it through a redacted real attachment run, and explicitly confirm the shared XML canonicalization is the intended compatibility contract. Do we have a high-confidence way to reproduce the issue? No live end-to-end reproduction was run. Current main clearly has separate cache and extractor MIME decisions, and the PR’s focused tests exercise the previous precedence divergence. Is this the best way to solve the issue? Yes for the implementation shape: the attachment cache owns byte acquisition, so carrying its classification through the gate and extractor is the narrowest maintainable repair; global XML canonicalization still needs maintainer confirmation. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 7fe75acb5f46. 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)
|
40a1691 to
971d619
Compare
971d619 to
b8f5f9f
Compare
2260532 to
96c69a0
Compare
96c69a0 to
4abd5d1
Compare
4abd5d1 to
07d858f
Compare
…ore (openclaw#122168) Attachment MIME gating and extraction dispatch used nine separate byte policies across five files; the allowlist could approve one MIME while dispatch observed another after a second sniff. @openclaw/media-core/attachment-classify now owns byte sniffing, text heuristics, extension mapping, and the seven attachment classes; the cache stores one classification that gates and dispatch share. Channel-declared MIME leads with the transport Content-Type as a byte-arbitrated hint, normalizeMimeType folds YAML/XML synonyms so existing configured allowlists keep matching, and input_file API callers keep declared-MIME precedence over cosmetic filenames. Net -135 production LOC. Proof: 2,153 focused tests across media-core/media-understanding/media plus boundary-contract and deadcode-mirror suites; ClawSweeper local review clean (round 5, zero findings); live Telegram default-turn probe green. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Attachment MIME gating and extraction dispatch used separate byte policies. Media-understanding cached one MIME, applied its own text/archive/extension heuristics, then
extractFileContentFromSourcesniffed the same bytes again. The allowlist could therefore approve one MIME while dispatch observed another.Why This Change Was Made
@openclaw/media-core/attachment-classifynow owns byte sniffing, text heuristics, extension mapping, and the seven attachment classes.MediaAttachmentCachestores that complete result. Media-understanding gates on it and passes the same object into extraction, so dispatch cannot re-sniff or disagree.The extension tables are now one table.
.xmlresolves totext/xml;.yaml/.ymlresolve toapplication/yaml;.logremainstext/plain(current main had no literal-value disagreement)..tsv,.ini,.cfg,.conf, and.envmoved into media-core.web-media.tskeeps its separate host-read validator because it validates the whole buffer at> 0.95, enforces a 70/30 single-byte shape, and intentionally rejects UTF-16. Reusing attachment thresholds there would weaken its security boundary.User Impact
Attachment gates and extraction now agree on one MIME and class. Existing marker, PDF, Office, archive, UTF-16, CP1252, CSV/TSV, image/audio/video, and configured-allowlist behavior remains covered. No new marker, config, gate, or extractor-registry behavior is introduced.
Evidence
node scripts/run-vitest.mjs packages/media-core src/media-understanding src/media: 132 files passed, 6 skipped; 2,117 tests passed, 29 skipped.node scripts/run-oxlint.mjs packages/media-core src/media-understanding src/media: passed.pnpm tsgo:core: passed.pnpm tsgo:test:src: passed.pnpm check:import-cycles: 0 runtime value cycles.pnpm plugin-sdk:api:check: baseline clean.git diff --check: passed.+236/-371, net-135.