Skip to content

fix(tui): exit cleanly during local auth - #126476

Merged
steipete merged 1 commit into
mainfrom
steipete/sad-noether-74cac4
Aug 19, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/sad-noether-74cac4

Conversation

@steipete

Copy link
Copy Markdown
Contributor

AI-assisted repair; the implementation and tests were reviewed and verified by the maintainer.

What Problem This Solves

Fixes an issue where users running the local TUI /auth flow could leave the foreground auth process alive—and keep the TUI process from exiting—when shutdown was requested by SIGTERM, SIGHUP, terminal loss, or the embedded backend.

Why This Change Was Made

The local TUI now owns the exact foreground auth child for its full lifetime. Shutdown sends a graceful signal and then a bounded force signal only while that same child remains active. POSIX keeps direct-PID signaling because the auth child intentionally shares the TUI foreground process group; Windows uses the existing taskkill /T path so .cmd wrappers cannot strand descendants. The suspended TUI also no longer restarts after exit has begun.

The separate local ! shell process path remains unchanged because it has different piped-output and process-tree semantics.

User Impact

Local TUI sessions now exit cleanly during an in-progress auth flow instead of hanging or orphaning the Codex/OpenClaw auth process. Auth flows that finish normally still restore the TUI and continue working.

Evidence

Before the fix, a real PTY reproduction started /auth openai, sent SIGTERM directly to the TUI, and observed both processes still alive 750 ms later.

After the fix:

  • node scripts/run-vitest.mjs src/tui/tui-auth-child.test.ts src/tui/tui.local-auth.test.ts src/tui/tui-pty-local-test-support.test.ts — 13 tests passed across 3 files / 2 shards.
  • node scripts/run-vitest.mjs run --config test/vitest/vitest.tui-pty.config.ts src/tui/tui-auth-child-pty.e2e.test.ts — 2 real-PTY tests passed, covering exit-during-auth child termination and normal auth completion/TUI resume.
  • node scripts/check-changed.mjs -- src/tui/tui-auth-child.ts src/tui/tui-auth-child.test.ts src/tui/tui-auth-child-pty.e2e.test.ts src/tui/tui-pty-local-test-support.test.ts src/tui/tui-pty-test-support.ts src/tui/tui.ts test/vitest/vitest.tui-pty.config.ts — all required type, lint, format, import-cycle, dead-export, and policy checks passed.
  • git diff --check — passed.
  • Fresh autoreview — no accepted/actionable findings.

Direct dependency-contract inspection confirmed that codex login remains one blocking foreground CLI process (../codex/codex-rs/cli/src/main.rs and ../codex/codex-rs/cli/src/login.rs), so detaching it would violate the intended terminal/job-control model.

Production LOC: +127/-33 (net +94), establishing the missing exact-child lifecycle owner. Tests/test support/tooling: +211/-0.

@clawsweeper

clawsweeper Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 19, 2026 23:33
@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Aug 19, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 19, 2026
@clawsweeper

clawsweeper Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 19, 2026, 7:39 PM ET / 23:39 UTC.

ClawSweeper review

What this changes

The PR gives the local TUI ownership of its foreground authentication child so shutdown terminates that child and does not restart the suspended interface.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

The lifecycle owner is a coherent repair and its PTY test exercises the real TUI process, but this review cannot complete the repository-required direct Codex CLI contract check because the required sibling source checkout is unavailable. Likely related people: steipete (high), vincentkoc (medium).

Priority: P1
Reviewed head: afce1dee6431dc9941e7fc4fd47d5dc535a284a3
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch has focused owner-boundary and PTY coverage, but the required direct Codex process-contract review remains unavailable.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR reports an after-fix real-PTY run of the TUI with a fixture auth CLI; the external-contributor proof gate does not apply.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR reports an after-fix real-PTY run of the TUI with a fixture auth CLI; the external-contributor proof gate does not apply.
Evidence reviewed 6 items Current-main failure path: Current main waits only for the auth child exit and always restarts the suspended TUI; it does not retain the child for the separate shutdown path.
Owner-boundary repair: The branch records exactly one active auth child, signals it during TUI exit, clears the force timer on either exit or spawn error, and prevents another launch after closure.
Process-signal contract: The shared helper honors detached:false with direct-PID signaling on Unix and uses taskkill /T on Windows, matching the branch’s foreground-process-group rationale.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs run --config test/vitest/vitest.tui-pty.config.ts src/tui/tui-auth-child-pty.e2e.test.ts

