Skip to content

fix(runtime): defer optional work on low-memory Linux hosts - #200180

Merged
vincentkoc merged 6 commits into
mainfrom
fix/host-physical-memory-pressure-20261117
Nov 25, 2026
Merged

vincentkoc merged 6 commits into
mainfrom
fix/host-physical-memory-pressure-20261117

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Optional background work can continue consuming memory on Node/Linux hosts that have little available physical memory but no finite process memory limit. A zero process.constrainedMemory() means no known OS constraint, not zero headroom. See the Node 24.22.1 contract.

User Impact

The shared admission check now also defers optional work when available host memory is at or below 20% of physical capacity. Eight runtime owners use it: prompt-cache keep-warm, cron maintenance, GitHub publication, idle database page-cache work, startup database maintenance, handler prewarming, per-agent session-history prewarming, and update checks. Existing retry owners resume eligible work after pressure clears. Handler prewarm is different: skipping it at startup leaves handlers to load on demand; it does not add a recovery timer.

Mandatory session-fact registration, cron startup, and delivery recovery remain unchanged. No configuration, migration, timer, or new polling loop is added.

Why This Change Was Made

The canonical host-memory owner independently checks physical headroom while preserving finite process-limit handling, including zero available process memory. On Node/Linux, the host reading includes reclaimable memory (MemAvailable), rather than raw MemFree; the pinned libuv source defines this reading. Unknown/zero host readings do not manufacture pressure. Current Bun/macOS Mach-memory handling, cgroup readers, and non-Linux/Bun admission behavior are preserved.

The existing PR's percentage policy applies to all host sizes. A 1 TiB host with 200 GiB available still defers this optional work. That is the deliberate tradeoff of preserving the shared 20% reserve; this change does not introduce a board-specific threshold or claim that every such large host is thrashing.

The earlier reconciliation preserved the original signed PR commit and merged frozen main 1bec22471ad0114e4d3fe57954ccb443c5672262, including its newer keep-warm and handler-prewarm callers. Against that main revision, production changes add 11 net lines and tests/setup add 136.

Evidence

The signed integration commit is 46660f9d1691144835ad12c163520eff12d1cb83. It merges main ab45e28c4d2bb615a90f5cba3331a7a2fe4a6641 into the existing PR. A clean Git merge with the prior head left a removed export in the history prewarmer, two unbound calls in late warmups, and stale test doubles. Node reproduced the missing-export error. The corrected import executes, all eight runtime owners use the shared admission check, and the suite covers a pressure change between history warmups and delayed handlers. This integration changes eight references across four files, with zero net lines. Against this main baseline the whole PR adds 11 net production lines and 133 net test lines.

All 11 affected suites passed on Linux Testbox at that integration commit. The five shards reported 136 passing tests and 23 skipped database variants. Independent P0–P3 review of the full integrated diff found no actionable issue. This is controlled admission and recovery evidence. The exact-head battery does not measure absolute RSS or real-provider first-turn survival.

The current signed head is 126bff771209245d49f40d3dcec51c7e372a9e04. Hosted CI identified a formatting difference in the deferred prewarm condition. The correction joins two lines. The entire condition and all other source bytes match the tested integration commit. Pinned oxfmt 0.74.0 passed all 21 changed files. The final diff is +10 net production lines and +133 net test lines.

Prior results

Candidate: 27b226477bafd32cb56fffe4599d9cc57a04bf31. Signed merge 2897a5414502774a410a8300c72b7352552b95d9 preserves the prior PR head 3abd7087d6999fa735efad34d8ce28a8930874a9 and frozen main 1bec22471ad0114e4d3fe57954ccb443c5672262; the following signed commit contains only native formatter line wrapping.

On Node 24.22.1, Linux ARM64, the native repository wrappers passed all 10 selected test files: 123 passed, 23 declared PostgreSQL-only skips, across five Vitest shards. This includes host/process pressure recovery in cron, keep-warm session-recovery admission, startup-only prewarm skipping, and the existing publication/page-cache/update consumers. PostgreSQL execution is not claimed.

Targeted formatting and lint passed on all 19 changed files. The production core type check and all 29 test type graphs selected by the native changed-path owner passed. The isolated container reused the canonical build target at frozen main: all 256 dependency inputs matched byte-for-byte, and all 19 candidate source hashes were verified before and after proof. The network-isolated wrapper used its supported Node fallback because the pinned Bun fork was unavailable; this is Node proof, not native Bun execution.

At the time of the prior result, that head had not completed hosted PR CI or a full packaged build. The baseline build image is dependency qualification, not a claim that the reconciled candidate was packaged.

Independent source review found no actionable issue across the seven callers, current runtime contracts, test isolation, and mandatory-work boundaries. The repository's autoreview fallback also completed with no actionable P0–P2 finding on the frozen delta; its supplied-diff scope does not replace the full-owner source review. A controlled-input run of the complete host-memory source passed 16 cases, including no-limit and unsafe-sentinel hosts, both sides of the 20% threshold, large hosts, unknown metrics, zero process headroom, and unchanged Bun/macOS behavior. All 19 changed TypeScript files also passed native syntax stripping. These checks do not measure RSS savings or exercise live Gateway admission.

A separate idle sample on a 353 MiB Linux host with Node 24.22.1/libuv 1.52.1 observed constrainedMemory() = 0 and matching process.availableMemory(), os.freemem(), and Linux MemAvailable of about 201 MiB; raw MemFree was only 34 MiB. This validates the reclaimable-memory signal and healthy-host classification. Earlier pressure samples were taken separately; they are not a measured Node threshold crossing or a live admission/recovery test.

Historical proof belongs to the old head: manual CI 43914849970 passed its focused tests/type graphs/build, while ordinary PR CI 43921148731 had a Bun readiness fixture mismatch and a separate unresolved PostgreSQL deadline cancellation. Neither run qualifies this reconciled head.

No live low-memory Gateway recovery or fresh-install/upgrade run is claimed. No measured memory saving is claimed.

Operator qualification: one physical trial

One isolated ARM64 trial on a 353 MiB host running uncapped Node used a backport onto the previously tested 01640493-based build. HTTP binding was observed at 17m15s, while the previous matched build was still refusing connections at 20m53s: earlier binding in one trial only. /readyz returned HTTP 503 with startup-sidecars; no HTTP 200 or model reply was observed. At 29m31s elapsed, the watchdog terminated the Gateway after an approximately 301-second main-thread stall. No kernel OOMs were observed.

This hardware result does not prove defer/resume behavior at the exact upstream head or establish that this change makes the Gateway work on this board. The automated tests above cover admission.

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

clawsweeper Bot commented Nov 16, 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 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: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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 16, 2026
@clawsweeper

clawsweeper Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR defers optional background work when Node/Linux reports available host memory at or below 20% of physical capacity.

Example: An uncapped Node/Linux Gateway has 353 MiB of physical memory and 40 MiB available.

  • Before: The process-limit-only check admits optional maintenance because constrainedMemory() returns zero.
  • After: Optional maintenance waits for memory recovery, while skipped startup handlers retain their request-time loaders.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused shared-owner patch has no identified correctness defect, but controlled tests do not satisfy the required runtime proof.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
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 competes with foreground requests on Linux hosts with little available memory and no finite process limit.
Reason: The source confirms the admission gap, and the maintainer-authored direction explicitly accepts the percentage policy without introducing configuration or another owner.

Merge readiness

✅ Ready for maintainer review

This PR addresses a current-main admission gap with a small, coherent change; no actionable code defect was found, and its maintainer-authored direction is already accepted.

Reviewed head: 126bff771209245d49f40d3dcec51c7e372a9e04

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Provide sanitized shipped-Gateway evidence on uncapped Node/Linux showing optional work defer under host pressure and eligible work resume after recovery, including fresh-install and latest-stable upgrade behavior with settings and data intact; base-failing regression execution is also not established by the supplied results.
Agent review details

How this fits together

The host-memory owner converts operating-system memory readings into a shared admission decision consumed by Gateway warmups, cron, publication recovery, and update scheduling.

flowchart TD
  A[Operating system memory readings] --> B[Host memory owner]
  B --> C[Shared optional work admission]
  C --> D[Gateway warmups and maintenance]
  C --> E[Cron and prompt cache warming]
  C --> F[Publication and update checks]
  D --> G[Existing retry or request time loading]
Loading

Technical review

Best possible solution:

Keep the shared host-memory repair and existing recovery owners, then establish its runtime behavior before landing.

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

Source establishes the failure path: with constrainedMemory() equal to zero, current main returns false regardless of available physical memory; the added cases exercise that input, but no product execution was performed during this read-only review.

Is this the best way to solve the issue?

