Skip to content

fix: pause optional Gateway work under parent memory pressure - #206041

Merged
vincentkoc merged 6 commits into
mainfrom
fix/ancestor-cgroup-memory-pressure-20261127
Nov 26, 2026
Merged

vincentkoc merged 6 commits into
mainfrom
fix/ancestor-cgroup-memory-pressure-20261127

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

A Linux Gateway can see ample headroom in its own cgroup and on the host while a sibling consumes most of their shared parent allowance. The Gateway still schedules optional startup and cache work in that state.

User Impact

On Linux with Node.js and cgroup v2, optional work pauses when a visible ancestor's working set reaches 80% of its finite reclaim or hard memory limit. It resumes as soon as a fresh check finds headroom.

Why This Change Was Made

Node 24 reads the current cgroup's limits. The Gateway also needs to check each visible ancestor's charge against its own memory.high and memory.max. The new check deducts inactive file cache. It uses the root of the mounted cgroup controller to avoid a similarly named sibling and can skip an unknown view. Existing process, host, profile and worker-budget checks keep their policies. Node's cgroup reader · Linux mount information

Evidence

The Linux x64 fixture called the production Gateway prewarm scheduler with a recording queue. An ordinary sibling shared a finite parent. The Gateway's leaf still had 419–423 MiB available out of 512 MiB. Linux proof run

Parent working set 34% 86% 34% again
Stock jobs scheduled 2 2 2
Fixed jobs scheduled 2 0 2

A second fixture used a real read-only delegated bind. When only the unrelated sibling was pressured, the Gateway scheduled two jobs. It scheduled zero when the real parent was pressured and two once pressure cleared. All scoped max and OOM counters stayed at zero.

On this runner, 160 fresh helper calls per phase gave p50/p95 times in microseconds of 18/22, 18/21 and 18/21 on stock, and 82/110, 52/61 and 78/133 on the Linux-tested repair (9f28bd16). These are measurements of the admission check.

All 62 focused host-memory, Gateway resource-profile and child-memory tests passed on Node 24.22.1 at 9f28bd16. The final lint-only change (3be0695d) names the five fields parsed from mountinfo and uses a local traversal cursor. All 26 host-memory tests passed on its actual merge object ac35920f, including the delegated mount control. Final CI job Both original threshold cases failed on stock. The hard-limit case retains a 512 MiB cap with unreadable mount information and with an identity-preserving bind. The final committed-range review, pinned formatter, 259-rule scoped lint and git diff --check passed.

@vincentkoc vincentkoc self-assigned this Nov 26, 2026
@clawsweeper

clawsweeper Bot commented Nov 26, 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.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:other This issue has meaningful maintainer-visible impact outside the owned taxonomy. labels Nov 26, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review November 26, 2026 16:36
@vincentkoc
vincentkoc enabled auto-merge (squash) November 26, 2026 16:39
@vincentkoc
vincentkoc disabled auto-merge November 26, 2026 16:46
@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: 🦪 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 26, 2026
@clawsweeper

clawsweeper Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: passed.

What this changes

This PR pauses optional Gateway work when a visible parent cgroup reaches 80% of its finite memory allowance.

Example: A Linux Gateway has 419–423 MiB available in its 512 MiB leaf while its parent's working set reaches 86% of its allowance.

  • Before: The reported production-scheduler fixture schedules two optional prewarm jobs.
  • After: It schedules zero jobs under parent pressure and two on a fresh invocation after pressure falls to 34%.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused source and regression coverage support the repair, with green exact-head CI; behavioral evidence exercises the production admission boundary through an in-process fixture.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the contributor proof gate; its supplied Linux fixture exercises production scheduling under real sibling pressure with reported 2/0/2 admission, while whole-Gateway operation remains outside that scenario and raw linked logs were unavailable here.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Optional background work can consume memory while sibling processes exhaust the Gateway's shared parent allowance.
Reason: The maintainer-authored direction addresses a demonstrated gap in the existing pressure policy without adding settings or changing stored data.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it repairs an ancestor-memory-pressure blind spot still present on main, has no actionable introduced defects, and its exact-head CI gate passes.

Reviewed head: 3be0695d1c40564a0bc651dd4fcf9c3b7ec5b46e

Before merge

None.

Findings

None.

Agent review details

How this fits together

The shared host-memory owner reads process, host, and Linux cgroup facts and returns a pressure decision consumed by optional maintenance and prewarming.

flowchart TD
  A[Process and host memory] --> D[Shared pressure decision]
  B[Cgroup membership and mount information] --> C[Visible ancestor working sets]
  C --> D
  D --> E[Optional Gateway schedulers]
  E --> F[Schedule or defer work]
Loading

Technical review

Best possible solution:

Keep ancestor-pressure detection in the shared memory owner while preserving existing budget readers and caller-owned retry behavior.

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

Current-main source and Node's pinned implementation establish the ancestor-charge blind spot; the author supplies a controlled real-cgroup reproduction, which this read-only review did not rerun.

Is this the best way to solve the issue?

The patch repairs the existing admission owner, compares each ancestor's own working set with its own limits, and preserves separate profile and worker-budget contracts.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Pinned introduction and current-main gap: The introduced range changes only host-memory production code and tests; fetched main still checks process and host headroom without checking ancestor charges. (src/infra/host-memory.ts:94, 3be0695d1c40)
  • Existing contracts preserved: Mount-aware ancestry serves optional-work admission, while existing hard-limit and worker-budget readers retain their previous traversal and measurement policies, consistent with the documented resource profiles. (src/infra/host-memory.ts:215, 4038ca354cc9)
  • Distinct regression coverage: Tests cover finite and absent leaf limits, inactive-file subtraction, hard and reclaim thresholds, unreadable ancestors, delegated mounts, obscured controllers, and preservation of existing hard-limit readings. (src/infra/host-memory.test.ts:191, 3be0695d1c40)
  • Reported kernel-backed scheduler evidence: The complete PR body and maintainer clarification describe real sibling pressure and delegated-bind controls exercising the production scheduler with a recording queue, reporting stock 2/2/2 versus fixed 2/0/2 jobs. The linked run is cancelled; raw logs could not be inspected because its storage host is blocked by this review environment. (9f28bd16279f)
  • Final change and CI: The final commit only names parsed mount fields and introduces a local traversal cursor. The exact-head CI, dependency-review, and security-sensitive-review statuses are successful; GitHub currently reports a clean merge. (src/infra/host-memory.ts:148, 3be0695d1c40)
  • Feature ownership and provenance: Symbol history identifies Vincent Koc's constrained-process admission and later host-pressure extension, and Josh Lehman's macOS memory repair, resource profiles, and cgroup working-set budget. Following the file farther back encounters an unavailable historical object; that limit does not affect these verified changes. (src/infra/host-memory.ts:80, 4038ca354cc9)

Likely related people:

  • Vincent Koc: Raw commit 67ecf6b adds src/infra/host-memory.ts:18 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 67ecf6bf352d; files: src/infra/host-memory.ts)
  • Josh Lehman: Raw commit 28aa5c8 adds src/infra/host-memory.ts:124 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 28aa5c88fd45; files: src/infra/host-memory.ts)

PR surface

Source +108, Tests +161. Total +269 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 134 26 +108
Tests 1 161 0 +161
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 295 26 +269

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 LOC Production +134/-26; tests +161/-0 The growth implements mount-aware ancestor admission and distinct topology and threshold regressions without adding configuration, persistent state, or another scheduler.

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:

  • 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-26T16:51:34.122Z sha 9f28bd1 :: passed. :: none

Reviewed November 26, 2026, 12:25 PM ET / 17:25 UTC (Revision 2).

@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review 3be0695d1c40564a0bc651dd4fcf9c3b7ec5b46e. The production scheduler was exercised under real sibling pressure with a recording queue so each eligible job could be counted before, during and after pressure. The PR evidence covers that admission decision. Whole-Gateway memory and first-reply behavior are tracked separately. The final merge-object job passed all 26 mount and host-memory cases.

@clawsweeper

clawsweeper Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added 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. labels Nov 26, 2026
@vincentkoc
vincentkoc merged commit 589a70a into main Nov 26, 2026
124 checks passed
@vincentkoc
vincentkoc deleted the fix/ancestor-cgroup-memory-pressure-20261127 branch November 26, 2026 17:30
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 27, 2026
…aw#206041)

* fix: pause optional Gateway work under parent memory pressure

* fix: resolve visible cgroup controllers from their mounted subtree

* fix: retain visible memory limits above covered controllers

* fix: honor controller masks on the visible mount only

* fix: keep existing cgroup budget readers independent of admission

* refactor: name parsed cgroup mount fields
tideclaw-bot pushed a commit that referenced this pull request Nov 28, 2026
* fix: pause optional Gateway work under parent memory pressure

* fix: resolve visible cgroup controllers from their mounted subtree

* fix: retain visible memory limits above covered controllers

* fix: honor controller masks on the visible mount only

* fix: keep existing cgroup budget readers independent of admission

* refactor: name parsed cgroup mount fields

(cherry picked from commit 589a70a)

Backport adaptation: Cherry-pick applies cleanly after the release optional-work pressure backport; no cgroup code or fixtures needed adaptation.

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
* fix(runtime): defer optional work under host memory pressure

* style(infra): format memory pressure admission

* style(gateway): format the deferred prewarm check

(cherry picked from commit 9f50802)

Companion audit: #207993 selected later for publication fixture isolation. #206779 required if the new Cron host-memory fixture spoofs platform: preserve native SQLite namespace. #206041/#206230/#206308/#206746 are separate cgroup detection and optimization changes; #206322 is service-aware cron run budget, #206483 forks chat and #206384 changes a main-only warmer.

Release adaptation: Extend the stable optional-memory owner and its existing callers only. Preserve cgroup/Bun/macOS behavior and upstream threshold cases; omit main-only prompt warmer, cgroup diagnosis, and Cron platform-spoof changes.

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
* fix: pause optional Gateway work under parent memory pressure

* fix: resolve visible cgroup controllers from their mounted subtree

* fix: retain visible memory limits above covered controllers

* fix: honor controller masks on the visible mount only

* fix: keep existing cgroup budget readers independent of admission

* refactor: name parsed cgroup mount fields

(cherry picked from commit 589a70a)

Release adaptation: take the pressure-owner slices of #206230 (verified mount mapping), #206308 (delegated leaf), and #206746 (mount discovery reused per membership). Do not import resource sizing, diagnostics or #206322 cron scheduling APIs; none are needed by stable optional callers.

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

impact:other This issue has meaningful maintainer-visible impact outside the owned taxonomy. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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