Repository navigation
fix: let the macOS app answer the first chat instead of reporting low memory - #200373
Conversation
… memory OpenClaw-Publication: 6e8fd73b-396e-8724-877c-ed5d5e30291d
|
🦞👀 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 changes before merge. What this changesThis PR centralizes reclaimable-memory readings for Bun on macOS and uses them for session admission, background work, and update-worker sizing. Example: A 48 GB Mac reports 496,746,496 available bytes under the bundled Bun runtime.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Regression provenancePossible regression — probable (reviewed change; failure trace). No predecessor PR is attributed. Merge readiness⛔ Needs changes before merge - 1 item remains Keep open: this PR addresses a source-confirmed macOS first-chat blocker and has clear maintainer value, but the patch needs correction before merge. Priority: P0 Before merge
Findings
Tests
Agent review detailsHow this fits togetherThe shared host-memory reader translates runtime and operating-system readings into byte counts consumed by session admission, host statistics, background scheduling, and worker sizing. flowchart TD
A[macOS Mach statistics] --> C[Shared memory reader]
B[Runtime memory APIs] --> C
C --> D[CLI session admission]
C --> E[Background scheduling]
C --> F[Host statistics]
C --> G[Update worker sizing]
Technical reviewBest possible solution: Keep the shared reclaimable-memory reader and genuine-pressure guards, and include its new dependency in the wrapper extraction inventory. Do we have a high-confidence way to reproduce the issue? The reporter's native Bun reading falls below the unchanged 1 GiB guard, and inspection of fetched main plus the pinned Bun source confirms the complete failure path; no reviewer-run macOS reproduction is claimed. Is this the best way to solve the issue? Correcting memory semantics in the existing shared owner is a focused repair that preserves pressure protection and fixes its affected consumers without adding settings or persistent state. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f57dbb4ff67e. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +62, Tests +101. Total +163 across 11 files. Added test files: 1. 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: 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 Reviewed November 16, 2026, 10:02 PM ET / November 17, 2026, 03:02 UTC. |
Packaged macOS app end-to-end proofI tested the packaged macOS app on the affected Mac, a 48 GB Apple silicon MacBook Pro running macOS 26.5.1. Each turn is a chat message ("hi") to the app's local Gateway with Builds (signed Apple Development builds from
To keep free pages consistently low, a helper process held 6 GiB for each run. That matches the Mac's ordinary state: macOS keeps truly free pages low, and most memory is inactive or purgeable. For each turn:
Before (d29fad4): 0 of 8 turns replied. Each one failed with the error from the issue. After (90aa806, this PR): 8 of 8 turns replied. Bun's raw reading was just as low. The Gateway log (
Without the memory hold, Not covered: I didn't click through onboarding in the app UI. The Mac was in active use, so I sent turns through the app's Gateway instead of driving its chat window. The turns run through the same Gateway agent run, CLI backend and memory guard that the app's chat uses. |
OpenClaw-Publication: 6164efbe-6191-8a83-8a7f-8c492b603b47
Fixes #200340
What Problem This Solves
On the macOS app, the first message after onboarding fails with "This host is low on memory, so it could not start another session", even on a Mac with plenty of free memory. The app's local Gateway runs on Bun. On macOS, Bun's
process.availableMemory()counts only truly free pages, about 0.5 GB on a 48 GB Mac in normal use. The 1 GiB Claude CLI live-session guard therefore refuses the session.The same reading also made optional background work think the process was out of memory on every Mac. Bun reports
process.constrainedMemory()as physical RAM, so "available ≤ 20% of the limit" was always true. Cron retention, update checks, GitHub publication scans, post-ready maintenance and startup prewarming were deferred indefinitely.User Impact
macOS app users get a reply to their first message. Background maintenance and prewarming run again on Macs. Gateway and node host stats report reclaimable memory instead of only free pages. Node runtimes, and Bun on Linux and Windows, are unchanged.
Why This Change Was Made
readProcessAvailableMemoryBytes()insrc/infra/host-memory.tsis now the single owner of the "available memory" reading. Under Bun on macOS, it bindshost_statistics(HOST_VM_INFO)from libSystem once through Bun's built-in FFI. It returns the same formula Node uses (libuvuv_get_available_memory: free + inactive + purgeable pages × page size). Speculative pages are already part offree_count. Each reading is one Mach call, about 0.1 ms after the first, with no cache.Callers that read
process.availableMemory()directly now use the owner:readHostFreeMemoryBytes(): the CLI live-session guard, doctor rebuild concurrency,system.info, node host stats.isConstrainedProcessLowOnMemory().resolveUpdateHashWorkerCount().scheduleGatewayPrewarm(), which repeated the same 20% check inline. With the shared check, Node/Linux hosts without a cgroup limit also prewarm. Node reportsconstrainedMemory()as 2^64 there, which the shared check already treats as no limit.Tests that faked memory pressure by stubbing
process.availableMemory()now stubisConstrainedProcessLowOnMemory(). On a Mac under the Bun test runner, the old stub would be bypassed. The threshold itself stays covered inhost-memory.test.ts.Not changed: the guard error is still classified as
rate_limit/429. Changing that alters failover and user-copy behavior beyond this fix; it is noted as a follow-up in the issue.Evidence
Packaged app, before and after (full output). I built and signed the macOS app twice on the affected Mac: from
maind29fad4and from this PR's head90aa806. On the app'sonboardingprofile, I sent "hi" eight times through its local Gateway, which runs on the bundled Bun 1.4.4 and uses the Claude CLI live session. Each turn used a new session. A helper held 6 GiB so that truly free pages stayed low throughout, as they do in normal use.availableMemory()maind29fad4claude-clilive sessionmemory_pressurereported 58–61% free during both runs. Without the memory hold,mainfails only some of the time, because free pages on this Mac swing around 1 GiB.Helper under the bundled Bun. The final
host-memory.ts(sha256e31ed057…c965) ran under the app's bundled Bun 1.4.4, alternating with Node 26.12.1 at the same moments:process.availableMemory()process.availableMemory()Under Bun,
isConstrainedProcessLowOnMemory()isfalse(constrainedMemory()= 51,539,607,552 =totalmem()). The first call, including the FFI bind, takes 1.6–5.4 ms; later calls take 0.01–0.13 ms.Tests:
src/infra/host-memory.test.tssimulates Bun on macOS (availableMemory() == freemem()= 512 MiB,constrainedMemory()= 48 GiB) with fake Mach counters. Plentiful reclaimable memory admits a CLI live session through the realensureCliLiveSessionMemory. Genuinely low Mach memory (256 MiB) still throwscli_live_session_host_memory. Further cases cover pressure, update-hash workers and Node's unchanged reading.origin/main's helper, 3 of the 4 Bun cases fail. The guard fails with the same "Host memory is too low for another CLI live session" as the issue.pnpm check:changedpasses; its dead-export scan was skipped because of existing failures onmainin files this PR does not touch. Test-lines ratchet: +101 of 400.Gap: I sent the turns through the app's Gateway with its CLI instead of clicking through onboarding in the chat window, because the Mac was in active use. The turns take the same Gateway, CLI-backend and memory-guard path as the app's chat.
🦞 Made with OpenClaw