Skip to content

Fix TUI exit after gateway disconnect#75381

Open
udaymanish6 wants to merge 2 commits intoopenclaw:mainfrom
udaymanish6:codex/issue-75379-tui-unresponsive-after-gateway-close
Open

Fix TUI exit after gateway disconnect#75381
udaymanish6 wants to merge 2 commits intoopenclaw:mainfrom
udaymanish6:codex/issue-75379-tui-unresponsive-after-gateway-close

Conversation

@udaymanish6
Copy link
Copy Markdown

Summary

  • bound TUI input draining during shutdown so terminal teardown cannot hang indefinitely
  • make Ctrl+C exit immediately after a gateway disconnect and force-exit on repeated Ctrl+C/timeout
  • cover the bounded drain arguments in the TUI shutdown test

Validation

  • pnpm install --frozen-lockfile
  • pnpm exec vitest run src/tui/tui.test.ts

Fixes #75379

@clawsweeper
Copy link
Copy Markdown
Contributor

clawsweeper Bot commented May 1, 2026

Codex review: needs changes before merge.

Summary
The PR bounds TUI shutdown input draining, adds forced-exit behavior for repeated or timed-out shutdown after gateway disconnect, treats Ctrl+C after disconnect as immediate exit, and updates the shutdown unit test.

Reproducibility: yes. The linked issue gives concrete gateway-restart steps, and current main still has matching code gaps in disconnected Ctrl+C handling and shutdown fallback behavior.

Next step before merge
The remaining repair is a narrow required changelog entry; no runtime code change is needed from this review.

Security
Cleared: The diff only touches local TUI shutdown control flow and one colocated unit test, with no CI, dependency, install, secret, package, or publishing changes.

Review findings

  • [P3] Add the required changelog entry — src/tui/tui.ts:255-258
Review details

Best possible solution:

Land the focused TUI lifecycle fix with a single-line active-version Fixes changelog entry, keeping the runtime surface limited to the TUI shutdown path.

Do we have a high-confidence way to reproduce the issue?

Yes. The linked issue gives concrete gateway-restart steps, and current main still has matching code gaps in disconnected Ctrl+C handling and shutdown fallback behavior.

Is this the best way to solve the issue?

Yes, with one mechanical policy gap. The runtime diff is narrow and fits the reported TUI hang; it needs the required changelog entry before merge.

Full review comments:

  • [P3] Add the required changelog entry — src/tui/tui.ts:255-258
    This is a user-facing openclaw tui fix, but the PR only changes TUI code and its unit test. Repo policy requires a single-line active-version CHANGELOG.md Fixes entry with contributor credit before merge.
    Confidence: 0.93

Overall correctness: patch is correct
Overall confidence: 0.88

Acceptance criteria:

  • pnpm exec oxfmt --check --threads=1 CHANGELOG.md
  • git diff --check

What I checked:

  • Current main still has unbounded shutdown drain: drainAndStopTuiSafely still calls terminal.drainInput() without explicit bounds, and requestExit only finishes after that helper resolves. (src/tui/tui.ts:261, 9fff2b779159)
  • Current main records disconnects but Ctrl+C ignores them: onDisconnected sets wasDisconnected = true, while handleCtrlC still always uses the normal two-press resolveCtrlCAction path. (src/tui/tui.ts:1066, 9fff2b779159)
  • PR diff targets the reported behavior: The PR adds drainInput(500, 100), a 2s hard-exit timer, repeated Ctrl+C force exit, disconnected Ctrl+C immediate exit, and a unit-test assertion for the drain bounds. (src/tui/tui.ts:252, 1468823269e0)
  • Dependency contract supports the bounded drain call: The locked @mariozechner/pi-tui 0.71.1 Terminal.drainInput(maxMs?, idleMs?) type and implementation accept max and idle milliseconds. (package.json:1661, 9fff2b779159)
  • Required changelog entry is still missing: The active 2026.5.2 Fixes section has no TUI gateway-disconnect/Ctrl+C shutdown entry, and the PR diff does not modify CHANGELOG.md. (CHANGELOG.md:33, 9fff2b779159)
  • Linked issue remains actionable: The linked issue gives concrete gateway-restart reproduction steps, remains open, and this PR body says it fixes that issue.

Likely related people:

  • vignesh07: Introduced the responsive Ctrl+C exit helper and later hardened TUI SIGTERM shutdown around the same signal and terminal teardown path. (role: introduced and adjacent maintainer; confidence: high; commits: b4cdffc7a429, fca0467082cb; files: src/tui/tui.ts, src/tui/tui.test.ts)
  • biefan: Authored terminal keyboard-state restoration work touching TUI exit and terminal cleanup behavior adjacent to this shutdown path. (role: adjacent owner; confidence: medium; commits: 0f075e1b8aa5; files: src/tui/tui.ts, src/tui/tui.test.ts, src/terminal/restore.ts)
  • rogerdigital: Recently changed TUI reconnect and streaming-watchdog behavior around gateway disconnect/reconnect handling adjacent to this PR's disconnected-state logic. (role: recent adjacent maintainer; confidence: medium; commits: d4e52f454255; files: src/tui/tui.ts, src/tui/tui-event-handlers.ts, src/tui/tui-event-handlers.test.ts)

Remaining risk / open question:

  • This read-only pass did not run the live macOS gateway-restart reproduction or tests; the verdict rests on the supplied reproduction, current source, dependency contract, and PR diff.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 9fff2b779159.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TUI fully unresponsive to Ctrl+C / Ctrl+D / SIGINT after gateway WebSocket close

1 participant