Skip to content

fix: keep cancellation diagnostics when setup closes - #1980

Merged
karkarl merged 4 commits into
openclaw:mainfrom
karkarl:karkarl-native-gateway-setup-recovery
Nov 6, 2026
Merged

karkarl merged 4 commits into
openclaw:mainfrom
karkarl:karkarl-native-gateway-setup-recovery

Conversation

@karkarl

@karkarl karkarl commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Related: #1978 (fix(setup): record terminal state when commands are cancelled)

What Problem This Solves

Fixes missing native Gateway setup cleanup diagnostics when the setup page
closes while an operation is being cancelled.

User Impact

When the setup log file is available, cancellation cleanup can continue recording
to it until the current native setup operation finishes. A failed or unavailable
file sink remains memory-only. This does not fix a Gateway startup or validator
stall and does not guarantee logs after navigation to later setup stages.

Why This Change Was Made

The page can request logger disposal before asynchronous cancellation cleanup
has finished. An operation-scoped lease defers file-sink closure until that
operation releases it, without changing cancellation or rollback behavior.

Evidence

An isolated file-sink regression observed cancellation cleanup after disposal
was requested, and a separate regression covered multiple and idempotent
leases. A page source guard checks acquisition before the first await. Native
page cancellation and diagnostics-bundle inclusion have not been exercised.

Before the commit, an independent Copilot rubber-duck review reported a
retry/lease race, but the proposed interleaving is inconsistent with the page's
busy guard and lease counter. Several other review statements were inaccurate,
so the full-scope source-review assessment remains incomplete.

Change Type

  • Bug fix
  • Feature
  • Refactor
  • Docs or instructions
  • Tests or validation
  • Security hardening
  • Chore or infrastructure

Scope

  • Tray or WinUI UX
  • Windows node capability
  • Local MCP or winnode
  • Gateway, connection, or pairing
  • Setup or onboarding
  • Permissions, privacy, or security
  • Tests, CI, or docs

Required proof pools

  • windows-winui-interactive: exercise current-head native setup cancellation,
    page teardown, and the retained diagnostics state.
  • windows-11-arm64: the reported native setup scenario is on ARM64 and needs
    current-head runtime proof.

Validation

The following ran before the commit on the source identified below, with
isolated tray directories and a process-scoped PowerShell execution policy. The
committed diff matches that tested source. $dir was a fresh private result
directory for each suite.

  • pwsh -NoProfile -NonInteractive -ExecutionPolicy RemoteSigned -File .\build.ps1: passed, Debug win-arm64.
  • dotnet test ".\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj" --no-restore --logger "trx;LogFileName=Shared.trx" --results-directory "$dir" --verbosity normal: 4,808 passed, 24 skipped.
  • dotnet test ".\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj" --no-restore --logger "trx;LogFileName=Tray.trx" --results-directory "$dir" --verbosity normal: 4,754 passed.
  • dotnet test ".\tests\OpenClaw.SetupEngine.Tests\OpenClaw.SetupEngine.Tests.csproj" --no-restore --logger "trx;LogFileName=SetupEngine.trx" --results-directory "$dir" --verbosity normal: 2,486 passed, 1 skipped.
  • git diff --check: passed.

The tests ran under pwsh -NoProfile -NonInteractive -ExecutionPolicy RemoteSigned -Command and produced fresh TRX files. These are not
inventory-bound proof-pool executions.

Real Behavior Proof

  • Environment tested: local Windows ARM64; isolated test files and tray state.
  • PR head or commit tested: tests ran on base 1912df7e2f976314d82baa88a5decf31218b33a1 plus uncommitted diff blob c43a6f49479b359977a58e5d8afed4aac8e2c433; that diff matches commit 0544f7b27ba4afac11e9ac8be1a76a8cdc068875.
  • Exact steps or command run: OperationLeaseKeepsFileOpenThroughCancellationCleanup in the full SetupEngine suite above.
  • Evidence after fix: the test requests disposal during cancellation and reads the temporary log after cleanup.
  • Observed result: cleanup entries were present; an entry written after the operation ended was absent.
  • Screenshot or artifact links verified? (Yes/No/N/A): N/A.
  • Not verified or blocked: current-head interactive page teardown, actual Gateway validation, diagnostics-bundle inclusion, signed Store runtime, and tests against the current target-branch merge. Source-review coverage remains incomplete as noted above.

Security Impact

  • New permissions or capabilities? (Yes/No): No.
  • Secrets or tokens handling changed? (Yes/No): No; the existing sanitization remains in use.
  • New or changed network calls? (Yes/No): No.
  • Command or tool execution surface changed? (Yes/No): No.
  • Data access scope changed? (Yes/No): Yes; already-generated cleanup entries can now reach the existing setup log file after page unload.
  • If any answer is Yes, explain the risk and mitigation: The extended file retention may include additional diagnostic entries, including command output or exception fields already logged by existing code. It uses the same sanitization, location, and file-sink failure behavior and creates no new sink. Sanitization does not guarantee removal of arbitrary user content.

Compatibility and Migration

  • Backward compatible? (Yes/No): Yes, except for the intended retention of cleanup entries.
  • Config or environment changes? (Yes/No): No.
  • Migration needed? (Yes/No): No.
  • If yes, list the exact upgrade steps: N/A.

Review Conversations

  • I replied to or resolved every bot review conversation addressed by this PR.
  • I left unresolved only conversations that still need maintainer judgment.

@clawsweeper

clawsweeper Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 2, 2026
@clawsweeper

clawsweeper Bot commented Nov 2, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge.

What this changes

This PR retains the native setup log file until the active setup operation finishes, including cancellation cleanup after page unload.

Example: Native setup is cancelled and its page unloads before cleanup logs "Native Gateway setup cancelled."

  • Before: Disposal closes the file immediately, so the later cancellation entry remains memory-only.
  • After: The operation lease keeps the file writable through cleanup and closes it when the operation ends.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, source-correct repair with useful file-backed tests, but limited evidence beyond the logger boundary; existing log format and persisted settings remain unchanged.
Proof confidence 🦐 gold shrimp (3/6) The ordinary contributor-proof gate does not apply to this collaborator-authored PR; supplied Windows ARM64 tests exercise SetupLogger with real temporary files, while native page teardown and diagnostics-bundle inclusion remain explicitly unverified.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: People investigating cancelled native setup can lose cleanup details from the setup log when the page unloads.
Reason: The collaborator-authored direction repairs a concrete diagnostic lifetime gap and explicitly limits retention to the current operation.

Merge readiness

✅ Ready for maintainer review

Keep this collaborator-authored draft open: current main still closes the log before asynchronous cancellation cleanup finishes, and no actionable introduced defect was found.

Priority: P3
Reviewed head: 0544f7b27ba4afac11e9ac8be1a76a8cdc068875

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No supplied shipped setup run demonstrates page teardown retaining cleanup entries in the diagnostics bundle, and a base-failure run is not shown.
Agent review details

How this fits together

The native setup page passes SetupLogger to setup hosts, command execution, and runtime adapters; sanitized diagnostic entries leave through the existing JSONL file, console, and subscribers.

flowchart TD
A[Native setup page] --> B[Operation lease]
A --> C[Setup hosts and runtime]
C --> D[SetupLogger]
B --> D
D --> E[Existing JSONL file]
D --> F[Console and subscribers]
Loading

Technical review

Best possible solution:

Keep file lifetime in SetupLogger and retain it around the existing native setup operation without changing cancellation, rollback, or later-stage ownership.

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

Source shows unload requesting disposal before awaited cleanup completes, after which main drops file writes; this review did not execute a runtime reproduction.

Is this the best way to solve the issue?

The defect is premature sink closure, the invariant is that active-operation cleanup remains writable, and the smallest complete fix is a scoped retention lease in the existing logger acquired before the page's first await.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 2ff4d168588d.

Provenance checked

  • Logger disposal and native page lifetime changes intended behavior with a stated reason (e5122db: File writes were deliberately dropped after disposal because the native setup runtime and host could outlive the page.)
  • Native setup operation ownership keeps the original intent (dba8121: The page orchestrates guided native package preparation and hands the prepared session to subsequent onboarding stages.)

Testing

Proof path: unit tests only.

Security

None.

Evidence

What I checked:

  • Verified introduced scope: The pinned parent-to-head diff adds one operation lease at the page entry point and deferred disposal inside the existing logger, plus focused tests and documentation. (src/OpenClaw.SetupEngine.UI/Pages/NativeGatewaySetupPage.xaml.cs:92, 0544f7b27ba4)
  • Current-main lifetime gap: Main's SetupLogger.Dispose immediately sets _disposed and stops the sink; the page requests disposal on unload while its asynchronous operation can still hold the logger. (src/OpenClaw.SetupEngine/SetupLogger.cs:296, 2ff4d168588d)
  • Preserved disposal and failure boundaries: Lease acquisition and disposal share the existing write lock; disposal rejects new leases, the last release closes the sink, and Interlocked.Exchange makes lease release idempotent. Existing sink-failure and sanitization paths remain intact. (src/OpenClaw.SetupEngine/SetupLogger.cs:296, 0544f7b27ba4)
  • Original lifetime intent: fix(setup): native Gateway start timeout leaves no details or recovery actions #1787 (fix(setup): native Gateway start timeout leaves no details or recovery actions) established the file-backed native setup log and deliberately dropped file writes after disposal because runtime consumers can outlive the page; this PR explains its narrower operation-lifetime exception. (src/OpenClaw.SetupEngine/SetupLogger.cs:23, e5122db3c943)
  • Distinct regression coverage: The added file-backed tests check cleanup writes after a disposal request, closure after operation completion, multiple outstanding leases, rejection of new leases, and repeated release; the page guard protects acquisition before asynchronous work. (tests/OpenClaw.SetupEngine.Tests/SetupLoggerTests.cs:44, 0544f7b27ba4)
  • Reported validation and explicit limits: The full REST body reports an ARM64 build and passing Shared, Tray, and SetupEngine suites, while explicitly leaving native page cancellation and diagnostics-bundle inclusion unexercised. Captured source identity is 562ed35c9127cabd2cae5312d7ec599faf77d295c212e128981b6a9777fe57e8; this review ran no target code. (0544f7b27ba4)

Likely related people:

  • Pedro Larroy: Raw commit e5122db adds src/OpenClaw.SetupEngine/SetupLogger.cs:23 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e5122db3c943; files: src/OpenClaw.SetupEngine/SetupLogger.cs)
  • Karen: Raw commit dba8121 adds src/OpenClaw.SetupEngine.UI/Pages/NativeGatewaySetupPage.xaml.cs:17 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: dba81213371c; files: src/OpenClaw.SetupEngine.UI/Pages/NativeGatewaySetupPage.xaml.cs)

Review metrics

Metric Value Why it matters
Introduced scope Production +43/-3; tests +79/-0; documentation +4/-0 Growth stays within the existing logger and page owners and protects distinct disposal and cancellation boundaries.

Labels

Label changes:

  • add P3: The patch preserves cancellation diagnostics without changing setup completion, availability, or recovery behavior.
  • 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.

Label justifications:

  • P3: The patch preserves cancellation diagnostics without changing setup completion, availability, or recovery behavior.
  • 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.

Rank-up moves

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

  • Capture redacted current-head native setup output showing page teardown, cleanup entries, and their inclusion in the diagnostics bundle.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 2, 2026, 4:13 PM ET / 21:13 UTC.

@karkarl
karkarl force-pushed the karkarl-native-gateway-setup-recovery branch 2 times, most recently from 0cb9b22 to f4c1208 Compare November 4, 2026 18:08
@karkarl
karkarl marked this pull request as ready for review November 4, 2026 18:35
@karkarl
karkarl force-pushed the karkarl-native-gateway-setup-recovery branch from ea74184 to 35cddee Compare November 6, 2026 18:31
karkarl and others added 4 commits November 6, 2026 18:21
Synchronize cross-thread activation and allow a bounded foreground handoff while retaining exact window and pointer ownership checks.

Co-authored-by: Copilot App <[email protected]>
@karkarl
karkarl force-pushed the karkarl-native-gateway-setup-recovery branch from 35cddee to 1c5fe00 Compare November 6, 2026 23:22
@karkarl
karkarl merged commit 1d8e426 into openclaw:main Nov 6, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. 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