Skip to content

fix(connection): retry promptly while the Gateway is starting - #1917

Merged
karkarl merged 3 commits into
mainfrom
karkarl-startup-rejection-handling
Nov 4, 2026
Merged

karkarl merged 3 commits into
mainfrom
karkarl-startup-rejection-handling

Conversation

@karkarl

@karkarl karkarl commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #1735 (feat(setup): stream live native Gateway activity log and typed failure diagnosis). This is an independent protocol-handling change, not a replacement for that contributor's diagnostics or UI work.

What Problem This Solves

Fixes: Companion can exhaust its connection window while a starting Gateway explicitly asks it to retry sooner.

User Impact

User impact: Companion retries supported startup rejections without treating them as authentication or pairing failure; native setup still stops at its existing deadline and reports typed startup unavailability when that state remains current.

This is the bottom of the requested Companion stack. Real native Gateway, WSL/MXC and UI proof remains blocked by runtime authority. The additional full Setup suite also has 15 host execution-policy failures, so this draft is not a ready-to-merge claim.

Why This Change Was Made

The existing connection owners now recognize only a correlated current-handshake UNAVAILABLE response with retryable: true and details.reason: startup-sidecars, without a competing structured detail code. A generation-bound retry hint is floored and clamped to 100 through 2000 ms, with a 500 ms fallback matching the pinned Gateway contract.

Ordinary transport backoff, terminal auth/protocol failures, exact pairing, accepted device tokens, pre-credential native ownership checks and cancellation remain intact. No default timeout, HTTP readiness gate, Gateway admission policy or UI copy changes.

Evidence

The real managed-loopback WebSocket regression sends three structured startup rejections with close code 1013, checks all reconnect and handshake authorizations, then completes hello-ok. With the new rejection branch removed, this regression failed on the original backoff path with a connection-window timeout. With the fix restored it passes, without auth, pairing or Error events.

Parser and native-owner tests also cover invalid/bounded hints, unrelated responses, terminal structured-code precedence, preservation of an accepted device token, ownership drift, cancellation and the unchanged finite setup deadline. Synthetic fixture proof does not establish the cause of the earlier released Companion/Store Gateway failure.

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-wsl-gateway-e2e: operator protocol/reconnect and setup connection behavior changed. Not run, runtime provisioning is not authorized.
  • windows-wsl-mxc: Gateway setup/connect changes require the real Gateway-to-node MXC closeout. Not run, WSL/MXC provisioning is not authorized.

Validation

Automatic CI remains blocked: run 40951646643, attempt 1 for head fea2adbba185db491d37a2b6192eecb941b96cc4 failed the UI lane and CI Gate. Job 123722840914 completed the preceding integration suite with 34 passed, then the Gateway fixture suite with 38 passed / 1 failed. At 2026-10-29 21:04:44Z, SharedRootDialog_DefersNavigationAndRejectsNativeBinding(destination: Chat, settingsOrigin: True) failed at GatewayFixtureSettingsModalUiTests.cs:153: the retained composer control had an empty value instead of Keep this draft behind the shared-root dialog. Core/CLI, Tray/setup/integration and all three WSL Latest E2E jobs (setup/connect, network recovery, revocation recovery) succeeded. These automatic results do not turn unrun native/MSIX/MXC proof into a pass.

Failure classification: evidence points to the unchanged shared-root UI/composer draft-retention path, not this startup-retry branch. In fixture run abc25bcd79ff47feb9fbeff2100bb1c6, the sanitized log records immediate hello-ok at 21:04:39.901Z; both recorded connect requests and openclaw.setup.verify completed ok. There were no startup rejections, reconnects or startup retry delays. The added fixture rejection switch defaults to zero and this UI case does not enable it. The failing test and chat/composer owners are unchanged from base; the same-control runtime-ID assertion immediately before the text assertion passed. An exact UI timing/root cause or pre-existing baseline failure has not been reproduced, so this is not labeled a proven flake. No unrelated UI edits, test weakening, app launch, CI rerun or workflow dispatch was performed. Branch remains unchanged.

Windows ARM64, .NET SDK 10.0.403. OPENCLAW_REPO_ROOT pointed at this task worktree. Test processes used isolated tray data/AppData/local-AppData overrides, cleared the competing local-data override, and left integration/GPU/E2E/MXC opt-ins unset. No installed app or shared Gateway was launched or changed.

  • .\build.ps1: passed all five projects, native win-arm64 target, including documentation validation.
  • dotnet build .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --verbosity quiet: passed, zero warnings/errors; prevents fresh-worktree test no-op.
  • dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore: passed 4,834, skipped 24, failed 0. Skipped opt-in/native cases are not runtime proof.
  • dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore: passed 4,754, skipped 0, failed 0.
  • dotnet test .\tests\OpenClaw.Connection.Tests\OpenClaw.Connection.Tests.csproj: passed 1,700, skipped 1 (distinct-volume migration fixture not configured), failed 0.
  • dotnet test .\tests\OpenClaw.SetupEngine.Tests\OpenClaw.SetupEngine.Tests.csproj --no-restore: failed, 2,473 passed / 15 failed / 1 skipped. All 15 failures are unchanged GatewayPackageCleanupTests fixture scripts refused by Windows PowerShell execution policy before the cleanup guards run. The focused changed-owner suite passes. Host policy was not changed and these failures were not skipped or weakened.
  • dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore --filter 'FullyQualifiedName~GatewayStartupUnavailableTests|FullyQualifiedName~StartupUnavailable|FullyQualifiedName~StartupReason': passed 26, skipped 0, failed 0.
  • dotnet test .\tests\OpenClaw.SetupEngine.Tests\OpenClaw.SetupEngine.Tests.csproj --no-restore --filter 'FullyQualifiedName~NativeGatewaySetupConnectionTests': passed 43, skipped 0, failed 0.
  • .\scripts\validate-agent-skills.ps1: passed 15 skills / 24 Markdown files.
  • .\scripts\test-agent-skills-validator.ps1: passed 27 fixtures plus repository skills.
  • git diff --check: passed.

Independent P0-P3 source/rubber-duck review covered all 11 changed files, unchanged transport/credential owners, tests and proof plan. No blocking findings. Codex CLI is unavailable, so the canonical installed autoreview skill's independent Copilot subagent route was used, with model/host identity unverified. It is a narrative assessment, not helper-validated status or helper-owned isolation/frozen-input evidence.

Two non-blocking observations were retained intentionally: startup classification is current-state only, so a deadline during a newly opened, unanswered handshake can still be an ordinary timeout; and the transport attempt counter is not reset before hello-ok, even after hinted startup retries. Retaining those choices avoids stale startup diagnoses and preserves the existing backoff reset contract.

Real Behavior Proof

  • Environment tested: native Windows ARM64; real loopback TCP/WebSocket with synthetic Gateway input and isolated signing identity.

  • PR head or commit tested: fea2adbba185db491d37a2b6192eecb941b96cc4. Checks ran against its exact task diff before commit on base 1912df7e2f976314d82baa88a5decf31218b33a1; local diff and new-file hashes were recorded with validation. No product or test source changed between validation/review and commit.

  • Exact steps or command run: dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-build --no-restore --filter 'FullyQualifiedName~StartupUnavailable_RetriesFreshAuthorizedSockets' --logger 'console;verbosity=detailed'.

  • Evidence after fix, copied from the passing test output:

    Three startup-sidecars / 1013 rejections retried at 100ms on fresh authorized sockets; hello-ok connected. No auth, pairing or Error events.
    Test Run Successful.
    Total tests: 1
         Passed: 1
    
  • Observed result: three fresh reconnects with three reconnect authorizations and four pre-credential handshake authorizations; typed startup clears after acceptance.

  • Screenshot or artifact links verified? (Yes/No/N/A): N/A, copied synthetic socket output, no UI claim.

  • Not verified or blocked: automatic CI UI fixture/CI Gate failure documented above; the full Setup suite's 15 host execution-policy failures; real packaged/native Gateway connect, visible UI, WSL Gateway E2E and MXC proof. App launches, runtime registration/provisioning, process stopping and workflow dispatch are outside this task's authority. No claim that this fixes either historical startup incident or makes an indefinitely starting Gateway healthy.

Security Impact

  • New permissions or capabilities? (Yes/No): No
  • Secrets or tokens handling changed? (Yes/No): No
  • New or changed network calls? (Yes/No): Yes
  • 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: existing reconnects can occur sooner, but only for the exact structured startup reason and bounded hint. Every native reconnect and credential-bearing handshake still revalidates provenance. No additional endpoint, credential fallback or RPC is introduced.

Compatibility and Migration

  • Backward compatible? (Yes/No): Yes
  • Config or environment changes? (Yes/No): No
  • Migration needed? (Yes/No): No
  • If yes, list the exact upgrade steps: N/A. Gateways without the structured startup contract retain existing behavior; close 1013 or generic UNAVAILABLE alone is not recognized as typed startup.

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.

@clawsweeper clawsweeper Bot added 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. labels Oct 29, 2026
@clawsweeper

clawsweeper Bot commented Oct 29, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge.

What this changes

This PR honors bounded Gateway startup retry hints and reports typed startup unavailability when native setup reaches its existing deadline.

Example: A Gateway rejects three operator handshakes with startup-sidecars and retryAfterMs=100 before accepting.

  • Before: Ordinary backoff takes at least seven seconds, exceeding the regression's five-second connection window.
  • After: Three 100 ms retries reach hello-ok within that window.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused implementation with meaningful transport proof and no actionable source findings; required native runtime validation remains incomplete.
Proof confidence 🦐 gold shrimp (3/6) 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.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Companion can miss its connection window while the Gateway explicitly requests shorter startup retries.
Reason: Collaborator-authored direction addresses an independently verified Gateway contract through the existing owners without changing settings, admission policy or persisted credentials.

Merge readiness

✅ Ready for maintainer review

Keep open: this collaborator-authored draft adds useful startup retry handling absent from main; source review found no definite introduced defect.

Priority: P2
Reviewed head: fea2adbba185db491d37a2b6192eecb941b96cc4

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied loopback run and reported negative control cover hinted retry recovery, but repository-required real Gateway setup/connect and MXC closeout remain unverified.
Agent review details

How this fits together

Native setup and the connection manager use the shared operator client, which interprets Gateway handshake responses and delegates socket recovery to WebSocketClientBase.

flowchart TD
A[Connection manager or native setup] --> B[Operator Gateway client]
B --> C[WebSocket transport]
C --> D[Gateway handshake response]
D --> E[Structured startup classification]
E --> C
C --> F[Fresh endpoint authorization]
F --> B
Loading

Technical review

Best possible solution:

Retain the bounded startup hint in the existing operator and transport owners while preserving authorization, credential precedence and caller deadlines.

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

Main deterministically applies ordinary backoff to the verified startup rejection shape; the supplied loopback regression reports failure without the new branch and success with it, but this review executed no target code.

Is this the best way to solve the issue?

The patch is a small complete protocol fix: one parser, generation-bound state and an existing reconnect-loop hook preserve ordinary backoff and native setup ownership without introducing HTTP gating or extending deadlines.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 1912df7e2f97.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Scott Hanselman: Raw commit d4707db adds src/OpenClaw.Shared/WebSocketClientBase.cs:622 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d4707db710d6; files: src/OpenClaw.Shared/WebSocketClientBase.cs)
  • Anna Koenig: Raw commit 2ba89f3 adds src/OpenClaw.SetupEngine/NativeGatewaySetupConnection.cs:82 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 2ba89f377ce8; files: src/OpenClaw.SetupEngine/NativeGatewaySetupConnection.cs)
  • Sytone: Raw commit 1d83639 adds src/OpenClaw.Shared/WebSocketClientBase.cs:234 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 1d836390e9ee; files: src/OpenClaw.Shared/WebSocketClientBase.cs)

Review metrics

Metric Value Why it matters
Change size Production +91/-6; tests and fixture +243/-0; docs +18/-0 Growth covers parsing, socket-bound retry state and distinct transport, credential, cancellation and deadline regressions without adding another lifecycle owner.

Labels

Label changes:

  • add P2: A focused connection reliability fix with a verified protocol contract and bounded scope; it does not establish a fix for the separate released pre-WebSocket boot failure.
  • 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:

  • P2: A focused connection reliability fix with a verified protocol contract and bounded scope; it does not establish a fix for the separate released pre-WebSocket boot failure.
  • 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.

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, 4:57 PM ET / 20:57 UTC.

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

Co-authored-by: Copilot App <[email protected]>
@karkarl
karkarl force-pushed the karkarl-startup-rejection-handling branch from c9c3137 to ac75809 Compare November 4, 2026 18:04
@karkarl
karkarl marked this pull request as ready for review November 4, 2026 20:34
@karkarl
karkarl merged commit c495801 into main Nov 4, 2026
25 checks passed
@karkarl
karkarl deleted the karkarl-startup-rejection-handling branch November 4, 2026 21:50
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: 🦐 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