Skip to content

WIP: fix trapped SIGINT discarding the line after builtin sleep (#1811) - #1821

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix7/issue1811
Oct 27, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix7/issue1811

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fixes #1811

Divergence (sig-trap GATE-READJUDICATION §C, the one real product divergence of the 11)

Interactive PTY: trap 'echo TRAPPED_INT' INT; sleep 6; echo AFTER1639 rc=$?, ^C during the sleep.

  • GNU bash 5.3.20: trap is recorded, the list continues — AFTER1639 rc=130 prints, next line sees $?=0.
  • rubash (master 5275dde): trap ran (TRAPPED_INT printed) but the rest of the line was discarded via the untrapped path (next line saw $?=130).

Root cause

The builtin-sleep fast path re-adjudicates the abort after sleep_interruptibly returns Some(SIGINT) (the trap has already run by then). Its untrapped test looked the trap table up with the bare name "INT". The table is keyed verbatim by trap_key() over the canonical names normalize_signal returns — SIG-prefixed SIGNALS entries for real signals ("SIGINT"); bare names exist only for the EXIT/ERR/DEBUG/RETURN pseudo-signals — and every other lookup site honors that form (signal_trap_name(), the "SIGCHLD" literal). The bare-"INT" lookup could never hit a stored trap, so every trapped abort read as untrapped, fg_sigint_unwind was marked, and the list boundary converted it to SigintUnwind.

GNU: jobs.c:3315-3316 waitchld queues ADDINTERRUPT only when signal_is_trapped(SIGINT) == 0; a trapped delivery is only recorded (trap.c:553 trap_handler -> trap.c:545 set_trap_state) and its action runs at the next boundary (execute_cmd.c:643 run_pending_traps), after which the list continues with the wait's 130.

Fix

One lookup in src/executor/command_dispatch_primary.rs now uses the canonical "SIGINT" key (with the invariant spelled out in the comment). No new predicate; untrapped case unchanged (lookup still misses, discard still marked); ignored case (trap '' INT stores Some("") under the canonical key) now also continues, as GNU counts it as trapped for ADDINTERRUPT; #1809 DISCARD semantics and the G-01 lock narrowing untouched; src/lexer/continuation.rs untouched.

Regression seed: issue1639_trapped_int_runs_trap_and_continues_line — unchanged, expected to turn green with this fix (verification numbers land in the cluster REPORT and a follow-up comment; PR stays draft, no self-merge).

… sleep (#1811)

GNU spec: jobs.c:3315-3316 waitchld (foreground job killed by
SIGINT) queues ADDINTERRUPT only when signal_is_trapped(SIGINT) == 0.
A trapped delivery is merely recorded (trap.c:553 trap_handler ->
trap.c:545 set_trap_state, pending_traps[sig]++); its action runs at
the next command boundary (execute_cmd.c:643 run_pending_traps) and
the executing list then CONTINUES with the interrupted command's
128+SIGINT status.

rubash divergence (PTY, interactive):
  trap 'echo TRAPPED_INT' INT; sleep 6; echo AFTER1639 rc=$?
  ^C -> TRAPPED_INT printed, then the rest of the line was discarded
  (next line saw $?=130); GNU prints AFTER1639 rc=130 and the next
  line sees $?=0.

Root cause: the builtin-sleep fast path re-adjudicates the abort
after sleep_interruptibly returns Some(SIGINT) (by then the trap
has already run). Its untrapped test looked the trap table up with
the bare name "INT". The table is keyed verbatim by trap_key() over
the canonical names builtins::trap::normalize_signal returns — the
SIG-prefixed SIGNALS entries for real signals ("SIGINT"); bare names
exist only for the EXIT/ERR/DEBUG/RETURN pseudo-signals — and every
other lookup site honors that form (signal_trap_name(), the
"SIGCHLD" literal). The bare-"INT" lookup could therefore never hit
a stored trap: every trapped abort of the virtual child read as
untrapped, fg_sigint_unwind was marked, and the list boundary
converted it to SigintUnwind, discarding the rest of the line.

Fix: look up the canonical "SIGINT" key, restoring the invariant
that this adjudication consults the same trap table every sibling
site consults. No new predicate, no behavior change for the
untrapped case (lookup still misses, discard still marked), the
ignored case (trap '' stores Some("") under the canonical key, so
no discard — GNU counts an ignored SIGINT as trapped for
ADDINTERRUPT), or the #1809 DISCARD semantics for untrapped waits.

Regression seed: tests/issue1639_1640_interactive_sigint_regressions
::issue1639_trapped_int_runs_trap_and_continues_line (unchanged).

Fixes #1811
@caomengxuan666

Copy link
Copy Markdown
Member Author

Verification evidence (cluster issue1811, all runs via the single build slot, python file-handle logs + .done markers; full logs in the cluster REPORT):

Fix: commit cbfc4c1 — one lookup in the builtin-sleep arm of command_dispatch_primary.rs now uses the canonical trap-table key "SIGINT" (was "INT", which can never hit a stored trap). Tests untouched: tests/issue1639_1640_interactive_sigint_regressions.rs sha256 7ab9ee9f… identical to master, git diff 5275dde2 -- tests/ empty.

Seed: issue1639_trapped_int_runs_trap_and_continues_line — red on baseline 5275dde, green after the fix (1 passed / 0 failed). PTY transcripts match GNU 5.3.20's shape (TRAPPED_INT → AFTER rc=130 → next line $?=0); untrapped control still discards with $?=130.

Six sig files: fixed tree 32 passed / 2 failed. Baseline control on pristine 5275dde (same two affected files): the seed plus the same two failures — i.e. the fix flips exactly the seed and introduces no new failure. The two remaining reds are pre-existing on this master and outside #1811's surface (untrapped discard in subshell/read frames; transcripts byte-identical in shape on both trees):

issue1662 targeted: 4 passed / 0 failed (#1809 semantics intact).
lib (--skip login_posix_env): 771 passed / 1 failed / 1 ignored — the one failure is the standing allowed ownership_unary_operators_check_existing_file, identical to baseline.
diffcorpus 306: raw failset {bi08}; bi08 is a documented timing flake — isolated re-runs PASS/PASS/FAIL on the same binary (nondeterministic), effective failset ∅ ⊆ {ms10}.
PTY matrix (tmux, bare rubash vs GNU): loop / pipe / ext cells identical to GNU (session alive, INTRC=130) on both trees.
Changed file: rustfmt --check clean, CR=0.

One adjacent residual documented in the cluster REPORT (not fixed here, different mechanism): untrapped ^C during the wait builtin exits the interactive session voluntarily with code 130 instead of GNU's DISCARD-and-survive (wait_pending_signal_status returns ExitCode without the DISCARD classification).

@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 27, 2026 05:16
@caomengxuan666
caomengxuan666 merged commit f8ea59e into master Oct 27, 2026
10 of 11 checks passed
@caomengxuan666
caomengxuan666 deleted the fix7/issue1811 branch October 30, 2026 01:41
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.

[executor] Trapped SIGINT at a wait point discards the rest of the line instead of continuing (#1639 residual shape)

1 participant