Repository navigation
fix(skills/bounding-heavy-commands): stop the suggested budget from counting file cache - #67
Conversation
cff49b0 to
ac75a60
Compare
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The fallback undercounts kernel memory, guidance remains inconsistent, and the cache floor lacks required validation.
Review effort: Balanced
Findings: 2
Open (5)
What changed in this PR
Adjusts capped-command measurement so reclaimable file cache does not dominate suggested memory budgets.
Changes:
- Samples non-reclaimable cgroup memory and reports
held. - Applies held-memory margins and a cache floor.
- Updates guidance and test coverage.
| File | Description |
|---|---|
skills/bounding-heavy-commands/SKILL.md |
Documents held-memory budgeting and output. |
skills/bounding-heavy-commands/scripts/bounded_run.py |
Implements sampling and budget calculation. |
skills/bounding-heavy-commands/scripts/tests/test_bounded_run.py |
Tests calculations, sampling, and output. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Review round on ac75a60 (review 5360813901). No suppressed findings.
Comment gate: the comment above |
03022ae to
56f1670
Compare
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
The operational cache-floor behavior remains intentionally unvalidated on representative large builds, and the fixed-form documentation needs a minor correction.
Review effort: Balanced
Findings: 1
Open (1)
56f1670 to
625017d
Compare
625017d to
8fa8e02
Compare
|
Review round on 625017d (review 5363991968). No suppressed findings.
Comment gate, self-evaluated: one new inline comment, "The 'kernel' line also counts the reclaimable slab, the cache of file names and inodes." It stays, because it gives the outside fact that the subtraction depends on. |
…ounting file cache The suggested budget came from memory.peak of the command's cgroup, which counts the page cache that the kernel takes back under the cap. A command that writes many files, such as a development server with a build cache, got a budget near the whole queue. While a capped command runs, the one sampler now also reads memory.stat and keeps the peak of the memory that the kernel cannot take back at once: anon, shmem, kernel (or its parts on an older kernel), and dirty and writeback file pages. The suggested budget is that peak with the margin for a sample, at least a quarter of memory.peak with its margin as a floor for the cache that a command reads again, and never more than the budget from memory.peak. Without a cgroup the budget is as before. The row line gains held=<n>M after peak= (held=- without the cap), and the summary line names both peaks. Fixes #59 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the held memory of an older kernel A kernel with a 'kernel' line in memory.stat counts page tables and vmalloc memory in it. On an older kernel the wrapper added the parts of kernel memory itself but left out pagetables, sec_pagetables, and vmalloc, so the same command reported less held memory there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…asurement, and stop calling the budget the peak The suggested budget can now be far below the cap that stopped a run, so "two times the budget that the wrapper printed" could retry below the failed cap. The rule now names the budget of the cap in the summary line. A Red Flags row still said that the budget is the measured peak plus a margin. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…f the row line The wrapper prints held=- when it has no sample of the held memory, and the prose says so, but the fixed form in the skill showed only a number. It now shows both, as the usage text does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…f the held memory on a newer kernel The 'kernel' line of memory.stat includes slab_reclaimable, the cache of file names and inodes, which the kernel can take back under the cap. The held memory counted it, so a command that walks many files got a larger held peak than it needs. The wrapper now subtracts slab_reclaimable from the kernel line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…budget moves, not only the peak Under the hard cap the suggested budget follows the held memory, so it can change while the full peak stays the same. The record rule changed a row only when the peak moved, so an agent kept a budget that the wrapper no longer suggested. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1f53642 to
0a8c95d
Compare


Description
Fixes #59
The budget that
--measuresuggested counted file cache. The peak of a command's cgroup includes the pages of the files it reads and writes, and under the cap the kernel takes those back before it stops the command. So a command that writes many files got a budget far above its need: an end-to-end suite with a development server got 20480M, the whole queue on its machine. Under the cap, the wrapper now also samples the memory that the kernel cannot take back at once, and suggests that plus a margin. It keeps a floor of a quarter of the full peak for the cache, and never suggests more than before. The floor is a reasoned default, not one measured on a large build yet: a command that thrashes under its new cap needs a higher floor, and the constant isCACHE_FLOOR_DIVISOR.Changes
memory.statand keeps the peak ofanon + shmem + file_dirty + file_writeback + kernel. It falls back to the kernel fields that exist on older kernels.min(old suggestion, max(held + approximate margin, peak / 4 + margin)). Without the cap, it is the old suggestion.held:row label=… cpus=… budget=NM peak=NM held=NM|- exact=… exit=….Challenges
Dirty and writeback pages count as held memory, because the kernel must write them out before it can drop them. A command that writes fast can be stopped by its cap while its cache is still dirty, even though the cache is reclaimable in principle. Counting those pages keeps the budget of such a command high enough.
Related
CACHE_FLOOR_DIVISORif the build thrashes or if a quarter is still far too high.Testing
TDD with fake
memory.statfiles. The tests cover the exact field sum (cache and reclaimable slab left out), the fallback kernel fields (with page tables and vmalloc, which a newer kernel counts in itskernelline), missing fields, dirty and writeback pages, and the budget arithmetic: a peak that is mostly cache gets the floor, grown anonymous memory is covered, and the budget is never above the old one. In-process runs with a faked cap check the full row and summary lines. The real-cgroup test checks that a command which holds 150 MiB of anonymous memory reports at least 140 MiB held. A real byte-compile of the Python standard library under a 2G cap reported peak 229 MiB, held 175 MiB, and 512M suggested, the same as before: a small workload that confirms the code path, not the floor. The full suite passes through the queue on top of the layer below.🤖 Generated with Claude Code