Skip to content

fix: native setup cannot remain stuck finishing indefinitely - #1927

Merged
karkarl merged 16 commits into
mainfrom
karkarl-native-setup-finalization
Nov 5, 2026
Merged

karkarl merged 16 commits into
mainfrom
karkarl-native-setup-finalization

Conversation

@karkarl

@karkarl karkarl commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Final Companion layer of the native Gateway recovery stack, stacked on #1926 (fix(setup): wait safely for native Gateway operator admission). Targets karkarl-native-gateway-admission at d99b6a7cc591de722d325f73f58c3822ae6e3427. Native Companion stack 1928 is now registered in order 1917 -> 1924 -> 1926 -> 1927.

What Problem This Solves

Fixes: Companion can remain on Finishing indefinitely when native Gateway finalization or restart publication stops responding.

User Impact

User impact: finishing reports an existing localized timeout after one finite execution window (27 minutes by default, following the existing native startup override), without enabling duplicate writes or restarts.

Retry cannot renew that deadline. Back and Retry remain unavailable while admitted work settles; Close remains the recovery action. Cleanup can outlive the presentation deadline because an admitted operation must not be abandoned. Signed Store Gateway x64/ARM64 and visible UI proof remain blocked by missing runtime authority, so this is a draft, not a merge-readiness claim.

Why This Change Was Made

SetupWindow actually calls SetupCompletionPreparation, not the similarly named destination coordinator. Keep ownership there: start one monotonic execution deadline on admission, request cooperative cancellation at expiry, bound the presentation wait, and retain/join the real execution plus prior page drain before releasing setup ownership.

Preserve uncertain-finalization and confirmed-committed resume behavior, committed-publication exceptions, exact verification, pairing policy and durable registry ordering. The already-bounded persisted restart handoff is unchanged. No new operation registry, receipt API or blanket mutation retry.

The lower base advanced from e41f54d4 to d99b6a7c only to fix an existing Tray source-guard expectation for the linked admission token. No lower production source changed; git range-diff confirms this layer's patch stayed identical across rebase.

Evidence

Deterministic production-owner cases cover deadline after finalization/publication admission, exact expiry across retries and idle time, late success/committed-publication failure, caller cancellation, cancellation-honoring asynchronous cleanup, confirmed-committed resume, and refusal to duplicate mutation/publication. A narrow WinUI source guard protects Back while retained work is pending.

Negative control: removing only the bounded _execution.WaitAsync(ct) observation made all four finite finalization/publication deadline/cancellation cases fail at their watchdogs. Restoring it passes. This is a targeted negative control, not a live installed-Gateway reproduction.

Independent Copilot rubber-duck review covered the eight-file candidate plus unchanged finalization/close paths, with P0-P3 source and proof-plan assessment. Codex CLI was unavailable; reviewer model identity is unverified. It reported one blocking cancellation/ownership concern. Disposition: cancellation requests do not abandon the retained task; the native owner holds its gate through cleanup, and the window joins cleanup before releasing the session/setup lock. Retained cooperative cancellation and added a cancellation-honoring cleanup regression. No other findings reported. Supplemental test/comment and ledger-schema corrections were directly checked, not independently re-reviewed. This narrative fallback provides no helper-owned isolation, frozen-input checks or machine-clean verdict.

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: current-head finishing timeout, pending-work Back/Retry gating and Close presentation on an authorized isolated native Gateway path. Not run; runtime authority unavailable.
  • windows-11-arm64: signed native Store Gateway finalization/restart/late settlement on ARM64. Local ARM64 compilation does not establish this runtime contract.
  • windows-wsl-gateway-e2e: shared finishing orchestration also serves managed WSL setup; real setup/pairing/handoff regression remains unverified.
  • windows-wsl-mxc: required setup-to-node/MXC path remains blocked by runtime authority. No -AllowSkip result is claimed.

Validation

Final source: 4f2452bdbb71fd6da133315a25919a99e95e0698, clean task-owned worktree on native Windows ARM64. Set OPENCLAW_REPO_ROOT to this worktree and OPENCLAW_TRAY_DATA_DIR to an isolated session profile. Removed inherited integration/GPU/E2E/MXC opt-ins. Built Shared/Tray test projects first so --no-restore cannot silently no-op.

All results below were rerun at that final head. $root is the isolated session evidence directory; TRX and command logs remain local.

  • .\build.ps1: passed, all five product projects, Debug win-arm64; includes documentation validation (68 Markdown files).
  • dotnet build .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --verbosity quiet and dotnet build .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --verbosity quiet: passed, zero warnings/errors each.
  • dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore --logger 'trx;LogFileName=head-shared.trx' --results-directory $root --verbosity quiet: passed, 4,847 passed, 24 skipped, 0 failed (4,871 total).
  • dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore --logger 'trx;LogFileName=head-tray.trx' --results-directory $root --verbosity quiet: passed, 4,754 passed, 0 skipped/failed.
  • dotnet test .\tests\OpenClaw.SetupEngine.Tests\OpenClaw.SetupEngine.Tests.csproj --no-restore --logger 'trx;LogFileName=head-setup.trx' --results-directory $root --verbosity quiet: failed with the 15 known host policy denials, 2,486 passed, 15 failed, 1 skipped (2,502 total). Every failure is in unchanged GatewayPackageCleanupTests; all 15 TRX messages confirm temporary scripts cannot load because running scripts is disabled. No policy/test weakening or unrelated fix.
  • Focused owner command below: passed, 84 passed, 0 skipped/failed.
  • git diff --check: passed; tracked worktree clean.
dotnet test .\tests\OpenClaw.SetupEngine.Tests\OpenClaw.SetupEngine.Tests.csproj --no-restore --filter 'FullyQualifiedName~SetupCompletionAuthorityTests|FullyQualifiedName~SetupNativeCompletionTimingTests|FullyQualifiedName~NativeGatewaySetupConnectionTests' --logger 'trx;LogFileName=head-focused.trx' --results-directory $root --verbosity quiet

Before native stack registration, product build/test CI had not triggered for this feature-base PR; .github/workflows/ci.yml ordinarily filters push/pull-request branches to main/master. After native Companion stack 1928 registration, Build and Test run 40964792074 automatically started for pull_request, attempt 1, at exact head 4f2452bdbb71fd6da133315a25919a99e95e0698. Latest verified state: in progress, not yet green (no conclusion). No workflow dispatch, retarget, or workflow configuration change was made. A bot dispatch is not product validation. All local results, review limitations and runtime-proof blockers above remain unchanged. The root layer's separate composer draft-text assertion failure remains unresolved and is not classified as a proven baseline/flake here.

Real Behavior Proof

  • Environment tested: native Windows ARM64, .NET 10; managed owner tests and loopback fixtures, no installed Companion/Gateway launch.
  • PR head or commit tested: 4f2452bdbb71fd6da133315a25919a99e95e0698.
  • Exact steps or command run: focused production-owner filter in Validation. Advance the injected monotonic clock to exactly 27 minutes after admission, including failed-attempt time; hold admitted work/cleanup behind explicit gates, observe timeout, reject replay/Back, then release and join actual settlement.
  • Evidence after fix: final-head output: Passed! - Failed: 0, Passed: 84, Skipped: 0, Total: 84, Duration: 7 s - OpenClaw.SetupEngine.Tests.dll (net10.0).
  • Observed result: bounded presentation without releasing admitted-work ownership, renewing retries, or duplicating mutation/publication. This is managed contract proof, not signed Store Gateway, visible UI or real inference proof.
  • Screenshot or artifact links verified? (Yes/No/N/A): N/A. TRX/logs retained locally; no public screenshot/artifact links are asserted.
  • Not verified or blocked: signed Store Gateway x64/ARM64 execution, current-head visible UI, real Gateway inference/restart/pairing, and required WSL/MXC runtime paths. Explicit runtime authority was not granted; no shared app/service/configuration was changed or remote host allocated.

Security Impact

  • New permissions or capabilities? (Yes/No): No
  • Secrets or tokens handling changed? (Yes/No): No
  • New or changed network calls? (Yes/No): No
  • Command or tool execution surface changed? (Yes/No): No
  • Data access scope changed? (Yes/No): No
  • If any answer is Yes, explain the risk and mitigation: N/A. Existing calls receive the whole-operation cancellation signal; retained ownership and uncertainty guards prevent replay.

Compatibility and Migration

  • Backward compatible? (Yes/No): Yes. Intentional behavior change: finishing waits and retries share a finite in-process deadline; cleanup still joins admitted work.
  • Config or environment changes? (Yes/No): No. Reuses the existing startup-derived timing convention; no new setting.
  • Migration needed? (Yes/No): No
  • If yes, list the exact upgrade steps: N/A. Persisted handoff deadlines and legacy package compatibility are unchanged.

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 Oct 29, 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.

@karkarl
karkarl added this pull request to stack #1928 October 29, 2026 22:18
@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 29, 2026
@clawsweeper

clawsweeper Bot commented Oct 29, 2026

Copy link
Copy Markdown

Codex review: needs changes before merge.

What this changes

This PR gives setup finishing one execution deadline across retries while retaining ownership of admitted work until cleanup settles.

Example: Native Gateway finalization remains pending for 27 minutes with the default startup allowance.

  • Before: Companion can continue displaying Finishing indefinitely.
  • After: Companion displays a timeout and Close action while retaining pending work and preventing duplicate finalization or restart.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused implementation preserves the important lifecycle invariants and has one low-impact copy defect, but required runtime behavior remains unproven.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Companion can remain on Finishing indefinitely when native Gateway finalization or restart publication stops responding.
Reason: A bounded failure presentation has clear user value, and the maintainer-authored direction explicitly preserves admitted-work ownership and prevents duplicate writes or restarts.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep open: this maintainer-authored draft addresses an unbounded finishing wait still present on main; one low-impact recovery-message defect needs correction.

Priority: P2
Reviewed head: 4f2452bdbb71fd6da133315a25919a99e95e0698

Before merge

  • Show recovery guidance valid after execution expiry (P3) - When the execution deadline expires during admitted finalization or publication, CanRetry is false and HasPendingWork prevents Back, but this mapping displays “Choose again to retry, or return to AI setup.” AiCompletionPage hides both buttons in that state. The separate InfoBar correctly offers Close, so recovery remains discoverable, but the main detail contradicts it and mislabels finalization/publication expiry as verification failure. Use the existing localized interruption guidance or execution-specific localized copy that describes the available recovery.

Findings

  • [P3] Show recovery guidance valid after execution expiry — src/OpenClaw.SetupEngine/AiSetupReadinessPresentation.cs:12

Tests

  • Missing end-to-end proof: Current-head installed-Gateway and visible finishing-timeout, action-gating, and Close/late-settlement proof remains unverified, including fresh and existing-state setup and the declared WSL/MXC paths; the reported negative control removes one guard rather than demonstrating the complete base failing and head passing.
Agent review details

How this fits together

SetupWindow passes verified Gateway and model information to SetupCompletionPreparation, which drains the previous page, verifies readiness, finalizes setup, and publishes the Companion restart handoff.

flowchart TD
  A[Verified AI action] --> B[SetupWindow]
  B --> C[SetupCompletionPreparation]
  C --> D[Page drain and verification]
  D --> E[Gateway finalization]
  E --> F[Restart publication]
  C --> G[Timeout presentation]
  C --> H[Retained cleanup]
Loading

Technical review

Best possible solution:

Keep the existing completion owner’s deadline and retained cleanup, and display localized recovery guidance matching the available actions.

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

Current main directly awaits finalization and restart publication without an execution deadline, so a nonsettling delegate leaves finishing pending; no runtime reproduction or tests were run during this read-only review.

Is this the best way to solve the issue?

Bounding observation in SetupCompletionPreparation while joining the real execution is the smallest complete repair using existing owners, provided timeout guidance reflects the recovery actions actually available.

Full review comments:

  • [P3] Show recovery guidance valid after execution expiry — src/OpenClaw.SetupEngine/AiSetupReadinessPresentation.cs:12
    When the execution deadline expires during admitted finalization or publication, CanRetry is false and HasPendingWork prevents Back, but this mapping displays “Choose again to retry, or return to AI setup.” AiCompletionPage hides both buttons in that state. The separate InfoBar correctly offers Close, so recovery remains discoverable, but the main detail contradicts it and mislabels finalization/publication expiry as verification failure. Use the existing localized interruption guidance or execution-specific localized copy that describes the available recovery.
    Confidence: 0.99

Overall correctness: patch is correct
Overall confidence: 0.91

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 4cbbe51c45a7.

Provenance checked

  • Completion execution and teardown changes intended behavior with a stated reason (d318127: Window-owned completion must drain the prior page, finalize once, and reject replay after uncertain writes or committed restart publication.)
  • Completion phase timing keeps the original intent (3e6ac76: Separate finite readiness phases avoid premature timeouts while retaining exact-model and ownership verification; this PR reuses the current startup-derived execution budget.)
  • Back navigation from finishing keeps the original intent (d318127: Back is allowed only before context finalization or Gateway publication; the new guard also prevents navigation while timed-out execution still owns work.)

Testing

Proof path: unit tests only.

Security

None.

Evidence

Acceptance criteria:

  • ./build.ps1
  • dotnet build ./tests/OpenClaw.SetupEngine.Tests/OpenClaw.SetupEngine.Tests.csproj
  • dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restore
  • dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restore
  • dotnet test ./tests/OpenClaw.SetupEngine.Tests/OpenClaw.SetupEngine.Tests.csproj --no-restore --filter FullyQualifiedName~SetupCompletionAuthorityTests

What I checked:

  • Pinned PR introduction: The introduced diff adds the execution deadline, retained execution task, pending-work Back guard, localized failure classification, and focused regressions without introducing another completion owner. (src/OpenClaw.SetupEngine/SetupCompletionPreparation.cs:78, 4f2452bdbb71)
  • Current main retains the unbounded waits: Current main directly awaits finalization and publication using only the window lifetime token; it has no whole-operation execution deadline. (src/OpenClaw.SetupEngine/SetupCompletionPreparation.cs:92, 4cbbe51c45a7)
  • Admitted work remains owned: Cleanup joins ActiveTask, the retained execution, and the previous page drain; SetupWindow waits for that cleanup before releasing its native session and setup lock. (src/OpenClaw.SetupEngine/SetupCompletionPreparation.cs:157, 4f2452bdbb71)
  • Recovery message contradicts available actions: Execution expiry maps to Onboarding_Ready_Timeout, whose English text recommends retrying or returning to AI setup, although expiry disables Retry and retained work disables Back. (src/OpenClaw.SetupEngine/AiSetupReadinessPresentation.cs:12, 4f2452bdbb71)
  • Full discussion and declared proof limits: The full PR body and both comments were read through REST. The supplied body identity is SHA-256 1b01bc210815f20c264ebca8275ff5980e8662a25badddd1f5d104f6457b8920. The author reports 84 passing focused tests and explicitly leaves installed-Gateway, visible UI, WSL, and MXC proof unverified. (4f2452bdbb71)
  • Accepted deadline tradeoff: The maintainer-authored PR explicitly chooses a finite presentation deadline, nonrenewable retries, and cleanup that can outlive the deadline; this direction needs no second product approval. (4f2452bdbb71)

Likely related people:

  • Barbara Kudiess: Raw commit d318127 adds src/OpenClaw.SetupEngine/SetupCompletionPreparation.cs:62 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d318127350b5; files: src/OpenClaw.SetupEngine/SetupCompletionPreparation.cs)
  • Karen: Raw commit 3e6ac76 adds src/OpenClaw.SetupEngine/SetupNativeCompletionTiming.cs:31 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3e6ac7621eca; files: src/OpenClaw.SetupEngine/SetupNativeCompletionTiming.cs)
  • Pedro Larroy: Raw commit e5122db adds src/OpenClaw.SetupEngine/SetupNativeCompletionTiming.cs:38 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: e5122db3c943; files: src/OpenClaw.SetupEngine/SetupNativeCompletionTiming.cs)

Review metrics

Metric Value Why it matters
Introduced scope Production +57/-10; tests +253/-0; documentation +17/-1 Growth stays within existing owners and covers distinct deadline, retry, cancellation, late-settlement, and navigation failures.

Labels

Label changes:

  • add P2: The change addresses a source-confirmed setup stall, without evidence establishing an urgent widespread regression.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: The change addresses a source-confirmed setup stall, without evidence establishing an urgent widespread regression.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rank-up moves

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

  • Provide current-head native finishing-timeout and Close/late-settlement evidence through the shipped app, together with the declared setup regression proof.

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 October 29, 2026, 6:37 PM ET / 22:37 UTC.

karkarl and others added 11 commits November 4, 2026 11:49
Honor bounded structured startup retry hints without changing auth, pairing, provenance or caller deadlines.

Co-authored-by: Copilot App <[email protected]>
Keep client attempt ordinals unique across replacement native setup sessions. Classify observed transport failures without scanning exception stack frames, leaving existing failure policy unchanged. Cover both regressions and document the page-owned file sink boundary.

Co-authored-by: Copilot App <[email protected]>
Use the setup host's current logger parameter and describe window-owned sink lifetime after the lower stack's main rebase. No UI, logging lifetime or handshake policy changes.

Co-authored-by: Copilot App <[email protected]>
Cover the upstream-added keepalive cancellation path with the same current-generation disconnect observation as adjacent transport loss paths. Extend the existing real-socket ping timeout test to protect generation and ordering without changing recovery or timing policy.

Co-authored-by: Copilot App <[email protected]>
Share the launch-to-operator budget across preparation, authorization and retries. Use optional packaging launch receipts for conditional, attempt-owned cleanup without changing shipping v1 compatibility.

Co-authored-by: Copilot App <[email protected]>
Update the existing ownership guard for preparation's linked caller, session and admission-deadline token.

Co-authored-by: Copilot App <[email protected]>
Capture the current transport rejection before prompt cancellation disposal and synchronize the callback before classifying a delayed continuation. Preserve caller and session cancellation, and reject stale startup state after a fresh transport.

Co-authored-by: Copilot App <[email protected]>
Use the existing logged package invocation and result parser for receipt operations. Align independent fake-clock thresholds and documentation with the inherited five-minute startup budget plus thirty-second handoff allowance, preserving the existing production deadlines.

Co-authored-by: Copilot App <[email protected]>
karkarl and others added 3 commits November 4, 2026 12:42
Bound production finalization and restart publication with one retained execution deadline across retries. Join admitted work through late settlement before releasing setup ownership.

Co-authored-by: Copilot App <[email protected]>
Keep the original execution deadline and reject late retries with the existing timeout diagnostic rather than an unrelated replay error.

Co-authored-by: Copilot App <[email protected]>
Advance lifecycle clocks to the configured execution window after lower-stack startup defaults changed. Keep timing defaults independently asserted and avoid duplicating the default in finishing documentation.

Co-authored-by: Copilot App <[email protected]>
@karkarl
karkarl force-pushed the karkarl-native-setup-finalization branch from f47cfa3 to 8499d9a Compare November 4, 2026 17:54
)

* fix: preserve native startup budget after slow validation

Co-authored-by: Copilot App <[email protected]>

* fix(setup): preserve validation timeout and reject exhausted retries

Run legacy restart validation before a new admission window without renewing existing deadlines. Preserve the configurable native CLI validation timeout and reject exhausted retries before restart side effects.

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Copilot App <[email protected]>
@karkarl
karkarl marked this pull request as ready for review November 4, 2026 22:27
Base automatically changed from karkarl-native-gateway-admission to main November 4, 2026 23:07
Preserve validation-before-admission and retained finalization ownership while resolving current-main conflicts. Include the two deterministic chat test completion synchronizations.

Co-authored-by: Copilot App <[email protected]>
@karkarl
karkarl merged commit 2566c57 into main Nov 5, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant