Skip to content

fix(file-ops): shell-layer non-regular-file guard for all read paths (salvage #82075) - #83008

Merged
teknium1 merged 3 commits into
mainfrom
salvage/82075-shell-layer-special-file-guard
Aug 10, 2026
Merged

fix(file-ops): shell-layer non-regular-file guard for all read paths (salvage #82075)#83008
teknium1 merged 3 commits into
mainfrom
salvage/82075-shell-layer-special-file-guard

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Salvage of #82075 by @Drexuxux: the shell-layer complement to the merged stat-based guard (0e63ed1 / #82792). read_file, read_file_raw, and read_file_bytes in ShellFileOperations all open the path via wc -c with no deadline — on a FIFO/socket/device that never reaches EOF, remote backends (docker/ssh/modal) still wedge, because the merged guard is host-only (_file_ops_uses_host_paths gate) and doesn't cover the raw/bytes paths.

Drexuxux's mechanism folds a [ -f ] check into the existing size probe (sentinel echo in the same shell invocation), so all three read paths on every backend refuse non-regular files with zero added round-trips. This beats the earlier #29428 approach (separate preflight exec = +1 round-trip per read); @haileymarshall was the earliest submitter on this bug class (May 20) — credit to both.

Eval check (evals/readtool fifo battery, 3 reps, this branch vs main): no per-read regression on regular-file tasks; fifo task unchanged vs merged guard (tool layer still intercepts first on host; the sentinel is the remote/raw safety net behind it).

Changes

  • tools/file_operations.py (authored by @Drexuxux, cherry-picked): combined [ -f ]/wc -c probe + NOT_REGULAR_SENTINEL handling in read_file, read_file_raw, read_file_bytes; _not_regular_error() helper.
  • tests/tools/test_file_operations.py, tests/tools/test_file_read_guards.py: contributor's regression tests + follow-up commit adapting 5 stale wc -c mocks and reconciling the fifo tool-layer test with the merged note-based guard (tool layer notes, shell layer errors — either surface is a pass).

Validation

result
E2E (real FIFO) read_file 0.03s, read_file_raw 0.01s, read_file_bytes 0.01s — all refused instantly
Stack intact normal read / empty note / past-EOF note / unicode retry all pass on top
Targeted tests 164 passed, 0 failed across 6 files (run_tests.sh)

Closes #82075 (salvaged, authorship preserved). Supersedes #29428 (same class, earlier submission, costlier mechanism — close with credit).

Infographic

shell-layer read guard

Drexuxux and others added 2 commits August 9, 2026 23:59
The size probe every read path starts with — `wc -c < path` — opens the
path. On a FIFO with no writer, a socket, or a character device that never
reaches EOF, that read never returns, and read_file/read_file_raw/
read_file_bytes all pass no timeout to _exec. The turn wedges until the
process is killed.

The device blocklist in tools/file_tools.py cannot close this: it matches
literal /dev/* names, so it can only ever cover paths someone thought to
enumerate. A FIFO is a file type and can sit at any path.

Gate the probe behind `[ -f ]`, which stats instead of opening, and report
a path that exists but is not a regular file as such. A missing path keeps
its existing not-found handling.
The combined [ -f ]/wc -c probe changes the first shell command each
read issues; update the stale mocks that only answered bare 'wc -c'.
The fifo tool-layer test now accepts the merged stat-guard's
success=False note (a fact, not an error) with the shell sentinel
behind it.
@github-actions

github-actions Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

૮ >ﻌ< ა ci review

running on 746d409 — test: adapt edge-case pagination mock to the sentinel probe

waiting for jobs to start…

Same stale-mock class as the previous commit — the sweep missed
test_file_operations_edge_cases.py. Verified no bare wc -c mocks
remain anywhere under tests/.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists tool/file File tools (read, write, patch, search) labels Aug 10, 2026
@teknium1
teknium1 merged commit 56dc01d into main Aug 10, 2026
47 checks passed
@teknium1
teknium1 deleted the salvage/82075-shell-layer-special-file-guard branch August 10, 2026 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Medium — degraded but workaround exists tool/file File tools (read, write, patch, search) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants