Skip to content

fix(cli): reject worker --file FIFOs and bound --spec-fd - #220

Open
nillikechatchat wants to merge 6 commits into
higress-group:mainfrom
nillikechatchat:fix/cli-worker-file-fifo
Open

nillikechatchat wants to merge 6 commits into
higress-group:mainfrom
nillikechatchat:fix/cli-worker-file-fifo

Conversation

@nillikechatchat

@nillikechatchat nillikechatchat commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Worker --file opened the path with a blocking File::open, so a FIFO without a writer hung. Unix --spec-fd opened /dev/fd/N and read JSON until EOF with no time bound, unlike Windows --spec-handle (1 MiB / 2s). Opening /dev/fd/N with O_NONBLOCK also does not bound an inherited blocking pipe on macOS.

Change

  • Open --file with O_NONBLOCK / O_NOCTTY and require a regular file, matching --request-file.
  • Read Unix --spec-fd through the shared poll helper: accept inherited regular files and pipes, keep stdin (0) valid, reject devices, and stop at 1 MiB or 2s.
  • Do not change inherited file-status flags.
  • Watchdog subprocesses cover an empty pipe and complete JSON without EOF.

Fixes #217

Validation

Worker --file opened the path with a blocking File::open, so a FIFO
without a writer hung. Unix --spec-fd opened /dev/fd/N and read JSON
until EOF with no time bound, unlike Windows --spec-handle.

Open --file with O_NONBLOCK and require a regular file. Read --spec-fd
with a 1 MiB / 2s bound, keep stdin (0) valid, and reject devices.

Fixes higress-group#217

Signed-off-by: nillikechatchat <yuanhenglizhen2050@163.com>
Co-authored-by: monkeycode-ai <monkeycode-ai@chaitin.com>
@nillikechatchat

Copy link
Copy Markdown
Contributor Author

@johnlanni ready for review.

Fixes #217. Candidate SHA 0bc7f1dc.

backend-shard (unit) failed in hiroute-cpa-bridge (cancelled_ready_start_retains_owner_and_auth_lock_when_stop_fails_until_retry Timeout; each_unmet_pin_condition_is_reported_without_per_poll_logging Null vs false). This PR only changes crates/cli. A rerun of https://github.com/higress-group/HiRoute/actions/runs/40160745074 would confirm.

@johnlanni

Copy link
Copy Markdown
Contributor

Review: Worker file fix is sound; setup FD timeout remains incomplete

Reviewed commit: 0bc7f1dc54e01c6d93c2b23f7405f123db3ccff9.

Importance of the original issue: medium (P2), mainly automation reliability. A Worker --file pointing to a FIFO with no writer blocks in open(), before the byte limit can help. A setup --spec-fd pipe can wait indefinitely for EOF. These are real defects under unusual or faulty input and can stall a calling script. Ordinary finite regular-file inputs are generally unaffected; the report does not establish an ongoing production incident requiring an emergency release.

The Worker --file change is reasonable: open without waiting for a FIFO writer, verify the opened object is a regular file, then retain the existing bounded prompt parsing. Focused tests at this exact head passed on Linux: submission_file_reads_regular_prompt_text, submission_file_rejects_fifo_without_waiting_for_a_writer, and json_from_fd_accepts_file_and_pipe_and_rejects_device_stall_and_oversize (3 passed). An isolated FIFO-open probe also confirmed prompt-file rejection on both Linux and macOS.

Change needed before merge: read_json_from_fd_timed relies on O_NONBLOCK supplied while opening /dev/fd/N. On macOS this duplicates the inherited descriptor without enabling that flag, so a blocking read() can prevent the 2-second deadline from being checked. A syscall probe using the same operations on macOS 26.3.2 arm64 remained blocked beyond an external 3-second watchdog for both an empty pipe and valid JSON followed by a still-open writer. Linux rejected both after about 2 seconds. This is OS-level evidence; the candidate CLI was not executed on macOS.

Please:

  1. Fix the descriptor/deadline handling for macOS as well as Linux, coordinating with the same issue in fix(cli): bound Unix secret and capability fd reads #219. Preserve the 1 MiB limit, regular-file and pipe support, stdin FD 0, strict JSON decoding, and borrowed-descriptor ownership/state.
  2. Add macOS coverage for no data and data without EOF. Put blocking cases behind an independent subprocess watchdog. The current elapsed-time assertion runs only after the function returns and cannot stop a hung read.
  3. Resolve or establish the cause of the red unit shard before merge. Its failures are in unchanged CPA bridge code (a readiness timeout and missing diagnostic fields); that suggests separate investigation, but the current evidence does not prove an environmental flake. The three focused passing CLI tests do not make the whole shard green.

Recommendation: retain the Worker file fix and complete the cross-platform setup-reader behavior before merging.

macOS /dev/fd/N follows dup semantics, so opening with O_NONBLOCK
does not bound an inherited blocking pipe. Reuse the shared poll
reader without changing file-status flags.

Keep the 1 MiB / 2s bound, stdin FD 0, regular-file and pipe
acceptance, and device rejection. Watchdog subprocesses cover empty
pipes and complete JSON without EOF.

Signed-off-by: nillikechatchat <yuanhenglizhen2050@163.com>
Co-authored-by: monkeycode-ai <monkeycode-ai@chaitin.com>
Co-authored-by: monkeycode-ai <monkeycode-ai@chaitin.com>
@nillikechatchat

Copy link
Copy Markdown
Contributor Author

@johnlanni follow-up for the macOS --spec-fd deadline gap is on a3e67b0c.

Unix --spec-fd now uses the shared poll reader on /dev/fd/N without changing file-status flags. Bounds remain 1 MiB / 2s, stdin FD 0 stays valid, and devices are rejected. Watchdog subprocesses cover an empty pipe and complete JSON without EOF. Worker --file still opens with O_NONBLOCK and requires a regular file.

Linux focused tests: cargo test --locked -p hiroute-cli --lib -- unix_bounded_fd json_from_fd submission_file — 9 passed.

Hosted on this SHA:

The earlier unit-shard failures in unchanged hiroute-cpa-bridge (cancelled_ready_start_retains_owner_and_auth_lock_when_stop_fails_until_retry, each_unmet_pin_condition_is_reported_without_per_poll_logging) did not recur on this SHA.

This checkout has no macOS validation target, so the watchdog tests have not been executed on macOS here. The same tests are in the candidate.

Shared reader: crates/cli/src/unix_bounded_fd.rs, also used by #219.

@johnlanni

Copy link
Copy Markdown
Contributor

Follow-up review (2026-10-29): macOS tests pass; shared FIFO-open gap remains

Reviewed commit: fbd268556e89c8a6ccec4e208d1680d909b91673.

I ran cargo test --locked -p hiroute-cli --lib -- unix_bounded_fd json_from_fd submission_file on macOS arm64 at this exact head: 9 passed. This covers the new pipe watchdogs, JSON input checks, regular prompt files, and immediate Worker FIFO rejection. The Worker --file repair remains reasonable, and the previous macOS anonymous-pipe timeout finding is addressed in these tested cases. The current hosted checks, including the previously red unit shard, are all green.

Correction to my earlier impact description: at this head, setup.apply is still Planned in the command registry and the public CLI resolves only released commands. A direct hiroute setup apply ... returns UNKNOWN_COMMAND before reading its input. Consequently, --spec-fd is currently a staged/component concern; Worker --file is a public path. This reduces the immediate user impact of the setup part. Those rejected public invocations are not evidence of the reader's timeout correctness.

Remaining P2 finding: the shared read_unix_fd_bounded, line 31 reopens /dev/fd/N with blocking File::open before starting its deadline. On Linux, an inherited named FIFO with no writer blocks during that open; the later poll cannot enforce the time bound. This helper is byte-for-byte identical to #219's helper. I reproduced the stall through #219's actual public protected-input CLI at 20f83d740d298648c67d127da9c4d42727d590f0: a read descriptor opened with O_NONBLOCK and inherited without a writer remained blocked beyond an external 3-second watchdog, while an ordinary anonymous stalled pipe rejected in about 2 seconds.

Please coordinate the helper correction with #219:

  • Bound descriptor acquisition as well as subsequent reads, preserving borrowed-descriptor ownership/state on Linux and macOS.
  • Add watchdog coverage for named FIFOs with no writer and with an already-closed writer. Keep stdin FD 0, byte limits, strict JSON, and the passing macOS cases covered.
  • Preserve the Worker regular-file restriction and its immediate FIFO rejection.

Merge recommendation: retain the current improvements and address this remaining shared-reader gap before merge. Its priority remains medium; the staged setup path does not establish an ongoing public CLI outage. GitHub currently reports the branch behind main, so the final candidate also needs a base refresh, required checks, and code-owner approval.

nillikechatchat and others added 3 commits October 29, 2026 03:59
…-fifoCo-authored-by: monkeycode-ai <monkeycode-ai@chaitin.com>
Copy the shared /dev/fd/N O_NONBLOCK reopen from the secret-fd
reader. Linux File::open can stall on a named FIFO before poll
sees the 2s --spec-fd deadline. Inherited file-status flags stay
unchanged.

Watchdog coverage includes an empty named FIFO and a closed writer
that must finish inside the deadline.

Signed-off-by: nillikechatchat <yuanhenglizhen2050@163.com>
Co-authored-by: monkeycode-ai <monkeycode-ai@chaitin.com>
…ix/cli-worker-file-fifoCo-authored-by: monkeycode-ai <monkeycode-ai@chaitin.com>
@nillikechatchat

Copy link
Copy Markdown
Contributor Author

@johnlanni Linux named-FIFO follow-up is on 7fad07c1 (rebased onto upstream/main 5eb39d29 via merge 20407424).

--spec-fd now reopens /dev/fd/N with O_RDONLY|O_CLOEXEC|O_NONBLOCK through the copied shared helper. That flag applies to the new description; the inherited descriptor's file-status flags stay unchanged. macOS /dev/fd/N still follows dup semantics, so poll remains the read deadline. Worker --file already used O_NONBLOCK for FIFO rejection.

Watchdog coverage:

  • empty named FIFO without a writer times out inside 2s
  • hung-up named FIFO with a buffered payload completes inside the deadline
  • --spec-fd empty and partial JSON pipes still time out

Linux focused tests at db6ead36: cargo test --locked -p hiroute-cli --lib -- unix_bounded_fd json_from_fd worker::input — 17 passed.

This checkout has no macOS validation target, so the watchdog tests have not been executed on macOS here. Hosted CI after this push is the remaining remote evidence. Human review remains the default.

Shared reader: crates/cli/src/unix_bounded_fd.rs, copied from #219. The PRs stay unstacked.

This branch has not been deployed

No deployments
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.

[Bug] worker --file and setup --spec-fd still block on FIFOs

2 participants