Repository navigation
feat(diagnostics): capture Code Mode worker GC storms - #173306
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review in progressClawSweeper is reviewing this revision. This supersedes any previous blocked status. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
| signal: new AbortController().signal, | ||
| hasAuthority: () => true, |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
💡 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".
| } else if (source.memoryPort === port) { | ||
| port.postMessage({ captureGcProfile: storm }); |
There was a problem hiding this comment.
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 👍 / 👎.
* feat(diagnostics): capture Code Mode worker GC storms * fix(build): isolate standalone worker compatibility bindings
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_eventsis 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=1passed (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.