Skip to content

executor: report untrapped-SIGINT unwinds on the bind -x outcome - #3273

Merged
caomengxuan666 merged 5 commits into
masterfrom
fix/977-bindx-interrupted
Nov 10, 2026
Merged

caomengxuan666 merged 5 commits into
masterfrom
fix/977-bindx-interrupted

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs unixwin/niubash#977

Engine half of the bind -x Ctrl+C work. While a bind -x widget
runs, the tty is cooked, so a ^C in that window never reaches
the line editor as a byte: GNU runs the widget with readline's
signal handlers cleared (bashline.c:4603
bash_execute_unix_command, parse_and_execute at
bashline.c:4688), an untrapped SIGINT kills the foreground
job, and waitchld's ADDINTERRUPT (jobs.c:3316) throws the list
to the top-level reader — the host must discard the edit line
on resume. The host cannot rebuild that fact from the returned
status (a discard and an ordinary failure share statuses), so
the engine now reports it on the outcome:

  • BindXRunOutcome::interrupted — true exactly when the
    widget run's unit ended in a signal discard. The verdict is
    the engine's own Q6 arm B unit signal-discard record, noted
    at the unwind-capture point where the source driver
    classifies the unwind (the SigintUnwind arm and the
    discard-marked ExitCode arm of run_source_impl), and
    consumed by run_bind_x_command, which is this unit's
    driver. A trapped SIGINT (trap runs, list continues), an
    ignored SIGINT (no-op), normal completion and an exit
    jump all leave it false.
  • docs/api-ledger.md records the widened return contract
    (§2.2 seam record appended); the niubash mirror is synced
    by the host half.

The host half (repl consumption, and the $? = 1 settlement
ruled for the untrapped shape) lands on the niubash side once
this and the in-flight repl rework are both in.

Pin: tests/issue977_bind_x_interrupted.rs — five cells
driven with real kill(2) deliveries against an in-process
interactive executor: the untrapped discard (shell-directed
delivery, rubash#1640 shape), the trapped control (trap runs
exactly once, widget completes, flag false), the ignored
control, a quiet control, and a boundary lock for the
builtin-sleep mid-wait fold (rubash#1640: the fold produces
no unwind, so the flag stays false there). On the base the
pin does not compile (E0609, the field does not exist); on
this head all five cells pass, the lib suite is unchanged
(1207 passed / 0 failed on both base and head), and a
-D warnings check of the lib plus the pin target is clean.

Deletion section: no code path is deleted. The change adds
one field, one record consumption in the bind -x runner, two
lib-test assertions, one test file, and one ledger record.
One latent leak is incidentally closed: a widget run's
discard record can no longer linger into the next reader
unit's classification on the engine's own console-readline
route, which also calls this runner.

…unixwin/niubash#977)

BindXRunOutcome gains interrupted: true exactly when the widget
run's unit ended in a signal discard. GNU: bashline.c:4603
bash_execute_unix_command runs the widget with readline's signal
handlers cleared (parse_and_execute, bashline.c:4688); an
untrapped SIGINT kills the foreground job and jobs.c:3316
waitchld ADDINTERRUPT throws the list to the top-level reader.
The verdict is the engine's Q6 arm B unit signal-discard record,
noted at the unwind-capture point where the source driver
classifies the unwind; run_bind_x_command, this unit's driver,
takes the record for its own run. Trapped, ignored, normal and
exit-jump endings leave it false. Ledger record appended;
niubash mirror sync rides with the host half.
…nixwin/niubash#977)

The generated definition omitted the terminator before }, so
the brace was read as a word of the last command and the
definition unit failed with a syntax error at EOF (status 2)
in every cell — a pin-side construction error, confirmed
against the GNU oracle with the corrected script-file shape.
unixwin/niubash#977)

The deliveries are addressed to the shell's pid only. For the
external-sleep cell that is the rubash#1640 shape — the child
is not a target, the wait runs out, and the recorded interrupt
discards the list at its end (interrupted, 130, no post-sleep
commands) — not the instant group-delivery death the first
draft asserted on elapsed time. The builtin-sleep cell now
locks the #1640 mid-wait fold boundary instead of demanding a
discard the fold adjudication does not produce.
caomengxuan666 added a commit to unixwin/niubash that referenced this pull request Nov 10, 2026
…sh#3273)

docs: mirror the api-ledger record for the bind -x interrupted outcome into the niubash copy of the ledger.

The record text is taken byte-for-byte from the rubash ledger entry carried by the engine-side change. Once both sides land, the two ledger copies are byte-identical again (sha256 d8aff861d91c0c9864f34f9238d66a5437b49c3cc4df1da50afd92297675e061).

Refs unixwin/rubash#3273
Refs #977

本 PR 删除了什么:无删除,纯新增 10 行(docs-only 台账同步,按删除节豁免口径记此一笔)。
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 10, 2026 19:48
@caomengxuan666
caomengxuan666 merged commit 3755d72 into master Nov 10, 2026
11 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 15, 2026
) (#3469)

Replace the blind 500ms settle in drive() with a poll-with-timeout
for the widget's foreground wait: foreground_sleep_child_running()
(/proc scan for this process's sleep child) + wait_for_foreground_wait()
(2s poll, 250ms arming grace, deliver regardless on timeout; degrades
to a 2s fixed settle without /proc).

Root cause: under box load the runner thread can sit unscheduled for
longer than 500ms between creating started.txt and spawning the child,
and a SIGINT delivered in that window is never registered (trap count
0, no unwind) -- a load-shaped flake, not a product defect (adjudicated
in the PR #3273 merge round). The foreground wait is a 10ms-slice loop
(wait_fg_child_draining / wait_fg_child_sliced in external_inner.rs,
each slice calling observe_signals_while_blocked); delivering only
once the child exists closes the whole window.

The trapped/ignored cells' external sleep goes 2s -> 4s so the
delivery still lands mid-sleep at the poll's worst case (2s + 250ms);
the ignored cell's elapsed guard tightens 1800ms -> 3800ms to match.
The builtin-sleep cell already sleeps 4s.

GNU anchors (unchanged, per the pin header): bashline.c:4603/4688,
jobs.c:3316 (ADDINTERRUPT), eval.c parse_and_execute DISCARD arm.

UNVERIFIED-BY-CAPTAIN: no build slot available this round (local
write wall, box disk full, old server ssh down, X299 not yet
reachable) -- repeat runs, full-lib alignment and -D warnings check
are owed to the review round.

Co-authored-by: 曹梦轩 <[email protected]>
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.

1 participant