Skip to content

refactor(gateway): centralize connect failure classification - #120505

Merged
steipete merged 7 commits into
mainfrom
steipete/connect-failure-classifier
Aug 9, 2026
Merged

steipete merged 7 commits into
mainfrom
steipete/connect-failure-classifier

Conversation

@steipete

@steipete steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Related: #120492

What Problem This Solves

Gateway connect failures were classified independently by the probe, health diagnostics, and TUI using different regular expressions over close-reason text. Modern Gateways already send structured details.code values, so the three surfaces could disagree about pairing, device identity, scope upgrades, and rejected credentials or miss the most actionable recovery command.

Why This Change Was Made

This adds one structured-first classifier to the existing gateway protocol connect-error owner and routes all three consumers through it. Probe and daemon status preserve structured connect details, the TUI classifies its existing structured request error before formatting it, and one centralized text fallback preserves older/string-only Gateway behavior.

The classifier distinguishes shared Gateway token mismatch from paired-device token mismatch: shared tokens point operators back to matching gateway.remote.token with gateway.auth.token, while device tokens show the valid openclaw devices rotate --device <deviceId> --role operator command. Pairing and scope-upgrade failures use the documented openclaw devices approve --latest preview flow.

Production LOC is +122/-32 (net +90), tests are +166/-14, and generated API metadata is +1/-1. The positive production delta is the new shared ownership boundary and its actionable remediation contract; the three local regex/policy copies and duplicated TUI help text are removed.

User Impact

CLI health/status and the TUI now agree on the class of a Gateway connect failure. Pairing, scope-upgrade, and token failures produce consistent next steps, while probe capability remains pairing_pending for the same legacy close reasons and now also recognizes structured pairing codes with generic close text.

Evidence

  • node scripts/run-vitest.mjs packages/gateway-protocol/src/connect-error-details.test.ts packages/gateway-client/src/reconnect-policy.test.ts src/gateway/probe.test.ts src/cli/daemon-cli/probe.test.ts src/commands/health.test.ts src/commands/doctor-gateway-health.test.ts src/commands/gateway-readiness.test.ts src/tui/gateway-chat.test.ts src/tui/tui.test.ts — 5 shards, 9 files, 262 tests passed.
  • OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 node scripts/check-changed.mjs — passed all core, coreTests, and generated API manifest checks locally. The normal Testbox route could not start because no remote provider was ready, so this is the documented trusted-source local fallback.
  • .agents/skills/autoreview/scripts/autoreview --mode uncommitted ... — clean; no accepted/actionable findings.

AI-assisted: yes.

@steipete
steipete marked this pull request as ready for review August 8, 2026 06:56
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime cli CLI command changes commands Command implementations size: M maintainer Maintainer-authored PR labels Aug 8, 2026
@steipete steipete closed this Aug 8, 2026
@steipete steipete reopened this Aug 8, 2026
@steipete steipete closed this Aug 8, 2026
@steipete steipete reopened this Aug 8, 2026
@clawsweeper clawsweeper Bot added 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. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Aug 8, 2026
@clawsweeper

clawsweeper Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 8, 2026, 6:46 PM ET / 22:46 UTC.

ClawSweeper review

What this changes

Centralizes Gateway connection-failure classification so probes, health checks, Doctor, and the terminal UI show consistent recovery guidance.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open. The current head resolves the prior rate-limit ordering blocker at the request owner, but the useful change is neither on current main nor shipped and this maintainer-labeled PR needs normal landing review.

Priority: P2
Reviewed head: c47df08b7f0d5247525c18c3ea2eea0c79c7bcf9

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The current head repairs the prior blocker at the owner boundary with focused transport-to-CLI regression coverage and no remaining actionable finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; it nevertheless adds a production-boundary WebSocket-to-CLI regression test.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; it nevertheless adds a production-boundary WebSocket-to-CLI regression test.
Evidence reviewed 6 items Current-main failure path: Current main can replace a pre-hello request error with the following close unless the caller opts into broadly surfacing request errors; this is the ordering fault the final PR commit addresses.
Owner-boundary repair: The PR narrowly preserves only structured AUTH_RATE_LIMITED failures before the subsequent close callback can synthesize a transport error.
Protocol and consumer contract: The protocol client preserves failed connect details, and the shared classifier prefers those structured codes over legacy close-reason text before consumers project safe facts.
Findings None None.
Security None None.

