Skip to content

fix(exec): reduce memory-watch allocation for thread-heavy processes - #196416

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-procfs-readfile-64k-churn-20260919
Nov 10, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-procfs-readfile-64k-churn-20260919

Conversation

@steipete

@steipete steipete commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes excessive allocation and CPU use by host exec memory protection when watched commands have many threads on Node's older readFile implementation.

User Impact

Thread-heavy command trees remain fully protected while their memory scans allocate less temporary Buffer storage. Descendants spawned by non-main threads, oversized procfs records, shared budgets and runaway termination retain their existing behavior. No configuration or migration is required.

Why This Change Was Made

Procfs reports zero file sizes, causing the JavaScript readFile path to allocate at least 64 KiB per read, even for an empty thread children file. Use the supported caller-buffer API with a 4 KiB buffer reused within each PID's thread walk. Oversized records fall back to an unrestricted read. Node owns descriptor cleanup and EOF handling.

Apply this on Node 24.19+ and 26.4–26.7. Preserve Node 26.8+'s faster native one-job reader and Bun's reader. An unchanged thread start time cannot establish that its children are unchanged, so the complete per-thread discovery remains. Production code grows by 28 lines for runtime selection and complete-record fallback; a hand-written open/read/close loop was measured and rejected.

Evidence

Isolated Linux, Node 24.22.1: 280 processes / 6,720 threads, including 260 descendants spawned by non-main threads. Five interleaved A/B pairs plus A/A; 10-second warmup and 60-second uninstrumented timing captures. Separate 15-second allocation captures use the same watch cadence.

Metric Baseline Candidate Change
Requested Buffer storage 95.683 MB/s 0.459 MB/s -99.52%
Mean main-thread CPU 13.963 ms/s 10.268 ms/s -26.46%
Mean process CPU 26.451 ms/s 19.302 ms/s -27.02%
Mean GC 0.02738 s/min 0.02625 s/min roughly flat

Every CPU pair improved. A/A main CPU varied +4.63%, process CPU +7.34%, and GC +0.00284 s/min. Allocation results were identical across all five pairs: 21,000 procfs reads per capture in both arms, with 64 KiB allocation chunks eliminated in the candidate. These are synthetic owner measurements, not a full Gateway GC projection. Saturated local-host timing was rejected as acceptance evidence.

Node 26.12.1 preservation: five pairs plus A/A, mean main CPU 5.505 → 5.251 ms/s and process CPU 12.166 → 11.689 ms/s. Treat this as preservation, not a speedup: A/A main CPU varied -10.56%, and one of five pairs was adverse (+15.89% main CPU); the other four improved. The native reader remains selected.

Final real runaway proof watched 20 disjoint three-process trees: baseline 114 ms, candidate 1,122 ms, both below the six-second acceptance bound. Different tick phases mean these prove the bound, not relative speed. A separate single sampled V8 heap pair (excluding external Buffer storage) was 3.921 → 3.042 MB/s overall and 2.657 → 2.422 MB/s attributed to the owner; supporting evidence only.

Exact-head CI run passed for 00ce454652f170b059d70098a1306a6633a8b7eb.

Focused Node tests: 81 passed (child-memory, process supervisor and Linux exec cgroup); Bun owner/supervisor tests: 55 passed; durable systemd integration: passed. Extended existing coverage for non-main-thread children and RSS/swap records beyond 4 KiB. The Buffer allocation budget fails on the baseline and passes on the candidate. Codex review: no actionable findings.

pnpm check:changed: typechecks, core/scripts lint, format, import-cycle checks and every other selected guard passed; the dead-export scan remains red with exactly the same 21 findings reproduced on parent eaa8aebfb69368a748f4aaf39166a8bf339f70ec. No new findings. No Control UI importer of the changed owner was found.

Inherited dead-export regressions, reproduced and traced

These are existing main regressions requiring follow-up, not passing checks:

Reuse the supported readFile buffer API for procfs walks while preserving the faster native Node reader and complete oversized records. Keep per-thread discovery and runaway enforcement unchanged.
@clawsweeper

clawsweeper Bot commented Nov 10, 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 the scripts Repository scripts label Nov 10, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T03:32:48.638621Z 00ce454 PR opened
ℹ️ 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. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. 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 10, 2026
@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR reuses small kernel-read buffers on affected Node versions while preserving complete oversized records and newer native readers.

Example: Monitoring 280 Linux processes with 6,720 threads on Node 24.22.1.

  • Before: Reported requested Buffer storage was 95.683 MB/s.
  • After: Reported requested Buffer storage falls to 0.459 MB/s with the same 21,000 procfs reads per capture.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused patch and successful exact-head CI support correctness; behavioral evidence remains at the real production-owner harness boundary.
Proof confidence 🦐 gold shrimp (3/6) The ordinary contributor proof gate does not apply to this maintainer-authored PR; its updated evidence reports real Linux owner measurements and runaway termination, while inspected browser-pairing images are unrelated.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Monitoring thread-heavy Linux commands creates excessive temporary Buffer allocation and avoidable CPU work on affected Node versions.
Reason: The maintainer-authored direction is supported by substantial measured allocation reduction while retaining the existing memory-protection contract.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR addresses verified allocation waste in the existing memory watcher, and review found no actionable defects.

Priority: P2
Reviewed head: 00ce454652f170b059d70098a1306a6633a8b7eb

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied evidence exercises the production watcher with real procfs and process-group termination, rather than a full Gateway command flow.
Agent review details

How this fits together

Host exec memory protection reads process ancestry, RSS, swap, and durable cgroup usage, then asks existing cancellation owners to terminate workloads exceeding the shared budget.

flowchart TD
  A[Host exec callers] --> B[Shared memory watcher]
  B --> C[Runtime-selected kernel reader]
  C --> D[Procfs and cgroup files]
  D --> E[Parsed usage and descendants]
  E --> B
  B --> F[Existing cancellation owner]
Loading

Technical review

Best possible solution:

Keep the existing sampling owner and use Node-managed buffer reuse only where measurements justify it, retaining unrestricted overflow reads and existing enforcement.

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

Current main uses Node's unrestricted reader for zero-size procfs records, whose implementation allocates unknown-size chunks; the PR supplies matched real-procfs measurements, but this review ran no target code.

Is this the best way to solve the issue?

The change fixes allocation at the existing reader owner, preserves complete discovery and accounting, and avoids a custom descriptor lifecycle or cache.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Callback-based kernel file reads keeps the original intent (9302c11: Reduce promise overhead while leaving complete reads, descriptor cleanup, and EOF handling with Node.)
  • Byte parsing and every-thread child discovery keeps the original intent (c737f7a: Avoid decoding allocations while inspecting every thread on every sample so worker-spawned descendants remain visible.)
  • Watched-tree sampling keeps the original intent (b1e0c9a: Follow watched ancestry instead of scanning unrelated host processes, sharing parsed facts within each tick.)
  • Shared budget and durable cgroup accounting keeps the original intent (0af74c7: Account ordinary and durable commands under one shared RAM/swap allowance while preserving existing cleanup owners.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Josh Avant: Raw commit 0af74c7 adds src/process/child-memory.ts:154 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 0af74c76da98; files: src/process/child-memory.ts)

PR surface

Source +28, Tests +36, Other +254. Total +318 across 6 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 34 6 +28
Tests 2 68 32 +36
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 3 257 3 +254
Total 6 359 41 +318

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus test growth Production +28 net lines; tests +36 net lines Growth supports runtime selection, complete-record fallback, and existing consumer fixtures without adding another sampling or cancellation owner.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P2: The measured overhead affects thread-heavy Linux command monitoring, with no demonstrated loss of enforcement or urgent user-facing outage.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-10T03:45:08.900Z sha 00ce454 :: needs maintainer review before merge. :: none

