Layered VM resource management: cgroup isolation, monitoring, eviction - #1980
Layered VM resource management: cgroup isolation, monitoring, eviction#1980simple-agent-manager[bot] wants to merge 7 commits into
Conversation
Adds PSI memory pressure monitoring, Docker OOM/die-137 event subscription, per-container stats tracking, ResourceGuard lifecycle wiring, env-configurable thresholds/intervals, parser/degradation/race tests, and staging VM verification evidence.
…r-gxcq6m Merging cgroup resource isolation into feature branch for layered resource management
…ot-bs3vz9 Implement pre-stop eviction snapshots
|
|
@coderabbitai review |
|
|
Warning Review limit reachedNext included review available in 35 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (64)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |




Summary
VM_AGENT_MEMORY_RESERVE_MB, default 768MB), ensuring the vm-agent process survives container OOM pressure.PressureEvents() <-chan PressureEventfor consumers. All thresholds env-configurable withDEFAULT_*constants.docker stop— snapshot commands run inside containers), stops the container, and POSTs an eviction callback to the control plane. Callback route uses callback JWT auth (rule 34), mounted beforeprojectsRoutes. Addsevictedworkspace status.Step 4 (control-plane rescheduling) is captured as SAM idea
01M190M3EQK3PFXRKR3DTF7Q8Konly — not implemented in this PR.Validation
pnpm lintpnpm typecheckpnpm testStaging Verification (REQUIRED for all code changes — merge-blocking)
sam/layered-resource-managementevictedstatus type and minor hook type guard).{"status":"healthy"}, staging deploy smoke tests passedStaging Verification Evidence
curl https://api.sammy.party/health→{"status":"healthy","timestamp":"2026-08-31T14:39:20.586Z"}curl https://api.sammy.party/api/projects/test/workspaces/test/eviction→ 401 (callback JWT auth working correctly)UI Compliance Checklist (Required for UI changes)
N/A: no UI changes. The only
apps/web/modifications are addingevictedto the workspace status type guard inuseWorkspacePorts.tsand the API client types.End-to-End Verification (Required for multi-component changes)
Data Flow Trace
Memory pressure detected by kernel
→
packages/vm-agent/internal/resourcemon/pressure.go:parsePSI()reads/proc/pressure/memory→
guard.go:monitorPSI()checks thresholdsOR Docker OOM kill event
→
docker_events.go:Subscribe()listens forevent=oomandevent=diewith exit code 137→
guard.go:monitorDocker()processes eventsResourceGuard emits PressureEvent
→
guard.go:PressureEvents()channel delivers to consumersEviction controller receives event
→
eviction.go:handlePressureEvent()debounces, acquires mutex→
eviction.go:selectEvictionTarget()picks largest memory consumer→
eviction.go:evictContainer()captures snapshot, stops containerServer-side eviction integration
→
server/eviction.go:handleEviction()resolves workspace/session from container→ Captures session snapshot via
captureHibernateSnapshot()with captured ACP identity (rule 49)→ Marks runtime state as
evicted→ POSTs callback to control plane
Control plane receives eviction callback
→
routes/projects/workspace-eviction-callback.tsvalidates callback JWT (rule 34)→ Validates workspace ownership
→ Transitions workspace status to
evicted→ Broadcasts status update via WebSocket
Untested Gaps
01M190M3EQK3PFXRKR3DTF7Q8K.Post-Mortem (Required for bug fix PRs)
N/A: not a bug fix. New feature implementation.
Agent Preflight (Required)
Classification
External References
Codebase Impact Analysis
packages/cloud-init/— systemd slice + MemoryMax override generationpackages/vm-agent/internal/resourcemon/— new package: PSI parser, Docker events, container metrics, ResourceGuard, eviction controllerpackages/vm-agent/internal/server/— eviction integration, snapshot coordination enhancementspackages/vm-agent/internal/config/— resource monitoring configurationapps/api/src/routes/projects/workspace-eviction-callback.ts— new callback routeapps/api/src/index.ts— callback route mountingpackages/shared/src/constants/status.ts—evictedworkspace statusapps/www/src/content/docs/— configuration reference updatesDocumentation & Specs
apps/www/src/content/docs/docs/reference/configuration.md— updated with new env varsapps/www/src/content/docs/docs/reference/vm-agent.md— updated with resource monitoring docsConstitution & Risk Check
All thresholds, timeouts, and limits use
DEFAULT_*constants with env var overrides per Principle XI:DEFAULT_VM_AGENT_MEMORY_RESERVE_MB(768)DEFAULT_RESOURCE_MON_PSI_POLL_INTERVAL_MS(5000)DEFAULT_RESOURCE_MON_PSI_SOME_THRESHOLD(25.0)DEFAULT_RESOURCE_MON_PSI_FULL_THRESHOLD(10.0)DEFAULT_RESOURCE_MON_EVICTION_DEBOUNCE_MS(5000)DEFAULT_RESOURCE_MON_EVICTION_COOLDOWN_MS(30000)Specialist Review Evidence
🤖 Generated with Claude Code