Skip to content

fix6: state-vis slice — job-state observation timing, mapfile -C callback, BASH_SOURCE (#1586, #1587, #1604, #1607, #1612) - #1705

Merged
caomengxuan666 merged 5 commits into
masterfrom
fix6/slice-state-vis
Oct 26, 2026
Merged

caomengxuan666 merged 5 commits into
masterfrom
fix6/slice-state-vis

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

State-visibility slice (wave 6, fix6/state-vis cluster): five fixes around job-state observation timing, mapfile -C callback evaluation, and BASH_SOURCE in functions. Cluster verification on the f6b5a3f baseline: targeted 13/13, lib 771 pass / 1 fail / 1 ignored (failure set = {ownership_unary_operators_check_existing_file}, same as baseline), fmt clean. Integrated onto current master by cherry-pick (no conflicts).

Fixes #1586
Fixes #1587
Fixes #1604
Fixes #1607
Fixes #1612

Per issue

#1604 window correction (found during cluster final verification)

The original cluster fix kept the fatal-signal mark alive for one reader command, but the opportunistic reap actually lands in the pre-execution sweep of the next command (the ast_exec refresh runs before a command executes, not after the previous one, and before that command's redirections are installed) — by then the mark had already been retired. Measured on the baseline tree under load 13–16: baseline 3/24 leaks, one-command window 10/24, widened window (send command + the one immediately after; one-line change in each of the note_reader_command retain and take_fresh_fatal predicates in src/jobs/table.rs) 0/24. Adjacent job-notice nets re-run after the widening: 14 pass / 0 fail.

Integration gates (this tree): targeted tests for all five issues, #1604 leak count ≥20 runs, lib full suite failure-set identity vs baseline, diffcorpus 306 failure set ⊆ {ms10}, rustfmt on changed files. Results are posted as a PR comment when the gates finish.

caomengxuan666 and others added 5 commits October 26, 2026 00:05
…fired per record during the read (rubash#1586)

GNU mapfile.def run_callback appends ` <index> <quoted line>` to the
callback string and evals the whole thing; rubash whitespace-split
the string into a command + fixed words, shifting every argument.
The callback form now builds "<cb> <idx> '<line>'" with the line
sh-single-quoted and runs it through execute_eval_source (its
visibility widened to pub(in crate::executor) for this call).

Firing also moves into the read itself: execute_mapfile_with_callback
pulls records incrementally (byte-domain puller over real fds/files,
pre-split values for materialized sources) and fires the callback
after binding the previous record and before binding the current
one, matching GNU's array state during the callback.

Regression: tests/issue1586_mapfile_callback_eval_regressions.rs
(6 tests, GNU bash 5.3.20 oracle; the streaming case drives a coproc
fd — a builtin pipeline stage is fed from the parked FUNCTION_STDIN
mirror on this tree, so a pipe shape cannot observe interleaving).

Co-Authored-By: Muse Spark <[email protected]>
…n file, not the caller (rubash#1587)

Entering a function call framed BASH_SOURCE[0] from the caller's
source stream, so a function defined in lib.sh but invoked from
main.sh saw main.sh. The call frame now takes element 0 from
function_definition_locations (the file the definition was read
from), falling back to the caller source only when no definition
site was recorded.

Regression: tests/issue1587_bash_source_definition_regressions.rs
(2 tests: file invocation and -c invocation).

Co-Authored-By: Muse Spark <[email protected]>
…e command early (rubash#1607)

Deferred stop/continue marks from the shell's own kill were applied
by reader-command count (seq + 1 < now), so `kill -STOP %1`, one fast
builtin, then `jobs` already showed Stopped; GNU still shows Running
until a notification point (its waitchld runs when the shell blocks
in wait_for, or at the post-command notify cadence).

Marks now carry their send instant and publish when the refresh is a
real observation event — a wait/fg observed refresh, the shell having
blocked on a foreground process since the last refresh, or job
control live on a terminal — or, failing that, once the mark is a
full reader command old AND ~5ms of wall time has passed (GNU's
SIGCHLD-delivery latency across a busy builtin stretch). The
state_observe predicate is computed once in the jobs refresh and
feeds apply_deferred_state_marks.

This commit also widens stdin_source_is_terminal to
pub(in crate::executor): the predicate calls it from job_builtins.rs.
That widening is rubash#1612's enabling change — its monitor+terminal
arm is #1612's publication mechanism, and the refresh face cannot be
split further; #1612's own commit carries its regression test.

Regression: tests/issue1607_stopped_observation_lag_regressions.rs
(3 tests: fast-builtin lag, same-line lag, publish after a foreground
wait with promotion to current job).

Co-Authored-By: Muse Spark <[email protected]>
…rubash#1612)

Mirror of rubash#1607: with job control live on a terminal, GNU
publishes a stop at the first notification point after the signal,
but rubash's command-count lag never published at all in the pty
cadence, so `jobs` kept showing a stopped job as Running forever.

The fix itself (the refresh's state_observe predicate and its
monitor+terminal arm, plus the stdin_source_is_terminal widening it
calls) landed in the previous commit — the jobs-refresh face is
shared with #1607 and cannot be split further. This commit carries
the regression test and the verification record.

Regression: tests/issue1612_pty_stopped_observation_regressions.rs
(1 test, driven through a util-linux `script -qec` pty carrier;
manual pty run byte-identical to GNU bash 5.3.20:
"[1]+  Stopped                    sleep 30").

Co-Authored-By: Muse Spark <[email protected]>
…ated cannot leak past `wait $p 2>/dev/null` (rubash#1604)

GNU learns a death asynchronously and the following wait claims the
job, suppressing its notice (jobs.c wait_for marks it notified).
Rubash's boundary sweep could reap the zombie first and queue the
notice outside the wait, printing it to raw stderr (~1/6 of runs).

The kill builtin now records each fatally-signalled pid
(JobTable::note_fatal_signal); when the boundary sweep reaps such a
job it stashes the completion instead of applying it, and the wait's
own observed refresh applies it under the wait's fd 2, where the
notice drains through the redirect. The mark's window spans the
sending reader command AND the following one: the incidental reap
lands at the following command's pre-execution sweep (ast_exec runs
the refresh before a command executes, not after the previous one),
which is where the leak actually escaped — a one-command window
still leaked 10/24 seed runs under load; the two-command window
leaks 0/24 against the baseline's 3/24.

Regression: tests/issue1604_killed_notice_wait_leak_regressions.rs
(1 test, 6 seed runs per invocation, each demanding exactly one
Killed notice — the second job's).

Co-Authored-By: Muse Spark <[email protected]>
@caomengxuan666

Copy link
Copy Markdown
Member Author

Integration gates on this tree (base master 2157a3a + the five cherry-picks, no conflicts):

  • Build: rc=0 (cargo build --locked, build slot, purified env).
  • Targeted: issue1586 6/6, issue1587 2/2, issue1604 1/1, issue1612 1/1 green on first pass. issue1607: 2/3 on first pass — stopped_state_not_published_after_one_fast_builtin failed once. Flake adjudication (isolated re-runs): the same test binary interleaved with the cluster tree's own reference binary under identical load — cluster binary 7 pass / 1 fail, integrated binary 7 pass / 1 fail, then 7 consecutive integrated passes. The reference binary flakes at the same rate (the cluster report documents ~1/8 at load 13–16 for the 5 ms wall-clock aging gate), so this is the known load sensitivity, not an integration regression.
  • [bug] Killed notification intermittently leaks through wait $p 2>/dev/null (residual of #1303) #1604 leak count on the integrated binary: 0 / 24 (seed from the cluster; baseline tree was 3/24, one-command-window variant 10/24).
  • Lib full suite (--skip login_posix_env): 771 passed / 1 failed / 1 ignored — the only failure is ownership_unary_operators_check_existing_file, identical to the baseline failure set.
  • diffcorpus 306: 304 pass; failures {ms10, ps06}; ps06 isolated 5 runs = 4 pass / 1 fail (known reaping-order timing flake) → effective failure set {ms10}.
  • rustfmt on all 13 changed files: clean. CR bytes in changed files: 0.

Merging on green.

@caomengxuan666
caomengxuan666 merged commit 1560ea4 into master Oct 26, 2026
7 of 10 checks passed
@caomengxuan666
caomengxuan666 deleted the fix6/slice-state-vis branch October 30, 2026 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment