Skip to content

fix(redirect): open output/append FIFO redirects via cwd anchor in bind phase (Refs #3286) - #3735

Merged
caomengxuan666 merged 1 commit into
masterfrom
ai-fix/rubash-3286
Nov 17, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
ai-fix/rubash-3286

Conversation

@arookieofc-ai

Copy link
Copy Markdown
Contributor

Root cause

From a deleted cwd, a relative output (>) / append (>>) redirect to an existing FIFO failed instantly with ENOENT, while GNU bash 5.3.20 blocks for the reader rendezvous and then succeeds (or blocks with no reader).

The anchor carve-out (#3268) classified an existing FIFO out of the anchor open and fell back to the joined string path (File::create(path)), which dies at the dead component under a deleted cwd. The carve-out rationale is real — an anchor O_WRONLY open in the probe phase would consume/block the bind's rendezvous (#1820 discipline) — but it turned a GNU success into an instant failure.

Fix

Two-phase split:

Evidence (fixed binary vs GNU 5.3.20)

  • Reader present, echo hello > ../fifo: rubash rc=0, reader got hello (baseline: instant ../fifo: No such file or directory, rc=1).
  • No reader: rubash blocks (timeout kill after 8s, same as GNU; baseline: instant ENOENT in 0.06s).
  • Append >> and compound-inner echo: identical to GNU with a holding reader (rc=0, reader got bytes).
  • Empty-stream echo -n "" > ../fifo pairs (EOF) like GNU; external /bin/echo and printf neighbors identical.
  • Background echo bg > ../fifo & does not block the parent (spawn rc=0, parent survives).

Verification

Notes (out of scope, pre-existing)

Refs #3286

…nd phase (Refs #3286)

From a deleted cwd, a relative output/append redirect to an existing FIFO failed instantly with ENOENT: the anchor carve-out (#3268) classified the FIFO out of the anchor open and fell back to the joined string path, which dies at the dead component. GNU opens the target once, in the child (redir.c:237), so the write open blocks for the reader rendezvous and then succeeds.

Split the two phases: the bind opens (create_redirect_output, open_append_target) take the anchor O_WRONLY openat for a FIFO, while the probe faces (setup-walk probes, compound prepared phase, #1868 validation walk) validate a FIFO by anchor faccessat and never open it (#1820). The background guard (#1862) and procsub plan-capture guard still defer the FIFO open to the child, and the empty-stream pairing open goes through the anchor-aware append opener.

Regression tests: tests/issue3286_deleted_cwd_fifo_redirect_regressions.rs (11 pins: reader/no-reader cells for > and >>, compound-inner echo, empty-stream pairing via echo -n, live-cwd/external/regular-file neighbors, missing-target control, background-job non-blocking).
@caomengxuan666 caomengxuan666 added the bug Something isn't working label Nov 15, 2026
@caomengxuan666 caomengxuan666 self-assigned this Nov 15, 2026
@caomengxuan666 caomengxuan666 added gnu-baseline Tracked by the GNU Bash 5.3.0 true-baseline ledger P2-medium 中:次要缺陷或边缘路径,排期修复 area:fd redirection, fd table, /dev/* emulation, dup/close ordering labels Nov 15, 2026
@caomengxuan666

Copy link
Copy Markdown
Member

Thanks for the PR — intake has read the full diff and checked CI, and this is queued for captain review. A few verified notes first:

CI, checked by name (not just red/green): the three failing Rust-test legs (GNU goldens, Rust tests, Rust tests macOS) all fail on exactly one cell, api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell — the known issue2875 baseline cell, not a PR-specific failure. The niubash-builds leg fails at the ledger step while the API ledger tripwire itself is green, which matches the known ledger-drift pattern. No PR-specific red was seen in the failed logs. The captain will re-verify by name before any merge decision.

First-pass read of the mechanism (from the diff, not yet run): the two-phase split is coherent with the stated GNU anchor (redir.c:237, single open in the child) and the #1820 discipline — bind faces (create_redirect_output, open_append_target) take the anchor O_WRONLY openat, probe faces validate by anchor faccessat without opening, and the background-defer (#1862) and procsub plan-capture guards are extended to the deleted-cwd case. The new suite (tests/issue3286_deleted_cwd_fifo_redirect_regressions.rs, 11 cells, watchdog-bounded, with regular-file / live-cwd / missing-target / background non-blocking controls) covers the cells the issue names. This is a first pass only — the captain's review is the deciding one.

Sequencing — please read: #3286 already has an earlier open PR, #3363 by Uarz (opened 2026-11-11, draft, Fixes #3286, all CI green). Per repo rule the earlier PR is reviewed first, so #3735 is queued behind #3363: the two are not run in parallel and neither will be closed on the other's account. The captain will adjudicate which one lands (and, if #3363 cannot land, whether #3735 should absorb its tests). Please hold off on rebase churn until that call.

One small hygiene ask: the body has no "What was deleted" section — please add a line confirming nothing was deleted (or list it), so the merge checklist is complete.

Nothing is merged from intake, and no changes are requested beyond the note above. Thanks again for the careful GNU-oracle evidence in the body.

@caomengxuan666

Copy link
Copy Markdown
Member

队长裁断:#3286 的先行实现是 Uarz 的草稿 PR #3363(2026-11-11 开,Fixes #3286,早于本 PR 四天)。按外部 PR 优先规矩:先审 #3363,本 PR 暂缓、不关闭、不并行实现;#3363 若最终不能落地,再回到本 PR,并吸收其测试(本 PR 的 11 格新钉与 #3363 的 7 钉届时逐格对照)。本 PR 的 CI 红已按名核为基线(issue2875 + ledger 漂移),无 PR 专属红,机制初读与 GNU 锚自洽——暂缓不是质量判定。#3363 侧的文本冲突由队长侧处理。

@caomengxuan666

Copy link
Copy Markdown
Member

【WIN-AGENT-AUDIT】PR #3735 第1轮 — 建议:PENDING(缺腿)
head: b33edbf(gh 实时)state: OPEN(非 draft)
关联 issue: #3286

处置:队长已裁先行实现 = #3363(2026-11-11 开,Fixes #3286,早于本 PR 四天),本 PR 暂缓、不关闭;若 #3363 不能落地再回本 PR 并吸收其 11 格新钉。本轮不重跑腿。

@caomengxuan666

Copy link
Copy Markdown
Member

【WIN-AGENT-AUDIT】PR #3735 第2轮 — 建议:PENDING(缺腿已补;排序仍待队长裁)
head: b33edbf(gh 实时复核未变)base(merge-base): d6e4ade 文件: 6 个 +641/-47
关联 issue: #3286(状态:open)

本轮补齐上一轮缺的 Linux 原生腿(fd/FIFO 语义 Windows 仿真不可信,规程要求 WSL 原生构建复核)。环境:WSL ~/rubash-v1 独立 clone,cargo 1.99.0,-j 2,CARGO_INCREMENTAL=0。

机制核查(维持第1轮结论,补 GNU 引用):

  • diff 面:bind 面(create_redirect_output/open_append_target)对 FIFO 改走 cwd anchor openat;probe 面用 anchor fstatat 分类 + faccessat(W_OK) 验证(只验不 open,不消耗 rendezvous 配对,rubash#1820 纪律);background/procsub 路径把 FIFO open 延迟到子进程(rubash#1862:父进程不得替后台 job 取 rendezvous);empty-stream 配对走 anchor 感知 append。
  • GNU 依据:redir.c:237 do_redirections 在子进程内对目标 open 一次;redir.c:348 heredoc_expand/redir.c:423-434 here_document_to_fd 同族「先分类后开」次序;相对路径解析相对实际 cwd inode(deleted cwd 下 joined path 必死于死组件,anchor openat(dirfd,...) 才是 GNU 语义)。
  • diff 无顺手无关改动;无桥接/翻译层。

腿(逐项数字与名字):

  • 钉自跑(Linux 原生,head):issue3286_deleted_cwd_fifo_redirect_regressions 11 passed / 0 failed(11.47s)——reader-present/no-reader-blocks × >/>>、compound-inner、empty-stream、regular-file、live-cwd、external、missing-target、background 全绿。
  • fail-first(Linux 原生,base d6e4ade):4 passed / 7 failed;红名 = {output_reader_present, output_no_reader_blocks, append_reader_present, append_no_reader_blocks, output_compound_inner, output_empty_stream_pairs, output_external_command};base 上仍绿的 4 条均为对照/邻格(missing_target、regular_file、live_cwd、background)→ 钉有效、非废钉,红的正是 deleted-cwd FIFO 七格。
  • lib 双边(Linux 原生):head 失败名集 {} / base 失败名集 {} / 差集 ∅(两侧各 1249 passed; 0 failed; 4 ignored;Linux 侧无 issue2084/issue2875 失败名)
  • -D warnings:RUSTFLAGS="-D warnings" cargo check --locked --lib --bins → 0 警告(第1轮已记;本轮产品文件未变,Linux 侧 cargo test 编译亦无警告)
  • 卫生:rustfmt --edition 2021 --check 六个涉及文件 clean;marker-lint / utf8 第1轮已记 clean
  • CI(head b33edbf):红任务 = Rust tests / GNU goldens / macOS / niubash builds,失败名均为基线 issue2875_input_procsub_child_runs_as_rubash_shell 与 ledger Session::cwd 漂移,无本 PR 归因红(第1轮已按名核过)
  • GNU 对照:WSL /usr/local/bin/bash 5.3.20(1)-release,脚本 target/probe-3735/gnum-{reader,noreader}.sh:
    • deleted cwd + echo hello > ../fifo(有 reader)→ GNU 阻塞至 rendezvous 后写入成功 rc=0、reader 收到 hello —— 与钉期望一致
    • 同形状无 reader → GNU 阻塞(timeout 3 杀出 rc=124),非即时 ENOENT —— 与钉期望「必须阻塞」一致

F 点:无(本轮未发现新问题;机制与 GNU 语义一致)

续作记录:无(未动代码、未 push)

未跑/VOID 的腿:

@caomengxuan666
caomengxuan666 merged commit 6e17fb6 into master Nov 17, 2026
11 of 15 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 18, 2026
…deleted cwd (Refs #3286) (#3867)

* fix(executor): open exec-face FIFO redirects via the cwd anchor in a deleted cwd (Refs #3286)

Absorbs the two trap_exec.rs residuals of PR #3363 after #3735
landed the command-attached faces: bare `exec > fifo` /
`exec >> fifo` (persistent bind) and `exec <cmd> >> fifo`
(replacement spawn) still died ENOENT from a deleted cwd.

Root cause: the redirect machine's probe/bind split classifies an
existing FIFO by anchor fstatat/faccessat and keeps no File for it,
so the bind performs the one real open — but the two exec-face binds
opened by dead joined string path instead of the cwd anchor:
`set_fd_output_file` did a plain `FileFd::open_write`, and
`exec_spawn_open_output`'s append arm did a raw
`open_redirect_append`, bypassing the registry (rubash#1964) and
the anchor.

GNU anchors (audit tree `build-gnu/bash-5.3/redir.c`): :237
`do_redirections` (one `do_redirection_internal` per entry), :790
`do_redirection_internal`, :725 `redir_open` (the single open per
redirect entry). (`redir.c:348` is inside `heredoc_expand`'s doc
comment, not the dispatcher.)

Changes (`src/executor/trap_exec.rs` only):
- `set_fd_output_file`: for a relative operand, try
  `open_via_cwd_anchor` with O_WRONLY|O_CREAT|(O_TRUNC|O_APPEND)
  first; fall back to the plain open when the anchor does not
  apply (live cwd / non-unix). For an existing FIFO this is the
  rendezvous open.
- `exec_spawn_open_output`: the append arm now calls
  `open_append_target_for(Some(redirect), target)` — the
  redirect-aware classified open whose Filesystem arm opens via
  the anchor — instead of the raw `open_redirect_append`.

Regression pins (`tests/issue3286_deleted_cwd_fifo_redirect.rs`,
unix only, 3 tests): bare `exec > ../fifo`, bare
`exec >> ../fifo`, and `exec echo hello >> ../fifo` from a deleted
cwd, each with a background reader; the command-attached faces
and the missing-target control already live in
`tests/issue3286_deleted_cwd_fifo_redirect_regressions.rs` (#3735)
and are not duplicated here.

## 本 PR 删除了什么

- 无文件删除,无公开面删除,无行为删除。
- 唯一移除的调用点是 `exec_spawn_open_output` 追加臂里的
  `open_redirect_append(&self.session_path(...))` 原始打开,
  由等价的分类打开 `open_append_target_for` 替代(同一
  O_WRONLY|O_CREAT|O_APPEND 语义,另加分类与锚路由)。
- PR #3363 的钉 1–4、7 未随附:已由 #3735 的
  `issue3286_deleted_cwd_fifo_redirect_regressions.rs` 覆盖,
  不重复。

UNVERIFIED-BY-CAPTAIN

* fix(executor): stamp exec-spawn cwd through the session anchor (Refs #3286)

external_exec_process set current_dir(cwd) unconditionally, so an
'exec <cmd> >> fifo' replacement spawn from a deleted session cwd
failed the child's chdir with ENOENT (127 'cannot execute'). Carry
stamp_spawn_cwd's three-outcome decision on ChildFdSetup and replay
it in the exec Command builder: resolving cwd keeps current_dir, a
dead cwd the anchor names becomes the same pre_exec fchdir the
Command faces register, and a dead cwd no anchor names stays
unstamped.

---------

Co-authored-by: 曹梦轩 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:fd redirection, fd table, /dev/* emulation, dup/close ordering bug Something isn't working gnu-baseline Tracked by the GNU Bash 5.3.0 true-baseline ledger P2-medium 中:次要缺陷或边缘路径,排期修复

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants