Skip to content

fix(setup): wait safely for native Gateway operator admission - #1926

Merged
karkarl merged 4 commits into
mainfrom
karkarl-native-gateway-admission
Nov 4, 2026
Merged

karkarl merged 4 commits into
mainfrom
karkarl-native-gateway-admission

Conversation

@karkarl

@karkarl karkarl commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Stack layer 3. Base: karkarl-gateway-handshake-diagnostics at e4ce43f01bd4759f8748e0b510dfe39e27941495.
Depends on #1924 (improve(setup): diagnose native Gateway handshake delays (Layer 2)), above #1917 (fix(connection): retry promptly while the Gateway is starting).
Stronger launch ownership requires openclaw/openclaw-windows-packaging#225 (fix: prevent onboarding cleanup from stopping another Gateway launch), head cf04dfaaa30f67415a8434c146fe61a278c12aeb, above openclaw/openclaw-windows-packaging#224 (fix: keep accepted Gateway launches starting until listener readiness).

What Problem This Solves

Fixes premature native setup connection failure while an owned Gateway is still starting, and prevents receipt-capable cleanup from stopping a different launch after an uncertain start.

User Impact

User impact: slow native starts can reach authenticated operator admission within one finite allowance rather than an unrelated nested twenty-second wait. Exhausted unadmitted sessions need new setup preparation. Shipping v1 packages retain existing lifecycle behavior; stronger attempt-owned cleanup needs the optional newer packaging extension.

Why This Change Was Made

NativeGatewaySetupSession remains the runtime/finalization owner and now retains the monotonic admission start through failed connection retries. NativeGatewaySetupConnection spends only the remaining existing native allowance: 180-second start plus ten-second confirmation plus twenty-second admission margin, 210 seconds by default. Initial preparation, command time, challenge authorization, startup-sidecar retries, pairing and token recovery all count. No outer deadline increases or HTTP /startupz gate are introduced. Terminal failures remain terminal, cancellation remains cancellation, and current-generation typed startup state explains deadline expiry.

NativeGatewayPackageClient validates optional integration.gatewayLaunch={version:1} and launch receipts even for non-running or failed status responses. IsolatedGatewayRuntime retains a fresh caller-selected GUID-N before dispatch, so lost acknowledgement does not lose correlation. A successful created receipt is intent, not listener readiness; an adopted launch grants no cleanup authority. Receipt-capable rollback/detach uses stop --if-attempt-id only, with no unconditional fallback after refusal, malformed data or uncertain response. Fresh listener/process-sequence proof stays independent and is still required immediately before credentials.

No ownership transfer, Gateway configuration API, installation, shared-runtime mutation, finalization-deadline change, merge or auto-merge is included.

Evidence

Fake-clock tests demonstrate initial 90-second preparation plus 90-second authorization, progress at 209.999 seconds and exact expiry at 210 seconds, startup retry admission after 21 seconds, command-time exhaustion before hello, and failed same-session retries without budget renewal. Package/runtime tests cover missing/malformed/unsupported advertisements and receipts, created versus adopted, lost acknowledgement, replacement before stop and refusal with no unconditional fallback. Existing cancellation, token precedence/recovery, listener provenance and lower current/stale transport-generation regressions remain intact.

Independent Copilot rubber-duck P0-P3 narrative source and proof-plan review covered the implementation candidate. It identified renewal across failed top-level retries; this was corrected and protected by a focused regression. A subsequent one-line existing source guard was updated to require preparation's linked cancellation token rather than its old direct caller token; its ownership assertions were retained and the focused test passed. Those corrective edits were verified locally, not independently re-reviewed. Model identity is unverified. Codex CLI was unavailable; this route does not provide helper-enforced isolation, frozen-input checks or structured helper status. Review is not packaged/runtime proof.

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-11-arm64: native ARM64 Store cold-start and operator admission, not inferred from mocks or cross-compilation.
  • windows-winui-interactive: current-head onboarding progress/error state and associated local MCP diagnostics.
  • windows-wsl-gateway-e2e: connection/setup regression boundary and real Gateway-mediated operator/node flow.
  • windows-wsl-mxc: required setup/connect MXC path proof.

All are not verified / blocked by the explicit runtime/provisioning authority exclusions for this task. Real x64 native packaged/Store launch-receipt compatibility is also not verified.

Validation

Tested head: d99b6a7cc591de722d325f73f58c3822ae6e3427. OPENCLAW_REPO_ROOT points at the task worktree; settings are isolated for tests. Required test projects received genuine initial builds before --no-restore runs.

Before native stack registration, product build/test CI had not triggered for this feature-base layer under the existing main/master push/pull-request filters; the earlier not-triggered report describes that historical state only. The native Companion stack is now registered as stack 1928, ordered 1917 -> 1924 -> 1926 -> 1927. After registration, real Build and Test CI, run 40964791695, attempt 1 automatically started via pull_request at exact head d99b6a7cc591de722d325f73f58c3822ae6e3427. GitHub reports in_progress with no conclusion as of 2026-10-29 22:23 UTC: running, not yet green. ClawSweeper dispatch checks are not build/test validation. No workflow dispatch, retarget or workflow change was performed. Root #1917 has an unresolved unchanged UI composer draft-text assertion failure, classified by its owner as unrelated to typed startup retry, not established as baseline or flaky.

  • .\build.ps1: passed all five Debug projects, native win-arm64, including WinUI.
  • dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore --verbosity minimal: passed 4,847, skipped 24, failed 0 (4,871 total).
  • dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore --verbosity minimal: passed 4,754, skipped 0, failed 0.
  • dotnet test .\tests\OpenClaw.Connection.Tests\OpenClaw.Connection.Tests.csproj --no-restore --verbosity minimal: passed 1,723, skipped 1, failed 0 (1,724 total).
  • dotnet test .\tests\OpenClaw.SetupEngine.Tests\OpenClaw.SetupEngine.Tests.csproj --no-restore --verbosity minimal: failed 15, passed 2,477, skipped 1 (2,493 total). All 15 failures are unchanged GatewayPackageCleanupTests: the host refuses their temporary PowerShell scripts because script execution is disabled. This file has no delta against the lower base; the same limitation is recorded on the lower layer. No policy change or bypass was used.
  • dotnet test .\tests\OpenClaw.SetupEngine.Tests\OpenClaw.SetupEngine.Tests.csproj --no-restore --filter 'FullyQualifiedName~NativeGatewaySetupConnectionTests|FullyQualifiedName~NativeGatewaySetupTests' --verbosity quiet: passed 135, skipped 0, failed 0.
  • .\scripts\validate-docs.ps1: passed, 68 Markdown files and proof-pool documentation checks.
  • git -c core.whitespace=cr-at-eol diff e4ce43f01bd4759f8748e0b510dfe39e27941495 HEAD --check: passed. The repository's existing C# index blobs are CRLF; plain git diff --check reports CR as trailing whitespace.

The first closeout found one task-coupled Tray source guard still requiring the old direct cancellation argument. It was corrected without removing the guard; its focused case and the complete final build/Shared/Tray/Connection/Setup closeout were rerun. Ordinary opt-in skips are not completed native proof.

Real Behavior Proof

  • Environment tested: Windows ARM64 host, .NET 10, native win-arm64 Debug build, isolated managed tests and loopback synthetic Gateway only.
  • PR head or commit tested: d99b6a7cc591de722d325f73f58c3822ae6e3427.
  • Exact steps or command run: required and focused commands above.
  • Evidence after fix: copied current-head runner summaries: native owning setup Passed: 135, Failed: 0, Skipped: 0; full Connection Passed: 1723, Failed: 0, Skipped: 1; full Tray Passed: 4754, Failed: 0, Skipped: 0. Deterministic clock/loopback/qualified-command-boundary regressions are described above.
  • Observed result: source contract proof only. No live Store/packaged Gateway, app UI, MCP or MXC claim.
  • Screenshot or artifact links verified? (Yes/No/N/A): N/A. Dependency links are canonical GitHub URLs; no private local artifact is presented as public evidence.
  • Not verified or blocked: native ARM64 Store/x64 packaged execution, current-head visible UI and MCP discovery/invocation, real Gateway pairing/invocation, WSL/MXC provisioning, and historical Store payload compatibility. Task authority explicitly excludes those operations. Draft is not merge-ready proof.

Security Impact

  • New permissions or capabilities? (Yes/No): No.
  • Secrets or tokens handling changed? (Yes/No): No. Device-token precedence, credential retirement guards and fresh endpoint proof are preserved.
  • New or changed network calls? (Yes/No): No. Existing authenticated operator connection only; no new HTTP readiness call.
  • Command or tool execution surface changed? (Yes/No): Yes.
  • Data access scope changed? (Yes/No): No.
  • If any answer is Yes, explain the risk and mitigation: only a qualified package advertising optional launch receipt v1 receives fresh --attempt-id start and --if-attempt-id stop arguments. Strict schema/ID checks and package-side lifecycle-lock ownership checks reject malformed or replaced attempts. Refusal never becomes an unconditional stop.

Compatibility and Migration

  • Backward compatible? (Yes/No): Yes for genuinely absent optional receipt support. Shipping schemaVersion 1, isolated-session version 1 behavior is preserved.
  • Config or environment changes? (Yes/No): No new setting. Existing OPENCLAW_NATIVE_GATEWAY_START_TIMEOUT validated whole seconds 30..3600 remains the owner of the startup allowance.
  • Migration needed? (Yes/No): No.
  • If yes, list the exact upgrade steps: N/A. Optional stronger cleanup requires the packaging producer linked above; malformed advertised support is an integration error rather than a legacy downgrade. The shipping-compatible admission fix does not require that upgrade. No mock-based packaged compatibility claim is made.

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. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 29, 2026
@clawsweeper

clawsweeper Bot commented Oct 29, 2026

Copy link
Copy Markdown

Codex review: needs real behavior proof before merge.

What this changes

This PR shares one native Gateway admission deadline and adds optional attempt-qualified launch cleanup.

Example: A verified native Gateway needs 21 seconds of startup retries before accepting Companion.

  • Before: The separate twenty-second handshake wait can fail setup.
  • After: Admission can succeed within the remaining shared allowance, which defaults to 210 seconds.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) Useful owner-directed work with substantial focused coverage, but an introduced recovery defect and unproven termination authority prevent merge readiness.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦪 silver shellfish (2/6) Security review found an item that needs attention.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Native setup can fail while its verified Gateway is still starting, and uncertain cleanup lacks attempt-specific ownership on older packages.
Reason: The collaborator-authored direction addresses concrete source-defined failures, reuses existing owners, and explicitly accepts the weaker legacy-package cleanup contract.

Merge readiness

⛔ Blocked before merge - 7 items remain

Keep open: current main retains the premature admission timeout, and this maintainer-authored PR contains useful, distinct work; its expired-session recovery path needs correction.

Priority: P2
Reviewed head: d99b6a7cc591de722d325f73f58c3822ae6e3427

Before merge

  • Add real behavior proof - Authority-chain proof required: supplied tests exercise admission over synthetic WebSockets and cleanup through mocked package commands, not actual termination through the package controller and session host. Show an owned attempt stopping after lost acknowledgement, while adopted, replaced, mismatched and unverified attempts survive through the final process effect with no unconditional fallback. The full body explicitly leaves these scenarios unverified; collaborator authorship does not waive this gate. Latest-stable upgrade preservation is also unverified. Redact credentials and non-public endpoints from supplied output. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Route exhausted admission sessions to fresh setup preparation (P2) - When a staged page reconnect consumes the admission allowance, BeginAdmission keeps returning zero and EndAdmission is reached only after success. AiSetupPage.RecoverNativeAsync still offers Restart Gateway, calls native.RestartAsync on that same owner, and reruns InitializeAsync, which immediately fails here even if the Gateway is now ready. The new timeout messages do not explain that restarting or retrying this session cannot recover it. Preserve the finite budget, but expose exhaustion to the recovery presentation and direct the user through Cancel setup and fresh preparation instead of repeating an ineffective restart.
  • Update the connection guide for the shared admission deadline (P3) - The changed wait removes the independent twenty-second handshake deadline, but docs/CONNECTION_ARCHITECTURE.md still states that native setup retains it and does not extend it. Contributors following that required architecture guide receive the opposite contract from the implementation and the two updated guides. Replace that paragraph with the shared remaining-budget behavior and its exhaustion semantics.
  • Resolve security review attention item - Source preserves conditional cleanup and process-identity checks, but cross-session termination authority still needs final-effect evidence.
  • Resolve merge risk - Before merge, the PR owner must establish that retained cleanup authority cannot terminate a replacement or independently owned launch at the package's final process-stop boundary.
  • Improve patch quality - Add final-effect proof that a replacement or independently owned Gateway survives stale cleanup authority, including lost acknowledgement and reassignment before termination.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

  • [P2] Route exhausted admission sessions to fresh setup preparation — src/OpenClaw.SetupEngine/NativeGatewaySetupConnection.cs:77-78
  • [P3] Update the connection guide for the shared admission deadline — docs/CONNECTION_ARCHITECTURE.md:421-424

Tests

  • Missing end-to-end proof: Missing are current-head package-boundary termination/refusal evidence, visible exhausted-session recovery, latest-stable upgrade preservation, required native/MXC proof, and a demonstrated base-fail/head-pass run of this layer's regressions.
Agent review details

How this fits together

Native setup prepares a staged Gateway session, verifies package and listener ownership, and opens an authenticated operator connection; the package executes lifecycle commands inside its isolated Windows session.

flowchart LR
  A[Native setup UI] --> B[Setup session]
  B --> C[Setup connection]
  C --> D[Gateway operator socket]
  B --> E[Isolated runtime]
  E --> F[Package command client]
  F --> G[Package controller and session host]
  G --> H[Gateway process]
Loading

Technical review

Best possible solution:

Keep the deadline and receipt logic in the existing owners, route exhausted sessions to fresh setup preparation, and preserve independent listener verification.

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

Source establishes the current-main twenty-second wait and the introduced exhausted-session recovery failure; no target code, builds or tests were executed during this read-only review.

Is this the best way to solve the issue?

Sharing the monotonic allowance and delegating conditional termination to the existing package owner is appropriate, but the retained UI recovery actions must recognize permanent session exhaustion.

Full review comments:

  • [P2] Route exhausted admission sessions to fresh setup preparation — src/OpenClaw.SetupEngine/NativeGatewaySetupConnection.cs:77-78
    When a staged page reconnect consumes the admission allowance, BeginAdmission keeps returning zero and EndAdmission is reached only after success. AiSetupPage.RecoverNativeAsync still offers Restart Gateway, calls native.RestartAsync on that same owner, and reruns InitializeAsync, which immediately fails here even if the Gateway is now ready. The new timeout messages do not explain that restarting or retrying this session cannot recover it. Preserve the finite budget, but expose exhaustion to the recovery presentation and direct the user through Cancel setup and fresh preparation instead of repeating an ineffective restart.
    Confidence: 0.9
  • [P3] Update the connection guide for the shared admission deadline — docs/CONNECTION_ARCHITECTURE.md:421-424
    The changed wait removes the independent twenty-second handshake deadline, but docs/CONNECTION_ARCHITECTURE.md still states that native setup retains it and does not extend it. Contributors following that required architecture guide receive the opposite contract from the implementation and the two updated guides. Replace that paragraph with the shared remaining-budget behavior and its exhaustion semantics.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.9

AGENTS.md: found and applied where relevant.

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

Merge-risk options

Maintainer options:

  1. Verify conditional termination before landing (recommended)
    The PR owner supplies final-effect evidence for an owned launch and for stale, adopted, replaced and unverified launch authority using the pinned packaging producer.
  2. Keep the receipt integration parked
    Retain the draft until the cross-repository termination contract can be exercised in an authorized Windows environment.

Provenance checked

Testing

Proof path: in-process harness.

Security

Needs attention: Source preserves conditional cleanup and process-identity checks, but cross-session termination authority still needs final-effect evidence.

Evidence

What I checked:

Likely related people:

  • Karen: Raw commit 3e6ac76 adds src/OpenClaw.Connection/NativeGateway/IsolatedGatewayRuntime.cs:21 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.Connection/NativeGateway/IsolatedGatewayRuntime.cs)
  • Barbara Kudiess: Raw commit d318127 adds src/OpenClaw.SetupEngine/NativeGatewaySetupConnection.cs:60 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/NativeGatewaySetupConnection.cs)
  • Dallin Romney: Raw commit 7cd646b adds src/OpenClaw.Connection/NativeGateway/IsolatedGatewayRuntime.cs:296 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 7cd646b23ef5; files: src/OpenClaw.Connection/NativeGateway/IsolatedGatewayRuntime.cs)

Review metrics

Metric Value Why it matters
Introduced diff Production +205/-34; tests +291/-10; documentation +48/-0 Growth extends existing deadline, package-client and runtime seams; no additional module or competing lifecycle owner is introduced.

Labels

Label changes:

  • add P2: The change addresses slow native startup and a bounded setup recovery defect, without evidence of a widespread urgent regression.
  • add merge-risk: 🚨 security-boundary: Attempt identity becomes authority for cross-session process cleanup, and mocked command responses do not establish rejection before termination of a replacement launch.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Label justifications:

  • P2: The change addresses slow native startup and a bounded setup recovery defect, without evidence of a widespread urgent regression.
  • merge-risk: 🚨 security-boundary: Attempt identity becomes authority for cross-session process cleanup, and mocked command responses do not establish rejection before termination of a replacement launch.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

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:40 PM ET / 22:40 UTC.

@karkarl
karkarl force-pushed the karkarl-native-gateway-admission branch from 85bc001 to 0149479 Compare November 4, 2026 17:37
@karkarl
karkarl force-pushed the karkarl-native-gateway-admission branch from 0149479 to 1c4ca89 Compare November 4, 2026 18:36
@karkarl
karkarl marked this pull request as ready for review November 4, 2026 21:58
@karkarl
karkarl force-pushed the karkarl-native-gateway-admission branch from 1c4ca89 to 0ee5bc2 Compare November 4, 2026 22:10
Base automatically changed from karkarl-gateway-handshake-diagnostics to main November 4, 2026 22:42
karkarl and others added 4 commits November 4, 2026 14:42
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
karkarl force-pushed the karkarl-native-gateway-admission branch from 0ee5bc2 to 242c97b Compare November 4, 2026 22:42
@karkarl
karkarl merged commit 4796173 into main Nov 4, 2026
25 checks passed
@karkarl
karkarl deleted the karkarl-native-gateway-admission branch November 4, 2026 23:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. 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: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant