Skip to content

refactor(gateway): make fixture teardown wait for owned work - #157114

Merged
vincentkoc merged 8 commits into
mainfrom
refactor/gateway-test-fixture-cleanup-20260923
Nov 6, 2026
Merged

vincentkoc merged 8 commits into
mainfrom
refactor/gateway-test-fixture-cleanup-20260923

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Gateway fixtures could reset shared state while policy work or a failed WebSocket acquisition was still running. Some race checks observed a precreated resolver rather than entry into the policy recheck.

User Impact

No production behavior, configuration, migration, or user action changes. This improves the reliability of Gateway tests and their cleanup failures.

Why This Change Was Made

The auth openers and E2E harness now use the existing WebSocket acquisition helper, preserving headers, challenge nonces, connect options, and the actual hello response. Policy and acquisition scenarios release gates and join their owned work before reset. Callback errors still reach the state owner; the isolated rejected-close proof remains intact.

This replaces the original broad rewrite with five existing test/support files. Config, cron, client, agents, ControlUI, and other lifecycle work remain separate, unqualified follow-ups. Named follow-up: preserve callback-error propagation in the excluded control-ui-session-prs-staleness.test.ts and control-ui.response-authority.test.ts wrappers.

The final change adds 387 private source lines and no production lines. The native test counter counts +391 because the harness reduction is outside its filename patterns. An exact 391-line allocation covers the acquisition/error/cancellation coverage; the shared scalar baseline is unchanged.

Evidence

  • At 5bf55183, Node 26.12.1 passed all 33 acquisition cases. Targeted Oxlint and all four selected Gateway test-type graphs passed.
  • Retained unchanged-file evidence from 4131c8e9: 42 Node policy/receipt/session/harness cases and 17 pinned-Bun lifetime/cleanup helper cases passed. These are prior-head executions, giving 92 selected cases across both heads. Native processes joined normally; JSON/JUnit identities match where both reporters were used.
  • The mock-export guard passed on 4131c8e9. Its full line-budget check passed with 39 lines of headroom; the final +1 source/+1 allocation adjustment preserves that headroom arithmetically, without claiming another full counter run.
  • Independent source review found no actionable findings in the corrected scope.

Unresolved local failure: the original Bun Gateway run failed during startup error reporting with TypeError: code.charCodeAt is not a function and produced no Gateway case results. Installed Vitest/Vite source explains the reporter failure, but the masked startup cause remains unknown. The passing Node runs do not establish a Bun fix or an inherited failure. This remains recorded as an investigated failure, not green proof.

Exact-head hosted CI passed: 37 successful jobs, 29 skipped, none failed or pending. Selected guard, lint, type, test, and PostgreSQL conformance jobs passed. This does not claim a separate full execution of the three broad deadcode commands. The exact-head ClawSweeper review found no actionable findings and no before-merge blocker. Named rank-up follow-up: add a real Vitest timeout control. It is deferred because a runner-level timeout fixture is beyond this correction; current cancellation/join evidence does not constitute direct real-Vitest timeout integration. The queued remote attempt executed no tests; focused local proof was on Darwin, and no live product behavior was exercised. Final merge approval remains with Vincent.

@vincentkoc vincentkoc self-assigned this Sep 24, 2026
@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
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.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XL labels Sep 24, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 Sep 24, 2026
@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR makes Gateway test fixtures join pending policy and WebSocket acquisition work before resetting shared state.

Example: A Gateway harness connection receives HTTP 403 during WebSocket upgrade.

  • Before: The opener waits only for the open event and does not own upgrade failure through socket cleanup.
  • After: The existing acquisition helper rejects with the transport error after joining socket closure.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused test maintenance with no identified correctness defect; reported harness execution supports the change, while direct runner-timeout coverage remains limited.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored test-only PR is outside the contributor runtime-proof gate; its body reports native-peer acquisition and cleanup execution, with prior-head evidence distinguished and the Bun startup failure retained.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Test only · Worth it: Yes · Fix scope: Complete
User problem: Developers can receive misleading race-test results or leaked fixture work after a failed acquisition or canceled test.
Reason: The maintainer-directed correction improves test reliability using established owners and adds no product configuration or public contract.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR contains useful fixture-lifetime repairs that current main still lacks. No actionable introduced defect was found; exact-head CI remains pending.

Priority: P3
Reviewed head: 5bf55183e245ff7efe64583a0f929be1ef9f3e0c

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The correction has no recorded direct real-Vitest timeout integration or red-on-base execution; controlled cancellation and reported native-peer runs provide narrower evidence.
Agent review details

How this fits together

Gateway test fixtures create clients, temporary state, and held policy operations; their lifetime helpers coordinate completion and cleanup before shared observers and registries reset.

flowchart TD
 A[Test scenario] --> B[Existing fixture lifetime]
 B --> C[Policy or WebSocket acquisition]
 C --> D[Result or cancellation]
 D --> E[Release held gates]
 E --> F[Join operations and socket closure]
 F --> G[Restore state and reset observers]
Loading

Technical review

Best possible solution:

Use the existing acquisition and fixture-lifetime owners to drain held work before resetting Gateway test state.

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

Current-main source exposes the open-event-only failure path and the premature policy-state reset boundary; supplied validation reports exercise the correction, but this read-only review ran no tests.

Is this the best way to solve the issue?

The narrowed patch addresses the owning boundaries with existing helpers, removes the replaced acquisition paths, and preserves distinct transport and authority assertions without adding production machinery.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 887a8a1108ea.

Provenance checked

  • Auth WebSocket openers keeps the original intent (75e7c0d: The test-cleanup batch consolidated duplicate openers while preserving headers and nonce observation; the replacement retains those contracts and adds existing failure ownership.)
  • E2E harness failed acquisition keeps the original intent (c78d27e: Bound harness teardown and terminate failed clients so sockets cannot indefinitely block cleanup; the patch preserves this intent while joining failed socket closure.)
  • Acquisition fixture cleanup keeps the original intent (65f3ca0: Consolidate repeated fixture setup while retaining distinct cleanup contracts; the patch strengthens completion ownership in the retained native-peer suite.)
  • Policy authority and receipt assertions keeps the original intent (40a6b50: Preserve dispatch authorization and prevent attribution after runtime authority closes; the patch retains those assertions and waits for actual policy entry before closing authority.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Pinned change and unchanged checkout: The introduced diff contains only tests, test support, and a separate test-line allocation; the checkout remained clean and no target code was executed. (5bf55183e245)
  • Distinct work remains on main: Fetched main still uses open-event-only waits in the auth opener and E2E harness; the latter terminates failed acquisitions without awaiting socket closure. (src/gateway/server.e2e-ws-harness.ts:68, 887a8a1108ea)
  • Existing acquisition owner reused: The harness preserves nonce tracking, browser origin, connect options, and the returned hello while delegating failure ownership to the established acquisition helper; fix(test): retain Gateway setup owners through authentication #138037 documents that helper's authentication and rollback contract. (src/gateway/server.e2e-ws-harness.ts:69, 5bf55183e245)
  • Cleanup reaches the state owner: The acquisition fixture passes cleanup verification into the existing state owner, propagates callback failures, releases gates, and joins tracked operations before resetting observers. (src/gateway/test-helpers.acquisition.test.ts:315, 5bf55183e245)
  • Prior review and validation reconciled: The full current body records 33 acquisition cases on the reviewed head, unchanged-file policy and helper results on its parent, and targeted static checks. The earlier conflict is cleared by current mergeable=true metadata; the Bun startup-reporting failure remains explicitly unresolved rather than claimed fixed. (5bf55183e245)
  • Exact-head CI incomplete: Live check results still include running changed-test, lint, typecheck, and guard jobs; no completed failure was returned by this read. (5bf55183e245)

Likely related people:

  • Vincent Koc: Raw commit c78d27e adds src/gateway/server.e2e-ws-harness.ts:58 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: c78d27e4b3f8; files: src/gateway/server.e2e-ws-harness.ts)

PR surface

Source -4, Tests +391, Other +1. Total +388 across 6 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 6 10 -4
Tests 4 530 139 +391
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 0 +1
Total 6 537 149 +388

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus test growth Production +0/-0; tests and test support +536/-149 Growth supplies native transport, adapter, and cancellation controls while reusing existing ownership helpers.

Labels

Label changes:

  • 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.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P3: This is internal test reliability maintenance with no production behavior change or demonstrated urgent user 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.

Rank-up moves

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

  • Add a real Vitest timeout control showing the original scenario drains before shared-state reset.

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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-24T07:25:52.618Z sha 24c6fbd :: blocked before merge. :: none
  • reviewed 2026-10-08T20:33:41.989Z sha 24c6fbd :: needs changes before merge. :: none

Reviewed November 5, 2026, 5:54 AM ET / 10:54 UTC (Revision 3).

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed 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. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Oct 8, 2026
Baseline-Refresh: 8f326929873324ed4b01d0f49f7b4641f9babb59
Use canonical WebSocket acquisition and join held policy work before fixture teardown. Cover native transport errors, adapter forwarding, and failure cleanup with real owned peers. Allocate exactly 390 counted test lines; the shared scalar remains unchanged.
@vincentkoc vincentkoc changed the title refactor(gateway): make test cleanup and assertions explicit refactor(gateway): make fixture teardown wait for owned work Nov 5, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review November 5, 2026 10:48
@clawsweeper

clawsweeper Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper reviews are opt-in for maintainers. If a review is required, finish the work and validation first, then comment @clawsweeper review. Please avoid repeated requests while a review is queued or running; agents should not request reviews automatically.

@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review exact head 5bf55183e245ff7efe64583a0f929be1ef9f3e0c. The correction is limited to five existing Gateway test/support files plus its exact test-line allocation. The PR body preserves the unresolved Bun startup-reporting failure and the separate Node/helper proof.

@clawsweeper

clawsweeper Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Nov 5, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 5, 2026
@vincentkoc
vincentkoc merged commit 10951e1 into main Nov 6, 2026
240 checks passed
@vincentkoc
vincentkoc deleted the refactor/gateway-test-fixture-cleanup-20260923 branch November 6, 2026 00:59
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 6, 2026
…w#157114)

* refactor(gateway): own asynchronous test fixture cleanup

* refactor(gateway): verify prepared auth fence forwarding

* refactor(gateway): assert successful hybrid config patches

* refactor(gateway): exercise cron delivery validation

* refactor(gateway): use canonical agent mutation fixtures

* test(gateway): join acquisition and policy fixture lifetimes

Use canonical WebSocket acquisition and join held policy work before fixture teardown. Cover native transport errors, adapter forwarding, and failure cleanup with real owned peers. Allocate exactly 390 counted test lines; the shared scalar remains unchanged.

* test(gateway): fix acquisition fixture static checks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L 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