Skip to content

feat(diagnostics): attribute Code Mode GC storms to reasons and runs - #172945

Merged
steipete merged 5 commits into
mainfrom
steipete/perf-micro-gc-reason-attribution-20260919
Oct 15, 2026
Merged

steipete merged 5 commits into
mainfrom
steipete/perf-micro-gc-reason-attribution-20260919

Conversation

@steipete

@steipete steipete commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Code Mode GC storms can occur with a small live heap, but the GC histogram omits Node's callback flags and cannot correlate a busy slot with its current run.

User Impact

Operators gain bounded GC reasons per thread/slot and a rate-limited warning identifying the active worker/cell and isolate memory counters, supplying evidence for a later causal fix.

Why This Change Was Made

The native GC observer carries a fixed reason label: none, six named Node flags, or other for combinations/unknown values. SDK diagnostic ingress bounds it once. openclaw_gc_duration_seconds retains thread/slot attribution, including its _count series. These are Node callback flags, not V8's complete internal collection cause.

The existing Code Mode observer emits a snapshot after a window of at least 10 seconds exceeds 600 major collections/minute, at most once per worker/minute. It uses the existing memory port, including while parked or warm; the main-thread registry supplies the authoritative reusable slot. Warnings carry generated Code Mode run ID, session-key hash, cell counts, bounded bridge methods, heap/external/arrayBuffers counters, and V8 heap limit. Completed cells clear run attribution; parked cells retain it. Attribution describes the cell at callback delivery, not necessarily the cause of every collection in the window.

No guest source, arguments, results, or raw session keys are logged. No configuration, schema, retention, execution-policy, or near-limit fatal-guard change. This explicitly requested observability requires +136 production lines (166 added, 30 removed) for the telemetry contract, warning window, and correlation plumbing. It adds no competing GC or worker owner.

Evidence

Before: no reason dimension or per-run storm warning. After: deterministic VM-cell/memory-port proof warns for 101 majors/10 seconds, suppresses another warning within the minute, clears completed attribution, and ignores incremental-only collections and exactly 600 majors/minute. No speedup or memory reduction is claimed; no production benchmark or deployment was performed. The real storm reason and representative guest workload remain unknown.

Focused tests passed: GC observer/transport 6 tests; Prometheus event-loop 9; Code Mode lifecycle 15; new GC storm regression 1. Wrapper-source closure passed 3 tests. The transport-accounting regression fails before the fix (0 instead of 2 unknown-size messages) and passes afterward. File-scoped formatting/lint and git diff --check pass. No full local validation or Testbox/Crabbox leases. The first lint wrapper attempted declaration preparation and was stopped; its task-owned lock was removed after process exit.

Independent subagent review (autoreview route unavailable): clean. The helper rejected the requested provider/operator-configuration mismatch; configuration was not changed. Each substantive follow-up was independently reviewed. CI/review findings fixed here: remove the extra logging dependency that broke wrapper closure; explain three closed test mocks; count storm messages on the existing memory transport.

Exact-head CI and inherited failures

Current head: 1b4afc31a09941fde11f04e5b2159d1fd5f8028c. CI run 38719828237, tested merge d7c3029bab01e093d748862ab81378d1dc303bbb into main parent 129049bbc3a5dbcc6b83bbabf5703e1d847d714a.

The following failures have matching baseline evidence; none is claimed fixed:

Failing job/case Baseline evidence
UI 1: session-management.sidebar.e2e.test.ts, both personal-pin cases, expected 4 child rows to be 0 at line 137 Same cases and signature on scheduled main job 116305821390, main 47b0a1cc734cbfc5dd7fc40548bd5c8ec6bdac87.
UI 2: session-management.promotion.e2e.test.ts, native-pointer nested promotion, child-row visibility timeout at line 35 Same case and signature on scheduled main job 116305821502.
UI 8: chat-pull-requests.e2e.test.ts:167, expected #103469, received openclaw/openclaw#103469 Main change e8eef4f656d0 (#172836) changed the renderer without updating this expectation. Exact earlier CI base 86380bba721a2719434d701f2badfaf629fda87c and tested merge 6f25763a5d10e04d3a3ebfa93ae44bf462017a49 both fail identically (42.06s / 40.10s; 1 failed, 11 skipped). Entire UI diff is empty.
Node compact-large-4: session-row-projection.worker-read.test.ts:361, replacement shared-state bytes while agent-row preparation is pending; promise resolves undefined instead of rejecting Exact current CI base 129049bbc3a5dbcc6b83bbabf5703e1d847d714a and tested merge d7c3029bab01e093d748862ab81378d1dc303bbb both fail the same case, 1 failed / 15 passed each (21.56s / 21.26s Vitest; 39.97s / 39.28s wrappers). Test and relevant projection owners have an empty diff.

Paired reproductions used isolated synthetic Team sandboxes, Node 24.19.0, scoped CPUs/memory and low priority, own HOME/OPENCLAW_HOME/TMPDIR, and high loopback ports. The projection proof used eight CPUs and an 8192 MiB heap. Only failing files/cases and their required preparation ran. All sandboxes were removed and remaining process counts verified zero. No CI rerun was requested.

Earlier CI findings and remaining uncertainty

An earlier head failed Bun runtime.retention.test.ts recovery-bundled cjs/mjs weak-reference assertions. Exact earlier base 86380bba... and PR head 9598548b... passed 5/5 single-file runs each, 15/15 cases per run, on pinned Bun 1.4.3-canary.1+65d94e715 and Node 24.19.0. Its bundled recovery path executes unchanged PluginInstance/module-loader/cache code and no changed behavioral branch, satisfying the standing unrelated-flake criterion. The defect remains unidentified; current-head CI determines admission.

The preceding head also failed the first local turn of skill-library-worker-wire.e2e.test.ts with agent.wait status error. Exact CI base 9abed103... and merge 98eab362... each passed 5/5 single-file replays (50.20–53.35s / 49.82–54.51s), and newer scheduled main passed. Those passing replays do not establish inheritance or a fix because generic changed worker transport code is on the fixture's path.

The assertion now includes its synthetic marker and complete agent.wait response so a recurrence exposes the previously hidden error. RPC arguments, timeouts, ordering, and required status: "ok" are unchanged. That diagnostic improvement passed once on the exact earlier merge plus patch using CI's Node version, eight CPUs, and 8192 MiB heap: 1/1 passed, 69.18s. It is not presented as a causal repair. No test expectations, retries, or timeouts were weakened.

Final CI: all planned jobs completed on the current head. The only failing test jobs are the four attributed entries above; the aggregate gate reports those failures. The worker E2E job passed, including skill-library-worker-wire.e2e.test.ts (1/1, 99.95s), so the earlier unexplained error did not recur. Its diagnostic change is not claimed to have fixed the underlying failure. Current-head security checks and independent review are clean. Landing uses the operator-authorized inherited-failure exception; CI is not described as green. A PR-context check caught changed template headings during the evidence rewrite; the required headings are restored without a code change or CI rerun.

@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 08:31
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Oct 15, 2026
@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-15T10:26:32.843732Z 1b4afc3 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.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 15, 2026
@clawsweeper

clawsweeper Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR adds bounded GC callback-reason labels and rate-limited Code Mode storm warnings with worker and run attribution.

Example: A parked Code Mode cell records 101 major collections over 10 seconds.

  • Before: Operators see slot-level GC counts without callback reasons or current-run correlation.
  • After: The histogram includes a bounded reason label, and a storm warning identifies the worker, run, hashed session, pending bridge methods, and memory counters.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, coherently owned observability with controlled integration coverage, a confirmed CI repair, and a small transport-accounting omission.
Proof confidence 🦐 gold shrimp (3/6) The ordinary contributor-proof gate does not apply to this maintainer-authored change; supplied evidence exercises the production VM and real memory port with injected GC samples, without claiming native workload or deployed Gateway verification.
Patch quality 🦐 gold shrimp (3/6) 2 actionable review findings remain.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: Operators cannot distinguish GC callback flags or correlate a busy Code Mode isolate with its active run when heap occupancy is modest.
Reason: The maintainer-authored direction fills a concrete diagnostic gap while preserving bounded labels, existing execution behavior, and worker ownership.

Merge readiness

⛔ Needs changes before merge - 2 items remain

Keep open: this PR adds useful, maintainer-directed diagnostics that current main lacks, with two focused repairs needed for CI and transport accounting.

Priority: P2
Reviewed head: 29de66152d5a977e1ea99afedf44b49e0ea9aee9

Before merge

  • Make the new mock factories pass the export-preservation check (P2) - The three new first-party mocks at lines 19, 25, and 30 neither preserve real exports nor declare their intentional isolation. scripts/check-test-mock-exports.mts rejects precisely these factory shapes, and exact-head CI reports mock-exports failed. Preserve exports where appropriate, or add a specific isolation rationale for fixtures that must exclude real initialization; do not expand the baseline.
  • Count storm messages in the worker transport totals (P3) - Every new gcStorm message returns before recordWorkerMessage. These messages cross the private memory port directly, so the Worker message hooks do not count them elsewhere. Consequently openclaw_worker_messages_total undercounts memory traffic whenever a storm warning is emitted. Record the crossing before returning, using the existing unknown-size accounting if no byte estimate is supplied.

Findings

  • [P2] Make the new mock factories pass the export-preservation check — src/agents/code-mode-node.gc.test.ts:19-24
  • [P3] Count storm messages in the worker transport totals — src/infra/worker-cpu.ts:376-380

Tests

  • Missing end-to-end proof: No shipped Gateway run demonstrates native storm warnings and exported reason labels; the supplied VM-and-port test injects GC samples.
Agent review details

How this fits together

Native GC observers feed the existing worker memory transport and diagnostics event owner; Prometheus exports bounded labels, while the worker registry attaches physical-worker identity to storm logs.

flowchart LR
  A[Native GC observer] --> B[Code Mode worker]
  A --> C[Diagnostics events]
  B --> D[Worker memory port]
  D --> E[Worker registry]
  E --> C
  E --> F[Storm warning log]
  C --> G[Prometheus exporter]
Loading

Technical review

Best possible solution:

Keep the existing observer, transport, and registry ownership while fixing the new mock factories and counting storm-message crossings.

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

Source inspection establishes the omitted transport accounting and rejected mock-factory shapes, and exact-head CI confirms the mock-exports failure; no target code was executed.

Is this the best way to solve the issue?

The existing observer and memory-port path are appropriate owners for this observability addition, with no need for another sampler, registry, configuration option, or execution-policy change.

Full review comments:

  • [P2] Make the new mock factories pass the export-preservation check — src/agents/code-mode-node.gc.test.ts:19-24
    The three new first-party mocks at lines 19, 25, and 30 neither preserve real exports nor declare their intentional isolation. scripts/check-test-mock-exports.mts rejects precisely these factory shapes, and exact-head CI reports mock-exports failed. Preserve exports where appropriate, or add a specific isolation rationale for fixtures that must exclude real initialization; do not expand the baseline.
    Confidence: 0.99
  • [P3] Count storm messages in the worker transport totals — src/infra/worker-cpu.ts:376-380
    Every new gcStorm message returns before recordWorkerMessage. These messages cross the private memory port directly, so the Worker message hooks do not count them elsewhere. Consequently openclaw_worker_messages_total undercounts memory traffic whenever a storm warning is emitted. Record the crossing before returning, using the existing unknown-size accounting if no byte estimate is supplied.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Native GC attribution and SDK normalization keeps the original intent (95e3daf: Expose native collection kinds and worker attribution through one shared observer, bounding SDK labels at ingress.)
  • Worker memory transport keeps the original intent (9ed9c2c: Batch GC observations with existing memory replies while preserving individual samples and bounded buffering.)
  • Physical worker slots keeps the original intent (960eacc: Keep reusable metric slots under the physical-worker registry until native exit.)
  • Code Mode GC-pressure guard keeps the original intent (289b2bb: Stop sustained near-limit major collections even when each collection is cheap.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm check:test-mock-exports --base a065e6a
  • node scripts/run-vitest.mjs src/agents/code-mode-node.gc.test.ts --maxWorkers=1
  • node scripts/run-vitest.mjs src/logging/diagnostic-gc.test.ts --maxWorkers=1
  • git diff --check

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 95e3daf adds src/infra/gc-observer.ts:8 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 95e3dafc0040; files: src/infra/gc-observer.ts)

PR surface

Source +135, Tests +220, Docs +24. Total +379 across 18 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 13 165 30 +135
Tests 3 250 30 +220
Docs 2 27 3 +24
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 18 442 63 +379

Review metrics

Metric Value Why it matters
Production versus test growth Production +135 net lines; tests +220 net lines Production growth carries the bounded telemetry contract and correlation metadata; tests cover native flags, ingress normalization, exporter output, and storm lifecycle behavior.

Labels

Label changes:

  • add P2: Useful operator diagnostics with a focused CI blocker and a low-impact accounting defect; no urgent runtime failure is established.
  • add merge-risk: 🚨 compatibility: Public diagnostic and executor types gain optional fields, and the Prometheus histogram gains a label; the maintainer-authored direction documents aggregation and omitted-field behavior.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: Useful operator diagnostics with a focused CI blocker and a low-impact accounting defect; no urgent runtime failure is established.
  • merge-risk: 🚨 compatibility: Public diagnostic and executor types gain optional fields, and the Prometheus histogram gains a label; the maintainer-authored direction documents aggregation and omitted-field behavior.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • 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, 5:01 AM ET / 09:01 UTC.

@steipete
steipete merged commit 138e763 into main Oct 15, 2026
165 of 174 checks passed
@steipete
steipete deleted the steipete/perf-micro-gc-reason-attribution-20260919 branch October 15, 2026 11:04
@steipete

Copy link
Copy Markdown
Contributor Author

Merged reviewed head 1b4afc31a09941fde11f04e5b2159d1fd5f8028c as 138e7632abd5bae9c15aa9b2c48ada2d2b93b498 using the operator-authorized inherited-failure exception and a pinned squash request. CI was not green: run 38719828237 completed with four attributed failing jobs and the downstream aggregate gate. Current-head security checks, PR context, and independent review passed.

  • session-management.sidebar.e2e.test.ts: both pin cases fail with 4 child rows instead of 0, matching main job 116305821390.
  • session-management.promotion.e2e.test.ts: the nested-conversation pointer promotion has the same child-row visibility timeout as main job 116305821502.
  • chat-pull-requests.e2e.test.ts: repository-qualified PR text conflicts with the old expectation. Exact earlier CI base 86380bba721a2719434d701f2badfaf629fda87c and tested merge 6f25763a5d10e04d3a3ebfa93ae44bf462017a49 both failed identically; the UI diff is empty.
  • session-row-projection.worker-read.test.ts: the pending read resolves undefined after the fixture swaps databases. Exact current CI base 129049bbc3a5dbcc6b83bbabf5703e1d847d714a and tested merge d7c3029bab01e093d748862ab81378d1dc303bbb both fail the same assertion, with 15 other tests passing (21.56s / 21.26s). The test and projection owners are unchanged.

The worker E2E shard passed on the merged head, including skill-library-worker-wire.e2e.test.ts (99.95s). Its earlier opaque error remains unexplained; improved assertion diagnostics are not claimed as a causal fix. No CI reruns were requested. All isolated synthetic proof sandboxes were removed. This change supplies GC evidence; it claims no performance improvement and does not deploy or repair the underlying storm.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 16, 2026
…penclaw#172945)

* feat(diagnostics): attribute Code Mode GC storms to reasons and runs

* fix(diagnostics): keep storm logging within the existing wrapper closure

* test(diagnostics): explain GC storm fixture isolation

* fix(diagnostics): count GC storm memory-port messages

* test(qa): include run errors in skill-library failures
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 extensions: diagnostics-prometheus gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L 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