Skip to content

fix(code-mode): retire idle workers after persistent GC storms - #173577

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-storming-worker-retire-20260919
Oct 16, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-storming-worker-retire-20260919

Conversation

@steipete

@steipete steipete commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Idle Code Mode workers can continue a sustained major-GC storm far below their heap limit. The near-limit watchdog does not retire them, so they remain in the Gateway process until ordinary idle expiry.

User Impact

A persistently storming warm worker is retired with reason gc-storm, and the next cell acquires a healthy worker on demand. Active cells and parked continuations retain their worker until completion, cancellation, timeout, or existing continuation expiry. No configuration or schema changes.

Why This Change Was Made

The existing detector now sends a small control signal after two consecutive windows above 600 major collections/minute, each at least 10 seconds. Warning/profile cadence stays unchanged. The existing Code Mode pool lifecycle owns the decision: retire completed warm workers, mark other workers draining, and never return a draining worker to the warm pool. At most one worker enters draining per minute across the executor; later detector windows retry other candidates. Deferred exits can coincide when continuations settle.

This is containment, independent of the GC-observer feedback-loop repair in #173574; gc-observer.ts is unchanged. The two PRs have no overlapping files, and the replacement sampler preserves the GC sample contract consumed here. It does not establish or fix the underlying native V8 crash cause.

Evidence

  • Synthetic detector/transport measurement: one storm window sends no retirement signal; the second signals at 20,000 ms. A quiet window resets persistence. Existing warning/profile behavior is preserved.
  • Before/after regression: the two focused test files on the original production code produce 4 expected failures and 19 passes; with this change all 23 pass. Warm workers now close with gc-storm, replacement is lazy, and active/parked work survives until completion or disposal.
  • Focused local command: node scripts/run-vitest.mjs src/agents/code-mode-node.lifecycle.test.ts src/agents/code-mode-node.gc.test.ts --maxWorkers=1 — 23 passed, 22.40 s wrapper wall time (19.25 s Vitest, mostly transformation; test bodies below one second).
  • Changed-file formatting, changed-file repository lint, and git diff --check. Broad validation belongs to PR CI; no Testbox/Crabbox lease, production access, or load benchmark.
  • Independent subagent review (autoreview route unavailable): clean at P0/P1/P2. Autoreview preflight refused the requested route because it differs from operator configuration; configuration was not changed.
  • Simplification review: reused the detector, memory port, and pool cleanup owner; no additional timer, queue, manager, or compatibility path. Production LOC delta: +43. Growth implements the explicitly requested containment and work-preserving drain contract; there was no superseded retirement implementation to delete.

Related: #172945, #173306, #173382.

CI Attribution and Landing Evidence

The exact-head CI run 38827361061 has one substantive failed shard: checks-node-changed-19. Its only file, test/e2e/qa-lab/runtime/required-native-same-session.e2e.test.ts, failed with implicit-main after-agent-wait run failed before settlement; the terminal error was WorkspaceAccessUnavailableError: Remote workspace skill discovery failed, before the first native inference request. The aggregate CI gate remains red; it is not represented as passing.

The failing path is workspace skill discovery/admission. This PR changes neither that owner nor the native-workspace fixture. The test uses plain-text responses without Code Mode cells, and the failed run has no Code Mode storm signal or retirement. The new diagnostic control branch handles only that absent signal. Independent source review found no connection from the changed retirement path to this failure.

Under the operator-authorized unrelated-flake rule, ran the single failing file five times on each revision in an isolated Linux sandbox, with Node 24.19.0 matching CI, an unprivileged user, synthetic state, private loopback networking, and one Vitest worker:

node scripts/run-vitest.mjs test/e2e/qa-lab/runtime/required-native-same-session.e2e.test.ts --maxWorkers=1
Revision Results Wrapper seconds, runs 1–5
CI main parent 012bb1ccaf0b63696b2608599b1cf4ea869a4245 5/5 passed; exit 0 each 76.32, 79.05, 77.57, 77.74, 79.27
Exact PR head 5a423e8cfb9026037517bbe895140af4a4dae65b 5/5 passed; exit 0 each 95.80, 79.36, 82.92, 84.68, 75.87

CI tested merge 26853b2c6be18f35da1effc99c272645d1cecb9c, whose ordered parents are the baseline and PR head above. Each replay reported Test Files 1 passed (1) and Tests 1 passed (1). These are validation durations, not performance measurements. The matching qaRuntime build preparation passed on both revisions. Initial root-user attempts hit the fixture's explicit root-quiescence refusal and are excluded from attribution; an initial full build also exceeded an unrelated declaration-size budget by 1,272 bytes, while the required QA build profile passed.

Relevant sibling CI proof also passed: Code Mode detector 1 test, lifecycle 22, executor 15, watchdog 3, and worker CPU lifecycle 19. Production/test typechecks, lint, guards, docs, UI E2E, and security checks passed. No module, export name, or test file was added. GitHub code review and independent review found no actionable code defects; ClawSweeper's sole requested action was to establish CI attribution, covered here.

Landing classification: unrelated workspace E2E flake under the standing five-passing-runs-on-base-and-head exception. No CI rerun, branch update, or unrelated source change was used to obtain green. Native storm/V8-crash reproduction remains a stated gap; the requested containment is covered by synthetic detector transport and lifecycle regressions.

@clawsweeper

clawsweeper Bot commented Oct 16, 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.

@steipete
steipete marked this pull request as ready for review October 16, 2026 00:04
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: S labels Oct 16, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T00:07:54.494735Z 5a423e8 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Oct 16, 2026
@clawsweeper

clawsweeper Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

Retire persistently storming warm Code Mode workers and drain active workers before retirement.

Example: A completed worker records 101 major collections in each of two consecutive 10-second windows.

  • Before: Below the near-limit watchdog threshold, it remains warm until ordinary idle expiry.
  • After: When retirement admission is available, it closes with reason gc-storm and a later cell acquires a replacement.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused containment with no concrete introduced defect; synthetic boundary coverage supports limited runtime confidence.
Proof confidence 🦐 gold shrimp (3/6) The supplied maintainer-authored classification exempts ordinary contributor proof gating; evidence consists of synthetic detector/real-port coverage and mocked-pool lifecycle regressions, with reported base failures and head passes but no shipped-entry-point storm recovery.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Completed Code Mode workers can continue consuming resources in sustained major-GC storms below the existing watchdog threshold.
Reason: Maintainer-directed containment bounds retirement admission without interrupting active cells or parked continuations and adds no user configuration.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep open: this PR provides useful maintainer-directed containment absent from current main, and inspection found no concrete introduced correctness or security defect.

Priority: P2
Reviewed head: 5a423e8cfb9026037517bbe895140af4a4dae65b

Before merge

  • Complete next step - Have the CI owner resolve the shared same-session settlement failure or establish the supported inherited-failure exception before landing.

Findings

None.

Tests

  • Missing end-to-end proof: Supplied regressions show detector transport and mocked-pool lifecycle behavior, without a shipped Gateway run demonstrating native storm retirement and subsequent replacement.
Agent review details

How this fits together

The Node Code Mode worker reports GC observations through its existing memory port; the executor pool owns reuse, continuation custody, and native retirement.

flowchart LR
  A[V8 GC samples] --> B[Worker storm detector]
  B --> C[Existing memory port]
  C --> D[Code Mode pool owner]
  D --> E[Retire completed worker]
  D --> F[Drain active or parked cell]
  F --> E
  E --> G[Lazy replacement]
Loading

Technical review

Best possible solution:

Retain the bounded containment in the existing pool lifecycle alongside the separate sampler repair.

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

Current-main source permits below-limit storms to continue until idle expiry, and supplied synthetic regressions exercise that missing retirement path; the production storm itself was not reproduced.

Is this the best way to solve the issue?

The patch uses the established detector, transport, and lifecycle owner while preserving active work, making it a reasonable bounded containment measure rather than a claim to repair the underlying GC cause.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 44998b0afc07.

Provenance checked

  • Host-owned warm pool custody keeps the original intent (b2d26e4: Keep warm workers within their creating host and retain cleanup ownership until native exit.)
  • GC storm observation changes intended behavior with a stated reason (138e763: Expose sustained storm counters and run attribution for causal investigation; this PR explicitly adds bounded containment while preserving warning cadence.)
  • Retirement attribution keeps the original intent (e0f2d5d: Distinguish bounded retirement causes and count retirement only after native exit.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +43, Tests +94, Docs +7. Total +144 across 8 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 5 47 4 +43
Tests 2 95 1 +94
Docs 1 11 4 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 153 9 +144

Review metrics

Metric Value Why it matters
Production versus test LOC Production +47/-4; tests +95/-1 Production growth carries persistent detection and work-preserving drain state through existing owners; test growth covers detector transport, lazy replacement, admission limits, and continuation preservation.

Labels

Label changes:

  • add P2: Focused runtime containment limits idle worker GC churn without evidence of an urgent outage or lost work.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: Focused runtime containment limits idle worker GC churn without evidence of an urgent outage or lost work.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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 15, 2026, 8:25 PM ET / October 16, 2026, 00:25 UTC.

@steipete

Copy link
Copy Markdown
Contributor Author

CI Attribution and Landing Evidence

The exact-head CI run 38827361061 has one substantive failed shard: checks-node-changed-19. Its only file, test/e2e/qa-lab/runtime/required-native-same-session.e2e.test.ts, failed with implicit-main after-agent-wait run failed before settlement; the terminal error was WorkspaceAccessUnavailableError: Remote workspace skill discovery failed, before the first native inference request. The aggregate CI gate remains red; it is not represented as passing.

The failing path is workspace skill discovery/admission. This PR changes neither that owner nor the native-workspace fixture. The test uses plain-text responses without Code Mode cells, and the failed run has no Code Mode storm signal or retirement. The new diagnostic control branch handles only that absent signal. Independent source review found no connection from the changed retirement path to this failure.

Under the operator-authorized unrelated-flake rule, ran the single failing file five times on each revision in an isolated Linux sandbox, with Node 24.19.0 matching CI, an unprivileged user, synthetic state, private loopback networking, and one Vitest worker:

node scripts/run-vitest.mjs test/e2e/qa-lab/runtime/required-native-same-session.e2e.test.ts --maxWorkers=1
Revision Results Wrapper seconds, runs 1–5
CI main parent 012bb1ccaf0b63696b2608599b1cf4ea869a4245 5/5 passed; exit 0 each 76.32, 79.05, 77.57, 77.74, 79.27
Exact PR head 5a423e8cfb9026037517bbe895140af4a4dae65b 5/5 passed; exit 0 each 95.80, 79.36, 82.92, 84.68, 75.87

CI tested merge 26853b2c6be18f35da1effc99c272645d1cecb9c, whose ordered parents are the baseline and PR head above. Each replay reported Test Files 1 passed (1) and Tests 1 passed (1). These are validation durations, not performance measurements. The matching qaRuntime build preparation passed on both revisions. Initial root-user attempts hit the fixture's explicit root-quiescence refusal and are excluded from attribution; an initial full build also exceeded an unrelated declaration-size budget by 1,272 bytes, while the required QA build profile passed.

Relevant sibling CI proof also passed: Code Mode detector 1 test, lifecycle 22, executor 15, watchdog 3, and worker CPU lifecycle 19. Production/test typechecks, lint, guards, docs, UI E2E, and security checks passed. No module, export name, or test file was added. GitHub code review and independent review found no actionable code defects; ClawSweeper's sole requested action was to establish CI attribution, covered here.

Landing classification: unrelated workspace E2E flake under the standing five-passing-runs-on-base-and-head exception. No CI rerun, branch update, or unrelated source change was used to obtain green. Native storm/V8-crash reproduction remains a stated gap; the requested containment is covered by synthetic detector transport and lifecycle regressions.

@steipete
steipete merged commit 0cda908 into main Oct 16, 2026
233 of 239 checks passed
@steipete
steipete deleted the steipete/perf-micro-storming-worker-retire-20260919 branch October 16, 2026 00:48
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant