Skip to content

[P1][reader] stray ")" inside an open multi-line group wedges the interactive REPL in PS2 with no diagnostic (GNU 5.3 recovers) #482

Closed
unixwin/rubash
#955

Description

@caomengxuan666

[audit #368-B] stray ")" inside an open multi-line group wedges the interactive REPL in PS2 with no diagnostic

From the #368 item B audit (read-unit division consistency between the host fast path and the grouped reader). GNU bash 5.3.0 oracle disagrees with niu; both GNU builds checked.

Repro (product REPL, interactive, ConPTY)

Type the two submissions:

{ echo c
)

The first line shows PS2 (correct). After the second line niubash prints no diagnostic and never returns to PS1 — the session stays in continuation; every later submission is swallowed by the still-open group and nothing executes (verified: a following echo rc=$? produced no output for the rest of the session; the only exit is Ctrl-C). Transcript on file with the probe run.

GNU bash 5.3.0 (and 5.2.21), same piped -i methodology:

bash-5.3# { echo c
> )
bash: syntax error near unexpected token `)'
bash-5.3# echo rc=$?      <- session RECOVERED; executes fine

GNU rc for the failed group is 2 and the shell keeps reading. A stray ) at PS1 is already handled correctly by niu (syntax error, rc 2, session recovers) — the divergence is specific to a stray close inside an open group reached via PS2.

Mechanism (audit reading)

The grouped reader gathers a submission by incremental completeness scanning (read_next_source_group, rubash src/script_driver.rs:291-439): while the { group is open, the scan always answers "needs more", so the stray-close guard (ParseLoopOptions::stray_close_is_error, the niubash#431 arm) never gets a chance to fire — it only judges syntactically complete groups. GNU's reader parses token-by-token (parse.y read_token) and hits the error the moment ) reaches command position inside the open group, abandoning the whole submission (parse.y y.error -> jump back to the top level). The niubash#431 guard gave the interactive non-grouped route and the non-interactive routes the GNU shape; the PS2-gather path has no equivalent terminal condition, so a one-character typo inside any open construct ({, (, if/case bodies) can silently wedge the session.

Adjacent observation (same family, non-interactive face)

niu -c on the same text reports a different diagnostic and line than GNU — niu: -c: line 3: syntax error: unexpected end of file from '{' command on line 1 vs GNU line 2: syntax error near unexpected token ')'. rc matches (2). Not item B's interactive scope, noted here for the reader-family cleanup.

Suggested direction (audit only — not fixed here)

Give the gather loop a GNU-shaped terminal condition: when the pending group contains a stray closing token at command position while a group opener is unresolved, abort the submission with the GNU diagnostic and return to PS1, instead of waiting for the opener forever.

Related: #368, #431, #367.

Activity

  1. added
    P1-high
    on Oct 20, 2026
  2. caomengxuan666 commented on Oct 21, 2026

    @caomengxuan666
    MemberAuthor

    Reopening: this was auto-closed by the cross-repo Fixes keyword when the engine half (unixwin/rubash#955, merged as rubash 95700a5b) landed. The engine half alone fixes the -c/-s/stdin/-i reader faces (verified: niubash master's failure set on issue482_stray_close_gather shrinks 6 → 2 with the new engine), but the two remaining faces (mid_command, case_body) need the host half — #484 is still open, on hold for a one-line Cargo.lock correction ("sha2", missing from the rubash entry; CI red is mechanical, details in the PR review comment). This ticket stays open until #484 merges.

  3. caomengxuan666 commented on Oct 21, 2026

    @caomengxuan666
    MemberAuthor

    宿主半(repl gather 终结)已随 #484 合入(rebase 后含引擎半 #955)——#482 双面修复完整落地,关闭。审计报告见 #368。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1-highrubash-bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions