Skip to content

feat(diagnostics): capture Code Mode worker GC storms - #173306

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

steipete merged 2 commits into
mainfrom
steipete/perf-micro-code-mode-storm-capture-20260919

Conversation

@steipete

@steipete steipete commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Code Mode's high-GC warning identifies the worker and cell but cannot explain allocation churn between cells. Operators need stacks from the affected worker while the storm is happening.

User Impact

The first qualifying Node Code Mode storm automatically captures five seconds of allocation and CPU samples in that worker. Completion warnings name the local files under <state>/diagnostics/; failures report a fixed reason. No deployment, schema change, or new setting is included.

Why This Change Was Made

The existing storm detector and memory port own admission and attribution. Each worker attempts capture at most once per hour, including failed attempts. Heap sampling uses 256 KiB intervals with both collected-object flags; CPU sampling uses 10 ms intervals over the same window. The existing profile owner handles cleanup, bounds, and guest-frame redaction. Because node:trace_events is unavailable inside workers, the Gateway checks tracing before authorizing capture on the existing diagnostics port.

Only sanitized JSON crosses back to one Gateway writer. Existing private atomic-write primitives persist at most 20 storm files globally (1 MiB per result), pruning only this feature's artifacts. No profiler or capture timer runs before a storm. Profiles contain stacks/counters, not guest source, arguments, results, or heap objects. Existing main-isolate profiling RPCs remain unchanged; worker-targeted RPC support was optional and deferred.

Production/tooling LOC delta: +189 (226 added, 37 removed, excluding tests/docs). This requested diagnostics feature adds code for capture, transport, and bounded retention; it is not a speculative performance optimization. Read-only inspection found no concrete idle spin: boundary waits are message-backed Promises, cancellation uses indefinite Atomics.waitAsync, and progress/console paths have no heartbeat timer. No speculative idle-path rewrite is included.

Evidence

Before: storm warnings supplied counters and attribution only; no in-worker allocation/CPU artifacts.
After: a real Node 26 worker captured both profiles successfully in about 5.03 seconds. Heap output was 4,903 bytes (3 allocation samples); CPU output was 5,508 bytes (404 samples). Both collected-object flags were enabled. This proves capture functionality, not a speedup or the production storm's cause.

Focused local proof: node scripts/run-vitest.mjs src/logging/diagnostic-worker-gc-profile.test.ts src/agents/code-mode-node.gc.test.ts --maxWorkers=1 passed (4 tests; test bodies 0.40 s and 0.81 s, total wrapper wall time 18.83 s). It covers the warning/port boundary, hourly cooldown, main-thread tracing refusal, profiler cleanup, guest-frame redaction, concurrent writes, private file permissions, and global retention. Changed-file formatting and syntax lint pass. The regular lint wrapper unexpectedly entered artifact preparation and was stopped; broad typecheck/build/lint gates are delegated to PR CI under the operator's host limits. No Testbox/Crabbox lease was allocated.

Gaps: the live storm has not been reproduced or profiled by this change yet; deployment and a subsequent qualifying storm are required. Blocking synchronous guest work can delay timer-based stopping, and worker termination can interrupt capture. The earlier lane report files were unavailable locally; the supplied observations and current source informed the implementation. The optional existing CPU-profile regression file triggered broad worker-bundle preparation locally and was stopped; PR CI owns that proof. Independent subagent review (autoreview route unavailable): clean through P2. Autoreview refused the requested provider/config mismatch; configuration was not changed.

PR CI on the first head caught three integration defects, now repaired: the native PR wrapper inventory omitted the four newly reachable profile modules; compatibility bridging considered duplicate bindings from separately bundled state/SQLite readers; and one test mock did not preserve real exports. Compatibility candidates now derive standalone namespaces from existing build metadata; ambiguity inside the shared runtime still fails. The focused compatibility regression failed on the original matcher (2 new failures) and passed after the fix (13/13). Wrapper/eager-import closure guards passed (21 tests). The repaired profile test passed again (3/3), and changed-file formatting/syntax lint passed. Independent subagent review (autoreview route unavailable) also found no actionable issues in these repairs. PR CI provides the full build, typecheck, and suite proof.

Final PR CI evidence: run 38775483268, head 13e39b808b1238901af4dfc6fde6170414434e11: all test, build, typecheck, lint, architecture, and ratchet jobs passed. The original closure, compatibility-build, and mock-export failures are green after repair; no CI reruns or inherited-failure waiver were used.

@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 in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: M labels Oct 15, 2026
@steipete
steipete marked this pull request as ready for review October 15, 2026 16:56
@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-15T17:17:07.319366Z 13e39b8 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.

@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: 60ceb1f67e

ℹ️ 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 on lines +21 to +22
signal: new AbortController().signal,
hasAuthority: () => true,

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.

P2 Badge Bind profiling to the storming cell's lifetime

When the storming cell completes during this five-second window, releasePool makes its singleton worker available for another run immediately. Because this detached capture uses a never-aborted signal and unconditional authority, it keeps both profilers active across that release, potentially sampling a subsequent session—and imposing profiling overhead on it—while the completion warning retains the previous cell's runId and sessionKeyHash. Bind capture authority to the originating cell generation or keep the worker unavailable until capture settles.

AGENTS.md reference: src/agents/AGENTS.md:L24-L26

Useful? React with 👍 / 👎.

@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label 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: 13e39b808b

ℹ️ 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 src/infra/worker-cpu.ts
Comment on lines +414 to +415
} else if (source.memoryPort === port) {
port.postMessage({ captureGcProfile: storm });

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.

P2 Badge Keep tracing admission live until worker profiling starts

If process-wide tracing is enabled after this check and message send but before the worker executes capture.start()—which follows cross-thread scheduling, a dynamic import, package-root resolution, and profiler setup—the worker unconditionally bypasses its own tracing check via workerTracingInactive. captureDiagnosticProfile documents that an active trace writer can receive raw ProfileChunk data before sanitization, so this authorization snapshot can expose guest frame names and URLs; synchronize capture with the tracing owner or otherwise retain and revalidate tracing authority at the actual profiler start.

AGENTS.md reference: AGENTS.md:L71-L71

Useful? React with 👍 / 👎.

@steipete
steipete merged commit 6edd765 into main Oct 15, 2026
160 checks passed
@steipete
steipete deleted the steipete/perf-micro-code-mode-storm-capture-20260919 branch October 15, 2026 17:36
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 16, 2026
* feat(diagnostics): capture Code Mode worker GC storms

* fix(build): isolate standalone worker compatibility bindings
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 scripts Repository scripts size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant