Repository navigation
fix(runtime): defer optional work on low-memory Linux hosts - #200180
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis 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.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete 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: Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe 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]
Technical reviewBest 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
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +10, Tests +133. Total +143 across 21 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. Review metrics
LabelsLabel changes: No label changes. Label justifications:
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 follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (3 earlier review cycles)Reviewed November 25, 2026, 4:51 AM ET / 09:51 UTC (Revision 4). |
|
@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. |
|
🦞👀 Re-review progress:
|
Dependency graph guard clearedThis PR no longer has dependency changes awaiting review. A future dependency graph change requires an admin or SecOps member’s
|
Security-sensitive guard clearedCurrent revision: This PR no longer changes files in the maintainer security-review tier. Separate CODEOWNERS requirements still apply to security policy and enforcement files. |
|
@clawsweeper re-review Please review the signed head |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review The new head |
|
🦞👀 Re-review progress:
|
|
Merged via squash auto-merge.
|
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 rawMemFree; 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 mainab45e28c4d2bb615a90f5cba3331a7a2fe4a6641into 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 merge2897a5414502774a410a8300c72b7352552b95d9preserves the prior PR head3abd7087d6999fa735efad34d8ce28a8930874a9and frozen main1bec22471ad0114e4d3fe57954ccb443c5672262; 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() = 0and matchingprocess.availableMemory(),os.freemem(), and LinuxMemAvailableof about 201 MiB; rawMemFreewas 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./readyzreturned HTTP 503 withstartup-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.