Skip to content

fix(memory): honor nested cgroup limits (#3273) - #3273

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/cgroup-cache-limit
Jul 26, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/cgroup-cache-limit

Conversation

@Sinity

@Sinity Sinity commented Jul 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

Caps adaptive parsed-session cache sizing to the current process's actual cgroup hierarchy, including nested systemd service limits.

Problem

The cache-sizing helper read only root cgroup files. For a rebuild worker constrained by a nested 10 GiB systemd limit, it instead observed host RAM and could admit an 8 GiB whale cache alongside normal replay overhead.

Solution

  • Discover v2 and v1 memory-limit files from proc self cgroup membership through the process ancestry.
  • Select the tightest finite limit together with host physical RAM.
  • Add focused tests for nested v2 discovery and the production cap calculation.

Verification

  • Focused parsed-tree sizing tests: 2 passed.
  • Quick verification: format, lint, mypy, generated-surface, layering, schema, and policy gates passed.

Summary by CodeRabbit

  • Bug Fixes

    • Improved effective memory detection for environments with nested container or cgroup limits.
    • Memory usage now respects the most restrictive finite limit across the full cgroup hierarchy, preventing overestimation.
  • Tests

    • Added coverage for nested cgroup ancestry and memory limits.
    • Added validation that effective memory is capped below available host RAM when required.

Problem: adaptive parsed-session caches observed host RAM from the root cgroup even when a systemd worker had a lower nested memory limit. A whale-bearing rebuild page could therefore size its cache beyond the worker envelope.

What changed: discover memory-limit files along the current process's cgroup v2 or v1 ancestry and cap cache sizing by the tightest finite limit. Focused tests cover nested v2 path discovery and the effective host-limit cap.

Co-Authored-By: Codex <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

parsed_tree_size.py now discovers cgroup v1/v2 memory-limit files across the process’s cgroup ancestry and caps host RAM using the smallest finite limit. Unit tests cover nested paths and effective-memory capping.

Changes

Cgroup memory limit handling

Layer / File(s) Summary
Discover cgroup ancestry limit paths
polylogue/pipeline/parsed_tree_size.py, tests/unit/pipeline/test_parsed_tree_size.py
The new helper parses /proc/self/cgroup, walks cgroup ancestors, identifies v1/v2 limit files, deduplicates paths, and tests nested v2 ancestry discovery.
Apply ancestry limits to effective memory
polylogue/pipeline/parsed_tree_size.py, tests/unit/pipeline/test_parsed_tree_size.py
effective_physical_memory_bytes() reads discovered finite limits, returns the minimum with host RAM, updates its docstring, and tests cgroup-based capping.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant effective_physical_memory_bytes
  participant _cgroup_memory_limit_paths
  participant cgroup_limit_files
  effective_physical_memory_bytes->>_cgroup_memory_limit_paths: obtain ancestry limit paths
  _cgroup_memory_limit_paths-->>effective_physical_memory_bytes: return candidate files
  effective_physical_memory_bytes->>cgroup_limit_files: read finite memory limits
  cgroup_limit_files-->>effective_physical_memory_bytes: return limit values
  effective_physical_memory_bytes-->>effective_physical_memory_bytes: select minimum with host RAM
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and clearly matches the main change: honoring nested cgroup memory limits.
Description check ✅ Passed The description matches the template well with Summary, Problem, Solution, and Verification filled in.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/cgroup-cache-limit

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Sinity Sinity changed the title fix(memory): honor nested cgroup limits fix(memory): honor nested cgroup limits (#3273) Jul 23, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 42ce0312e7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread polylogue/pipeline/parsed_tree_size.py Resolved
@Sinity
Sinity merged commit 1eeb37c into master Jul 26, 2026
3 checks passed
@Sinity
Sinity deleted the feature/fix/cgroup-cache-limit branch July 26, 2026 07:15
@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

  • 69.F084 / P2: fixed-already at the checked revision: polylogue/pipeline/parsed_tree_size.py:174 reads both the actual cgroup-v1 mount point and mount root from mountinfo. Lines 207-226 apply the process membership relative to those roots, covering combined-controller and nonstandard memory mounts.

Only the rows listed above are dispositioned. Held findings remain open.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant