Skip to content

fix(code-mode): distinguish worker retirement causes - #173382

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-code-mode-retirement-reasons-20260919
Oct 15, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-code-mode-retirement-reasons-20260919

Conversation

@steipete

@steipete steipete commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Code Mode worker churn was grouped under closed, hiding whether warm workers were evicted, expired, explicitly disposed, or shut down with their host.

User Impact

Operators can attribute Code Mode starts and retirements through existing Prometheus lifecycle counters and diagnostic stability logs. No execution, cache-capacity, configuration, schema, or persistence changes.

Why This Change Was Made

The pool owner now supplies bounded close reasons (eviction, idle-expiry, dispose, shutdown, and existing rotation/memory_pressure). Native Code Mode errors are attributed as crash or gc-thrash before generic failure cleanup. The existing lifecycle owner preserves the first cause and counts retirement only after native exit. Starts retain their script label; a newly started worker has no retirement cause.

Current main already retains four warm workers, expires surplus workers after 30 seconds, and keeps one for five minutes. This change first makes that policy measurable rather than increasing the retained set.

Evidence

  • Focused local tests: src/infra/worker-cpu.test.ts (19 passed) and src/agents/code-mode-node.lifecycle.test.ts (19 passed); 58.34 seconds wrapper wall time. Final lifecycle rerun after review fix: 19 passed, 46.70 seconds wrapper wall time. Test execution itself was under one second per file; source transformation dominated.
  • Formatting, changed-file lint, and git diff --check passed. Exact-head CI completed successfully on 9dfde4f1642e208471a82f6ae139c3c8cffa86cf; 80 checks passed and the required CI gate was green. The earlier run was superseded by the documentation correction; no CI reruns or inherited-failure exception were needed. No Testbox/Crabbox lease allocated under the current validation policy.
  • Independent subagent review (autoreview route unavailable): clean after fixing active runtime replacement attribution to rotation. Autoreview preflight rejected the requested provider route because it differed from operator configuration; no configuration was changed.
  • Dedicated Linux sandbox, Node 26.8.2, source-loaded real Code Mode executor and workers, synthetic 109-tool catalog, 512 MiB worker limit, one real resource host and scheduler with an accelerated clock. No production data or Gateway used. Measured baseline: 4668b290d506e508ae0ab1263fc9077e0e8fd3db; measured implementation: 6fc86f350b6fe084b518854f96641e74b5971753. Final head 9dfde4f1642e208471a82f6ae139c3c8cffa86cf only aligns the canonical Prometheus and troubleshooting docs after hosted review; runtime bytes are unchanged. That documentation follow-up received a clean independent review and passed formatting and diff checks.
Workload Before After
Mixed cadence: 3,385 cells over one simulated hour, serial traffic plus sixteen eight-cell bursts 68 starts/hour 68 starts/hour
Mixed cadence: one remaining worker after 30 quiet seconds 24.52 MiB heap 25.88 MiB heap
Ten eight-cell bursts, 15-second gaps (three fresh processes each) 44 starts in every run 44 starts in every run
Same burst workload: one remaining worker after 30 quiet seconds 26.51–33.43 MiB heap 25.62–32.49 MiB heap
Ten eight-cell bursts, 35-second gaps 71 starts 71 starts

The observed result is neutral: identical startup counts and retained worker counts, with overlapping idle-heap ranges. These are accelerated synthetic cadence rates, not production starts/hour or RSS measurements. Source-loader overhead contributes to absolute heap sizes. Full Gateway load and production cadence distribution were not reproduced.

The 15-second case now reports 40 eviction, 3 idle-expiry, and 1 shutdown; the 35-second case reports 40 eviction, 30 idle-expiry, and 1 shutdown, replacing undifferentiated closed counts. No extra counters or log pipeline were introduced.

A sandbox-only MRU candidate reused and protected the most recently active worker. It raised mixed-workload starts from 68 to 113/hour (+66%) while still retaining one worker after quiet time, so it was rejected and is absent from this PR. Keep the existing four-worker/30-second-surplus policy; no memory-neutral startup improvement was established.

  • Production delta: +27 lines. This is requested lifecycle attribution, not a performance fast path: the growth supplies the bounded reason contract and carries owner decisions to existing counters without adding a second registry, sampler, or cache.

The error-attribution tests inject native error events; actual out-of-memory and GC-watchdog execution remain covered by existing executor tests in PR CI.

Carry bounded owner reasons into lifecycle diagnostics, preserve native crash and GC-thrash attribution before cleanup, and count only confirmed exits. Keep the current four-worker warm-cache policy unchanged.
@clawsweeper

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

@steipete
steipete marked this pull request as ready for review October 15, 2026 18:21
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 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-15T18:39:04.179825Z 9dfde4f New commits
ℹ️ 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: S labels Oct 15, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6fc86f350b

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread docs/tools/code-mode/executors.md Resolved
@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Oct 15, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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 Oct 15, 2026
@clawsweeper

clawsweeper Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR distinguishes Code Mode worker retirement causes in existing lifecycle counters and documents the resulting metric labels.

Example: Six Code Mode cells complete concurrently under one resource host.

  • Before: The two workers exceeding the four-worker warm limit retire with reason closed.
  • After: Those two confirmed exits increment retirement counters with reason eviction.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused attribution with no identified blocking defect; evidence reaches real workers through a source-loaded harness, and some added assertions remain coupled to mocked calls.
Proof confidence 🦐 gold shrimp (3/6) The maintainer-authored exemption applies; supplied Linux sandbox results exercise real Code Mode executor workers and report the new retirement counts, while native-error attribution uses injected events and the shipped Gateway exporter is not exercised.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Operators cannot distinguish ordinary warm-worker retirement from shutdown, native crashes, or GC-watchdog retirement in lifecycle diagnostics.
Reason: The feature-history owner supplied the direction, and the narrow implementation makes existing counters useful without altering the accepted memory and latency tradeoff.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it adds useful worker-lifecycle attribution that current main lacks, preserves the existing retirement policy, and introduces no identified blocking defect.

Priority: P3
Reviewed head: 9dfde4f1642e208471a82f6ae139c3c8cffa86cf

Before merge

None.

Findings

None.

Tests

  • Low-value test src/agents/code-mode-node.lifecycle.test.ts: Remove the added mocked close-argument assertions in favor of observable lifecycle-counter coverage; they pin internal call shapes while the pool itself is replaced by a mock.
  • Missing end-to-end proof: The supplied sandbox results do not exercise exported reason labels through a shipped Gateway, and no base-fails/head-passes run is shown for the new attribution assertions.
Agent review details

How this fits together

Code Mode submits JavaScript cells to Node worker pools; pool owners select retirement causes, and the existing worker registry publishes confirmed exits to diagnostic snapshots and Prometheus.

flowchart LR
  A[Code Mode cells] --> B[Node executor]
  B --> C[Worker task pool]
  C --> D[Native worker lifetime]
  C --> E[Lifecycle registry]
  D --> E
  E --> F[Diagnostics and Prometheus]
Loading

Technical review

Best possible solution:

Retain this focused attribution change through the existing lifecycle owner while preserving worker retention, cancellation, and native-exit semantics.

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

Current-main source shows Code Mode retirement paths calling close without a specific cause, while the generic pool records closed; no target code was executed during this review.

Is this the best way to solve the issue?

The change is appropriately placed: existing pool owners supply causes, the existing registry preserves first-cause attribution, and confirmed native exit remains the counting boundary.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 9b12483b9065.

Provenance checked

  • Code Mode warm-worker policy and host cleanup keeps the original intent (perf(code-mode): retire surplus idle workers after bursts #173317: Retire surplus completed workers after 30 seconds while retaining one for five minutes and preserving host custody.)
  • Worker lifecycle first-cause and confirmed-exit accounting keeps the original intent (d61bf61: Expose bounded worker churn counters through the existing resource registry, counting confirmed native exits without duplicate retirement counts.)
  • Shared worker-pool close attribution keeps the original intent (0bc061b: The worker-runtime extraction retained the existing scheduler and lifecycle contracts; this PR keeps closed as the default while allowing the caller to supply a more specific cause.)
  • Native Code Mode failure attribution changes intended behavior with a stated reason (fix(code-mode): expose bridge causes and correct exec input failures #170947: Native failures previously used generic failure attribution while preserving their underlying cause; this PR explicitly explains distinguishing crash and gc-thrash before generic cleanup.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Pinned introduction: The verified merge-base-to-head diff adds bounded retirement reasons, forwards them through the existing pool, and updates diagnostics documentation without changing worker capacity or deadlines. (src/agents/code-mode-node.ts:213, 9dfde4f1642e)
  • Existing lifecycle ownership preserved: The registry preserves the first retirement cause and increments retirement counts only when forgetting an exited worker; the new native-error hook records crash or gc-thrash before generic cleanup. (src/infra/worker-cpu.ts:256, 9dfde4f1642e)
  • Current-main necessity: The affected runtime files on fetched main retain the merge-base behavior, including generic close attribution; this PR's diagnostic distinction is still absent. (packages/worker-runtime/src/worker-task-pool-core.ts:313, 9b12483b9065)
  • Supplied behavioral evidence: The full PR body reports real executor workers in an isolated Linux sandbox: identical startup counts before and after, with the 15-second burst case producing 40 eviction, 3 idle-expiry, and 1 shutdown retirements; native-error attribution uses injected events. (6fc86f350b6f)
  • Documentation feedback addressed: The earlier review requested canonical retirement-reason documentation; the final head updates both the Prometheus reference and troubleshooting guidance, with runtime bytes unchanged from the measured implementation. Public docs: docs/gateway/prometheus.md. (docs/gateway/prometheus.md:598, 9dfde4f1642e)
  • Public API compatibility: WorkerTaskPool is exported through plugin-sdk/process-runtime; its new close argument is optional, and omitting it retains the existing closed reason and cleanup behavior. (src/infra/worker-task-pool.ts:49, 9dfde4f1642e)

PR surface

Source +27, Tests +43, Docs +19. Total +89 across 10 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 5 51 24 +27
Tests 2 44 1 +43
Docs 3 23 4 +19
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 118 29 +89

Review metrics

Metric Value Why it matters
Public API addition 1 optional parameter WorkerTaskPool.close gains an optional retirement reason through its existing SDK export; existing calls retain their default behavior.

Labels

Label changes:

  • add P3: This improves diagnostic attribution without changing execution behavior or resolving an urgent runtime failure.
  • add merge-risk: 🚨 compatibility: The PR extends an SDK-exported method and changes observable metric reason values; the maintainer-authored direction documents those labels, and the optional argument preserves existing callers.
  • 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.

Label justifications:

  • P3: This improves diagnostic attribution without changing execution behavior or resolving an urgent runtime failure.
  • merge-risk: 🚨 compatibility: The PR extends an SDK-exported method and changes observable metric reason values; the maintainer-authored direction documents those labels, and the optional argument preserves existing callers.
  • 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.

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, 2:49 PM ET / 18:49 UTC.

@steipete
steipete merged commit e0f2d5d into main Oct 15, 2026
152 of 155 checks passed
@steipete
steipete deleted the steipete/perf-micro-code-mode-retirement-reasons-20260919 branch October 15, 2026 18:56
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 16, 2026
* fix(code-mode): distinguish worker retirement causes

Carry bounded owner reasons into lifecycle diagnostics, preserve native crash and GC-thrash attribution before cleanup, and count only confirmed exits. Keep the current four-worker warm-cache policy unchanged.

* docs(code-mode): align retirement metric references
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 gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S 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