Skip to content

fix(jobs): ambiguous %?pat jobspec errors instead of resolving (rubash#1302) - #1437

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/p1-1302
Oct 23, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/p1-1302

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fixes #1302 (devin lane fix/p1-1302, captain-verified + regression matrix added).

Root cause: name-jobspec matching never counted matches — first hit won. Now resolve_jobspec -> JobspecMatch{Job, Ambiguous, NoMatch} mirroring the C loop (stage command texts, %? case-folded strcasestr, %name STREQN prefix, %+x/%-x/%% first-byte dispatch). Consumers per GNU: kill (diagnostic only, rc=1 + any_succeeded/any_failed counters per kill.def:265-268), wait/wait -n (127), jobs/disown (diagnostic + no such job, rc=1), fg/bg (diagnostic only), jobs -x (diagnostic + passthrough).

Evidence: 16 script shapes diffed byte-identical (stdout+stderr+rc) vs GNU 5.3.20 (kill/wait/jobs/disown/jobs -x/prefix/fold/posix/exact/current/previous/fg/bg/wait -n/single).

Tests: new tests/issue1302_ambiguous_jobspec_regressions.rs (13 cases, all green); updated 5 stale rc=0 expectations in issue549 file to GNU-verified rc=1 (GNU jobs.def:174 any_failed -> FAILURE; process rc stays 0, builtin status rc=1); lib 716/0; fmt clean.

Note: 2 part_080 procsub tests fail on base (pre-existing persistent->(...) bug, fixed by forthcoming #1336 harvest-hang PR — verified green there). Rebase onto that PR before merge.

caomengxuan666 and others added 2 commits October 23, 2026 17:48
…U (rubash#1302)

GNU builtins/common.c:689 get_job_spec -> common.c:632 get_job_by_name
counts (job, process) matches and returns DUP_JOB (jobs.h:207) when
more than one fires; the matching p is not advanced before `job` is
assigned, so a match on any stage other than j->pipe is ambiguous with
itself.  Rubash's resolve_jobspec returned the newest matching job
silently: `kill -0 %?sleep` with two sleeps returned rc 0 with no
diagnostic, and wait/fg went on to hang on the wrong job.

- JobTable::resolve_jobspec now returns JobspecMatch {Job, Ambiguous,
  NoMatch}; get_job_by_name mirrors the C loop: newest-first jobs,
  per-stage commands (new JobEntry.stage_commands = GNU's j->pipe
  PROCESS texts), strcasestr for %?, STREQN prefix for %name, and the
  non-first-stage self-ambiguity quirk.  The `%`/`+`/`-` dispatch is
  first-byte like common.c:720-738 (%-x, %+x, %%x).
- bash_job_stage_commands splits pipeline stages at registration,
  unwrapping !/time like GNU's printed per-process commands.
- kill (kill.def:226-268): ambiguous -> `kill: name: ambiguous job
  spec`; operand status now uses GNU's any_succeeded/any_failed
  counters — spec diagnostics move neither, so `kill -0 %1 %?dup` is 0
  and posix `kill %99`/`kill foo` is 0; non-% operands get sh_badpid
  text, numeric operands outside the table take the real pid path.
- wait (wait.def:294-311): ambiguous -> diagnostic + 127, in the
  -n/set_waitlist arm (with the trailing "no such job" sh_badjob), the
  operand loop, and the all-failed fallback.
- jobs/jobs -x (jobs.def:156-164/execute_list_with_replacements) and
  disown (jobs.def:286-291): ambiguous prints the diagnostic AND
  sh_badjob.
- fg/bg (fg_bg.def:143-152): ambiguous prints the diagnostic only.

Verified byte-identical stdout/stderr/rc against GNU bash 5.3.20
across kill/kill -0, wait, wait -n, jobs, jobs -x, disown, fg, bg, and
%spec-as-command, for single/double/pipeline/!-pipeline jobs, prefix
and %? forms, case-fold, mixed operands, posix mode, and empty table.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666
caomengxuan666 merged commit 8503cb3 into master Oct 23, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/p1-1302 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.

[bug] Ambiguous %?pat jobspec silently resolves to one job (GNU: ambiguous job spec error); wait/fg hang

1 participant