Dashboardopencode-lorecgroup-memory.ts live hierarchy discove…

cgroup-memory.ts live hierarchy discovery

Category: gotcha
Confidence: 1.00
ID: 01a0aec4-490a-7415-ab6f-1d318375c410
Project ID: 6f4be9ff-ed84-4cca-a9e7-732a0b0b8677
Cross-project: No
Recalled in other projects: 0
Source session: 1JmtIdaVnn5PTPdxS
Created: 2026-09-15 14:53:06
Updated: 2026-09-17 09:48:14

Content

Trap: caching cgroup discovery, choosing the first matching mount, or using min(os.freemem(), process.constrainedMemory()) looks cgroup-aware, but memberships and mounts change, multiple roots may match, and constrainedMemory() is a limit—not headroom. Fix: re-read /proc/self/cgroup and mountinfo every call, safely decode and reject non-absolute/NUL/.. paths, select a mount whose root contains the membership, prefer explicit v1 memory on hybrid hosts, and take minimum limit-minus-usage through every readable descendant boundary. Never fall back to v2 when explicit v1 is unresolved; unknown or mid-call-changing state fails closed.

Move to: