Skip to content

perf(gateway): remove global async hooks from stall monitoring - #172531

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-micro-r122-churn-sites-20260919
Oct 14, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-micro-r122-churn-sites-20260919

Conversation

@steipete

@steipete steipete commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Always-on stall attribution installs process-wide async hooks, allocating and timing every promise continuation even though this work serves only diagnostics.

User Impact

Reduces Gateway main-thread allocation. Explicit synchronous task labels, bounded stall warnings, event-loop health sampling, and the CPU flight recorder remain. Async continuations no longer inherit task labels. Accepted tradeoff: during healthy idle windows the native histogram is disabled, so an unscoped stall that finishes before the next sampling deadline can go unreported; explicit task stalls and overdue idle wakes remain observable. Documentation now states this limitation.

Why This Change Was Made

Remove the async hook and its AsyncLocalStorage/promise-finally bookkeeping. The existing event-loop sampler remains the owner of best-effort unscoped detection. Production code delta: -22 lines across the monitor and sampler.

Evidence

On an isolated Linux benchmark sandbox (Node 26.8.2), five rounds of 100,000 named async tasks, each with one awaited continuation:

Median per operation Before After
Sampled allocated MB 0.003236 0.000807
Time per 100,000 operations 160.26 ms 26.67 ms

Allocation sampling includes objects collected by major and minor GC (32 KiB interval). This isolates monitor overhead, not end-to-end Gateway RPC allocation; no production data or services were used. A follow-up real sessions.list sidebar comparison used fresh synthetic fixtures with 5,000 sessions, 6,000 retained runs, 15,000 participants, 200 pending approvals, 100 cron jobs, and 12 projects; agent DB 235,978,752 bytes. Five rounds of 1,000 requests for 200 sidebar rows, one client: median allocation 2.8324 → 2.8153 MB/RPC; main-thread CPU 3.4653 → 3.4427 ms/RPC; wall time 3.9488 → 3.8148 ms/RPC; GC 0.1454 → 0.1392 ms/RPC. This is an effectively neutral end-to-end result, not the large isolated-workload gain. An initial 100-request pilot had higher head CPU; the longer matching comparison did not reproduce that regression. This fixture matches metadata counts, not production database/page-cache pressure.

Both production variants built successfully using pnpm build:runtime in the sandbox. Benchmark source at 08a98eb is production-identical to the subsequent test-only correction.

Focused local proof: node scripts/run-vitest.mjs src/infra/main-thread-stall.test.ts src/gateway/server/event-loop-health.test.ts --maxWorkers=1 passed 26 tests in 28.91 s including cold compiler preparation (test bodies approximately 0.13 s). Changed-file oxfmt, focused repository lint, and diff whitespace checks passed. Broad validation belongs to PR CI; no Testbox/Crabbox lease used. An initial ordinary lint invocation entered artifact preparation and was stopped; the supported focused lint path passed.

Independent subagent review (autoreview route unavailable): no remaining actionable P2+ findings. Reviewer identified the idle detection gap; it is explicitly accepted and documented above.

CI follow-up: the first run failed src/gateway/server-channels.test.ts because it still expected the retired global async hook to record a later callback. The correction removes that obsolete observation and Bun-only skip while preserving the startup/logging assertions. That single file passed all 91 tests locally (36.59 s wrapper, 33.14 s Vitest including cold compilation), with focused lint/format and independent review clean. No CI rerun was dispatched; the corrective commit receives normal PR CI.

A second CI run exposed the same retired-hook assumption in src/gateway/server-http.event-loop-health.test.ts. Its synthetic clock jump now supplies native histogram delay, preserving the actual HTTP readiness flow and the assertion that repeated readiness reads do not consume a pending sample. The obsolete async-task warning assertion and Bun-only skip were removed. The single test passed locally (12.60 s wrapper, 213 ms test body); focused lint/format and independent review passed. Production code and benchmark results are unchanged.

@steipete
steipete marked this pull request as ready for review October 14, 2026 20:43
@clawsweeper

clawsweeper Bot commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper reviews are opt-in for maintainers. If a review is required, finish the work and validation first, then comment @clawsweeper review. Please avoid repeated requests while a review is queued or running; agents should not request reviews automatically.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 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-14T21:15:57.493642Z afdf182 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 gateway Gateway runtime size: S labels Oct 14, 2026
@steipete
steipete merged commit eaa6938 into main Oct 14, 2026
132 of 133 checks passed
@steipete
steipete deleted the steipete/perf-micro-r122-churn-sites-20260919 branch October 14, 2026 21:27
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 15, 2026
…law#172531)

* perf(gateway): remove global async hooks from stall monitoring

* test(gateway): retire asynchronous stall capture expectation

* test(gateway): feed native delay into HTTP health fixture
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant