Skip to content

fix(devices): report available memory instead of raw free pages on macOS - #144293

Closed
ylcn91 wants to merge 1 commit into
openclaw:mainfrom
ylcn91:fix/issue-144176
Closed

ylcn91 wants to merge 1 commit into
openclaw:mainfrom
ylcn91:fix/issue-144176

Conversation

@ylcn91

@ylcn91 ylcn91 commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Closes #144176

What Problem This Solves

Fixes an issue where the memory meter in Control UI → Devices, on both paired node rows and the Gateway row, showed close to 100% used and rendered red on any macOS host, even when the machine was idle.

Why This Change Was Made

Both host-stat producers read os.freemem(), which on Darwin counts only free pages and ignores inactive and purgeable file cache, so total - free always lands near the total. Node's process.availableMemory(), available on the supported Node 24 and 26 baselines, counts reclaimable pages as well. One readHostFreeMemoryBytes() helper in src/infra/host-memory.ts now serves the node-host sampler and the Gateway system.info handler, and falls back to os.freemem() where the runtime reports no available-memory figure. The memoryFreeBytes wire field and the meter's 80/90% thresholds are unchanged; the field's meaning is stated in the presence protocol doc.

Not changed: the issue's debug.overlay.memoryMb claim concerns process heap, a different diagnostic that matches its current implementation.

User Impact

macOS operators see a memory meter that reflects memory actually under pressure instead of a permanent danger-level shortage. Linux and Windows readings are unchanged, because libuv already reports available memory there (verified on this Linux host: os.freemem() and process.availableMemory() both return the MemAvailable figure).

Evidence

  • src/node-host/host-stats.test.ts drives the sampler through process.availableMemory (fails on main, where the sampler still reads os.freemem) and covers the free-memory fallback; system-info.test.ts asserts the Gateway row uses the same reader.
  • node scripts/run-vitest.mjs src/node-host/host-stats.test.ts src/gateway/server-methods/system-info.test.ts packages/gateway-protocol/src/schema/nodes.test.ts: all passed.
  • Not captured: a live macOS Control UI screenshot; this devbox is Linux. The Darwin difference is libuv's uv_get_free_memory (free_count only) versus uv_get_available_memory (free + inactive + purgeable) in deps/uv/src/unix/darwin.c.
  • pnpm check:changed: pending, will update.

@clawsweeper

clawsweeper Bot commented Sep 10, 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.

Node and Gateway host stats read os.freemem(), which on Darwin counts only free
pages and ignores inactive and purgeable file cache. The Control UI memory meter
therefore sat at or near 100% on idle Macs and rendered as a danger-level
shortage. Read process.availableMemory(), which counts reclaimable pages, through
one shared host-memory helper for both producers, and keep os.freemem() as the
fallback where the runtime reports no available-memory figure. Wire fields and
meter thresholds are unchanged.

Closes openclaw#144176
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Sep 10, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 10, 2026
@clawsweeper

clawsweeper Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 10, 2026, 2:55 PM ET / 18:55 UTC.

ClawSweeper review

What this changes

The PR shares an available-memory reader between Gateway and node statistics, updates regression tests, and documents reclaimable memory in the existing wire field.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 5 items remain

The macOS correction remains necessary, but applying the new reader on Linux introduces misleading container memory readings. Real after-fix macOS proof is also still needed.

Priority: P2
Reviewed head: 12c0b82544eaf98795c5e1673bcdfd09d9b98af7

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The focused repair has useful regression coverage, but a cross-platform measurement defect and missing macOS runtime proof prevent merge readiness.
Proof confidence 🦪 silver shellfish (2/6) Needs stronger real behavior proof before merge: Needs real behavior proof before merge: the captured body reports tests and a Linux API comparison, but no after-fix macOS Gateway or node-stat result. Provide redacted production output or before/after Devices screenshots or video; remove private addresses, keys, and identifiers. Updating the PR body should trigger review; otherwise ask a maintainer for @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: Needs real behavior proof before merge: the captured body reports tests and a Linux API comparison, but no after-fix macOS Gateway or node-stat result. Provide redacted production output or before/after Devices screenshots or video; remove private addresses, keys, and identifiers. Updating the PR body should trigger review; otherwise ask a maintainer for @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 8 items Introduced platform-independent memory substitution: The new helper calls process.availableMemory on every platform; both producers retain os.totalmem as their denominator. The complete host-provided merge-base delta establishes these edits as PR-introduced.
Supported Node runtime confirms Linux cgroup mismatch: Node v24.16.0 resolves to this commit. Its bundled libuv returns cgroup limit minus current usage from uv_get_available_memory, while free and total memory read host MemAvailable and MemTotal. This dependency inspection applies because the introduced helper directly calls Node’s available-memory API.
Darwin correction has a native implementation: The supported runtime’s Darwin available-memory implementation includes free, inactive, and purgeable pages, supporting the intended macOS correction without a shell command.
Findings 1 actionable finding [P2] [P2] Restrict the available-memory substitution to Darwin
Security None None.

How this fits together

Gateway and node hosts publish resource statistics that feed the Control UI’s device memory meters. Those meters calculate usage by subtracting reported free memory from total host memory.

flowchart TD
  A[Operating system memory] --> B[Shared memory reader]
  B --> C[Gateway system information]
  B --> D[Node resource snapshots]
  C --> E[Device memory calculation]
  D --> E
  E --> F[Usage meter and warning color]
Loading

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: Needs real behavior proof before merge: the captured body reports tests and a Linux API comparison, but no after-fix macOS Gateway or node-stat result. Provide redacted production output or before/after Devices screenshots or video; remove private addresses, keys, and identifiers. Updating the PR body should trigger review; otherwise ask a maintainer for @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • [P2] Restrict the available-memory substitution to Darwin (P2) - On Linux with a memory cgroup limit, process.availableMemory() returns the cgroup allowance minus current usage, while both callers still report os.totalmem() for the whole host. For example, 1 GiB available in a container on a 64 GiB host produces roughly 98% used even when the host has ample memory. This introduces the same misleading red meter for existing Linux deployments and contradicts the claimed unchanged Linux behavior. Use the available-memory API on Darwin and preserve the existing host reader elsewhere.
  • Resolve merge risk (P1) - Existing memory-limited Linux deployments would receive different, misleading host utilization readings after upgrading.
  • Resolve merge risk (P1) - The available evidence does not establish the corrected macOS result through either production statistics entrypoint.
  • Complete next step (P2) - Fix the Linux cgroup mismatch and add redacted after-fix macOS proof for Gateway and paired-node statistics.

Findings

  • [P2] [P2] Restrict the available-memory substitution to Darwin — src/infra/host-memory.ts:9-10
Agent review details

Security

None.

PR surface

Source +13, Tests +8, Docs +2. Total +23 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 15 2 +13
Tests 2 10 2 +8
Docs 1 3 1 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 28 5 +23

Review metrics

None.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #144176
Summary: This PR is a candidate repair for the linked device-memory report; the issue remains open pending a validated fix.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Limit the substitution to Darwin (recommended)
    Preserve os.freemem on other platforms and cover constrained Linux readings alongside the Darwin correction.

Technical review

Best possible solution:

Keep one shared Darwin-aware reader that preserves other platforms’ host-memory semantics, existing wire fields, and meter thresholds.

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

Yes, through source: Darwin free-page accounting explains the original warning, and Linux cgroup accounting establishes the introduced mismatch. No runtime reproduction was executed during this read-only review.

Is this the best way to solve the issue?

No, the shared producer repair is appropriate but the API substitution must be Darwin-specific to preserve consistent host-level measurements elsewhere.

Full review comments:

  • [P2] [P2] Restrict the available-memory substitution to Darwin — src/infra/host-memory.ts:9-10
    On Linux with a memory cgroup limit, process.availableMemory() returns the cgroup allowance minus current usage, while both callers still report os.totalmem() for the whole host. For example, 1 GiB available in a container on a 64 GiB host produces roughly 98% used even when the host has ample memory. This introduces the same misleading red meter for existing Linux deployments and contradicts the claimed unchanged Linux behavior. Use the available-memory API on Darwin and preserve the existing host reader elsewhere.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: Misleading resource warnings affect operator diagnostics without blocking normal operation.
  • add merge-risk: 🚨 compatibility: The unconditional API substitution changes existing Linux container readings from host availability to cgroup allowance.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: Needs real behavior proof before merge: the captured body reports tests and a Linux API comparison, but no after-fix macOS Gateway or node-stat result. Provide redacted production output or before/after Devices screenshots or video; remove private addresses, keys, and identifiers. Updating the PR body should trigger review; otherwise ask a maintainer for @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Label justifications:

  • P2: Misleading resource warnings affect operator diagnostics without blocking normal operation.
  • merge-risk: 🚨 compatibility: The unconditional API substitution changes existing Linux container readings from host availability to cgroup allowance.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: Needs real behavior proof before merge: the captured body reports tests and a Linux API comparison, but no after-fix macOS Gateway or node-stat result. Provide redacted production output or before/after Devices screenshots or video; remove private addresses, keys, and identifiers. Updating the PR body should trigger review; otherwise ask a maintainer for @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Introduced platform-independent memory substitution: The new helper calls process.availableMemory on every platform; both producers retain os.totalmem as their denominator. The complete host-provided merge-base delta establishes these edits as PR-introduced. (src/infra/host-memory.ts:9, 12c0b82544ea)
  • Supported Node runtime confirms Linux cgroup mismatch: Node v24.16.0 resolves to this commit. Its bundled libuv returns cgroup limit minus current usage from uv_get_available_memory, while free and total memory read host MemAvailable and MemTotal. This dependency inspection applies because the introduced helper directly calls Node’s available-memory API. (deps/uv/src/unix/linux.c:2259, c7d10158bc31)
  • Darwin correction has a native implementation: The supported runtime’s Darwin available-memory implementation includes free, inactive, and purgeable pages, supporting the intended macOS correction without a shell command. (deps/uv/src/unix/darwin.c, c7d10158bc31)
  • Node binding reaches libuv: GetAvailableMemory returns uv_get_available_memory, connecting the changed JavaScript API to the inspected platform behavior. (src/node_process_methods.cc:256, c7d10158bc31)
  • Observable consequence in device meters: The renderer computes (total minus free) divided by total and uses 80/90 percent warning thresholds. A 64 GiB host with 1 GiB available within a constrained process therefore displays about 98 percent used regardless of healthy host memory. (ui/src/pages/devices/host-stats.ts:78, 12c0b82544ea)
  • Current main and latest release retain the original reader: The fetched main node sampler still uses os.freemem; separate inspection found the same reader in main’s Gateway producer and in the v2026.9.3 node sampler. No implemented-on-main closure is supported. (src/node-host/host-stats.ts:11, a4ad6f3137d0)

Likely related people:

  • Peter Steinberger: Raw commit fcc0d52 adds src/node-host/host-stats.ts:10 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: fcc0d52b880e; files: src/node-host/host-stats.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Preserve Linux host-memory semantics and add regression coverage for a constrained process on a larger host.
  • Provide after-fix macOS evidence covering Gateway and paired-node memory readings.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@ylcn91

ylcn91 commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

Closing this one: the user-visible proof for this change is a before/after Devices page capture on macOS, and I cannot produce that on my Linux host. The unit-level evidence in the description is not enough for a Control UI change. The branch stays available at ylcn91:fix/issue-144176 if someone with a Mac wants to pick it up with the missing capture.

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

Labels

docs Improvements or additions to documentation 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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Device inventory memory bar always red on macOS due to os.freemem() misunderstanding

1 participant