Result: PASS (completed)

node scripts/run-vitest.mjs run --config test/vitest/vitest.tui-pty.config.ts src/tui/tui-auth-child-pty.e2e.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-126476-IvUTUQ/target$ node scripts/run-vitest.mjs run --config test/vitest/vitest.tui-pty.config.ts src/tui/tui
-auth-child-pty.e2e.test.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-126476-IvUTUQ/target

node scripts/run-vitest.mjs run --config test/vitest/vitest.tui-pty.config.ts src/tui/tui-auth-child-pty.e2e.test.ts
 ✓  tui-pty  src/tui/tui-auth-child-pty.e2e.test.ts › TUI auth child lifecycle › terminates the foreground auth child when SIGTERM exits the TUI 8232ms











































Assertions:

  • PASS expect_output: TUI auth child lifecycle

How this fits together

The local terminal UI starts provider authentication as a foreground child process, then resumes after authentication completes. Terminal loss, signals, and embedded-backend shutdown flow through the TUI exit path and must also stop that child.

flowchart LR
A[User starts local auth] --> B[Terminal UI]
B --> C[Foreground auth process]
D[Signal or backend shutdown] --> B
B --> E[Auth child owner]
E --> C
C --> F[Child exits]
F --> G[Terminal UI exits or resumes]
Loading

Decision needed

Question Recommendation
Should this PR wait for a direct Codex-source confirmation that codex login remains the foreground process targeted by the new owner? Complete the Codex contract check: Inspect the Codex login entrypoint in an available sibling checkout and record the foreground-process evidence before merge.

Why: The TUI branch directly invokes codex login, and repository policy requires the acting reviewer to inspect that exact dependency contract; the mandated sibling checkout is absent here.

Before merge

  • Resolve merge risk (P1) - The repair adds net 94 production lines for child state, cancellation, and bounded escalation; no equally clear net-neutral placement was evident, but it remains a lifecycle-maintenance cost.
  • Resolve merge risk (P1) - The exact Codex CLI login process contract could not be inspected in this review environment, so the branch’s foreground-child assumption has not received the repository-required direct dependency check.
  • Complete next step (P2) - A maintainer must resolve the unavailable direct Codex contract check before this maintainer-labeled PR can be considered merge-ready.
Agent review details

Security

None.

PR surface

Source +96, Tests +209. Total +305 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 3 129 33 +96
Tests 4 209 0 +209
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 338 33 +305

Review metrics

Metric Value Why it matters
Production versus test LOC production +127/-33 (net +94); tests, test support, and PTY config +211/-0 The production growth establishes explicit child-lifecycle ownership; the added PTY coverage exercises shutdown and normal-resume behavior.

Stored data model

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

Merge-risk options

Maintainer options:

  1. Verify the foreground login contract (recommended)
    Confirm from Codex source that the launched login process remains the foreground lifecycle root before merging this shutdown behavior.
  2. Accept the bounded evidence gap
    Merge with the existing real-PTY fixture as the owner-boundary proof while accepting the uninspected Codex process-contract assumption.

Technical review

Best possible solution:

Keep the single auth-child lifecycle owner, then verify the exact Codex login foreground-process behavior from an available Codex source checkout before merging.

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

Yes, from source: current main starts local auth without retaining that child for requestExit, while the branch’s PTY scenario targets that exact signal-and-child sequence. The claimed after-fix PTY run was not re-executed in this read-only review.

Is this the best way to solve the issue?

Unclear: the dedicated lifecycle owner is the cleanest visible repair and preserves the existing error contract, but the required direct Codex CLI source check could not be completed here.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 1762f43a34c5.

Labels

Label changes:

  • add P1: A local TUI shutdown can remain blocked by an active authentication child, affecting an interactive workflow.
  • add merge-risk: 🚨 availability: The change alters signal and process-lifecycle behavior, while direct verification of the launched Codex login process contract is unavailable in this review environment.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR reports an after-fix real-PTY run of the TUI with a fixture auth CLI; the external-contributor proof gate does not apply.

Label justifications:

  • P1: A local TUI shutdown can remain blocked by an active authentication child, affecting an interactive workflow.
  • merge-risk: 🚨 availability: The change alters signal and process-lifecycle behavior, while direct verification of the launched Codex login process contract is unavailable in this review environment.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR reports an after-fix real-PTY run of the TUI with a fixture auth CLI; the external-contributor proof gate does not apply.

Evidence

What I checked:

  • Current-main failure path: Current main waits only for the auth child exit and always restarts the suspended TUI; it does not retain the child for the separate shutdown path. (src/tui/tui.ts:1321, 1762f43a34c5)
  • Owner-boundary repair: The branch records exactly one active auth child, signals it during TUI exit, clears the force timer on either exit or spawn error, and prevents another launch after closure. (src/tui/tui-auth-child.ts:62, afce1dee6431)
  • Process-signal contract: The shared helper honors detached:false with direct-PID signaling on Unix and uses taskkill /T on Windows, matching the branch’s foreground-process-group rationale. (packages/agent-core/src/harness/env/kill-tree.ts:66, afce1dee6431)
  • Boundary-level PTY coverage: The new PTY test starts the real TUI loop, starts an auth fixture, signals the TUI, and asserts both TUI exit and auth-child disappearance; it also covers normal TUI resume. (src/tui/tui-auth-child-pty.e2e.test.ts:66, afce1dee6431)
  • Feature provenance: Blame attributes the pre-existing local-auth spawn and error/exit handling to the merged local-auth work in commit 3415519; the current branch is a follow-up lifecycle repair. (src/tui/tui.ts:1366, 341551937ef0)
  • Codex dependency gate unavailable: The changed path invokes codex login, so the Codex CLI process contract is relevant; neither ../codex nor the available review scratch directory contains the required Codex source files, and network access prevented cloning it. (src/tui/tui.ts:1354, afce1dee6431)

Likely related people:

  • steipete: Introduced the current local-auth spawn path in merged commit 3415519 and has the dominant recent history on src/tui/tui.ts. (role: introduced the current local-auth path and recent TUI contributor; confidence: high; commits: 341551937ef0, afce1dee6431; files: src/tui/tui.ts, src/tui/tui-auth-child.ts)
  • vincentkoc: Authored the earlier installed-local-mode provider-auth repair, which is adjacent to the current local authentication flow. (role: adjacent local-auth contributor; confidence: medium; commits: bfcce12e6b38; files: src/tui/tui.ts)

Rank-up moves

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

  • Inspect and cite the Codex login entrypoint that establishes the foreground-process contract before merging.

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.

@steipete

Copy link
Copy Markdown
Contributor Author

Maintainer landing-gate resolution:

  • The ClawSweeper rank-up move is complete. I directly inspected the sibling Codex checkout at commit d65d31593926f26bc6dd030240bc009be87ef75d.
  • codex-rs/cli/src/main.rs:1389-1429 dispatches codex login in-process to the login functions. codex-rs/cli/src/login.rs:138-199 starts the local browser-login server and awaits block_until_done(); it does not detach a separate login worker. This confirms the spawned foreground CLI remains the lifecycle root owned by this repair.
  • I accept the production delta of +127/-33 (net +94): the new lines establish the missing exact-child lifecycle owner, graceful/forced cancellation, and the POSIX/Windows ownership split. The integration change in tui.ts is net -1; the growth is isolated in the owner module rather than duplicated across exit paths.
  • The reported serialized-state surface is test-fixture code only; this PR changes no persisted data model or schema.
  • Exact-head CI is green, there are no unresolved review threads, and no code changed after the clean autoreview and PTY proof.

Proceeding with the repository-native landing workflow.

@steipete
steipete merged commit 13fd888 into main Aug 19, 2026
287 of 293 checks passed
@steipete
steipete deleted the steipete/sad-noether-74cac4 branch August 19, 2026 23:57
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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.

1 participant