Skip to content

fix(process): scope child-memory sampling to watched trees - #190897

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-child-memory-census-cgroup-scope-20260919
Nov 2, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-child-memory-census-cgroup-scope-20260919

Conversation

@steipete

@steipete steipete commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Linux memory monitoring scans every host PID once twenty command watches are active. The shared census in #189629 was calibrated on a 200-process host; on hosts with thousands of unrelated processes, its CPU and allocation scale with the host rather than the commands being monitored.

User Impact

Monitoring now follows only watched command trees. RSS-plus-swap bounds, worker-thread descendants, callback context, independent stalled watches and the one/five-second cadence remain intact. Descendants that migrate to another cgroup remain covered while their ancestry is intact. No configuration or migration is required.

Why This Change Was Made

Remove the whole-host forest, crossover thresholds, hysteresis and census timeout/fallback. Share parsed memory totals and child PID arrays within one tick; each watcher retains its own visited set and total, and the next tick reads fresh kernel facts. Production code shrinks by 48 lines.

Cgroup membership alone loses migrated descendants. Per-command memory.max would change RSS-plus-swap accounting and require restructuring the populated agent-exec hierarchy. Keeping the ancestry owner preserves the existing enforcement contract.

Evidence

Synthetic Linux x64, Node 26.12.1; measured two CPUs, 7.65 GiB RAM. One fixed forest contains 40 roots with four worker-thread-spawned children each, plus 3,000 unrelated sleep processes (~3,350 visible processes). Five serial interleaved original/candidate pairs per watcher count; dense 30 s warmup + 30 s capture, quiet 10 + 30 s. Values are median [minimum, maximum]; with five samples, empirical nearest-rank p95 is the maximum, not a robust population-tail estimate. V8 allocation includes collected objects but excludes external Buffer storage.

Watches Metric Original Candidate Median change
1 Main CPU, ms/min 37.028 [31.850, 66.318] 47.700 [26.240, 55.386] +28.8%
1 Total CPU, ms/min 43.594 [38.720, 73.870] 54.382 [32.716, 62.378] +24.7%
1 V8 allocation, MB/min 11.357 [7.502, 11.796] 11.256 [7.698, 11.763] -0.9%
1 Loop p99, ms 20.136 [20.120, 20.169] 20.136 [20.120, 20.169] +0.0%
20 Main CPU, ms/min 241.406 [203.892, 378.260] 65.180 [62.524, 186.294] -73.0%
20 Total CPU, ms/min 597.532 [528.168, 872.766] 113.418 [110.792, 254.118] -81.0%
20 V8 allocation, MB/min 86.168 [85.285, 89.041] 42.223 [39.744, 46.192] -51.0%
20 Loop p99, ms 20.152 [20.120, 20.234] 20.152 [20.136, 20.201] +0.0%
40 Main CPU, ms/min 271.180 [217.034, 336.370] 119.404 [98.654, 128.296] -56.0%
40 Total CPU, ms/min 655.582 [560.506, 802.566] 237.112 [217.354, 242.526] -63.8%
40 V8 allocation, MB/min 93.473 [88.434, 97.116] 75.083 [72.627, 81.720] -19.7%
40 Loop p99, ms 20.185 [20.120, 20.218] 20.152 [20.136, 20.185] -0.2%

Baseline A/A controls:

Watches Main CPU, ms/min Allocation, MB/min Loop p99, ms
1 31.306 → 33.658 11.759 → 7.751 20.103 → 20.120
20 205.888 → 210.808 91.210 → 86.966 20.087 → 20.136
40 227.438 → 246.828 93.168 → 89.788 20.201 → 20.201

Accepted tradeoffs: one-watch median main CPU rises 37.028→47.700 ms/min (+10.672 ms/min), with effectively flat allocation and loop p99. At forty watches, total GC rises 8.608→10.366 ms/min (+20.4%); median maximum GC pause rises 0.303→0.440 ms, and the largest observation is 0.639→1.912 ms. I accept these measured costs for the repeatable loaded-work reduction: forty-watch total CPU falls by 418.470 ms/min, allocation by 18.390 MB/min, and old-space by 6.764→5.163 MB. The loop monitor has 20 ms resolution and cannot rule out smaller latency costs. This is not an all-metrics-improve claim.

An earlier complete local Linux arm64 VM series remains an adverse qualification result: forty-watch median loop p99 30.818→38.470 ms and median window maximum 43.876→99.877 ms; twenty-watch median maximum GC pause 2.032→3.501 ms. Later local pairs were steadier, but load observations do not prove the cause. I retain that uncertainty rather than dismissing it as noise; the controlled Linux result supports this scoped landing, not a universal tail-neutrality claim.

Separate ten-second work-count probe (instrumented, not timing evidence): filesystem callback jobs 6,694→3,520; directory jobs 2→400; promises 13,746→10,968; timer creations 5→81. Task-directory reads are needed for every-thread ancestry and timer rearming increases as walks settle independently; these costs are included in total CPU/allocation above. The regression test proves zero unrelated-host PID reads. Overlapping trees share each PID observation and count descendants once within each command's total.

Separate collected-object allocation profile attributes 65.771→40.045 MB/min to owner stacks. CPU profiles show sampled inclusive owner time 39.145→8.985 ms over the 20-second startup/warmup/capture profile; this supports attribution and is not the timing table. The first raw-buffer-sharing candidate was rejected for retained old-space and major GC; the final implementation retains parsed facts only.

Real Linux worst-phase runaway with twenty overlapping observers: 5.008→5.009 s from burst to SIGKILL, after forest cleanup. Separate cgroup-migration proof moves both worker children outside the parent cgroup: original 5.099 s, final 5.011 s, correct memory-limit diagnostic and six-second deadline. No fake clocks.

50 child-memory/supervisor tests pass; the new owned-only and overlap-sharing regressions fail against the exact parent (2 failures, 9 passes). Exec-runtime caller tests: 36 pass, two Linux broker cases skipped on macOS. Final pnpm check:changed passes. Fresh Codex autoreview of the full diff and owner/caller: scoped-clean P0–P2. Exact reviewed head 4ebc0ee has GREEN native CI-watcher result for run 41399986835, excluding ten superseded checks.

Rerun with the committed fixture and measurement scripts: start node scripts/perf/child-memory-fixture.cjs forest 40 4 <roots.json> 3000; bundle the original owner at 52c1064 and this head with the same esbuild settings, then run child-memory-measure.ts --owner <bundle> --roots <roots.json> --trees 40 --watched 1|20|40 --descendants 4 --warmup-seconds 30 --seconds 30 --output <json> serially, using 10 s quiet warmup. Run --work-counts and --allocations separately; --cpu-prof captures attribution. Use child-memory-adaptive-runaway.ts --owner <bundle> --observers 20 --descendant-cgroup <private fixture cgroup> --output <json> for the migration proof.

No live deployment or production data was used. Database/workspace size does not participate in this owner. No Control UI import boundary changed; no full-Gateway throughput is claimed.

Follow every thread descendant list and share reads within each sample instead of scanning every host PID. Preserve RSS-plus-swap accounting, migrated descendants, independent watcher deadlines, and cancellation. Remove the census crossover and timeout fallback.
@clawsweeper

clawsweeper Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts size: M labels Nov 2, 2026
@steipete
steipete marked this pull request as ready for review November 2, 2026 05:47
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 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-11-02T06:29:59.070739Z 4ebc0ee 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.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 2, 2026
@clawsweeper

clawsweeper Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR replaces whole-host Linux memory scans with shared reads confined to watched command trees.

Example: Forty watched command trees run alongside 3,000 unrelated sleep processes.

  • Before: The watchdog enumerates host processes and reads unrelated process statuses, potentially reaching its census timeout.
  • After: The watchdog reads watched roots and their thread-spawned descendants, sharing overlapping reads within each tick.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused simplification has useful regression coverage and reported real-kernel enforcement evidence, but its performance acceptance remains explicitly unresolved.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its body reports real Linux procfs enforcement through watchChildMemory, while the inspected scripts and tests establish an in-process proof path rather than a shipped Gateway run.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Concurrent commands make Linux Gateway monitoring consume CPU and allocate memory for thousands of unrelated host processes.
Reason: The maintainer-authored direction removes source-confirmed waste while preserving the existing command-tree memory contract.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep open: this maintainer-authored PR fixes a source-confirmed current-main inefficiency, with no discrete correctness findings; the author’s explicit performance hold remains unresolved.

Priority: P2
Reviewed head: 5d697c5c987677eeea023aceb1c4cc65b7dd92dd

Before merge

  • Resolve merge risk - Before merge, the author must resolve the reported dense-workload GC and latency-tail regression under the stated acceptance rule, or obtain explicit maintainer acceptance of the measured tradeoff for the final candidate.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied evidence exercises the production watchdog with real procfs directly; it does not show this candidate through the shipped Gateway exec entry point.
Agent review details

How this fits together

The process supervisor supplies command roots and memory limits to the Linux watchdog, which reads procfs and requests tree termination with a diagnostic when RSS plus swap exceeds the limit.

flowchart TD
  A[Gateway exec command] --> B[Process supervisor]
  B --> C[Shared sampling clock]
  C --> D[Watched tree procfs reads]
  D --> E[RSS plus swap accounting]
  E --> F[Tree termination and diagnostic]
Loading

Technical review

Best possible solution:

Retain one ancestry-based accounting owner with tick-local sharing, preserving enforcement and cancellation while meeting the recorded performance acceptance rule.

Do we have a high-confidence way to reproduce the issue?

Current main demonstrably selects a whole-host /proc census at twenty watches; the body supplies a concrete 3,000-unrelated-process workload and reports an exact-parent failing regression, but this review ran no reproduction.

Is this the best way to solve the issue?

Reusing the existing all-thread ancestry walker removes unnecessary host work without changing the accounting boundary; the remaining question is whether the chosen sharing representation meets its performance criteria.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against b31a8082cac3.

Merge-risk options

Maintainer options:

  1. Resolve the dense-workload regression (recommended)
    The author should complete the bounded implementation experiment and comparable baseline/candidate controls, retaining every result and satisfying the existing CPU, allocation, tail and enforcement criteria.
  2. Explicitly accept the final measured tradeoff
    A maintainer may accept quantified GC and tail costs for the final candidate after weighing them against the reduction in unrelated-host monitoring work.

Provenance checked

  • Whole-host census and shared scheduler changes intended behavior with a stated reason (3a46423: Reduce redundant monitoring work at concurrency using a measured crossover on a 200-process host, while keeping stalled reads independent.)
  • All-thread ancestry and RSS-plus-swap enforcement keeps the original intent (2d8051e: Bound runaway Linux exec memory through the existing supervisor and include worker-thread descendants without requiring cgroup containment.)
  • Adaptive one-second and five-second sampling keeps the original intent (a450743: Reduce quiet-tree monitoring work while explicitly accepting an approximately six-second runaway detection bound.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Current-main failure path: Current main still enumerates /proc and reads host process statuses; the scheduler selects this census at twenty active watches. (src/process/child-memory.ts:59, b31a8082cac3)
  • Introduced change: The pinned introduction removes the host forest, crossover thresholds and timeout fallback, retaining the existing all-thread descendant walker and independently settling watches. (src/process/child-memory.ts:144, 5d697c5c9876)
  • Original optimization and intent: improve: reduce memory-monitoring overhead for concurrent commands #189629 introduced the census to reduce repeated monitoring work on a 200-process fixture; its accepted timing uncertainty does not accept this PR’s newly reported GC and tail behavior. (src/process/child-memory.ts:55, 3a46423d29bf)
  • Recorded performance hold: The complete current PR body explicitly says performance validation is not accepted: dense captures increase old-space survival and major-GC pressure and worsen tails; final comparisons and A/A controls remain pending. (5d697c5c9876)
  • Enforcement evidence: The body reports real Linux worker descendants migrated to another cgroup, twenty overlapping observers, the memory-limit diagnostic, and candidate SIGKILL at 5.007 seconds; the committed script exercises the production watchdog directly. (scripts/perf/child-memory-adaptive-runaway.ts:74, 5d697c5c9876)
  • Regression coverage: Changed tests protect unrelated-host read exclusion, fresh observations, overlapping accounting, callback context, independent stalled reads and cancellation during shared discovery; the body reports the host-read regression fails on the exact parent. (src/process/child-memory.test.ts:185, 5d697c5c9876)

Likely related people:

  • Peter Steinberger: Raw commit 3a46423 adds src/process/child-memory.ts:190 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3a46423d29bf; files: src/process/child-memory.ts)

PR surface

Source -61, Tests -8, Docs 0, Other +24. Total -45 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 28 89 -61
Tests 1 32 40 -8
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 2 25 1 +24
Total 5 86 131 -45

Labels

Label changes:

  • add P2: The source-confirmed inefficiency affects concurrent Linux host commands on process-dense hosts without establishing an urgent outage.
  • add merge-risk: 🚨 other: The author reports increased old-space survival, major-GC pressure and worse dense-workload latency tails that have not been accepted.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.

Label justifications:

  • P2: The source-confirmed inefficiency affects concurrent Linux host commands on process-dense hosts without establishing an urgent outage.
  • merge-risk: 🚨 other: The author reports increased old-space survival, major-GC pressure and worse dense-workload latency tails that have not been accepted.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Resolve the dense-workload GC and tail behavior against the recorded acceptance criteria on the final candidate.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 2, 2026, 1:11 AM ET / 06:11 UTC.

Share numeric memory totals and descendant PID arrays instead of retaining raw procfs buffers and thread directory lists. Preserve independent watches, early memory enforcement, and cancellation-safe shared discovery.
@steipete steipete changed the title fix(process): memory monitoring scans unrelated Linux host processes fix(process): scope child-memory sampling to watched trees Nov 2, 2026
@steipete
steipete merged commit b1e0c9a into main Nov 2, 2026
135 of 136 checks passed
@steipete
steipete deleted the steipete/perf-micro-child-memory-census-cgroup-scope-20260919 branch November 2, 2026 07:27
@steipete

steipete commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 3, 2026
…190897)

* fix(process): scope child memory scans to watched trees

Follow every thread descendant list and share reads within each sample instead of scanning every host PID. Preserve RSS-plus-swap accounting, migrated descendants, independent watcher deadlines, and cancellation. Remove the census crossover and timeout fallback.

* perf(process): retain parsed child-memory facts per tick

Share numeric memory totals and descendant PID arrays instead of retaining raw procfs buffers and thread directory lists. Preserve independent watches, early memory enforcement, and cancellation-safe shared discovery.
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 merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant