Repository navigation
perf(process): sample quiet exec trees less frequently - #182452
Conversation
|
🦞👀 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 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. |
|
Codex review: needs maintainer review before merge. What this changesThis PR samples quiet Linux exec process trees every five seconds, returning to one-second sampling after discovering descendants or observing higher memory usage. Example: A Linux command tree uses 192 MiB against a 768 MiB memory bound.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored optimization addresses a verified source of repeated work, and the pinned diff introduces no discrete correctness defect. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe process supervisor supplies an owned command-tree root and memory bound to the watchdog; Linux procfs supplies descendant identities, RSS, and swap, and an over-limit sample requests existing supervisor cancellation. flowchart TD
A[Gateway exec] --> B[Process supervisor]
B --> C[Per-tree memory watchdog]
D[Linux procfs] --> C
C --> E[Adaptive sampling interval]
E --> C
C --> F[Supervisor cancellation and diagnostic]
Technical reviewBest possible solution: Keep adaptive scheduling inside the existing per-tree watchdog, preserving its accounting, independent cancellation, and documented sampled-protection limits. Do we have a high-confidence way to reproduce the issue? Current-main source establishes a fresh procfs traversal after each one-second timer for every watched tree; this read-only review did not independently reproduce the reported allocation magnitude. Is this the best way to solve the issue? The smallest complete change is to reuse the reader's existing PID set and select the next interval in the existing watcher, which this diff does without a shared scheduler, parser replacement, or competing owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d5872069d833. Provenance checked
TestingProof path: unit tests only. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +9, Tests +75, Docs 0, Other +459. Total +543 across 6 files. Added test files: 0. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 Reviewed October 24, 2026, 5:07 AM ET / 09:07 UTC. |
Keep RSS plus private swap, all-thread descendants, and visible memory-limit termination. Share a nonoverlapping sampler and parse procfs numbers without per-file scratch buffers or strings.
Parse procfs Buffers without decoded strings or regex allocations. Keep one shared sampler detached from execution async context. FileHandle promise I/O increased sampled allocation by 218%, so retain the native readFile round trip.
Keep one nonoverlapping shared tick while allowing per-read Buffer owners to progress independently. Preserve cancellation and independent memory limits when another tree read is blocked.
Keep independent per-tree readers and timers. Sample stable trees below half their RSS-plus-swap cap every five seconds, returning to one second for newly discovered descendants, higher usage, or read errors. This explicitly accepts approximately six-second fast-runaway detection from a quiet tree; measurements gate landing.
8dbc029 to
6a2caa0
Compare
|
Merged under the requested v5.6 decision and the standing unrelated-flake exception, pinned to reviewed head Allocation fell 78% and CPU 72%; GC +2.7 ms/min absolute = context under v5.6. Three real phase-aligned runaway trials crossed the synthetic cap within 123–141 ms and exited via SIGKILL in 5.028–5.031 s. Worst observed kill latency: 5.031 s, within the accepted approximately six-second bound. Exact-head CI run 40082138260 remains red only for Merge commit: |
* perf(exec): reuse procfs storage across memory watches Keep RSS plus private swap, all-thread descendants, and visible memory-limit termination. Share a nonoverlapping sampler and parse procfs numbers without per-file scratch buffers or strings. * test(exec): time runaway kills from allocation request * perf(process): preserve native procfs read fast path Parse procfs Buffers without decoded strings or regex allocations. Keep one shared sampler detached from execution async context. FileHandle promise I/O increased sampled allocation by 218%, so retain the native readFile round trip. * perf(process): parse procfs bytes without an async wrapper * perf(process): sample independent exec trees concurrently Keep one nonoverlapping shared tick while allowing per-read Buffer owners to progress independently. Preserve cancellation and independent memory limits when another tree read is blocked. * perf(process): sample quiet exec trees less frequently Keep independent per-tree readers and timers. Sample stable trees below half their RSS-plus-swap cap every five seconds, returning to one second for newly discovered descendants, higher usage, or read errors. This explicitly accepts approximately six-second fast-runaway detection from a quiet tree; measurements gate landing. * test(process): prove adaptive sampler runaway latency
Decision: land under v5.6
Reopened for landing under the lead’s v5.6 decision. This is the requested interval-only follow-up to #182234. Allocation falls 78% and CPU 72%; GC +2.7 ms/min absolute = context under v5.6. Phase-aligned runaway proof passed: worst observed kill latency 5.031 seconds across three trials. The rebased head is landing under the standing unrelated-flake exception: the single failed CI file passed five Linux replays on both baseline and head, and its failing path cannot reach the changed watcher. CI is not claimed green.
What Problem This Solves
The existing Linux exec watchdog scans every thread and descendant in every command tree each second. The motivating pre-change live signal was 79.68 MiB allocated over 30 seconds in this path.
The proposed change retains the original independent per-tree watcher, reader, parser, Linux-only behavior, RSS plus private swap, all-thread descendant discovery, and visible memory-limit failure. After a completed sample below half the cap, an unchanged tree waits five seconds; newly discovered descendants or usage at/above half the cap restore one second. Errors retry after one second. No shared tick, Buffer reuse, new production reader, configuration, or cache.
Runtime production delta: +9 lines (17 added, 8 removed). The retained PID set is needed to detect new descendants. Separately, regression tests add 75 lines and reproducible measurement/proof scripts add 459 lines.
This explicitly accepts approximately six-second detection/kill latency for a fast runaway from a previously quiet tree. The real-procfs phase-aligned proof passed all three trials below; the worst observed kill latency was 5.031 seconds, within the accepted approximately six-second bound, including sampling overhead. This is a sampled watchdog, not a hard real-time deadline under arbitrary host stalls.
Measurement
Original measurement head:
8dbc029534f28d7750cfa2fd70cfd34df1c53227. Runtime source SHA-256:ef71af869b5d1834053117139e924ce256b0033c55b0d68219109320c7f12a21. Baseline source SHA-256:8bf757074b77b4748d728a1b82fcd7e095fabbb053479df9af08314e8c77cda3, identical to the four preserved controls.Same committed workload and helper bytes, Node 26.12.1 and dependencies, prepared synthetic fixtures, 20 watched trees with two worker-thread-spawned descendants each, five-second warmup, synchronized future start, 60-second captures, counterbalanced launch order, swapped interleaved CPUs in one exclusive slot. Guard unchanged; low CPU/IO priority; MemoryMax 24G and MemorySwapMax 0. Allocation sampling, untraced timing, and traced promotion use separate passes.
The original v5.4 acceptance rule was recorded before any new result: reject at >=20% adverse paired mean or >=10% in both pairs; a mixed-sign/unstable metric gets one predeclared extra pair and a signed absolute mean decision against 20% of mean baseline cost. GC/promotion/max-pause rejection requires matched same-mode controls. No trimming, after-the-fact maintenance exclusions, or normalization by major-cycle count.
GC decision: original pairs were 5.39174→4.75683 ms (−11.78%) and 6.14154→6.65344 ms (+8.33%). Their mixed signs triggered the predeclared third pair: 6.26371→14.49040 ms (+131.34%). The three-pair signed absolute mean is +2.70122 ms/60 s, or +45.53% of the 5.93233 ms baseline mean. The lead subsequently classified this absolute increase as context under v5.6, reversing the initial rejection. The third candidate capture includes a 9.00921 ms incremental GC, retained in full. No untraced max-pause safeguard tripped. GC +2.7 ms/min absolute = context under v5.6: compared with the lead-reported production main-isolate GC of 1,000–3,000 ms/min, this is approximately 0.09–0.27% (order 0.1%). All observations remain reported unchanged.
Stable allocation/CPU/loop/promotion metrics retain their original two-pair decisions. Third-pair CPU was 1,255.175→176.296 ms and is retained as context, rather than changing the original CPU comparison.
Untraced post-capture 20-tree runaway request-to-root-exit times were baseline 122 / 1,023 / 1,011 ms, candidate 4,076 / 4,002 / 5,032 ms; all emitted the visible memory-limit diagnostic. These are three observations per side, not tail percentiles or phase-aligned worst-case proof.
Phase-aligned runaway proof
On the rebased source, a real tree with two worker-thread-spawned descendants began at approximately 202.5 MiB RSS plus swap, below half its synthetic 768 MiB cap. A leaf started with zero burst allocation, then touched a 768 MiB Buffer immediately after the watcher armed its real five-second timer. The proof observes and forwards timers unchanged; no fake clock or watcher override is used. Independent procfs observation verifies cap crossing, and the watcher’s ordinary limit callback kills the process group.
All trials emitted
Command killed for exceeding its host memory bound, observed approximately 905 MiB at enforcement, and exited with SIGKILL. Worst observed latency: 5.031 seconds; accepted bound: approximately six seconds. These are three phase-aligned observations, not tail percentiles. The synthetic cap avoids allocating the approximately 45 GiB production cap while exercising the same interval and protection path. Guarded exclusive slot B, interleaved CPUs, Node 26.12.1, MemoryMax 24G, MemorySwapMax 0; no guard interruptions or exclusions.Reproduction:
node scripts/perf/child-memory-adaptive-runaway.ts --owner <compiled-child-memory-module> --output <result.json>on Linux. The measured module was generated from the unchanged committed TypeScript with Node’sstripTypeScriptTypes; source SHA-256 is recorded above.Retained traced context: trace pair 1 recorded GC maxima of 7,469.05→6,615.30 ms (baseline/candidate) and totals of 7,498.83→6,621.04 ms. Both captures remain included; the guard did not abort. Traced timing is ineligible for the GC/max-pause gate under the predeclared rule. Promotion improved in both traced pairs (−53.14%, −47.18%), so no promotion-rejection calibration was needed.
Calibration and complete observations
Four same-workload untraced A/A controls were explicitly reused before new candidate results. Source, helper/fixture/benchmark bytes, runtime/dependencies, warmup, start barrier, duration, CPU placement/launch-order protocol, scopes and guard match. Their two swapped-block GC means were +14.67% and +10.16%; neither reached 20% mean or 10% adverse in both constituent pairs. No max-pause safeguard tripped. The original calibrated relative increase remains reported; v5.6 classifies its absolute cost as context.
Every capture: per-kind GC, tail sample counts, both maxima, and CPU
GC-kind cells are
count / total ms / p95 ms / p99 ms; incremental cells arecount / total ms / max ms. All GC tail counts are below 200, so those percentiles are context. Major counts are also below 50. Loop p99 counts are shown next to each value and exceed 1,000. Only untraced timing gates.All seven completed pairs are valid and retained, including four full allocation profiles. No capture was guard-aborted, trimmed, or excluded. One earlier setup attempt failed before fixture readiness/capture because the restored diagnostics import closure was incomplete. Its logs are preserved separately; the complete capsule passed import-only preflight before retry. No capture overlaps the predeclared production-restart exclusion window.
Evidence
43/43 focused sampler/supervisor tests and 22/22 source-closure tests passed. The adaptive regression cases failed on the original source at their intended quiet-cadence assertions. Process tests took 0.411 s; closure tests 51.70 s; combined wrapper 54.47 s. Core typecheck, changed-file lint/format, export-collision and diff checks passed.
Exact-head CI and aggregate PR gates passed on
8dbc029534f28d7750cfa2fd70cfd34df1c53227. Independent subagent review (autoreview route unavailable) is clean after correcting two type issues. The configured helper refused its provider selector at startup; no provider configuration was changed. The prior review remains applicable because the rebase changed none of the six PR files. Current rebased head:6a2caa039412cf580b5f7aaf6931d9c0dd91c871; Rebased exact-head CI completed with one failing test file:src/agents/bash-tools.exec-launch-policy.integration.test.ts, two authority-retirement cases reportingservice child cleanup identity lost: write EPIPE. This is classified as an unrelated relay-cleanup flake under the standing five-pass rule; see evidence below. All other selected test, lint, type and source-closure jobs passed; PR-context headings were corrected and its check now passes.Exact-head CI exception and attribution
CI run 40082138260, head
6a2caa039412cf580b5f7aaf6931d9c0dd91c871, has one actual failing job: checks-node-changed-3. Its two failing cases arestill rejects retired source authority after native launchwithPTY=false, retained false/true, insrc/agents/bash-tools.exec-launch-policy.integration.test.ts. Both reportservice child cleanup identity lost: write EPIPE; the aggregate CI gate fails downstream. All other selected jobs passed. Exact-head CI is red; landing uses the explicitly authorized unrelated-flake exception, not a green-CI claim.The single failing file was replayed on Linux with the unchanged baseline sampler and this PR’s sampler, identical other source/dependencies, pinned Bun
1.4.4-canary.1+ef37c31de, one worker. Both sides passed 5/5 runs, 11/11 tests each (55/55 each), all exit code 0. Baseline wrapper durations: 68.00/39.27/33.66/34.80/35.22 seconds; head: 77.38/43.49/65.20/58.39/48.34 seconds. Node launcher was 26.12.1 versus CI’s 24.22.1; the Bun test runtime was the same. Baseline source hash8bf75707…and headef71af86…match the measured sources. No CI rerun was requested.Command:
OPENCLAW_VITEST_RUNTIME=bun OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/agents/bash-tools.exec-launch-policy.integration.test.ts --maxWorkers=1.Causal source check: source-authority revocation rejects readiness at
service-child-relay-host.ts:643; its catch stops the owner and rethrows.supervisor.ts:555–561propagates that rejection beforewatchChildMemoryat line 604. Therefore no changed watcher code executes in either failing case. CI’s EPIPE is emitted by the unchanged lineage-close notification atservice-child-relay-host.ts:299. These files and the failing test are unchanged between the rebased main parent62ef3ab149c8and this PR; the comparison holds every other input fixed while replacing only the sampler with its baseline version. Passing replays establish the permitted flake attribution, not a repair of that cleanup race.The previous independent review remains clean because all six PR files are byte-identical after the requested rebase. The native workflow preflight targets a new worktree in the shared checkout, prohibited by this lane’s isolation/compute rules; the authorized fallback is a squash merge pinned to the exact reviewed 40-character head.
No production deployment or live-after profile was performed. The 79.68 MiB/30 s live signal is pre-change only. Benchmark allocation is sampled V8 heap, excluding external Buffer storage; full-Gateway effects were not measured. Phase-aligned proof now passes on the byte-identical rebased sampler. No production deployment was needed.
Related: #182111, #182163, #182234.