How this fits together

Gateway clients receive structured connection failures and pass them to status probes, CLI diagnostics, Doctor, and the terminal UI. The shared protocol classifier converts those facts into safe, actionable operator outcomes.

flowchart LR
  Gateway[Gateway connect response] --> Client[Gateway client]
  Client --> Details[Structured failure details]
  Details --> Classifier[Shared failure classifier]
  Classifier --> Probe[Status probe]
  Classifier --> Diagnostics[Health and Doctor]
  Classifier --> TUI[Terminal UI guidance]
Loading

Before merge

  • Resolve merge risk (P1) - The optional daemon-status failure field and auth-diagnostic semantics are compatibility-sensitive; preserve the allowlisted projection and typed-versus-close ordering through the final exact-head check.
  • Resolve merge risk (P1) - The branch is behind main, so final merge-queue or rebased-head validation is still required; GitHub reports it cleanly mergeable, and no three-way-merge regression was identified.
  • Complete next step (P2) - No bounded repair remains; use the normal maintainer landing path after exact-head validation.
Agent review details

Security

None.

PR surface

Source +264, Tests +803. Total +1067 across 22 files.

View PR surface stats
Area Files Added Removed Net
Source 11 311 47 +264
Tests 11 817 14 +803
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 22 1128 61 +1067

Review metrics

Metric Value Why it matters
Production versus test LOC production +90 net; tests +152 net The production growth is justified by moving duplicated classification and remediation policy to one protocol owner while adding boundary regression coverage.

Stored data model

Persistent data-model change detected: migration/backfill/repair: packages/gateway-protocol/src/connect-error-details.test.ts, migration/backfill/repair: packages/gateway-protocol/src/connect-error-details.ts, migration/backfill/repair: src/cli/daemon-cli/probe.test.ts, migration/backfill/repair: src/commands/doctor-gateway-health.test.ts, migration/backfill/repair: src/commands/doctor-gateway-health.ts, migration/backfill/repair: src/flows/doctor-core-checks.runtime.test.ts, and 6 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Validate the final merged head (recommended)
    Rebase or use the merge queue, then retain the WebSocket-to-Health regression while confirming the additive status shape and rate-limit outcome on the exact head.
  2. Accept the reviewed compatibility boundary
    Land with the documented additive status field and corrected rate-limit guidance if maintainers accept those public diagnostic semantics.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Rebase or use the merge queue, then run exact-head Gateway Health process coverage and required checks.

Technical review

Best possible solution:

Land the shared protocol classifier with the request-owner rate-limit preservation intact after exact-head validation confirms the additive status projection and Health-process regression.

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

Yes—source establishes the pre-hello request-error-then-close ordering, and the added isolated WebSocket-to-Health CLI regression provides a high-confidence reproduction path; it was not executed during this read-only review.

Is this the best way to solve the issue?

Yes. The protocol classifier and request owner are the narrowest shared boundaries, replacing independent consumer regexes while retaining a constrained legacy text fallback.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against cdaea2d6b67c.

Labels

Label justifications:

  • P2: This is a bounded reliability repair for inconsistent Gateway diagnostics rather than an emergency runtime outage.
  • merge-risk: 🚨 compatibility: The PR adds an optional daemon-status diagnostic field consumed by CLI-facing status paths.
  • merge-risk: 🚨 auth-provider: It changes how typed Gateway authentication lockouts are surfaced and remediated.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; it nevertheless adds a production-boundary WebSocket-to-CLI regression test.

Evidence

What I checked:

  • Current-main failure path: Current main can replace a pre-hello request error with the following close unless the caller opts into broadly surfacing request errors; this is the ordering fault the final PR commit addresses. (src/gateway/call.ts:1121, cdaea2d6b67c)
  • Owner-boundary repair: The PR narrowly preserves only structured AUTH_RATE_LIMITED failures before the subsequent close callback can synthesize a transport error. (src/gateway/call.ts:1135, c47df08b7f0d)
  • Protocol and consumer contract: The protocol client preserves failed connect details, and the shared classifier prefers those structured codes over legacy close-reason text before consumers project safe facts. (packages/gateway-protocol/src/connect-error-details.ts:494, c47df08b7f0d)
  • Production-boundary regression coverage: The added isolated WebSocket Gateway rejects connect with AUTH_RATE_LIMITED, closes afterward, and exercises the real Health CLI path while asserting the typed diagnostic and no credential-remediation leakage. (src/cli/gateway-backed-exit.process.test.ts:339, c47df08b7f0d)
  • Current-head validation: The PR body reports 262 focused tests and changed-check success; supplied CI context shows Gateway quality, build, guard, lint, and type checks passing. (c47df08b7f0d)
  • Main and release provenance: The PR head is not contained in current main or the latest release v2026.7.1-2, so this remains useful unshipped work rather than an implemented-on-main close. (c47df08b7f0d)

Likely related people:

  • steipete: Feature-history sampling spans the protocol, Gateway call, probe, and TUI surfaces; this person also carried the current classifier series. (role: recent Gateway-area contributor; confidence: high; commits: c47df08b7f0d, 2d087f01a0cc; files: packages/gateway-protocol/src/connect-error-details.ts, src/gateway/call.ts, src/gateway/probe.ts)
  • vincentkoc: History sampling identifies recurring work across the Gateway call, probe, protocol, and TUI surfaces. (role: adjacent current-history contributor; confidence: medium; files: src/gateway/call.ts, src/gateway/probe.ts, packages/gateway-protocol/src/connect-error-details.ts)

Rank-up moves

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

  • Run required validation on the exact merge-queue or rebased head.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (5 earlier review cycles)
  • reviewed 2026-08-08T09:40:03.415Z sha 1b7f848 :: needs changes before merge. :: [P1] Keep raw connect details out of JSON status | [P1] Preserve remote auth context in pairing recovery
  • reviewed 2026-08-08T10:44:32.381Z sha 6aff416 :: found issues before merge. :: [P1] Classify the close reason when the error message is generic
  • reviewed 2026-08-08T14:42:27.956Z sha 5be8a54 :: needs changes before merge. :: [P2] Preserve the rate-limit outcome in health diagnostics
  • reviewed 2026-08-08T16:45:39.183Z sha ab129ca :: found issues before merge. :: [P2] Preserve rate-limit details through the Health request path
  • reviewed 2026-08-08T16:53:09.482Z sha ab129ca :: found issues before merge. :: [P2] Preserve rate-limit details through the Health request path

@steipete
steipete force-pushed the steipete/connect-failure-classifier branch from 1b7f848 to 6aff416 Compare August 8, 2026 10:28
@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Aug 8, 2026
@steipete steipete self-assigned this Aug 8, 2026
@steipete
steipete force-pushed the steipete/connect-failure-classifier branch from 6aff416 to d6dba12 Compare August 8, 2026 14:12
@openclaw-barnacle openclaw-barnacle Bot added size: L and removed docs Improvements or additions to documentation size: M labels Aug 8, 2026
@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Aug 8, 2026
@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@steipete
steipete force-pushed the steipete/connect-failure-classifier branch from ab129ca to c47df08 Compare August 8, 2026 22:02
@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 8, 2026
@steipete
steipete merged commit c8cd98c into main Aug 9, 2026
131 checks passed
@steipete
steipete deleted the steipete/connect-failure-classifier branch August 9, 2026 01:34
@steipete

steipete commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 9, 2026
…w#120505)

* refactor(gateway): centralize connect failure classification

* fix(gateway): project connect failure into status JSON

* fix(protocol): restore remote-auth context in pairing remediation

* fix(gateway): classify generic probe failures by close reason

* fix(gateway): keep transport closes unreachable

* fix(gateway): preserve rate-limit diagnostics

* fix(gateway): preserve typed rate-limit failures
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui cli CLI command changes commands Command implementations gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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