Extending the existing shared owner and replacing its internal callers is the smallest complete repair; it preserves Bun/macOS handling, finite process limits, mandatory startup work, and existing retry ownership.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Current main retains the gap: The fetched main implementation requires a positive finite process limit before reporting pressure, so an uncapped Linux host cannot trigger this optional-work guard through low physical headroom. (src/infra/host-memory.ts:78, 40757d73039f)
  • Small shared-owner repair: The introduced diff preserves finite-limit handling, adds the Node/Linux host-headroom branch, and migrates all eight runtime consumers without retaining the old export or adding scheduling machinery. (src/infra/host-memory.ts:78, 126bff771209)
  • Re-review change is formatting only: Comparison with the previously reviewed integration head shows only joining the deferred-template condition onto one line. (src/gateway/server-startup-handler-prewarm.ts:181, 126bff771209)
  • Authoritative Linux memory contract: The PR depends on Node's memory-reading contract; pinned libuv uv_get_free_memory reads MemAvailable, including reclaimable memory, before its sysinfo fallback. (deps/uv/src/unix/linux.c:2058, ce7aaf1cee78)
  • Accepted percentage tradeoff: The maintainer-authored PR explicitly accepts applying the 20% reserve to every host size, including a 1 TiB host with 200 GiB available; this does not require another product approval. (126bff771209)
  • Proof scope and inspection limit: The body reports focused controlled-input tests and explicitly disclaims live admission/recovery and fresh-install/upgrade proof. The linked Testbox workflow is cancelled; its redirected logs were blocked by the network allowlist, so its reported test totals could not be independently confirmed. (126bff771209)

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 71d835b adds src/infra/host-memory.ts:56 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 71d835b63abc; files: src/infra/host-memory.ts)

PR surface

Source +10, Tests +133. Total +143 across 21 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 9 41 31 +10
Tests 12 165 32 +133
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 21 206 63 +143

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 +41/−31, net +10; tests/setup +165/−32, net +133 Growth is proportionate to the shared policy extension, platform boundaries, consumer recovery checks, and deterministic host-memory fixtures.

Labels

Label changes:

No label changes.

Label justifications:

  • merge-risk: 🚨 compatibility: Existing uncapped Node/Linux installations gain a host-wide reserve that can postpone maintenance, publication recovery, and update checks even on large hosts; the maintainer-authored body explicitly accepts this tradeoff.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab 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 (3 earlier review cycles)
  • reviewed 2026-11-16T17:23:01.127Z sha 3abd708 :: needs maintainer review before merge. :: none
  • reviewed 2026-11-25T01:05:21.967Z sha 27b2264 :: needs maintainer review before merge. :: none
  • reviewed 2026-11-25T09:40:05.539Z sha 46660f9 :: needs maintainer review before merge. :: none

Reviewed November 25, 2026, 4:51 AM ET / 09:51 UTC (Revision 4).

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: M labels Nov 25, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review current head 27b2264. The PR body now records the current seven admission owners, preserved Bun/macOS behavior, the all-size 20% reserve tradeoff, and exact-head test/type/format/lint evidence. The prior review covered 3abd708; live low-memory Gateway recovery and a full current-head packaged build remain unclaimed.

@clawsweeper

clawsweeper Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: discord Channel integration: discord channel: googlechat Channel integration: googlechat channel: imessage Channel integration: imessage channel: line Channel integration: line channel: matrix Channel integration: matrix channel: mattermost Channel integration: mattermost labels Nov 25, 2026
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Dependency graph guard cleared

This PR no longer has dependency changes awaiting review. A future dependency graph change requires an admin or SecOps member’s /allow-dependencies-change comment after the guard notice identifies that revision.

  • Current SHA: 126bff771209245d49f40d3dcec51c7e372a9e04

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Security-sensitive guard cleared

Current revision: 126bff771209245d49f40d3dcec51c7e372a9e04

This PR no longer changes files in the maintainer security-review tier.

Separate CODEOWNERS requirements still apply to security policy and enforcement files.

@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review the signed head 46660f9d1691144835ad12c163520eff12d1cb83. The integration updates the delayed handler and per-agent history warmups to the shared host-memory check. The current PR body records the Node import regression and the results from all 11 affected suites.

@clawsweeper

clawsweeper Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

The new head 126bff771209245d49f40d3dcec51c7e372a9e04 applies the CI formatter to one condition. Pinned oxfmt passes all 21 files. The PR body identifies the tested integration commit and remaining hardware qualification.

@clawsweeper

clawsweeper Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash auto-merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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