Repository navigation
fix(setup): record terminal state when commands are cancelled - #1978
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR records direct-child exit and cancellation state for setup commands without changing their execution or output-drain policy. Example: A command exits with code 0, its descendant holds stdout and stderr open, and the caller cancels.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this collaborator-authored draft open: main lacks these cancellation diagnostics, and no actionable introduced defect was found. Priority: P3 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherSetup callers pass commands and cancellation tokens to CommandRunner, which manages processes and redirected streams and sends structured observations to SetupLogger. flowchart TD
A[Setup callers] --> B[CommandRunner]
B --> C[Direct child process]
C --> D[Redirected output streams]
D --> B
B --> E[SetupLogger]
E --> F[JSONL and diagnostic subscribers]
Technical reviewBest possible solution: Keep cancellation observations in the existing runner and logger while preserving deadlines, output capture, cleanup, and exception propagation. Do we have a high-confidence way to reproduce the issue? The pinned main source demonstrates both cancellation paths bypass terminal command logging, and the author reports baseline failures for that exact missing event; no target code was executed during this review. Is this the best way to solve the issue? The patch is a small complete diagnostic fix: one phase marker and the existing logger cover execution and drain cancellation without replacing their owners or masking the underlying startup problem. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a4dd026cc5f8. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
Review metrics
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 2, 2026, 12:32 PM ET / 17:32 UTC. |
Record direct child exit before output drain and state-only caller cancellation observations without changing deadlines, cleanup or exception semantics. Co-authored-by: Copilot App <[email protected]>
6f90b29 to
dc7d172
Compare
Related: #1952 (fix: native Gateway setup loses startup window to slow validation), #1735 (feat(setup): stream live native Gateway activity log and typed failure diagnosis).
What Problem This Solves
Fixes: setup logs have no terminal command observation when a caller cancels a running command or its post-exit output drain.
User Impact
User impact: developers investigating cancelled setup can distinguish execution from output drain and see the observed direct-child/EOF state, without logging partial command output. No startup or guest-validator stall fix is claimed.
Why This Change Was Made
CommandRunnernow recordscmd.exitwhen its direct-child exit wait completes, before output drain, andcmd.cancelledwhen cancellation interrupts execution or drain. Cancellation records contain only the interrupted phase, direct-child-exit and per-stream EOF observations, elapsed time, and the existing runner-timeout classification.The original exception/token is rethrown. Existing execution cleanup, post-exit cancellation behavior, deadlines, timeout results, and success output capture are preserved. No retries or new waits are added. Observations are non-atomic and do not prove process-tree cleanup or guest process exit. A caller-linked deadline is still classified as caller cancellation; simultaneous timeout/cancellation does not establish which occurred first.
This is independently applicable to default
main, not based on the fork-only #1952 head. Packaging's separate guest invocation ownership repair is outside this diff.Evidence
Two real-process regression cases failed on the original production source at
a4dd026cc5f85a444a0fcd05eef5b86282dbda8c, specifically becausecmd.cancelledwas absent. Input cancellation is coordinated by the stdin copy callback. Post-exit cancellation is coordinated by the direct-exit observation while a task-owned fixture descendant holds output pipes open, not by a sleep.The initial focused implementation run passed 39 tests. Final coverage also includes normal/inherited-pipe drain variants and already-observed EOF racing cancellation.
Independent Copilot rubber-duck/source review covered the complete local candidate against the explicit base, P0-P3, and the proof plan. No blocking findings. It noted the existing timeout/caller race, additional intentional debug-log volume, and the existing synchronous logger subscriber exception behavior. The race limitation is documented. Codex CLI is unavailable; model identity is unverified. This narrative review does not provide helper-enforced isolation, frozen-input checks, or structured result validation.
Change Type
Scope
winnodeRequired proof pools
none: The changed contract is setup runner diagnostics, directly exercised by owned process/pipe fixtures without a desktop, WSL, installation, or Gateway. No UI, node dispatch, sandbox, or package contract changes. Live isolated native setup integration remains unverified with the coordinator; WSL proof would not establish native guest-validator behavior.Validation
Final validation ran after packaging released the serialized validation slot.
OPENCLAW_REPO_ROOTwas set to this worktree for all test commands. Fresh Shared and Tray test projects were built first withdotnet build <test-project> --verbosity quiet(both passed), so--no-restoredid not silently no-op. Tray settings used an isolated task-owned directory..\build.ps1: PASS. All five projects, Debugwin-arm64, on native Windows ARM64. Documentation/proof-pool gate passed.dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore --verbosity minimal: PASS. 4,810 passed, 24 skipped, 0 failed, 4,834 total. Skipped device-identity integration and native MXC opt-in cases are not live proof.dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore --verbosity minimal: PASS. 4,799 passed, 0 skipped, 0 failed.dotnet test .\tests\OpenClaw.SetupEngine.Tests\OpenClaw.SetupEngine.Tests.csproj --no-restore --filter 'FullyQualifiedName~CommandRunnerTests|FullyQualifiedName~SetupLoggerTests|FullyQualifiedName~NativeGatewaySetupTests|FullyQualifiedName~NativeGatewaySetupConnectionTests' --verbosity minimal: PASS. 171 passed, 0 skipped, 0 failed.powershell.exe -NoProfile -NonInteractive -ExecutionPolicy RemoteSigned -Command 'dotnet test .\tests\OpenClaw.SetupEngine.Tests\OpenClaw.SetupEngine.Tests.csproj --no-restore --verbosity minimal; exit $LASTEXITCODE': PASS. Full SetupEngine: 2,529 passed, 4 skipped, 0 failed, 2,533 total. RemoteSigned was process-scoped only, for generated-script fixtures; no persistent machine policy was changed. Skips: two console-visibility cases, the opt-in cleanup proof worker, and cross-volume Local AI compatibility..\scripts\validate-docs.ps1: PASS. 69 Markdown files and 7 proof pools checked.git diff --check: passed for the source candidate..\scripts\Get-CiChangeClassification.ps1 -EventName pull_request -ChangedPaths 'src\OpenClaw.SetupEngine\CommandRunner.cs','src\OpenClaw.SetupEngine\SetupLogger.cs','tests\OpenClaw.SetupEngine.Tests\CommandRunnerTests.cs','docs\SETUP_ENGINE_REDESIGN.md' -Human: PASS, selected targetedtray-testsandsetup-e2ehosted lanes. Hosted CI has not yet run. No changes to MXC execution, node commands, WSL setup policy, or packaging are claimed; real WSL/MXC/native Gateway proof was not run.Baseline command:
dotnet test .\tests\OpenClaw.SetupEngine.Tests\OpenClaw.SetupEngine.Tests.csproj --no-restore --filter 'FullyQualifiedName~RunAsync_CancellationDuring' --verbosity minimal: 2 failed, 0 passed, 0 skipped (expected missing-event regressions). A first fresh-worktree invocation omitted--no-restore.Real Behavior Proof
OpenClaw.Shared.TestHostprocesses only. No installed Companion, Gateway, WSL, package/profile, credentials or user processes were touched.6f90b291d38c1525d457863063d47a802e685b47, comparison basea4dd026cc5f85a444a0fcd05eef5b86282dbda8c. Tests ran against uncommitted source manually associated with full candidate diff hash0c623d8df068b981e784a654f928b4a73d4b7effbefore build. This equals the committed parent-relative diff hash; no source changed between final validation and commit.cmd.donesuccess/timeout result is manufactured.Yes/No/N/A): N/A.clawctl collect-logsor Companion/Gateway rerun, by explicit runtime restrictions. The coordinator owns collection and the integrated isolated retest with fix: native Gateway setup loses startup window to slow validation #1952. This patch does not prove startup succeeds, a guest validator exits, its stall cause, process-tree cleanup, or packaging's guest-invocation repair. Synchronous logger subscriber exception behavior is unchanged.Security Impact
Yes/No): No.Yes/No): No.Yes/No): No.Yes/No): No.Yes/No): No.Yes, explain the risk and mitigation: N/A. New records exclude executable paths, arguments, configuration, identities and raw/partial output.Compatibility and Migration
Yes/No): Yes. Existing command results and cancellation semantics retained; additive debug/warning diagnostic records.Yes/No): No.Yes/No): No.Review Conversations