Repository navigation
perf(gateway): capture main-thread stall stack samples - #169535
Conversation
Name worker, HTTP, WebSocket, RPC, scheduler, and watcher callbacks. Retain bounded coarse V8 profile windows for stalls on Node 26, with shared frame redaction and monitor-owned cleanup. Rig proof: 1500 ms unnamed callback identified; +0.66 CPU percentage points, 0.31 ms maximum rotation. Focused and sibling proof: 408 tests passed. Dead-export audit failures reproduced unchanged on main; all candidate findings are inherited.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
|
Codex review: needs maintainer review before merge. What this changesThis PR adds callback labels and trailing Node 26 CPU stack samples to Gateway stall logs. Example: An unnamed callback blocks the main thread for 1,500 ms on Node 26.
Review scores
ProductKind: Feature · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR adds useful stall diagnostics absent from current main, and no actionable patch defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe Gateway event-loop monitor combines callback timing with native CPU samples and emits sanitized diagnostic logs alongside existing health observations. flowchart TD
A[Gateway callbacks] --> B[Task attribution]
C[Native V8 samples] --> D[Rotating recorder]
B --> E[Event loop monitor]
D --> E
E --> F[Sanitized stall logs]
Technical reviewBest possible solution: Retain the monitor-owned recorder, existing callback attribution owner, and shared frame-redaction policy. Do we have a high-confidence way to reproduce the issue? Current main can emit unattributed stall warnings without retained stack samples, and the supplied native probe demonstrates the requested diagnostic capability. Is this the best way to solve the issue? The implementation fits the existing monitoring boundary, preserves dispatch decisions, and explains why rotating capped recordings replace neither callback attribution nor on-demand profiling. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 16d913005f97. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +192, Tests +166, Docs +18. Total +376 across 17 files. Added test files: 1. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed October 11, 2026, 11:04 PM ET / October 12, 2026, 03:04 UTC (Revision 2). |
|
Merged at the reviewed head CI run https://github.com/openclaw/openclaw/actions/runs/38195006595 failed only the existing Independent review found no actionable issues. Rig proof passed 408 tests, the final format/lint checks, and the type checks. The separate global dead-export audit was also qualified against unchanged main: all 84 candidate findings are inherited, with none in the changed files. The native merge wrapper refused its stale local Native capture identified the unnamed 1.5-second stall in 142 of 146 samples. Measured recording overhead was +0.66 CPU percentage points, with 0.31 ms maximum rotation and 3.6 ms capture/summary. No production Gateway was changed or restarted. |
Name worker, HTTP, WebSocket, RPC, scheduler, and watcher callbacks. Retain bounded coarse V8 profile windows for stalls on Node 26, with shared frame redaction and monitor-owned cleanup. Rig proof: 1500 ms unnamed callback identified; +0.66 CPU percentage points, 0.31 ms maximum rotation. Focused and sibling proof: 408 tests passed. Dead-export audit failures reproduced unchanged on main; all candidate findings are inherited.
What Problem This Solves
Main-thread stalls longer than one second can report
task=unattributedwith no stack evidence, making intermittent stalls difficult to investigate after they end.User Impact
Operators get code-owned callback labels and, on Node 26, a bounded trailing CPU sample window naming the top inclusive frames. This does not change request handling or configuration. Node 24 and Bun retain callback attribution; their native profiling APIs do not provide the bounded coarse-sampling contract used here. The next normal Gateway deployment enables recording; no live Gateway was changed for this work.
Why This Change Was Made
The event-loop monitor owns recording and cleanup. It samples at 10 ms and rotates five-second native profiles, starting the next before stopping the previous so V8 keeps its sampler and code map alive. A single capped profile is insufficient: V8 discards new samples after its cap. Two bounded retained windows feed one sanitized diagnostic line when a stall occurs. That line explicitly represents a trailing window, because several callbacks can finish before the monitor drains its records.
Callback labels reuse the existing main-thread task owner at worker/control-port and SQLite reply decoding, HTTP/WebSocket/RPC dispatch, scheduler wakes, and config/skills watcher boundaries. Dependency-native work can remain unlabelled; the recorder provides stack evidence when V8 can symbolize it.
Production LOC: +192. The requested recorder is new diagnostic capability, with native lifecycle, bounded retention, redaction, and aggregation contracts. Existing attribution and frame-redaction owners are reused; there is no superseded recorder implementation to remove. No schema, persistent state, new dependency, or configuration option was added.
Evidence
Independent review: clean after correcting an initial finding about associating a batch's trailing samples with an individual callback.
Linux rig, Node 26.8.1, three alternating eight-second baseline/recording pairs with 5 ms of synchronous work per 20 ms tick: mean process CPU 25.24% → 25.89% (+0.66 percentage points of one core; +2.6% relative to this 25% load). Maximum initial start 64.5 ms; maximum rotation 0.31 ms.
An unlabelled
setImmediatecallback blocked for 1,500.14 ms. The recorder namedsyntheticUnnamedStallin 142 of 146 samples; serializing and summarizing took 3.6 ms and emitted 436 bytes. This used the real native V8 profiler and the production recorder. An initial run exposed V8's numeric script IDs; the adapter and regression fixture now reflect the native format.Validation on the approved Linux rig: 408 tests across 27 files passed; one Windows-only test/file was skipped. Focused recorder/core/logging: 106 tests (70.42s wrapper); siblings: 167 tests (182.77s); export-collision guard passed; closure/PR-wrapper/test-plan guards: 135 tests (161.81s). The new recorder file executes in 37ms; the existing HTTP case with the new assertion executes in 716ms. Cold type/worker compilation accounts for the longer wrapper times.
Regression negative control: the HTTP test fails on the original handler at the new task-label assertion, then the patched source is restored and all 17 file hashes match.
The staged gate passed all type checks (core 78.07s, core-test shards 2640.05s) and failed only at the repository-wide dead-export audit. Re-running that exact audit on unchanged current
main(656287c940a5287da9efe69aabde2348695e07e1) also fails: all 84 candidate findings are present in the baseline; zero findings involve this diff. The completion run uses the existingOPENCLAW_CHECK_CHANGED_SKIP_DEADCODE=1switch for that verified inherited audit. After a mechanicaltoSorted()lint fix, the owning changed-file format/lint plan passed (0 warnings/errors across 16 linted files), and all six recorder tests passed again. All remaining staged-gate checks are satisfied. No production Gateway was touched.Remote setup attempts: Blacksmith Testbox
tbx_01m4phcw069kxj7sw7765cm0vkfailed source sync; AWScbx_ff8718722459lost workspace ownership during tests; Hetznercbx_b5b3a9b1a2efreached verified source but lacked pnpm on its bare image. All leases were stopped. The approved rig supplied the completed proof.CI on exact head
1b4f4adf1a1129b16edc426d9590d41e6edadd09failed onlyeager-import-closure.test.tsbecause the existing wrapper inventory duplicatessrc/chat/sender-identity.ts,src/sessions/input-provenance.ts, andsrc/sessions/user-turn-transcript.metadata.ts. Unchanged main parentd8d441f71b3c56639044912d3c55dca0768c48b2reproduces the same failure (16 tests passed, 1 failed, 31.94s wall). The inventory and test are unchanged in the actual CI baseline053dbe94df70aef67aa4e7c790933f8742869b35; the tested merge is4ab369168208e18a7c730c81e5896a306b2d83a8. The successful fail-fast monitor cancelled sibling CI jobs; those cancellations are not claimed as passing coverage. Run: https://github.com/openclaw/openclaw/actions/runs/38195006595 . No CI rerun requested.