Repository navigation
improve: reuse validated attachment read handles - #139168
Conversation
|
🦞👀 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: blocked before merge. Reviewed September 5, 2026, 12:41 PM ET / 16:41 UTC. ClawSweeper reviewWhat this changesReuse the validated file handle when reading local attachments, close it at the consuming boundary, and extend tests for successful, growing, and failed reads. Merge readiness⛔ Blocked before merge - 2 items remain Keep open: this remains a useful optimization absent from current main and the latest release. No introduced correctness defect was found; independent dependency-contract verification remains incomplete. Priority: P3 Review scores
Verification
How this fits togetherThe attachment cache supplies media bytes to understanding providers and file paths to command-line tools. It checks local access and size limits, supports remote fallback, and owns temporary-file cleanup. flowchart TD
A[Attachment reference] --> B[Attachment cache]
B --> C[Validate local file and roots]
C --> D[Bounded read using validated handle]
C --> E[Path-only consumer]
C -->|Unavailable local source| F[Store alias or remote fallback]
D --> G[Close handle and classify bytes]
G --> H[Media provider]
F --> H
Before merge
Agent review detailsSecurityNone. PR surfaceSource -18, Tests +21. Total +3 across 2 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep handle ownership within each cache operation, preserving root checks, bounded reads, fallback semantics, and immediate closure for path-only consumers. Do we have a high-confidence way to reproduce the issue? Not applicable to a functional bug: current-main source directly establishes the redundant cold-file open. This read-only review did not execute tests or benchmarks. Is this the best way to solve the issue? Unclear overall until dependency verification is complete; the cache-local refactor otherwise fits the ownership boundary better than a new reader API or a long-lived descriptor cache. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against ac4c669dc5ae. LabelsLabel changes:
Label 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
|
|
Merged via squash.
|
* commit '3e4becea5e2ce38ede69e8ecf5302805ecbfc09c': refactor: simplify outbound message execution context (openclaw#139107) fix(models): keep ordinary chat selections session-scoped (openclaw#139232) docs: slim root agent instructions and clarify testing scope (openclaw#139236) test(agents): give the sibling-drain completion wait a tolerance on slow runners (openclaw#139176) refactor(workboard): use canonical queries for card-tree writes (openclaw#139106) fix(canvas): recognize versioned macOS nodes (openclaw#138958) fix: load GitHub connections without a default agent (openclaw#139222) fix(memory): explain unsafe legacy host-event path recovery (openclaw#139195) refactor(talk): centralize typed voice session queries (openclaw#139103) fix(cli): preserve command dispatch and structured errors (openclaw#139067) refactor(agents): consolidate reply failure summaries (openclaw#139175) fix(auth): keep an unset default model unchanged during login (openclaw#139218) perf(media): reuse validated attachment read handles (openclaw#139168) refactor(channels): simplify account configuration updates (openclaw#139096) refactor(android): remove unused updater export root (openclaw#139198) fix(gateway): stop admitting post-ready producers during close (openclaw#139092) fix(gateway): expose agent hook completion outcomes (openclaw#139155) fix(config): return the saved configuration after plugin install commits (openclaw#139203) fix(android): reduce repeated retries to unreachable gateways (openclaw#138732)
What Problem This Solves
Reading a cold local media attachment opened and closed the same file twice: once to validate its path and metadata, then again to obtain the bytes needed by the provider.
Why This Change Was Made
The attachment cache now transfers the already validated descriptor to its bounded reader, which closes it in
finally. Path-only consumers close it immediately; a later request for bytes still reopens a previously cached path safely. The separate cold-validation and cached-read error mappings are preserved so URL and media-store fallback behavior stays unchanged.User Impact
A cold local attachment needs one open/close cycle instead of two. Local-root checks, file identity/symlink checks, actual-read byte limits, MIME classification, and temporary staging cleanup remain in place. Production is 18 lines smaller; tests add 21 net lines.
Evidence
@openclaw/fs-safe0.8.1 contract was inspected directly: safe open validates descriptor/path identity, and bounded read consumes at mostmaxBytes + 1without closing the caller-owned handle. Formatting/diff checks and managed P0–P2 review passed. Native Windows and current-head hosted CI are not asserted by this local packet.Latest review disposition
Both pre-merge dependency-verification requests (P1/P2) and the identical Rank-up move in the latest review are complete. Independent maintainer-side inspection of the installed, pinned
@openclaw/fs-safe0.8.1 implementation confirmed the required ownership contract:dist/root-impl.js:80–186(openVerifiedLocalFile) validates the regular file, opened descriptor identity, current path identity, and resolved canonical path identity. Failed validation closes the handle; success transfers a still-open handle.openLocalFileSafelyat lines 455–457 returns that verified result.dist/bounded-read.js:39–46(readFileHandleBounded) reads from the current offset, consumes at mostmaxBytes + 1, and leaves closure to its caller. The cache closes transferred or freshly reopened handles infinally, closes failed preparation, and closes path-only handles immediately.root-impl.js=1d2dd3ba081d5fea1f7b73250c6c29ad591bbc4e8fac88fb1ed5ab7a4985e619;bounded-read.js=73e939b611bb80f839ee49730119ee163e7884cb17b85e8d5eb4048ca08ece80.The existing 18 real-filesystem scenarios have identical before/after outcomes and consumed-byte totals, with every acquired descriptor closed. Focused validation passed 83 tests; five Windows-only cases remain unexecuted on macOS. Hosted CI passed on exact head
9de04ff5d6ab6912fb6ddecee12014a61b73f23c. This supplies the dependency evidence unavailable to the automated reviewer; it requires no source change or relaxation of the safety contract.