Skip to content

fix(setup): complete wizard on terminal hosted TUI SIGTERM - #1132

Merged
shanselman merged 1 commit into
mainfrom
shanselman-accept-terminal-sigterm-after-done
Aug 8, 2026
Merged

shanselman merged 1 commit into
mainfrom
shanselman-accept-terminal-sigterm-after-done

Conversation

@shanselman

Copy link
Copy Markdown
Collaborator

Problem

The gateway tears down its in-process hosted wizard TUI when the configuration applied by the final wizard step triggers a gateway restart. Setup answered every step through the final done acknowledgement, then received a terminal payload that parsed as IsDone=true with error exactly Error: TUI exited from signal SIGTERM. SetupWizardRunner returned failure, left wizardCompleted=false, issued a best-effort wizard.cancel against a gateway that was already restarting, and preserved that failure even after successful reload-mode restoration, managed restart, HTTP 200 health, and managed provenance verification.

This is not startup-migration lease contention and not a structured PROTOCOL_MISMATCH.

Evidence

Exposed by openclaw/openclaw PR #119762 at exact head 167c030cf9229ca5dcb6ea7c0de877f733185367 (immutable ref release-ci/167c030cf922-1786207973).

Both logs show the same transcript immediately before the failure:

[Info] Wizard step '[REDACTED_ID]' (note, key=done) answered with 'true'
[Info] [WS] [GatewayClient] Sending frame: wizard.next
[Info] [WS] Wizard response payload kind=Object len=78
[Warn] Cancelling gateway wizard session
[Warn] Failed to cancel gateway wizard session: wizard.cancel unavailable during gateway restart
[Info] Restored gateway.reload.mode to hybrid after wizard; restarting gateway to apply wizard configuration
[Error] SetupPipeline: Step 'run-wizard' failed: Gateway wizard failed: Error: TUI exited from signal SIGTERM

Step ids are GUIDs (hence [REDACTED_ID]); the stable answer key comes from the normalized step title, so the final step is a note titled Done.

Behavior contract

A terminal wizard payload carrying Error: TUI exited from signal SIGTERM completes the wizard only when all of the following hold:

  1. the payload is terminal (done: true);
  2. the request just sent answered the authoritative final step, which must be a plain acknowledgement note, with no options, whose normalized step id or title equals done, and which is last in order when the gateway supplies stepIndex/totalSteps (accepting both zero-based n-1 and one-based n);
  3. the error equals the exact message, tolerating only surrounding whitespace.

Everything else keeps the wizard failure and keeps best-effort cancellation: an earlier SIGTERM, a progress-poll acknowledgement, a replayed wizard session, any answerable or option-bearing step, any other step id or title, the step message text (no longer consulted), a non-terminal payload, a different signal, extra text, different casing, other terminal errors, PROTOCOL_MISMATCH, timeouts, exceptions, and cancellation.

#1129 behavior is preserved exactly: reload-mode restoration still retries only the exact startup-migration-lease diagnostic within the existing 15 second monotonic deadline, unrelated failures do not retry, cancellation and restoration ordering are unchanged, and the one-shot managed restart stays fail-closed. Wizard replay bounds, credential precedence, and provenance/ownership guards are untouched. The exact Gateway 2026.7.1 model-check terminal-restart path is unchanged.

Files changed

  • src/OpenClaw.SetupEngine/GatewayWizardRestartRecoveryPolicy.cs - generalized the private step-key matcher; added IsAuthoritativeFinalWizardStep and IsHostedWizardTerminationAfterFinalStep.
  • src/OpenClaw.SetupEngine/WizardFinalStepTracker.cs (new) - owns the final-step flag with ResetForNewSession / RecordProgressAcknowledgement / RecordAnsweredStep.
  • src/OpenClaw.SetupEngine/SetupWizardRunner.cs - pure DecideTerminalWizardError seam returning WizardTerminalDecision(MarksWizardCompleted, Result, LogWarning); the terminal-error branch assigns wizardCompleted from the decision, so cancel suppression happens only on accepted paths.
  • tests/OpenClaw.SetupEngine.Tests/GatewayWizardRestartRecoveryPolicyTests.cs
  • tests/OpenClaw.SetupEngine.Tests/WizardFinalStepTrackerTests.cs (new)
  • tests/OpenClaw.SetupEngine.Tests/SetupWizardTerminalCompletionContractTests.cs (new)
  • tests/OpenClaw.SetupEngine.Tests/SetupStepsTests.cs
  • docs/ARCHITECTURE.md (ledger invariant), docs/ONBOARDING_WIZARD.md

Validation

All commands run locally at PR head a92eb8c788c93c66733e6b9b1b1cff3f331e75b0.

Command Result
dotnet format --verify-no-changes --include <changed files> clean (repo-wide format has pre-existing failures in untouched files)
.\build.ps1 all 5 projects succeeded, doc validation passed
dotnet test .\tests\OpenClaw.Shared.Tests\... 3631 passed, 32 skipped, 0 failed
dotnet test .\tests\OpenClaw.Tray.Tests\... 2246 passed, 0 failed
dotnet test .\tests\OpenClaw.SetupEngine.Tests\... 865 passed, 0 failed
dotnet test .\tests\OpenClaw.Connection.Tests\... 574 passed, 0 failed
.\scripts\validate-mxc-e2e.ps1 -NoBuild (strict, no -AllowSkip) 17 passed, 0 skipped, MXC validation completed successfully

New deterministic coverage: exact accepted path; early SIGTERM before the final step; non-terminal payload; SIGKILL; missing Error: prefix; trailing extra text; lowercase variant; embedded newline plus extra text; PROTOCOL_MISMATCH; empty and null errors; whitespace-only tolerance; text/confirm/select/progress steps named done; option-bearing note named done; message-only done; non-final and impossible position metadata (5/42, 43/42) plus both final forms (41/42, 42/42); progress poll after the final step; replay after the final step; a later step after the final step; and that MarksWizardCompleted is false on every rejected path so cancellation is preserved.

Real behavior proof

Real paired gateway, current head. scripts\validate-mxc-e2e.ps1 ran the real WSL Gateway to Windows node path twice on this branch (once before and once after the review hardening), both green with no skips:

Gateway MXC proof passed: MirroredWslSafeGatewayPort_IsListeningAndRecorded
Gateway MXC proof passed: RealGateway_SystemRun_ExecutesThroughWindowsNodeMxcSandbox
Gateway MXC proof passed: RealGateway_SystemRun_BlocksWritesToTrayDataDirectoryInMxcSandbox
MXC validation completed successfully.

Its setup engine journal (TestResults\E2E\4fd5ffa0\setup-engine.jsonl) shows the full real flow at current head, including operator and node pairing, verify-e2e, and the wizard step itself completing with unchanged behavior:

step.completed: pair-operator → Success
step.completed: pair-node → Success
step.completed: verify-e2e → Success
step.started: Run gateway wizard
Suspended gateway reload immediately before wizard
Starting gateway wizard
Restored gateway.reload.mode to hybrid after wizard; restarting gateway to apply wizard configuration
step.completed: run-wizard → Success  message: "Gateway wizard completed with non-fatal finalization prompt warning"

That run exercised the pre-existing finalization-prompt acceptance path, proving the refactored decision seam preserves it end to end on a real gateway.

Not verified / blocked. The SIGTERM finalization path itself could not be reproduced on this host: the locally installed gateway release does not terminate its hosted wizard TUI at the final step, and forcing that teardown would require pinning the exact candidate build from openclaw/openclaw #119762. The accepted and rejected paths are instead proven deterministically against the exact payload shape and step transcript captured in jobs 93130477022 and 93130477025. Final confirmation belongs to the repin and rerun of #119762, which is owned by the requester.

Review

  • rubber-duck: first pass raised one blocking finding (the final step was inferred from untrusted text alone, so a non-final or answerable step named done could be accepted) plus two non-blocking findings. All were fixed: the step must now be an options-free acknowledgement note, message is no longer consulted, position metadata is enforced when present, sequencing moved into a tracker with behavioral tests, and whitespace tolerance is documented and tested. The follow-up pass confirmed no blocking issues remain and verified against upstream 167c030c that its outro step is a note titled Done with no options and no position metadata, so both failing lanes are still accepted. Its last non-blocking suggestion (reject impossible indexes such as 43/42) was applied.
  • autoreview (Codex gpt-5.6-sol, high, branch mode vs origin/main): autoreview clean: no accepted/actionable findings reported, overall: patch is correct (0.87).

The gateway tears down its in-process hosted wizard TUI when the
configuration applied by the final wizard step restarts the gateway. Setup
answered every step through the final `done` acknowledgement, then received a
terminal payload whose error was exactly `Error: TUI exited from signal
SIGTERM`, failed the run-wizard step, and issued a best-effort wizard.cancel
against a gateway that was already restarting. Two independent Windows-node
release-check lanes reproduced this after successful pairing, verify-e2e,
reload-mode restoration, managed restart, health, and provenance checks.

Accept that one terminal result as completion, and only that one. The payload
must be terminal, the request just sent must have answered the authoritative
final step (a plain acknowledgement note with no options whose id or title
normalizes to `done`, last in order when the gateway supplies position
metadata), and the error must equal the exact message apart from surrounding
whitespace. Every other terminal error, an earlier SIGTERM, a progress poll, a
replayed session, an answerable step, and a non-terminal payload keep the
wizard failure and keep cancellation.

Terminal-payload classification now goes through a pure decision seam, and the
final-step flag is owned by a tracker, so the accepted path and each rejected
path are directly testable. #1129 reload-mode restoration, its exact
startup-migration-lease retry inside the 15 second deadline, cancellation and
restoration ordering, and the one-shot managed restart are unchanged.

Co-authored-by: Copilot App <[email protected]>
@clawsweeper clawsweeper Bot added 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. P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 8, 2026
@clawsweeper

clawsweeper Bot commented Aug 8, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed August 8, 2026, 1:56 PM ET / 17:56 UTC.

ClawSweeper review

What this changes

The PR treats one exact terminal hosted-wizard SIGTERM response as successful completion only immediately after the authoritative final acknowledgement step.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep this collaborator-authored PR open for normal maintainer review. Current main does not contain this SIGTERM completion path; the implementation is narrowly guarded and well covered by deterministic tests, but direct after-fix proof against the pinned gateway build is still blocked.

Priority: P2
Reviewed head: a92eb8c788c93c66733e6b9b1b1cff3f331e75b0

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused implementation and deterministic coverage are solid, while direct after-fix proof for the reported gateway behavior is still unavailable.
Proof confidence 🦐 gold shrimp (3/6) Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Evidence reviewed 4 items Branch implementation: The policy accepts only a terminal payload with the exact trimmed SIGTERM text after an authoritative final note step, and the runner uses that decision to control completion.
Runner wiring: The runner records the outgoing step before wizard.next and assigns wizard completion only from the terminal-error decision, preserving cancellation for rejected results.
Regression coverage: Added tests cover exact acceptance, sequencing resets, non-final steps, non-terminal payloads, alternative signals, malformed text, and cancellation gating.
Findings None None.
Security None None.

How this fits together

The setup engine answers a gateway-hosted configuration wizard, restores the gateway reload mode, and verifies the restarted gateway. Terminal wizard responses decide whether setup completes or retains the failure and cancellation path.

flowchart LR
A[Gateway wizard step] --> B[Setup answer]
B --> C[Final-step tracker]
C --> D[Terminal gateway response]
D --> E{Exact SIGTERM after final done step?}
E -->|Yes| F[Complete wizard]
E -->|No| G[Fail and cancel]
F --> H[Restore gateway and verify]
G --> H
Loading

Before merge

  • Resolve merge risk (P1) - Merging changes an exact terminal gateway error from failure to completion and suppresses cancellation; the direct SIGTERM scenario has not yet been rerun after the fix against the pinned upstream gateway build.
  • Complete next step (P2) - Normal collaborator PR review should obtain the blocked direct gateway proof; there is no narrow automated repair to dispatch.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Implementation and coverage production +152, tests +408, docs +3 Most of the change is deterministic coverage for a narrow setup-state transition.

Merge-risk options

Maintainer options:

  1. Verify the pinned gateway path (recommended)
    Run setup against the gateway candidate that emits the exact SIGTERM payload and attach redacted terminal or journal output showing successful completion.
  2. Accept deterministic coverage
    Merge based on the narrow classifier and regression suite while accepting that the exact upstream terminal path remains unverified after the change.

Technical review

Best possible solution:

Land the narrow compatibility rule only after a pinned-gateway run shows the reported SIGTERM response completing setup while rejected terminal errors still fail.

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

Unclear. The pre-fix upstream trace is specific and the branch has deterministic payload coverage, but the exact SIGTERM-producing gateway build was not exercised after the fix.

Is this the best way to solve the issue?

Yes, provisionally. A stateful final-step tracker plus exact error matching is the narrowest maintainable repair, subject to direct pinned-gateway confirmation.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 77141d27ee69.

Labels

Label changes:

  • add P2: This is a bounded setup reliability fix after gateway configuration has been applied.
  • add merge-risk: 🚨 availability: A false-positive completion classification could let setup continue after an incomplete gateway wizard.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.

Label justifications:

  • P2: This is a bounded setup reliability fix after gateway configuration has been applied.
  • merge-risk: 🚨 availability: A false-positive completion classification could let setup continue after an incomplete gateway wizard.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.

Evidence

What I checked:

Likely related people:

  • shanselman: Scott Hanselman authored the immediately preceding merged gateway-wizard recovery change and this branch extends the same setup-runner and recovery-policy boundary. (role: recent area contributor; confidence: high; commits: 77141d27ee69, a92eb8c788c9; files: src/OpenClaw.SetupEngine/SetupWizardRunner.cs, src/OpenClaw.SetupEngine/GatewayWizardRestartRecoveryPolicy.cs)
  • Dallin Romney: The current-main history identifies Dallin Romney as author of the exact Windows release-artifact validation work that contextualizes this gateway candidate path. (role: adjacent release-validation contributor; confidence: medium; commits: 9f9a8eda6340; files: src/OpenClaw.SetupEngine/SetupWizardRunner.cs)

Rank-up moves

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

  • Attach a redacted pinned-gateway run showing the exact SIGTERM terminal response completing setup.

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.

@shanselman
shanselman merged commit c14ead3 into main Aug 8, 2026
32 of 33 checks passed
@shanselman
shanselman deleted the shanselman-accept-terminal-sigterm-after-done branch August 8, 2026 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal priority bug or improvement with limited blast radius. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant