Skip to content

fix(test): retain Gateway setup owners through authentication - #138037

Merged
steipete merged 1 commit into
mainfrom
steipete/gateway-auth-acquisition-final
Sep 4, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/gateway-auth-acquisition-final

Conversation

@steipete

@steipete steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Related: #137982 (landed raw WebSocket opening ownership) and #137924 (shared acquisition helpers). Fixture registration/accounting remains owned by the separate active lifetime work in #136146; this PR does not modify that checkout, its ownServer work, or server.e2e-ws-harness.ts.

Additional instructions

Keep Allow edits from maintainers enabled so maintainers can update this branch.

What Problem This Solves

Resolves a problem where Gateway test setup could return an unauthenticated or failed socket, lose a newly started server when client setup rejected, or restore process selectors while required shutdown had failed. Transport errors during awaited authentication preparation could also be replaced by later preparation errors, and a cleanup failure could hide the original setup failure.

Why This Change Was Made

Keep opening and the complete awaited authentication callback inside the existing WebSocket acquisition owner, with a fresh failure check before authentication and before handoff; this removes the separate shared-auth observer without racing away preparation work. A single private server/client acquisition flow now joins failed setup cleanup before restoring its token selector, while the GatewayClient-based E2E wrapper preserves setup and cleanup errors and restores exactly the selectors it changed only after successful close.

The E2E wrapper now captures its existing OPENCLAW_CONFIG_PATH mutation as well. This adds no configuration key or production seam. Raw socket close-event joining and GatewayClient's existing bounded shutdown contract remain distinct. All opening, nonce, RPC, and cleanup budgets remain unchanged.

User Impact

No production-runtime or user-facing API/configuration change. Test setup failures become deterministic: unreturned resources remain owned through cleanup, the original transport/setup error stays visible, and a failed cleanup does not falsely release the test environment. A failed client on a borrowed server never shuts that server down.

Evidence

The existing native HTTP/WebSocket peer is extended rather than copied into another test file. Coverage includes authenticated rejection, a coalesced hello plus malformed frame, a native error during held preparation, startup failure, construction/open/authentication failure with successful or rejected server cleanup, and returned-server selector ownership.

  • Before: run_ee2faf2d0d56, based on f113b70b285b223eb3346715d7167f37aa2d4c62, observed 14 intended failures and 13 passing controls. The identical repaired suite passed 27/27 in run_262cd5705693.
  • Final landed-parent proof: run_94ec1cc79662, based on immutable a550b3f7a1c3611c574f3c073ef2268de74b1a23, passed 29 acquisition cases plus 22 real Gateway caller tests, with no selected cases skipped. The two extra cases are the already-landed raw-opening regressions, preserved during composition.
  • The 46.4-second runtime build passed, with existing third-party direct-eval warnings from Playwright/web-tree-sitter. Fresh Codex P0 autoreview is scoped-clean. The complete changed-file gate pinned to the landed parent also passed in that VM, including all selected typechecks, lint, dead-export scans, and guards; the final Gateway process census was empty.

Exact application commands ran only in the credential-free physical VM:

node scripts/run-vitest.mjs src/gateway/test-helpers.acquisition.test.ts --reporter=verbose --reporter=json --outputFile=.artifacts/auth-a550.json
pnpm build qaRuntime
node scripts/run-vitest.mjs src/gateway/test-helpers.server-env.test.ts src/gateway/server.device-scope-upgrade.test.ts src/gateway/server.shared-token-hot-reload.test.ts --reporter=verbose --reporter=json --outputFile=.artifacts/auth-a550-native.json
node scripts/check-changed.mjs --base a550b3f7a1c3611c574f3c073ef2268de74b1a23 -- src/gateway/test-helpers.acquisition.test.ts src/gateway/test-helpers.server.ts src/gateway/shared-auth.test-helpers.ts src/gateway/test-helpers.e2e.ts test/helpers/gateway-websocket.ts

Proof used fresh VMs with no instance role, auth hydration, Tailnet, or shared cache volumes. The canonical bootstrap verified native IMDS returned 404 for IAM credentials and checked the immutable base. Exact hashes of all five changed files were verified; all application state was synthetic and VM-owned. One superseded composed run was stopped during synchronization and is not counted as proof.

LOC: production runtime 0; test support +89/-74 (net +15); tests +288/-16 (net +272). Total +377/-90 (net +287), five files. The small support increase adds missing authentication/composite rollback ownership while deleting duplicated observers. No changelog, dependency, lockfile, schema, or protocol-version changes.

Keep the complete awaited authentication callback inside the shared WebSocket acquisition owner. Roll back newly acquired servers before restoring selectors, preserve setup and cleanup errors independently, and capture the E2E helper config-path mutation. Extend native failure-boundary coverage without changing production runtime or timeout budgets. Builds on #137982 and #137924; fixture lifetime accounting remains with #136146.
@steipete steipete self-assigned this Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M maintainer Maintainer-authored PR labels Sep 4, 2026
@steipete
steipete marked this pull request as ready for review September 4, 2026 07:39
@steipete
steipete requested a review from a team as a code owner September 4, 2026 07:39
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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. labels Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 4, 2026, 3:50 AM ET / 07:50 UTC.

ClawSweeper review

What this changes

Gateway test helpers retain sockets through authentication, clean up newly started servers when setup fails, and restore test environment selectors only after successful shutdown.

Merge readiness

⛔ Blocked before merge - 4 items remain

This remains a useful, distinct follow-up to the merged acquisition fixes. No introduced correctness defect was found; direct dependency-contract inspection remains incomplete.

Priority: P3
Reviewed head: e14828e59f8c54291cc56c5074d032171b945c97

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused ownership repair with meaningful boundary regressions and no identified blocking code defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-authored test-helper change is exempt from contributor proof. The captured body reports native ws fault injection through the changed acquisition owners and passing real Gateway callers; linked VM artifacts were unavailable to this reviewer.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored test-helper change is exempt from contributor proof. The captured body reports native ws fault injection through the changed acquisition owners and passing real Gateway callers; linked VM artifacts were unavailable to this reviewer.
Evidence reviewed 11 items Pinned introduction and merge result: The introduced change contains only the five identified test/test-support files. The test merge has the pinned main and PR head as its recorded parents, and its versions of those files match the reviewed head.
Current main still has the setup gap: Current main awaits connectOk after acquiring the server/client pair, without rollback if authentication rejects. Its shared WebSocket acquisition helper also ends ownership after opening.
Socket acquisition boundary: The shared owner retains error observation across the complete authentication callback, checks failure before handoff, and joins socket cleanup through the existing error-aggregation helper.
Findings None None.
Security None None.

How this fits together

Gateway test fixtures create servers and authenticated WebSocket clients for integration tests. Their acquisition helpers must either return usable resources or finish cleanup before releasing the fixture’s environment.

flowchart TD
  A[Test fixture] --> B[Open socket]
  B --> C[Await authentication]
  C --> D[Return acquired resources]
  B -->|Failure| E[Join socket cleanup]
  C -->|Failure| E
  E -->|Borrowed server| H[Report setup and cleanup errors]
  E -->|Newly owned server| F[Close server]
  F -->|Success| G[Restore test selectors]
  G --> H
  F -->|Failure| H
Loading

Before merge

  • Resolve merge risk (P1) - Direct ws 8.21.3 contract inspection remains incomplete because dependency source was unavailable; linked native-run artifacts also could not be retrieved.
  • Resolve merge risk (P1) - Required secops owner involvement for the shared-auth helper is not established by the supplied review-request event.
  • Complete next step (P2) - Complete direct ws 8.21.3 contract inspection and confirm secops owner involvement for the shared-auth test helper before landing.
  • Resolve review confidence - ClawSweeper must reach high confidence before merge readiness is known.
Agent review details

Security

None.

PR surface

Source +29, Tests +258. Total +287 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 66 37 +29
Tests 3 311 53 +258
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 377 90 +287

Review metrics

Metric Value Why it matters
Runtime versus test growth Production runtime 0; test support net +15; tests net +272 All growth belongs to fixture ownership and regression coverage; the patch adds no production seam.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep one acquisition owner through authentication and rollback, with dependency-contract verification and applicable owner involvement completed before landing.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep one acquisition owner through authentication and rollback, with dependency-contract verification and applicable owner involvement completed before landing.

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

Yes, at source level: authentication rejection after startServerWithClient leaves the acquired server without rollback on current main. The native regression suite targets this boundary; it was not rerun during this read-only review.

Is this the best way to solve the issue?

The owner-boundary design is appropriate: extending shared acquisition removes duplicate observation and avoids abandoning awaited preparation. Final confirmation remains limited by the unavailable direct ws contract inspection.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P3: This improves internal test-fixture reliability without changing production behavior or user-facing contracts.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The maintainer-authored test-helper change is exempt from contributor proof. The captured body reports native ws fault injection through the changed acquisition owners and passing real Gateway callers; linked VM artifacts were unavailable to this reviewer.

Label justifications:

  • P3: This improves internal test-fixture reliability without changing production behavior or user-facing contracts.
  • 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: The maintainer-authored test-helper change is exempt from contributor proof. The captured body reports native ws fault injection through the changed acquisition owners and passing real Gateway callers; linked VM artifacts were unavailable to this reviewer.

Evidence

What I checked:

  • Pinned introduction and merge result: The introduced change contains only the five identified test/test-support files. The test merge has the pinned main and PR head as its recorded parents, and its versions of those files match the reviewed head. (21dc77f383ff)
  • Current main still has the setup gap: Current main awaits connectOk after acquiring the server/client pair, without rollback if authentication rejects. Its shared WebSocket acquisition helper also ends ownership after opening. (src/gateway/test-helpers.server.ts:894, 0d2169fdabc4)
  • Socket acquisition boundary: The shared owner retains error observation across the complete authentication callback, checks failure before handoff, and joins socket cleanup through the existing error-aggregation helper. (test/helpers/gateway-websocket.ts:73, e14828e59f8c)
  • Composite rollback and selector ownership: The private server/client acquisition path closes the newly owned server before restoring its token selector. The E2E wrapper additionally captures its existing config-path mutation and preserves independent setup/cleanup failures. (src/gateway/test-helpers.server.ts:881, e14828e59f8c)
  • Regression coverage and captured proof: The complete acquisition suite exercises native malformed frames, held preparation, borrowed-server survival, startup rejection, and successful/rejected composite cleanup. The captured PR body reports 14 intended pre-fix failures, then 29 acquisition cases and 22 real Gateway caller tests passing in https://crabbox.openclaw.ai/portal/runs/run_94ec1cc79662. Source context identity: 3fb8e829433a4121c47ecff137dec5397f6b9214dfdec478bc494978326d8ce8. Artifact retrieval failed because the hostname could not resolve; no tests were executed during this review. (src/gateway/test-helpers.acquisition.test.ts:297, e14828e59f8c)
  • Callers and distinct sibling contracts: Server-environment tests exercise webchat acquisition and repeated E2E startup/close; device-scope and shared-token tests use the changed helpers. GatewayClient retains its separate bounded stop contract, while one-shot device authentication owns its response waiters and raw socket close. (src/gateway/test-helpers.server-env.test.ts:198, e14828e59f8c)

Likely related people:

  • Peter Steinberger: Raw commit de14dd3 adds test/helpers/gateway-websocket.ts:25 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: de14dd375040; files: test/helpers/gateway-websocket.ts)
  • openclaw/openclaw-secops: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

  • Complete direct inspection of the pinned ws error, termination, and close contract in a dependency-equipped review environment.

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.

@steipete

steipete commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Land-ready review evidence for e14828e59f8c54291cc56c5074d032171b945c97. Required exact-head CI is now green; the original unavailable audit attempts remain recorded below and are not security clearance.

The ClawSweeper review found no code/security defect and identified dependency-proof and owner-involvement gaps in its environment. Disposition:

  • Pinned dependency contract and rank-up move — completed. I directly inspected the installed [email protected] implementation: lib/websocket.js:302–307,492–503,1053–1061,1102–1125,1201–1219 and lib/receiver.js:172–199,333–343,632–640. Terminating CONNECTING emits an error before close, so an error-rejecting events.once(close) is not a sufficient close join. Default synchronous frame delivery can produce open/hello and a native error in one batch before the awaiting owner resumes. The helper retains its own error observer and checks the recorded failure before authentication and before handoff; it does not remove caller listeners or abandon the awaited preparation callback.
  • Native evidence — completed and inspected. Final credential-free AWS run run_94ec1cc79662 passed 29 acquisition cases and 22 real Gateway caller tests with no selected skips. Native JSON outputs and the five-file source manifest were downloaded and inspected, rather than relying on broker summary text. The fixture verifies coalesced malformed-frame errors occur before public settlement and preserves the exact native Error; it also covers held authentication preparation, borrowed-server survival, rejected composite cleanup and selector restoration ordering. The comparative baseline had 14 intended failures and 13 controls; the identical repaired suite passed 27/27. Exact commands are retained in the PR Evidence section. Build and the complete parent-pinned changed gate passed; third-party direct-eval build warnings remain documented. The VM was released and its final Gateway process census was empty.
  • Secops involvement — verified. The PR author/requester @steipete is an active maintainer of the listed openclaw/openclaw-secops CODEOWNERS team, verified through the live team-membership API. This establishes owner authorship/direction, not an independent approval. Live rules require openclaw/ci-gate; no independent-review rule was returned. No server-enforced requirement is bypassed.
  • Review confidence — evidence gap resolved by the checks above. No code change is needed for the review worker's missing dependency/DNS access. The fresh review's actionable items and rank-up move are addressed here; a cosmetic re-review is not requested.

CI recovery: attempt1 security-fast job100949617742 exhausted the existing 240-second budget after four npm bulk request timeouts, returning incomplete, exit2, with no clearance. That failed log is retained. After backoff, the unchanged production graph completed with no matching high-or-higher npm bulk advisories (not comprehensive upstream vulnerability clearance). Exactly the failed job was rerun: run33849751288 attempt2 is now SUCCESS, with security-fast100958704167 and required ci-gate100960875478 green on the unchanged exact head. No dependency, source, timeout or audit-policy change was made to recover CI.

Additional recovery command, run against the unchanged candidate after bounded backoff:

node scripts/pre-commit/pnpm-audit-prod.mjs --audit-level=high

Scope remains production runtime 0 LOC; test support +89/-74 (net+15); tests +288/-16 (net+272). Fixture lifetime accounting and the ownServer integration remain in the separate lifetime PR136146; this PR neither changes that work nor claims to fix it.

@steipete
steipete merged commit 20279e2 into main Sep 4, 2026
311 of 313 checks passed
@steipete
steipete deleted the steipete/gateway-auth-acquisition-final branch September 4, 2026 08:35
@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 5, 2026
…aw#138037)

Keep the complete awaited authentication callback inside the shared WebSocket acquisition owner. Roll back newly acquired servers before restoring selectors, preserve setup and cleanup errors independently, and capture the E2E helper config-path mutation. Extend native failure-boundary coverage without changing production runtime or timeout budgets. Builds on openclaw#137982 and openclaw#137924; fixture lifetime accounting remains with openclaw#136146.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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