Skip to content

refactor(media): collapse attachment byte classification into media-core - #122168

Merged
obviyus merged 1 commit into
mainfrom
refactor/attachment-classification-core
Aug 11, 2026
Merged

obviyus merged 1 commit into
mainfrom
refactor/attachment-classification-core

Conversation

@obviyus

@obviyus obviyus commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

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 extractFileContentFromSource sniffed the same bytes again. The allowlist could therefore approve one MIME while dispatch observed another.

Why This Change Was Made

@openclaw/media-core/attachment-classify now owns byte sniffing, text heuristics, extension mapping, and the seven attachment classes. MediaAttachmentCache stores 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. .xml resolves to text/xml; .yaml/.yml resolve to application/yaml; .log remains text/plain (current main had no literal-value disagreement). .tsv, .ini, .cfg, .conf, and .env moved into media-core.

web-media.ts keeps 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.
  • Production runtime delta: +236/-371, net -135.

@clawsweeper

clawsweeper Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@obviyus
obviyus marked this pull request as ready for review August 11, 2026 17:35
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts size: L maintainer Maintainer-authored PR labels Aug 11, 2026
@obviyus
obviyus force-pushed the refactor/attachment-classification-core branch 4 times, most recently from 22be6d1 to ab25cd6 Compare August 11, 2026 17:51
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 11, 2026
@clawsweeper

clawsweeper Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 11, 2026, 3:03 PM ET / 19:03 UTC.

ClawSweeper review

What this changes

The PR moves attachment byte classification into media-core so cache policy checks and file extraction share one MIME, class, and charset result.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep 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
Reviewed head: 07d858f9495f260a46974a7b0fe1e5563ca6798a
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) PR readiness rating was derived from proof quality, review findings, security review, and reviewer confidence.
Proof confidence 🌊 off-meta tidepool Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Evidence reviewed 7 items Current-main owner boundary: Current main independently determines an attachment MIME in the cache and re-sniffs it before input-file extraction, so the PR addresses a real duplicated-policy boundary rather than an obsolete path.
Revised precedence repair: The PR head passes the declared channel MIME first and fetched Content-Type as an ordered secondary hint, then retains the resulting classification in the cache.
One classification reaches extraction: The file gate reads the cached classification and passes that same object into extraction, removing the former downstream re-sniff.
Findings None None.
Security None None.

How this fits together

Inbound 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
Loading

Decision needed

Question Recommendation
Should application/xml now canonically surface as text/xml across shared media-core callers, not only attachment extraction? Confirm canonical XML behavior: Keep the shared alias folding after adding real attachment-flow proof and checking affected XML consumers.

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

  • Resolve merge risk (P1) - Canonicalizing application/xml to text/xml changes a shared MIME normalizer used beyond attachment extraction; existing consumers that compare the former literal need upgrade-path confirmation.
  • Resolve merge risk (P1) - The checkout lacks installed file-type source, so this review verified the bounded OpenClaw wrapper and tests but could not inspect the dependency’s exact sniffing contract directly.
  • Complete next step (P2) - The protected maintainer path and missing real-behavior proof require human handling; there is no narrow automated repair to dispatch.
Agent review details

Security

None.

PR surface

Source -114, Tests +170, Config +11, Generated 0, Other +4. Total +71 across 36 files.

View PR surface stats
Area Files Added Removed Net
Source 9 260 374 -114
Tests 6 174 4 +170
Docs 0 0 0 0
Config 3 12 1 +11
Generated 16 16 16 0
Other 2 4 0 +4
Total 36 466 395 +71

Review metrics

Metric Value Why it matters
Production versus test delta production +276/-375; tests +174/-4; generated baselines +16/-16 The refactor is net-negative in production code while adding focused precedence and canonicalization coverage.

Stored data model

Persistent data-model change detected: persistent cache schema: src/media-understanding/media-understanding-misc.test.ts, serialized state: src/gateway/server-methods/sessions-files.test.ts, serialized state: src/media/input-files.extract.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Prove and retain canonical MIME values (recommended)
    Before merge, add redacted after-fix attachment-flow evidence and confirm that XML consumers tolerate the canonical text/xml value.
  2. Constrain alias folding
    If compatibility confirmation is unavailable, keep shared byte classification but limit XML alias conversion to the attachment flow.

Technical review

Best 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.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: The PR changes a shared attachment classification path with normal, bounded compatibility impact.
  • merge-risk: 🚨 compatibility: Shared MIME canonicalization can change the XML value observed by existing media and session-file consumers.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Current-main blame attributes the cache MIME detection and input-file re-sniff boundary to this commit; deeper history is unavailable in the shallow checkout. (role: current media-boundary author; confidence: medium; commits: 1dcac5b15f; files: src/media-understanding/attachments.cache.ts, src/media/input-files.ts)
  • obviyus: Recent main media-understanding work and this PR both cover per-attachment classification behavior. (role: recent media-understanding contributor; confidence: medium; commits: 82ba647673f9; files: src/media-understanding/apply.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-11T17:56:33.906Z sha ab25cd63f6ec38338e00f0ed5e55a8d5e4dd93d6 :: found issues before merge. :: [P1] Preserve attachment MIME-hint precedence | [P1] Preserve configured YAML and XML allowlist values

@obviyus
obviyus force-pushed the refactor/attachment-classification-core branch 2 times, most recently from 40a1691 to 971d619 Compare August 11, 2026 18:17
@obviyus
obviyus force-pushed the refactor/attachment-classification-core branch from 971d619 to b8f5f9f Compare August 11, 2026 18:25
@obviyus
obviyus enabled auto-merge (squash) August 11, 2026 18:25
@obviyus
obviyus force-pushed the refactor/attachment-classification-core branch 2 times, most recently from 2260532 to 96c69a0 Compare August 11, 2026 18:41
@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Aug 11, 2026
@obviyus
obviyus force-pushed the refactor/attachment-classification-core branch from 96c69a0 to 4abd5d1 Compare August 11, 2026 18:50
@obviyus
obviyus force-pushed the refactor/attachment-classification-core branch from 4abd5d1 to 07d858f Compare August 11, 2026 18:56
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 11, 2026
@obviyus
obviyus merged commit 746a188 into main Aug 11, 2026
130 checks passed
@obviyus
obviyus deleted the refactor/attachment-classification-core branch August 11, 2026 19:10
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 12, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: xai gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. scripts Repository scripts size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant