Repository navigation
fix(media): bound local reads and invalidate cleaned attachment paths - #130885
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
4bd4cd8 to
341571e
Compare
|
Codex review: needs maintainer review before merge. Reviewed August 27, 2026, 8:09 AM ET / 12:09 UTC. ClawSweeper reviewWhat this changesThe PR routes explicit local image reads through the attachment cache, bounds cache file reads by the caller’s byte limit, requires that limit for path staging, and clears deleted temporary paths after cleanup. Merge readinessKeep this maintainer-authored PR open for merge review: current main still has the unbounded local-image path, while the proposed cache-owner repair is coherent and has no discrete correctness finding. Priority: P2 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherMedia-understanding converts local or remote attachments into bounded buffers or temporary paths for provider runtimes. The attachment cache owns local file safety and cleanup before image or CLI providers consume an attachment. flowchart LR
A[Local image reference] --> B[Image input preparation]
B --> C[Attachment cache]
C --> D{Within byte limit?}
D -->|Yes| E[Buffer or temporary path]
D -->|No| F[Size rejection]
E --> G[Provider runtime]
Decision needed
Why: The implementation is internally coherent, but accepting rejection of previously unlimited local files is an upgrade-policy choice for maintainers. Before merge
Agent review detailsSecurityNone. PR surfaceSource -21, Tests +131. Total +110 across 6 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Adopt the attachment cache as the single owner of local image reads and merge after maintainers accept the documented 10 MB limit for explicit local image input. Do we have a high-confidence way to reproduce the issue? Yes in source: current main’s explicit local-image path calls an unbounded reader, while current-main staged-path code falls back to Infinity when maxBytes is omitted. The PR adds focused regression coverage, though this read-only review did not execute it. Is this the best way to solve the issue? Yes. The attachment cache already owns local attachment resolution and the sibling local-media access path already uses the same bounded file-handle helper, so consolidating here avoids parallel safety policies. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against baa3c3e6846d. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Merged via squash.
|
What Problem This Solves
Four violations of one invariant — local media file reads must respect the caller's byte limit, exactly as the remote branch already does — plus a cache lifecycle leak, all in
src/media-understanding:runtime.tsread local files throughreadLocalFileSafelywith nomaxBytes(installed@openclaw/fs-safeconfirms omitted limits do a whole-filereadFile), while the remote path used the cache withDEFAULT_MAX_BYTES.image. History (538605ff44d) shows a helper substitution, not an unlimited-input contract.attachments.cache.tslocal reads checked the opened stat, then did a fullhandle.readFile(), then checked length — a growing file was fully loaded before rejection (measured: 4,164 bytes consumed withmaxBytes68).getPathmademaxBytesoptional, defaulting toInfinity, and truthiness checks ignored a zero limit. The only production caller already supplies the resolved limit.cleanup()cleared cleanup responsibility but lefttempPath, so a post-cleanupgetPathreturned a deleted file's path.Why This Change Was Made
The attachment cache is the canonical local byte-read owner, so the fix consolidates rather than guards: the explicit-image local branch and its separate MIME read path in
runtime.tsare deleted and routed through the same cache policy as the remote API (the explicit-file selected-directory allowance is preserved vialocalPathRoots; history9f2b760d336/5d1f7bf0589confirms that policy is intentional). Cache local reads keep opened-handle + canonical-root checks and now use the existingreadFileHandleBoundedhelper (consumes at mostmaxBytes + 1bytes).getPath.maxBytesis required and zero-enforced. The cleanup callback invalidates its owntempPathonly (guarded so retained callbacks cannot invalidate a later restaged file, preserving the failed-staging retry chain fromfd3a919063b).User Impact
An oversized or concurrently-growing local attachment can no longer be fully loaded into memory before rejection, the local and remote image-description APIs now enforce the same byte limit, and a cleaned-up attachment can no longer hand a deleted temp path to a provider CLI.
Evidence
src/media-understanding: 527 passed, 5 platform skips, re-run green on rebased head 4bd4cd8c303. An obsolete readFile-only mock test ("enforces maxBytes after reading local attachments", history566fb73d9da) was replaced by a real-file growth test measuring actual bytes consumed at the filesystem boundary.apply.ts,agent-turn-attachments.ts, provider entries) verified already compliant.getPath.maxBytestype assertion), oxlint, oxfmt,git diff --check, and the eight post-typecheck repo guards (schema-version, database-first, media-download helper, sidecar loaders, import cycles, webhook body order, pairing guards) all pass.check-changed's aggregate lane stops at a pre-existing UI e2e type error on main (ui/src/e2e/sidebar-interactions.e2e.test.ts:45, TS2339 from9b4d4d08cf7, reproduced at exact base with media files unchanged) — separate follow-up.runner.entries.ts(output-resource policy, review-required);getPathdoes not claim to freeze externally mutable files for the consuming CLI (existing contract preserved).