You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Measure host memory in the opt-in PyTorch loader - #477
Stacked on #476. Implements C-139–143 from the #353 inventory.
Summary
The existing 33-anchor loader can now measure host memory during ingestion, fresh and reloaded materialization, iterator startup and each batch request. Every repetition runs unprivileged in a dedicated Linux cgroup. Choose kernel for per-interval memory.peak or sampled for memory.current every 10 ms. Both modes sample anonymous memory and keep the raw observations and gaps in the worker results.
Testing Done
From packages/experimental/kumo-pytorch on Linux, set PARENT to an existing delegated cgroup v2 parent with the memory controller enabled. Each loader invocation defaults to three workers.
On Linux 7.0.14, the unprivileged preflight worker saw memory.peak go from 524,288 B to 34,340,864 B after a 32 MiB allocation, then back to 520,192 B after resetting the same descriptor.
At commit 3708ec8e, the validator module recorded 7 passes and 1 skip for the separately opted-in cache validator. Both memory modes passed all three repetitions. Each produced 12 complete epochs, 84 batches and 117 memory intervals, including the three-anchor tail in each epoch. The ordinary loader passed four epochs and returned its original report format. Timeout and SIGTERM cleanup left zero worker cgroups.
Median of three workers’ stage peaks on this host, in MiB. Both modes sampled anonymous charges every 10 ms.
C-139–143 require stage-level host memory measurements on a delegated Linux host. The existing package runner already exercises both fit paths and all 33 anchors. The opt-in modes add cgroup isolation and memory observations to that workload.
Read the worker’s selected mode at the measured interval. Reset and read the kernel peak on one descriptor or sample total charges. Sample anonymous charges in both modes and save interval evidence.
Report stage peaks and expose the sampling gaps that can hide short allocations.
CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.
Parsing warnings: 1
Validation error: Unrecognized key: "tone_instructions" at "reviews"
If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
No actionable comments were generated in the recent review.
Walkthrough
The timing tools add optional Linux cgroup-v2 host-memory measurement in kernel and sampled modes. The supervisor runs workers in isolated cgroups. Measurement intervals record host and anonymous memory peaks for loader operations. The timing command accepts host-memory and cgroup-parent options and includes measurement metadata in reports. Tests cover allocation measurements, loader interval records, cgroup membership validation, and timeout cleanup.
Sequence Diagram(s)
sequenceDiagram
participant TimingCLI
participant TimingCampaign
participant run_isolated
participant Worker
participant memory_interval
participant cgroup_v2
TimingCLI->>TimingCampaign: Pass host-memory method and cgroup parent
TimingCampaign->>run_isolated: Run timing worker
run_isolated->>cgroup_v2: Create private cgroup
run_isolated->>Worker: Launch interpreter with cgroup settings
Worker->>cgroup_v2: Join cgroup and run loader operation
Worker->>memory_interval: Measure operation interval
memory_interval->>cgroup_v2: Validate membership and read memory counters
memory_interval-->>Worker: Record interval peaks
run_isolated->>cgroup_v2: Clean up worker cgroup
Loading
Merge Risk: Low · up to d6ea0
This adds opt-in host-memory measurement to the test tooling. Two minor issues remain: failure reports can omit a batch that was already returned, and the kernel-mode documentation omits the writable memory.peak prerequisite. Neither affects default runs, so the change is mergeable with owner awareness.
Security architecture risk: Moderate · up to d6ea0
When the benchmark runs with administrator privileges, an unprivileged worker can redirect a file read by the supervisor. If worker cleanup fails, the run can also leave a cgroup behind without a recovery step. These risks are limited to hosts that opt into memory measurement.
Retained concerns
Medium · security · observed: In root mode, the supervisor grants the worker group write access to the repetition directory and then follows the worker-controlled result pathname as root. The unchanged read now crosses a privilege boundary: a worker or another principal with write access to that directory can redirect the read to a regular file outside the run. Parsing and aggregation happen after the open, so they do not prevent the unauthorized read or resulting campaign failure. Disclosure through the report is conditional and was not demonstrated.
Low · reliability · observed: The new teardown can exit before removing the worker cgroup if a kill operation fails, the child wait times out, or the group remains populated. The campaign stops launching workers for caught cleanup errors but provides no retry or later cleanup owner. A stale group can remain, and surviving processes are possible if termination did not take effect. This is a recovery gap, not evidence of a cgroup escape.
Security review details
Security Blast Radius
inferred — The identified privileged read requires a root opt-in run and influence over its worker output. Its direct scope is files readable by that supervisor on the benchmark host; the inspected path does not establish remote or cross-service reachability.
Security Findings and Attack Paths
observed — The privileged input is the worker-writable result path. The supervisor's regular-file check follows links, and the subsequent read is not constrained to the repetition directory. The report's numeric aggregation is downstream of that read.
Trust Boundaries and Controls
observed — Each worker receives a fresh cgroup and a separate repetition directory. The root-owned campaign directory grants the worker group traversal but not write access; that protects the aggregate report's location, not the integrity of the path used to collect worker results.
Resilience and Maintainability Implications
observed — The supervisor defers cancellation during launch, targets its own child cgroup during teardown, and restores signal handlers. The timeout regression test checks descendant cleanup and sibling survival; it does not exercise a failed teardown or recovery.
Hardening Proposals
proposed — Collect results without root filesystem authority, or use a supervisor-controlled result channel with bounded reads and schema validation instead of opening a worker-controlled pathname as root.
proposed — On teardown failure, record the exact cgroup and cleanup phase, retain the original failure, and assign an explicit recovery owner before treating the campaign as finished.
Pre-merge checks: 2 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Change Map Design Review
(previously flagged, unaddressed)
Details from the previous assessment are unavailable.
Passed checks: 2 passed
Check name
Status
Explanation
Pr Size
The PR size check fails only when the changed-file count exceeds 40. git diff --name-status over the review range refs/coderabbit/pre-merge-check/base..head lists 7 changed files: 5 modified (`tes…
Public Resource Access
The check applies only to external resource references whose text this PR adds or modifies. I inspected the complete reviewed diff (7 changed files, about 435 insertions) for URLs, git/SSH/package-ind…
Full details: Pr Size
Explanation
The PR size check fails only when the changed-file count exceeds 40. git diff --name-status over the review range refs/coderabbit/pre-merge-check/base..head lists 7 changed files: 5 modified (tests/conftest.py, tests/e2e/loader_timing.py, tests/e2e/runs.py, tests/e2e/test_runs.py, tests/test_native_anchor_handoff.py) and 2 added (tests/e2e/host_memory.py, tests/e2e/memory_worker.py). No renames or deletions appear. The count is 7, which is at or below the threshold of 40, so the check passes. Line counts were ignored, as the check requires.
Full details: Public Resource Access
Explanation
The check applies only to external resource references whose text this PR adds or modifies. I inspected the complete reviewed diff (7 changed files, about 435 insertions) for URLs, git/SSH/package-index references, registry or package sources, and documentation links. Neither the case-insensitive pattern search nor the broader search for http, www, kernel.org, docs, .html, .md or "reference" text found any added external reference in the changed files. The changed files are conftest.py, host_memory.py, loader_timing.py, memory_worker.py, runs.py, test_runs.py and test_native_anchor_handoff.py. The only link-like text is the "File-by-file change map" link in the PR description. That is a pointer to a PR comment on the same PR. It is not repository content and is not required to understand, build, or test the changed code, so it falls outside this check. Because the check only fails on a confirmed inaccessible reference, and none was added to the code, the check passes.
Latest assessment: Change Map Design Review
Latest assessment: The latest assessment was inconclusive; the previous failure remains unresolved.
Latest explanation: The check reviews the PR conversation comment that starts with <!-- kumo-pr-change-map -->. That comment is not available to this run. What I checked: - The checkout has no copy of the comment. The marker appears only in the PR template, docs/development/review.md, .coderabbit.yaml, and .github/scripts/pr-change-table.cjs. - No tool in this run reads PR conversation comments. The primary PR record gives only the identity and author. - The PR description links to the comment (issuecomment-7075125627) but does not reproduce its table. - The PR objectives include a distilled "Comments summary" of the change map. It is a paraphrase, not the comment. It does not show whether the comment states the observed failure, the inspected existing behavior, the smallest sufficient change, focused verification, and a stopping condition. - The changed-file inventory matches the seven files named in the summary. The deterministic table check covers file coverage. This check does not assess coverage. Because the table text is missing, I cannot judge whether each change is necessary or belongs at the right layer. I did not assess the design from the summary alone. The previous FAIL has no details. I cannot confirm or refute it from the available evidence. The PR description also cites the "#353 inventory" (C-139–143) as the source of the requirement. That source is not in the checkout, so the observed failure cannot be verified here.
Latest resolution: Provide the full body of the <!-- kumo-pr-change-map --> comment, or make the PR comment readable to this check. Then rerun the check. The rerun should confirm that the comment: 1. States the observed failure or the explicit release requirement. It should name the C-139–143 inventory items or give the equivalent requirement text. 2. Describes the existing behavior that was inspected. 3. Explains why each row is the smallest sufficient change. Optional refinements should appear in a separate section. 4. Names the focused verification for each behavior change. 5. States a stopping condition. If the rerun finds an unsupported row, the author should narrow or remove that row. The table should describe material behavior, including the fallback to subprocess.run when host-memory measurement is off and the cleanup behavior on timeout and interruption.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 4 remain after this review.
275-275: Minor · Data Integrity & Integration · Quick win
Preserve a returned batch if memory finalization fails.
If next(batches, None) returns a batch and memory_interval then raises during its end sample or membership check, the exception handler reports only the previous batches. Lines 301-307 never record the returned batch or its native profile. time_loader then saves this incomplete accounting in results.json.
Track successful retrieval separately from measurement completion. If collection fails after retrieval, retain that batch's accounting before propagating the error. Keep requests that fail before returning a batch uncounted.
A delegated memory controller is not sufficient for kernel mode. Linux 6.8 exposes memory.peak as read-only, so host_memory.py fails when it opens that file with "r+b". Newer kernels document reset support through a writable file descriptor. (kernel.org)
State that kernel mode requires resettable memory.peak support. Direct users to sampled mode when that support is unavailable.
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 1 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #476. Implements C-139–143 from the #353 inventory.
Summary
The existing 33-anchor loader can now measure host memory during ingestion, fresh and reloaded materialization, iterator startup and each batch request. Every repetition runs unprivileged in a dedicated Linux cgroup. Choose
kernelfor per-intervalmemory.peakorsampledformemory.currentevery 10 ms. Both modes sample anonymous memory and keep the raw observations and gaps in the worker results.Testing Done
From
packages/experimental/kumo-pytorchon Linux, setPARENTto an existing delegated cgroup v2 parent with the memory controller enabled. Each loader invocation defaults to three workers.On Linux 7.0.14, the unprivileged preflight worker saw
memory.peakgo from 524,288 B to 34,340,864 B after a 32 MiB allocation, then back to 520,192 B after resetting the same descriptor.At commit
3708ec8e, the validator module recorded 7 passes and 1 skip for the separately opted-in cache validator. Both memory modes passed all three repetitions. Each produced 12 complete epochs, 84 batches and 117 memory intervals, including the three-anchor tail in each epoch. The ordinary loader passed four epochs and returned its original report format. Timeout and SIGTERM cleanup left zero worker cgroups.Median of three workers’ stage peaks on this host, in MiB. Both modes sampled anonymous charges every 10 ms.
Change map
File-by-file change map