Reviewed November 9, 2026, 10:55 PM ET / November 10, 2026, 03:55 UTC (Revision 2).

@steipete

Copy link
Copy Markdown
Contributor Author

The final evidence is now complete on unchanged head 00ce454652f170b059d70098a1306a6633a8b7eb; the PR body has been updated. The previous review had zero findings/open items, but its testing note read the earlier pending evidence:

  1. Node 26 preservation: five interleaved pairs plus A/A on Node 26.12.1 completed. Mean main CPU was 5.505 → 5.251 ms/s and process CPU 12.166 → 11.689 ms/s. One adverse pair (+15.89% main CPU) remains included; this supports preservation, not a speedup claim. The retained native path is at child-memory.ts:15–26.
  2. Runaway bound: the real Linux owner harness watched 20 disjoint three-process trees and terminated the runaway in 114 ms on baseline / 1,122 ms on candidate, both under six seconds. This invokes the real watcher and kills a real process group; it is not a full-Gateway trace. The measurement/termination boundary is at child-memory-measure.ts:425–443. Final-source supervisor tests pass, and the durable-process integration was rerun and passed.
  3. Final validation: exact-head CI passed. Both runtime comparisons and all five allocation pairs used the same verified source hash. The isolated lease is stopped. Browser-pairing images mentioned in the review are unrelated to this non-UI change and are not evidence for this PR.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 10, 2026
@steipete
steipete merged commit e275572 into main Nov 10, 2026
154 of 155 checks passed
@steipete
steipete deleted the steipete/perf-micro-procfs-readfile-64k-churn-20260919 branch November 10, 2026 04:05
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 10, 2026
…penclaw#196416)

Reuse the supported readFile buffer API for procfs walks while preserving the faster native Node reader and complete oversized records. Keep per-thread discovery and runaway enforcement unchanged.
steipete added a commit that referenced this pull request Nov 10, 2026
Allocate nine missing lines for #196385 and correct #196416 from 33 to its actual 36 test lines. #196423 is already fully allocated. Restore exactly 6615748 lines of ceiling with zero slack; preserve all regression coverage and the shared scalar.
steipete added a commit that referenced this pull request Nov 10, 2026
#196432)

* fix(test): reconcile warm reload and procfs test-line debt

Allocate nine missing lines for #196385 and correct #196416 from 33 to its actual 36 test lines. #196423 is already fully allocated. Restore exactly 6615748 lines of ceiling with zero slack; preserve all regression coverage and the shared scalar.

* fix(test): account for the latest main test-line offset

Main #196305 removed one test line after the first reviewed candidate. Reduce the warm-reload debt allocation from nine to eight so total credit is exactly 11 and the current 6615839-line tree has zero slack.
RomneyDa pushed a commit that referenced this pull request Nov 10, 2026
#196432)

* fix(test): reconcile warm reload and procfs test-line debt

Allocate nine missing lines for #196385 and correct #196416 from 33 to its actual 36 test lines. #196423 is already fully allocated. Restore exactly 6615748 lines of ceiling with zero slack; preserve all regression coverage and the shared scalar.

* fix(test): account for the latest main test-line offset

Main #196305 removed one test line after the first reviewed candidate. Reduce the warm-reload debt allocation from nine to eight so total credit is exactly 11 and the current 6615839-line tree has zero slack.

(cherry picked from commit 644ff7d)
RomneyDa added a commit that referenced this pull request Nov 10, 2026
…esults (#196266)

* improve(tool-search): show input signatures for MCP tools in search results

tool_search rendered input "unknown" for every MCP tool, so models called
tool_describe before almost every MCP call. Render the same bounded,
structure-only signature used for OpenClaw tools from the MCP input schema.
Client tools keep "unknown" because Code Mode lists them in its system prompt
from the same compact entries.

Remote schemas can carry huge literals, so string literals longer than the
hint budget are rejected before serialization. Code Mode prompt construction
skips MCP entries before compaction; it never listed them.

Co-authored-by: jalehman <[email protected]>
Co-authored-by: GrahamMcBain <[email protected]>

* improve(tool-search): show input signatures for MCP tools in search results

Worked on by:
- @jalehman
- @GrahamMcBain

Co-authored-by: jalehman <[email protected]>
Co-authored-by: GrahamMcBain <[email protected]>
OpenClaw-Publication: a0929bba-b988-4c27-b67d-606a685a1e6e

* fix(test): restore the main test-line budget after warm reload changes (#196432)

* fix(test): reconcile warm reload and procfs test-line debt

Allocate nine missing lines for #196385 and correct #196416 from 33 to its actual 36 test lines. #196423 is already fully allocated. Restore exactly 6615748 lines of ceiling with zero slack; preserve all regression coverage and the shared scalar.

* fix(test): account for the latest main test-line offset

Main #196305 removed one test line after the first reviewed candidate. Reduce the warm-reload debt allocation from nine to eight so total credit is exactly 11 and the current 6615839-line tree has zero slack.

(cherry picked from commit 644ff7d)

* test(agents): align host-denial proof with immediate failure settlement

---------

Co-authored-by: roboclaw-bot <[email protected]>
Co-authored-by: jalehman <[email protected]>
Co-authored-by: GrahamMcBain <[email protected]>
Co-authored-by: Dallin Romney <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 11, 2026
openclaw#196432)

* fix(test): reconcile warm reload and procfs test-line debt

Allocate nine missing lines for openclaw#196385 and correct openclaw#196416 from 33 to its actual 36 test lines. openclaw#196423 is already fully allocated. Restore exactly 6615748 lines of ceiling with zero slack; preserve all regression coverage and the shared scalar.

* fix(test): account for the latest main test-line offset

Main openclaw#196305 removed one test line after the first reviewed candidate. Reduce the warm-reload debt allocation from nine to eight so total credit is exactly 11 and the current 6615839-line tree has zero slack.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 11, 2026
…esults (openclaw#196266)

* improve(tool-search): show input signatures for MCP tools in search results

tool_search rendered input "unknown" for every MCP tool, so models called
tool_describe before almost every MCP call. Render the same bounded,
structure-only signature used for OpenClaw tools from the MCP input schema.
Client tools keep "unknown" because Code Mode lists them in its system prompt
from the same compact entries.

Remote schemas can carry huge literals, so string literals longer than the
hint budget are rejected before serialization. Code Mode prompt construction
skips MCP entries before compaction; it never listed them.

Co-authored-by: jalehman <[email protected]>
Co-authored-by: GrahamMcBain <[email protected]>

* improve(tool-search): show input signatures for MCP tools in search results

Worked on by:
- @jalehman
- @GrahamMcBain

Co-authored-by: jalehman <[email protected]>
Co-authored-by: GrahamMcBain <[email protected]>
OpenClaw-Publication: a0929bba-b988-4c27-b67d-606a685a1e6e

* fix(test): restore the main test-line budget after warm reload changes (openclaw#196432)

* fix(test): reconcile warm reload and procfs test-line debt

Allocate nine missing lines for openclaw#196385 and correct openclaw#196416 from 33 to its actual 36 test lines. openclaw#196423 is already fully allocated. Restore exactly 6615748 lines of ceiling with zero slack; preserve all regression coverage and the shared scalar.

* fix(test): account for the latest main test-line offset

Main openclaw#196305 removed one test line after the first reviewed candidate. Reduce the warm-reload debt allocation from nine to eight so total credit is exactly 11 and the current 6615839-line tree has zero slack.

(cherry picked from commit b67d29e)

* test(agents): align host-denial proof with immediate failure settlement

---------

Co-authored-by: roboclaw-bot <[email protected]>
Co-authored-by: jalehman <[email protected]>
Co-authored-by: GrahamMcBain <[email protected]>
Co-authored-by: Dallin Romney <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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 status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant