Skip to content

fix(cli): no panic on non-UTF-8 argv or broken stdio; doctor --help is help - #574

Merged
yifanxuaaa merged 4 commits into
layerfs_v2_0_0from
issue30/cli
Nov 5, 2026
Merged

yifanxuaaa merged 4 commits into
layerfs_v2_0_0from
issue30/cli

Conversation

@Mola-maker

Copy link
Copy Markdown
Member

Summary

The layerfs CLI panicked on a non-UTF-8 argument and on a closed or full stdout/stderr (exit 101), and layerfs doctor --help exited 2 as a usage error. This fixes those unambiguous defects and pins the existing exit-code behaviour with tests. Documented exit codes are not changed.

Refs Ephemeral-AI-Lab/layerfs-project#36 (native CLI), parent Ephemeral-AI-Lab/layerfs-project#30. Findings and decisions: https://github.com/Ephemeral-AI-Lab/layerfs-project/issues/31#issuecomment-6657201351

Changes (3 commits)

  • fix(cli): argv is read with args_os; a word that is not UTF-8 is exit 2 naming the word. help, --version and every stderr line used println!/eprintln!, which panic when the reader is gone or the device is full; they now go through output::print / output::diagnostic, so the exit code is the outcome's own (a stdout failure stays 125, as for results). layerfs doctor --help and layerfs help doctor print doctor's usage and exit 0. layerfs doctor still exits 0 whenever it produces a report, as documented. Production LOC +12.
  • test(cli): usage 2 / refusal 125 / success 0; stdin, --from, --, binary stdin; closed and broken stdout and stderr; workspace exec --stream with command exits 0..255, 256 and -1 against a stand-in worker (argv, closed_streams, exit_codes, stream_exit).
  • docs(cli): states the behaviour above in front-ends/cli.md.

Verification (Linux/WSL Ubuntu, rustc 1.85.1, --locked --offline, each run under timeout 120)

At the final commit: new tests argv 2, closed_streams 3, exit_codes 5, stream_exit 5 pass; the pre-existing doctor 2, store_closed 1, stream 1, worker 2 still pass; cargo fmt --all -- --check exit 0; clippy -p layerfs-cli --all-targets -D warnings clean; check_product_boundary.py PASS.

An independent review by a separate model had two minor points. One was real and is fixed: the tests used Linux-only /dev/full and the Linux O_NONBLOCK value (0o4000); they now use O_NONBLOCK per platform (Linux 0o4000, macOS 0x4) and /dev/full only on Linux. The other (add cfg(unix)) was declined: LayerFS supports Linux and macOS only.

Not done / risks

  • Not run on macOS. The platform guards above compile and pass on Linux only.
  • Exit-code policy is left for the owner, with the observed behaviour pinned by a test so a change is deliberate: a successful call whose stdout cannot be written exits 125, the same as a refusal; with --stream a command's own exit code 2 or 125 is indistinguishable from usage or refusal.
  • Only Linux was exercised for broken-pipe and full-device cases. No new dependency, no new subcommand, the retired JavaScript CLI is not touched.

🤖 Generated with Claude Code

root and others added 3 commits November 5, 2026 08:14
…elp is help

The CLI read argv with std::env::args(), which panics on a word that is not UTF-8. It now reads args_os and a bad word is exit 2 naming the word. help, --version and every stderr line were written with println!/eprintln!, which panic (exit 101) when the reader has gone or the device is full; they now go through output::print and output::diagnostic, so the exit code is the outcome's own (a stdout failure stays 125, as for results). layerfs doctor --help and layerfs help doctor print doctor's usage and exit 0 instead of 2. Exit-code policy is unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Usage 2, refusal 125 and success 0; stdin, --from, -- and binary stdin; a closed or broken stdout and stderr; workspace exec --stream with command exit codes 0..255, 256 and -1 against a stand-in worker.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Record the observed behaviour, including the --stream collision of a command's own exit code 2 or 125 with usage and refusal, which is left for the owner to decide.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Mola-maker

Copy link
Copy Markdown
Member Author

CI note: the test job reports 3 failures out of 1494 tests, and the same 3 fail on the unmodified baseline d4304741 (reproduced locally on a pristine checkout, Linux, rustc 1.85.1), so this PR does not introduce them:

  • layerfs-api tests/workspace_names.rs: a_name_is_unique_in_its_sandbox and every_workspace_call_takes_the_name_or_the_path, both with machine native's recorded daemon /nonexistent is not there (left: "Unavailable", expected "Exists" / "NoSuchSandbox"): they need a built daemon.
  • layerfs-persistence tests/sqlite_publication.rs:63: wal_full_settings_and_unavailable_engine_are_explicit.

fmt and guards, clippy and windows build (reports only) pass. Nothing here touches those tests, so I have not changed them; they likely need their own fix on layerfs_v2_0_0.

Limit the mutable sink list to the Linux-only block.

Verified on macOS: all 21 CLI tests pass; Clippy all targets with -D warnings passes. No tests deleted.

Production LOC: 137229 -> 137229 (delta +0)

Scope: first-party core, engine, connect, API Rust/SQL/JS and shipped Python
implementation plus handwritten Python stubs. Generated stubs, tests, tools,
examples, docs and third-party code excluded. Python comments and documentation
strings excluded. Counter blob 31b3cc2 (tools/production_loc.py
extended in #575), identical for both exact exported snapshots.
Command: python3 tools/production_loc.py --root <git-archive-tree> --json.
Reference absent (retired R9c; last counted 65,417 at tree 498dd19).
@yifanxuaaa
yifanxuaaa merged commit 345f181 into layerfs_v2_0_0 Nov 5, 2026
3 of 4 checks passed
@Mola-maker
Mola-maker deleted the issue30/cli branch November 7, 2026 02:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants