Repository navigation
fix: avoid false Gateway memory alerts from Linux file cache - #208658
LetMeSleep8h wants to merge 1 commit into
Conversation
|
🦞👀 ClawSweeper review completeClawSweeper finished reviewing this revision. |
|
Codex review: needs real behavior proof before merge. What this changesThis PR excludes verified inactive cgroup file cache from Gateway diagnostic pressure calculations. Example: A Linux cgroup has a 1,000-byte limit, 950 bytes charged, and 945 bytes of inactive file cache.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 1 item remains Keep open: current main still counts reclaimable file cache toward critical pressure, and this PR provides a focused repair without changing scheduling availability or worker-retirement policy. Reviewed head: Before merge
Findings
Tests
Agent review detailsHow this fits togetherThe Gateway heartbeat samples process memory, classifies pressure, and publishes diagnostic events and a channel signal consumed by idle-worker cleanup owners. flowchart TD
A[Gateway heartbeat] --> B[Memory sampler]
C[Native availability] --> B
D[Verified cgroup counters] --> E[Working set calculation]
E --> B
B --> F[Pressure classification]
F --> G[Diagnostic events]
F --> H[Idle worker cleanup]
Technical reviewBest possible solution: Complete this focused classification repair using the existing cgroup owner while preserving raw scheduler headroom and genuine-pressure signals. Do we have a high-confidence way to reproduce the issue? I did not run the Docker reproduction; current-main arithmetic and the existing delegated-cgroup fixture establish that reclaimable cache can produce critical pressure. Is this the best way to solve the issue? The implementation is appropriately narrow: it reuses verified cgroup mapping and working-set accounting, preserves raw fallback readings, and leaves scheduling and cleanup policy intact. Full review comments:
Overall correctness: patch is correct AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 871c188fbddc. Provenance checked
TestingProof path: unit tests only. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +37, Tests +55. Total +92 across 3 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. 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 readiness starts with the lower of the proof and patch scores. It is capped at 3/6 if the fix is partial, the change offers little benefit, a product decision is still open, or the PR reverses an earlier decision without saying why. ✨ 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 November 29, 2026, 7:29 PM ET / November 30, 2026, 00:29 UTC. |
|
Context from a now-closed duplicate (#208659), in case it helps you keep this one correct. I took a different route: subtract the leaf's
The remaining ask on both PRs is the same: redacted before/after output from an isolated running Linux cgroup v2 Gateway showing cache-only usage produces neither the alert nor the retirement publication, and anonymous pressure restores both. Good luck with it. |
|
Thank you for this. #208754 fixes the same false critical at the shared memory reader, so cron admission, optional-work deferral and update hashing use the same working set as the diagnostic signal. It reuses the shape of your regression test and credits you as co-author. I will close this PR after #208754 merges. |
…iners (#208754) Fixes #208631 ## What Problem This Solves A Gateway that runs in a memory-limited Linux container or systemd unit (cgroup v2) counts file cache as used memory. Normal file work fills the cgroup with cache that the kernel frees on demand, so the Gateway logs `memory pressure: level=critical reason=process_memory_threshold` every 5 minutes and never clears. The same false signal publishes `openclaw.memory.critical`, which retires idle SQLite workers and clears session caches, defers optional work, refuses extra automation runs, and starts no update-hash workers, while most of the limit is free. ## User Impact - Cache-heavy Gateways in containers and memory-limited units no longer report critical pressure or throw away warm workers and caches when only reclaimable file cache fills the limit. - Real pressure still reports: anonymous memory, active file cache and kernel charges still count. A charge above `memory.high` still reports no headroom. - Bare hosts, macOS and Bun keep their readings. cgroup v1 and hosts without a visible cgroup v2 leaf keep Node's reading (unchanged; see Limits). ## Why This Change Was Made Root cause: the leaf cgroup's headroom was `limit - memory.current`, and `memory.current` includes page cache. It was computed in two places, both raw: Node's native `process.availableMemory()` (libuv reads the leaf's `memory.current`) consumed at `src/logging/diagnostic-memory.ts:371` and `src/infra/host-memory.ts:62,305,310`, and OpenClaw's delegated-mount reader `readDelegatedCgroupMemory` (`src/infra/host-memory.ts:286`, "Node counts raw charges, including file cache"). The same module already used the working set (`memory.current - inactive_file`) for ancestor cgroups and the lean worker budget. The fix gives `src/infra/host-memory.ts` one reader, `readProcessMemory()`, for the process limit and the headroom left in it: - With a verified cgroup v2 view (ordinary or delegated mount), it reads the leaf files directly: headroom = limit - (`memory.current` - `inactive_file`). The charge is read unclipped, so above `memory.high` the headroom is 0, not cache credit added to libuv's clipped 0. - This is the working set that kubelet eviction and cAdvisor use ([Kubernetes node-pressure eviction](https://kubernetes.io/docs/concepts/scheduling-eviction/node-pressure-eviction/#active-file-memory-is-not-considered-as-available-memory), [cgroup v2 memory interface](https://docs.kernel.org/admin-guide/cgroup-v2.html#memory-interface-files)). - An ordinary leaf without memory counters (the root cgroup) and every non-cgroup-v2 case keep Node's native reading. - All four consumers read it: diagnostic pressure and the `openclaw.memory.critical` channel, `isMemoryPressureHigh`, cron's extra-run admission, and update-hash worker sizing. The delegated-only and cron-only capture readers are removed. The cgroup view is mapped once per membership (the existing `isMemoryPressureHigh` cache, now shared). - Cron shares the definition on purpose: it asks whether 1 GiB is available to a new run, and inactive cache is given back on demand. Earlier changes kept the raw leaf only to match Node (#206308, #206322). Supersedes #208658 (draft), which corrected only the diagnostic signal. ## Evidence Red on base, green on fix. The fix's unit fixtures (1000-byte leaf, `memory.current` 950, `inactive_file` 945) run against base 7215944 with the base API: on both ordinary (`/`) and delegated (`/pod`) mount roots, `isMemoryPressureHigh()` returned true and `openclaw.memory.critical` was published. With the fix: no pressure, no retirement. With anonymous memory holding the same charge (`inactive_file` 50): `critical`, `usedBytes: 900`, retirement published. Above `memory.high` (high 512 MiB, current 768 MiB, inactive 128 MiB): headroom 0. E2E on real cgroup v2 (Linux 7.2 kernel, Docker `--memory=2g --memory-swap=2g`), an isolated Gateway from the repo Dockerfile, built from base 7215944 and from this branch. Numbers from the container's `memory.stat`: | Phase | Base | Fix | | --- | --- | --- | | Idle (anon ~0.85 GB) | no critical | no critical | | File cache fills the limit (`memory.current` 2.14 GB, `inactive_file` 1.24-1.26 GB, anon 0.80-0.88 GB) | `level=critical reason=process_memory_threshold ... thresholdRatio=111.1% limit=2 GiB used=2 GiB` | no critical | | Anonymous memory to 93% working set (anon 2.11 GB, `inactive_file` 17 MB) | (already critical, throttled) | `level=critical reason=process_memory_threshold ... thresholdRatio=103.9% limit=2 GiB used=1.87 GiB` | A 1 GiB limit OOM-kills a stock Gateway during startup (RSS 963 MB at ready), so the runs use 2 GiB. The fix column was rerun on the PR's product code (f8371b6; later commits change tests only) with the same results. The other consumers, called from the built `dist` of each image: | Case | Base | Fix | | --- | --- | --- | | 2 GiB leaf full of file cache (`inactive_file` 2.14 GB, anon 0.4 MB) | cron headroom 0.00 GiB (no extra run), `isMemoryPressureHigh()` true | cron headroom 1.98 GiB, `isMemoryPressureHigh()` false | | Leaf without memory controller files (`0::/nomem`) | host reading 50.75 GiB, false | host reading 50.70 GiB, false | Cost: on that kernel, the leaf reads take 13.1 µs per call vs 8.5 µs for the native pair; the pressure check runs once per second. Checks: `host-memory`, `diagnostic-memory`, `worker-pool-sizing`, cron delegated/cross-tick/run-queue admission, page-cache, runtime-services maintenance and cron maintenance tests pass. Core typecheck (source and tests) and changed-file lint pass. `check:changed` also reports plugin-boundary and dead-export failures in files this change does not touch. ## Limits - Active file cache still counts as used, as in kubelet. On this kernel (MGLRU on), re-reading the same file kept it in `inactive_file` (active 5 MB of 1.27 GB). Not tested on a classic-LRU kernel, where re-read cache can move to `active_file` and still count. - cgroup v1 keeps Node's raw reading; OpenClaw already does not detect v1 limits. - Unchanged here: libuv's soft rlimits still lower the reported limit while headroom stays cgroup-wide, and a tighter parent limit is still checked only by `isMemoryPressureHigh`'s ancestor check. Co-authored-by: Sleep8h <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
…iners (openclaw#208754) Fixes openclaw#208631 ## What Problem This Solves A Gateway that runs in a memory-limited Linux container or systemd unit (cgroup v2) counts file cache as used memory. Normal file work fills the cgroup with cache that the kernel frees on demand, so the Gateway logs `memory pressure: level=critical reason=process_memory_threshold` every 5 minutes and never clears. The same false signal publishes `openclaw.memory.critical`, which retires idle SQLite workers and clears session caches, defers optional work, refuses extra automation runs, and starts no update-hash workers, while most of the limit is free. ## User Impact - Cache-heavy Gateways in containers and memory-limited units no longer report critical pressure or throw away warm workers and caches when only reclaimable file cache fills the limit. - Real pressure still reports: anonymous memory, active file cache and kernel charges still count. A charge above `memory.high` still reports no headroom. - Bare hosts, macOS and Bun keep their readings. cgroup v1 and hosts without a visible cgroup v2 leaf keep Node's reading (unchanged; see Limits). ## Why This Change Was Made Root cause: the leaf cgroup's headroom was `limit - memory.current`, and `memory.current` includes page cache. It was computed in two places, both raw: Node's native `process.availableMemory()` (libuv reads the leaf's `memory.current`) consumed at `src/logging/diagnostic-memory.ts:371` and `src/infra/host-memory.ts:62,305,310`, and OpenClaw's delegated-mount reader `readDelegatedCgroupMemory` (`src/infra/host-memory.ts:286`, "Node counts raw charges, including file cache"). The same module already used the working set (`memory.current - inactive_file`) for ancestor cgroups and the lean worker budget. The fix gives `src/infra/host-memory.ts` one reader, `readProcessMemory()`, for the process limit and the headroom left in it: - With a verified cgroup v2 view (ordinary or delegated mount), it reads the leaf files directly: headroom = limit - (`memory.current` - `inactive_file`). The charge is read unclipped, so above `memory.high` the headroom is 0, not cache credit added to libuv's clipped 0. - This is the working set that kubelet eviction and cAdvisor use ([Kubernetes node-pressure eviction](https://kubernetes.io/docs/concepts/scheduling-eviction/node-pressure-eviction/#active-file-memory-is-not-considered-as-available-memory), [cgroup v2 memory interface](https://docs.kernel.org/admin-guide/cgroup-v2.html#memory-interface-files)). - An ordinary leaf without memory counters (the root cgroup) and every non-cgroup-v2 case keep Node's native reading. - All four consumers read it: diagnostic pressure and the `openclaw.memory.critical` channel, `isMemoryPressureHigh`, cron's extra-run admission, and update-hash worker sizing. The delegated-only and cron-only capture readers are removed. The cgroup view is mapped once per membership (the existing `isMemoryPressureHigh` cache, now shared). - Cron shares the definition on purpose: it asks whether 1 GiB is available to a new run, and inactive cache is given back on demand. Earlier changes kept the raw leaf only to match Node (openclaw#206308, openclaw#206322). Supersedes openclaw#208658 (draft), which corrected only the diagnostic signal. ## Evidence Red on base, green on fix. The fix's unit fixtures (1000-byte leaf, `memory.current` 950, `inactive_file` 945) run against base 3f68ec0 with the base API: on both ordinary (`/`) and delegated (`/pod`) mount roots, `isMemoryPressureHigh()` returned true and `openclaw.memory.critical` was published. With the fix: no pressure, no retirement. With anonymous memory holding the same charge (`inactive_file` 50): `critical`, `usedBytes: 900`, retirement published. Above `memory.high` (high 512 MiB, current 768 MiB, inactive 128 MiB): headroom 0. E2E on real cgroup v2 (Linux 7.2 kernel, Docker `--memory=2g --memory-swap=2g`), an isolated Gateway from the repo Dockerfile, built from base 3f68ec0 and from this branch. Numbers from the container's `memory.stat`: | Phase | Base | Fix | | --- | --- | --- | | Idle (anon ~0.85 GB) | no critical | no critical | | File cache fills the limit (`memory.current` 2.14 GB, `inactive_file` 1.24-1.26 GB, anon 0.80-0.88 GB) | `level=critical reason=process_memory_threshold ... thresholdRatio=111.1% limit=2 GiB used=2 GiB` | no critical | | Anonymous memory to 93% working set (anon 2.11 GB, `inactive_file` 17 MB) | (already critical, throttled) | `level=critical reason=process_memory_threshold ... thresholdRatio=103.9% limit=2 GiB used=1.87 GiB` | A 1 GiB limit OOM-kills a stock Gateway during startup (RSS 963 MB at ready), so the runs use 2 GiB. The fix column was rerun on the PR's product code (f8371b6; later commits change tests only) with the same results. The other consumers, called from the built `dist` of each image: | Case | Base | Fix | | --- | --- | --- | | 2 GiB leaf full of file cache (`inactive_file` 2.14 GB, anon 0.4 MB) | cron headroom 0.00 GiB (no extra run), `isMemoryPressureHigh()` true | cron headroom 1.98 GiB, `isMemoryPressureHigh()` false | | Leaf without memory controller files (`0::/nomem`) | host reading 50.75 GiB, false | host reading 50.70 GiB, false | Cost: on that kernel, the leaf reads take 13.1 µs per call vs 8.5 µs for the native pair; the pressure check runs once per second. Checks: `host-memory`, `diagnostic-memory`, `worker-pool-sizing`, cron delegated/cross-tick/run-queue admission, page-cache, runtime-services maintenance and cron maintenance tests pass. Core typecheck (source and tests) and changed-file lint pass. `check:changed` also reports plugin-boundary and dead-export failures in files this change does not touch. ## Limits - Active file cache still counts as used, as in kubelet. On this kernel (MGLRU on), re-reading the same file kept it in `inactive_file` (active 5 MB of 1.27 GB). Not tested on a classic-LRU kernel, where re-read cache can move to `active_file` and still count. - cgroup v1 keeps Node's raw reading; OpenClaw already does not detect v1 limits. - Unchanged here: libuv's soft rlimits still lower the reported limit while headroom stays cgroup-wide, and a tighter parent limit is still checked only by `isMemoryPressureHigh`'s ancestor check. Co-authored-by: Sleep8h <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
Closes #208631
What Problem This Solves
A Linux Gateway inside a memory-limited cgroup can report critical pressure and ask idle SQLite workers to retire even when most of the charged memory is reclaimable file cache.
User Impact
Cache-heavy workloads no longer trigger these signals by themselves when the Gateway can verify the relevant cgroup counters. Genuine pressure still triggers the existing alert and reclamation path.
Why This Change Was Made
Diagnostic pressure uses the existing cgroup working-set calculation when raw usage approaches the warning threshold and the visible leaf matches the sampled limit. Missing or mismatched cgroup data falls back to the native reading. The scheduler's available-memory reader and the thresholds are unchanged.
Evidence