Skip to content

fix(tui): cancel buffered submissions on shutdown [AI-assisted] - #117331

Merged
steipete merged 3 commits into
mainfrom
codex/autoqa-tui-submit-shutdown-20260801
Aug 1, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/autoqa-tui-submit-shutdown-20260801

Conversation

@steipete

@steipete steipete commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #117329

What Problem This Solves

Fixes an issue where Terminal.app and iTerm users who pressed Ctrl+D immediately after submitting TUI input could have shutdown stall while the short paste-coalescing buffer still owned the submitted text.

It also repairs the real-local PTY proof path that blocked this PR and current main: the CI test launched a CLI-shaped child with raw node --import tsx, so a cold first turn could spend longer than the watchdog linking the combined agent runtime before reaching the mocked provider. That path contradicted the repository's CLI execution contract and made the TUI shard cache-dependent.

Why This Change Was Made

The submit coalescer now owns an idempotent disposal boundary that cancels pending buffered input and refuses future submissions. TUI shutdown disposes that owner before transport and terminal teardown, so no delayed callback can re-enter chat, command, or local-shell submission after exit begins.

The real-local PTY smoke now runs the exact-head built CLI from the dist-owning build-artifacts job. Source-level fake-backend and Gateway PTY coverage remains. Test-owned PTY cleanup retains output until exit, escalates only the spawned process tree when graceful shutdown expires, removes explicitly cleared inherited environment variables, and releases the mock server and temporary state even when setup or teardown fails.

Cancellation policy for a ! shell command that already started remains a separate product/lifecycle decision and is unchanged.

User Impact

Ctrl+D now exits cleanly even when it lands inside Terminal/iTerm's coalescing window. Buffered text is retired instead of remaining eligible to dispatch after shutdown starts, while normal submissions, commands, session transitions, and active-run shutdown behavior stay unchanged.

CI now proves the real local TUI against the built product rather than a cold source loader. This removes the repeated 300-second no-output failures without increasing timeouts, weakening assertions, or prewarming caches.

Evidence

Release-note context: TUI Ctrl+D shutdown now cancels Terminal/iTerm buffered submissions before they can dispatch.

AI-assisted: yes. I directly reviewed the coalescer, shutdown owner, pinned pi-tui submit behavior, built/source PTY boundaries, test cleanup lifecycle, exact before/after evidence, and final branch diff. A sanitized agent transcript was not included because it was not explicitly approved.

@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Aug 1, 2026
@steipete steipete self-assigned this Aug 1, 2026
@steipete
steipete marked this pull request as ready for review August 1, 2026 09:45
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. labels Aug 1, 2026
@clawsweeper

clawsweeper Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 1, 2026, 7:50 AM ET / 11:50 UTC.

ClawSweeper review

What this changes

The PR makes the TUI’s buffered-submit coalescer cancel pending input during shutdown and moves the slow local PTY smoke from a source-loader path to the exact-head built CLI artifact.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

The patch has a coherent owner-boundary repair, focused unit and real-PTY coverage, and no concrete correctness or security finding. It remains open because it carries the protected maintainer label and changes CI proof routing; a maintainer should approve it after the exact-head build-artifacts workflow completes successfully.

Priority: P2
Reviewed head: ab4c74b0971138ca8d77944ba4649cf2081b9873
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Strong real-runtime evidence and a focused repair make this a good merge candidate, pending protected-label maintainer approval and completion of the migrated CI lane.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The PR body supplies an exact-head built-runtime Testbox result for the changed TUI PTY path, including the formerly hanging exit scenario and an observed successful result; the remaining CI jobs are normal exact-head merge gates.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The PR body supplies an exact-head built-runtime Testbox result for the changed TUI PTY path, including the formerly hanging exit scenario and an observed successful result; the remaining CI jobs are normal exact-head merge gates.
Evidence reviewed 7 items Current-main owner boundary: Current main creates the submit coalescer as the editor callback but has no disposal hook, while its exit owner begins teardown after setting exitRequested; the PR adds disposal at that exit boundary before backend and terminal teardown.
Bounded cancellation implementation: The PR’s coalescer records disposal, clears the pending timer and payload, and ignores future submits; its focused test covers an idempotent dispose, a pending buffered value, and a later attempted submit.
Real terminal regression coverage: The new PTY case waits until the burst is captured, sends Ctrl+D, requires exit code 0 and backend stop, and asserts the buffered text never reaches sendChat. The PR body additionally supplies an exact-head built-runtime Testbox run with 66/66 TUI PTY tests passing.
Findings None None.
Security None None.

How this fits together

The TUI editor sends input through a short coalescing window before chat, command, or local-shell handling. Shutdown begins from Ctrl+D and other exit paths, then stops the backend and terminal; this change makes the coalescer part of that teardown boundary so delayed input cannot re-enter the TUI after exit begins.

flowchart LR
  A[Terminal input] --> B[TUI editor]
  B --> C[Submit coalescer]
  C --> D[Chat command or shell submit]
  E[Ctrl+D or exit request] --> F[Shutdown owner]
  F --> C
  F --> G[Backend and terminal teardown]
  H[Built CLI PTY smoke] --> I[CI build-artifacts job]
Loading

Decision needed

Question Recommendation
Should this maintainer-labeled TUI lifecycle repair be approved once the exact-head build-artifacts workflow reports a successful migrated PTY lane? Approve after exact-head CI: Confirm the build-artifacts job reports the built-CLI TUI PTY result successfully, then merge the bounded shutdown repair.

Why: The functional repair and supplied real-behavior proof are strong, but the protected maintainer label requires explicit human handling and the patch deliberately changes CI proof routing.

Before merge

  • Resolve merge risk (P1) - The PR changes CI execution ownership for the slow local PTY smoke; merge should wait for the exact-head build-artifacts job to show the migrated tui-pty result rather than relying only on the prior Testbox transcript.
  • Resolve merge risk (P1) - The checkout lacks the pinned @earendil-works/pi-tui source, so this review could not independently re-check the editor callback contract locally; no conflicting source evidence was found.
  • Complete next step (P2) - No mechanical repair is outstanding; the remaining action is protected-label maintainer approval plus exact-head confirmation of the CI lane whose ownership this PR changes.
Agent review details

Security

None.

PR surface

Source +41, Tests +118, Docs 0, Config +12, Other +1. Total +172 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 3 60 19 +41
Tests 5 224 106 +118
Docs 2 2 2 0
Config 1 14 2 +12
Generated 0 0 0 0
Other 1 2 1 +1
Total 12 302 130 +172

Review metrics

Metric Value Why it matters
PTY proof ownership 1 slow local PTY lane moved to built artifacts The workflow now validates the real local TUI through the exact-head built CLI, so its build-artifacts result is the key post-merge automation signal.

Stored data model

Persistent data-model change detected: serialized state: src/tui/tui-pty-local.e2e.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #117329
Summary: This PR is the concrete candidate fix for the linked report’s buffered-submit shutdown race; the issue should remain open until this candidate merges.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Require the migrated PTY lane (recommended)
    Wait for the exact-head build-artifacts job to pass and publish the tui-pty result before merge, confirming the smoke runs against the built CLI.
  2. Accept only with explicit CI ownership
    A maintainer may accept the routing change after confirming the build-artifacts job remains the intended owner for this slow smoke.

Technical review

Best possible solution:

Keep the coalescer as the single owner of buffered-submit cancellation, approve the patch after the built-artifact PTY lane passes on this exact head, and retain the focused source-level and real-PTY regression tests.

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

Yes. The supplied current-main real-PTY regression has a deterministic path: force a 500 ms submit window, submit text, wait for capture, then press Ctrl+D before expiry; source inspection confirms current main lacks the coalescer disposal boundary.

Is this the best way to solve the issue?

Yes. Disposing the coalescer at the shutdown owner is narrower and safer than adding downstream guards because it cancels the authoritative pending timer and rejects post-shutdown submissions before transport teardown begins.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 2d545c16c37d.

Labels

Label changes:

  • add merge-risk: 🚨 automation: The patch changes which CI job owns and executes the local PTY smoke, requiring exact-head workflow confirmation.

Label justifications:

  • P2: This is a deterministic, bounded TUI shutdown defect affecting users who exit during the short submit-coalescing window.
  • merge-risk: 🚨 automation: The patch changes which CI job owns and executes the local PTY smoke, requiring exact-head workflow confirmation.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The PR body supplies an exact-head built-runtime Testbox result for the changed TUI PTY path, including the formerly hanging exit scenario and an observed successful result; the remaining CI jobs are normal exact-head merge gates.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies an exact-head built-runtime Testbox result for the changed TUI PTY path, including the formerly hanging exit scenario and an observed successful result; the remaining CI jobs are normal exact-head merge gates.

Evidence

What I checked:

  • Current-main owner boundary: Current main creates the submit coalescer as the editor callback but has no disposal hook, while its exit owner begins teardown after setting exitRequested; the PR adds disposal at that exit boundary before backend and terminal teardown. (src/tui/tui.ts:1515, 982add961804)
  • Bounded cancellation implementation: The PR’s coalescer records disposal, clears the pending timer and payload, and ignores future submits; its focused test covers an idempotent dispose, a pending buffered value, and a later attempted submit. (src/tui/tui-submit.ts:143, ab4c74b09711)
  • Real terminal regression coverage: The new PTY case waits until the burst is captured, sends Ctrl+D, requires exit code 0 and backend stop, and asserts the buffered text never reaches sendChat. The PR body additionally supplies an exact-head built-runtime Testbox run with 66/66 TUI PTY tests passing. (src/tui/tui-pty-harness.e2e.test.ts:309, ab4c74b09711)
  • CI routing has focused plan coverage: The PR marks the slow local PTY shard as requiring dist and sets the built-CLI flag; the matching plan tests assert both values. This is a deliberate CI ownership move, so the exact-head build-artifacts result remains the remaining merge gate. (scripts/lib/ci-node-test-plan.mjs:1158, ab4c74b09711)
  • Current-main and provenance check: No affected TUI, PTY, CI-plan, or documentation path changed between the PR merge base and current main; the PR head is not contained in current main, so this remains the active candidate fix rather than an implemented-on-main close. (src/tui/tui-submit.ts:129, 2d545c16c37d)
  • Feature-history owner: The coalescer and its integration in current main date to commit 982add961804097f5a6b0b94255c5c855e8ad863, authored by Peter Steinberger; all three PR commits carry the same author identity. (src/tui/tui-submit.ts:129, 982add961804)

Likely related people:

  • steipete: Peter Steinberger introduced the current-main submit coalescer and authored all commits in this repair branch, tying the TUI input lifecycle and CI proof routing to the same feature history. (role: feature owner and recent area contributor; confidence: high; commits: 982add961804, c692269b920c, dd1ee342de16; files: src/tui/tui-submit.ts, src/tui/tui.ts, src/tui/tui-pty-test-support.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Confirm the exact-head build-artifacts job publishes a successful tui-pty result before merge.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-01T09:50:15.480Z sha c692269 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-01T10:43:11.664Z sha dd1ee34 :: needs maintainer review before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts size: M and removed size: S labels Aug 1, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. label Aug 1, 2026
@steipete

steipete commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready proof for exact head ab4c74b0971138ca8d77944ba4649cf2081b9873:

  • The submit coalescer owns pending buffered input and is disposed before backend/terminal teardown. Product runtime delta remains +21/-3.
  • The unrelated red-main blocker was the TUI PTY proof owner: a raw source CLI child could stall while cold-linking the agent graph. The real-local smoke now runs the exact-head built CLI; source fake/Gateway PTY coverage remains.
  • Exact hosted CI: run 30698295658 completed successfully with no failed jobs.
  • ClawSweeper rank-up move satisfied: build-artifacts job 91364861932 passed with the migrated built-CLI tui-pty result. Latest review has no findings.
  • Testbox run 30697437645, lease tbx_01kyygr382542q437cc6c2w6kc:
    • pnpm build passed.
    • OPENCLAW_TUI_PTY_INCLUDE_LOCAL=1 OPENCLAW_TUI_PTY_USE_BUILT_CLI=1 node scripts/run-vitest.mjs run --config test/vitest/vitest.tui-pty.config.ts: 66/66 passed; the formerly hanging local smoke completed in 8.0 seconds.
    • Focused workflow/plan tests: 121/121 passed.
    • PTY support tests: 12/12 passed.
    • pnpm check:changed: all selected core, coreTests, testRoot, docs, tooling gates passed.
    • pnpm docs:list passed.
  • Final complete-branch Codex autoreview: no accepted/actionable findings, patch is correct, confidence 0.98.
  • Independent source-blind shutdown behavior contract: 11/11 clauses passed. Direct inspection of pinned @earendil-works/pi-tui 0.82.1 confirmed the callable submit callback contract.

No known proof gap remains. Already-running ! shell-command cancellation is explicitly outside this PR and unchanged.

@steipete
steipete merged commit cd4bd7c into main Aug 1, 2026
139 of 142 checks passed
@steipete
steipete deleted the codex/autoqa-tui-submit-shutdown-20260801 branch August 1, 2026 12:00
@steipete

steipete commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 2, 2026
…claw#117331)

* fix(tui): cancel buffered submissions on shutdown

* refactor(tui): preserve callable submit coalescer

* test(tui): run local PTY smoke against built CLI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation maintainer Maintainer-authored PR merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: TUI buffered input can outlive Ctrl+D shutdown

1 participant