Skip to content

fix: avoid worker OOMs in full Gateway-core test runs - #148971

Merged
steipete merged 2 commits into
mainfrom
codex/test-gateway-core-worker-lifetimes
Sep 15, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/test-gateway-core-worker-lifetimes

Conversation

@steipete

@steipete steipete commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Related: #139428

What Problem This Solves

Full Gateway-core test runs can retain stale listeners between files and exhaust worker memory before completing.

User Impact

There is no user-visible product change. Gateway-core test files get separate workers, with their databases and asynchronous resources drained before the next file runs. Per-file isolation repeats imports and can increase startup cost; no overall speedup is claimed.

Why This Change Was Made

Resetting a module graph does not retire callbacks retained by process-global database lifecycle state. Enable isolation for Gateway-core while retaining the custom runner's awaited cleanup, and move its isolated return after that cleanup. The existing nonisolated cleanup remains intact; production lifecycle ownership is unchanged.

The regression runs two real test files. The first leaves a live database and provenance listener through afterAll; the second requires the prior database and asynchronous resource to have drained and verifies that its events never reach the retired listener.

Evidence

The original shared-worker control fails on a stale notification. Isolation without the drain fails on missing database closure. The repaired runner passes both obligations, 135 runner/config tests, and 458 isolated-method tests across nine files.

Before the mechanical main refresh, the full Linux command passed all 670 selected files: 11,123 tests passed, eight existing Windows/Bun cases were skipped, and none failed. All 670 observed workers exited. Complete artifacts, source bindings, and lease cleanup were verified. Test wall time was 33 minutes 20 seconds without OOM; GNU time recorded 5.05 GiB maximum RSS for the waited command, not a summed process-tree peak. Delegated Testbox workflow owns the lease and ends during cleanup; the native test command exited zero.

Mapped checks passed after a braces-only lint correction, and fresh independent review found no actionable P0–P2 findings. Fresh required CI is pending after including #149049's already-landed thinking-route auth-fixture repair; the prior run used an older main snapshot and failed those six fixture cases. A local timing pair overlapped unrelated log retrieval and is not evidence of a speedup. The routing contract now explicitly checks isolated core workers and shared database/server/method workers while retaining common hooks and file ownership. All 176 routing/config tests, the 16 mapped checks, and independent review passed for that correction. The refresh onto main preserves both commit patches and all four runner/config postimages; new-head hosted CI must validate the refreshed dependency graph. This repair adds 198 physical test/support lines, to be deducted from the campaign when merged.

@clawsweeper

clawsweeper Bot commented Sep 15, 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 size: M maintainer Maintainer-authored PR labels Sep 15, 2026
@steipete
steipete marked this pull request as ready for review September 15, 2026 09:28
@steipete
steipete force-pushed the codex/test-gateway-core-worker-lifetimes branch from 712df62 to f7342f5 Compare September 15, 2026 12:09
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 15, 2026
@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 15, 2026, 9:20 AM ET / 13:20 UTC (Revision 2).

ClawSweeper review

What this changes

The PR gives Gateway-core tests isolated workers, preserves awaited resource cleanup, and adds coverage for database closure and stale cross-file listeners.

Merge readiness

✅ Ready for maintainer review

The repair remains useful: current main still shares Gateway-core workers and skips cleanup for isolated files. No actionable introduced defect was found, and the recorded full-run evidence supports the change.

Priority: P2
Reviewed head: 1c81ed2df73fe80c2e6d2e9a815a6c668e1c7681

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with meaningful lifecycle coverage and recorded full-run success; no actionable patch defect was found.
Proof confidence 🐚 platinum hermit (4/6) ✨ media proof bonus Sufficient (linked_artifact): The captured evidence exercises the actual Gateway-core test runner on Linux: 670 files completed without OOM and all observed workers exited, supplemented by discriminating lifecycle controls. Changed-file blobs remain identical after refresh; detailed workflow logs could not be independently downloaded under the host allowlist.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The captured evidence exercises the actual Gateway-core test runner on Linux: 670 files completed without OOM and all observed workers exited, supplemented by discriminating lifecycle controls. Changed-file blobs remain identical after refresh; detailed workflow logs could not be independently downloaded under the host allowlist.
Evidence reviewed 8 items Current main still needs the repair: Gateway-core does not enable isolation, and the shared configuration defaults to nonisolated execution. The main runner returns before resource cleanup when isolation is enabled.
Cleanup precedes isolated return: The introduced change moves the isolation return after awaited singleton cleanup while retaining the existing shared-worker cleanup below it. No production lifecycle implementation changes.
Independent lifecycle regression: The producer leaves a real database open through afterAll; the observer requires database closure and awaited resource drain, then checks that new database events never reach the retired listener. The parent verifies both files, assertions, native completion, and normal child exit.
Findings None None.
Security None None.

How this fits together

OpenClaw’s test runner executes Gateway test files and cleans up their databases, callbacks, and asynchronous resources. Worker isolation determines whether later files can inherit earlier files’ runtime state.

flowchart TD
  A[Gateway test files] --> B[Gateway-core test configuration]
  B --> C[Isolated Vitest worker]
  C --> D[Test cases and afterAll hooks]
  D --> E[Await resource cleanup]
  E --> F[Worker retirement]
  F --> G[Next file in fresh worker]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Tests +198. Total +198 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 5 204 6 +198
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 204 6 +198

Review metrics

Metric Value Why it matters
Campaign accounting Production +0; tests/support +198 net lines The added lifecycle regression is justified, and its support cost must be deducted from the linked test-reduction campaign.

Technical review

Best possible solution:

Keep Gateway-core workers isolated and drain resources through the existing lifecycle owner before retirement, preserving shared-worker policies for the other Gateway projects.

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

Yes for the lifecycle defect: the real two-file fixture exposes retained listeners and missing database cleanup, with failing controls recorded in the PR. This read-only review did not independently reproduce the full-run OOM.

Is this the best way to solve the issue?

Yes. The patch uses existing isolation and cleanup owners, preserves sibling execution policies, and avoids changing production listener lifetimes to accommodate test module resets.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 83c1767446cb.

Labels

Label justifications:

  • P2: This repairs full Gateway-core test-run reliability without changing deployed product behavior.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The captured evidence exercises the actual Gateway-core test runner on Linux: 670 files completed without OOM and all observed workers exited, supplemented by discriminating lifecycle controls. Changed-file blobs remain identical after refresh; detailed workflow logs could not be independently downloaded under the host allowlist.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured evidence exercises the actual Gateway-core test runner on Linux: 670 files completed without OOM and all observed workers exited, supplemented by discriminating lifecycle controls. Changed-file blobs remain identical after refresh; detailed workflow logs could not be independently downloaded under the host allowlist.

Evidence

What I checked:

  • Current main still needs the repair: Gateway-core does not enable isolation, and the shared configuration defaults to nonisolated execution. The main runner returns before resource cleanup when isolation is enabled. (test/vitest/vitest.gateway-core.config.ts:24, 83c1767446cb)
  • Cleanup precedes isolated return: The introduced change moves the isolation return after awaited singleton cleanup while retaining the existing shared-worker cleanup below it. No production lifecycle implementation changes. (test/non-isolated-runner.ts:447, 1c81ed2df73f)
  • Independent lifecycle regression: The producer leaves a real database open through afterAll; the observer requires database closure and awaited resource drain, then checks that new database events never reach the retired listener. The parent verifies both files, assertions, native completion, and normal child exit. (test/non-isolated-runner.gateway-lifecycle-fixtures.ts:48, 1c81ed2df73f)
  • Dependency contract confirms awaited cleanup: The runner directly extends Vitest TestRunner, establishing the dependency signal. Vitest v5.0.0 awaits onAfterRunFiles after running files; its pool reuses workers only for nonisolated tasks. The target’s existing Vitest patch preserves that isolation distinction. (packages/vitest/src/runtime/runner/run.ts:1085, f441c6fab25e)
  • Recorded full-run proof: The captured PR body reports two failing controls followed by successful repaired execution, then a Linux run completing 670 files and 11,123 passing tests without OOM, with eight existing skips and all observed workers exiting. https://github.com/openclaw/openclaw/actions/runs/34946525469 is cancelled as described for lease cleanup; GitHub reports successful cleanup steps. Detailed log download was blocked by the review host’s network allowlist, so those logs were not independently inspected.
  • Review continuity: GitHub content blob identities for all five changed files at the previously reviewed f7342f57b081b2944b5c38b8aeaccec26d57910b match the current checkout. The supplied prior review has no findings or published rank-up moves. The refreshed head therefore preserves the reviewed patch content. (test/non-isolated-runner.ts, 1c81ed2df73f)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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 (1 earlier review cycle)
  • reviewed 2026-09-15T12:28:45.631Z sha f7342f57b081b2944b5c38b8aeaccec26d57910b :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the codex/test-gateway-core-worker-lifetimes branch from f7342f5 to 1c81ed2 Compare September 15, 2026 13:07
@steipete
steipete merged commit 540450d into main Sep 15, 2026
124 of 125 checks passed
@steipete
steipete deleted the codex/test-gateway-core-worker-lifetimes branch September 15, 2026 16:38
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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