Skip to content

fix(skills/bounding-heavy-commands): stop the suggested budget from counting file cache - #67

Merged
sourcehawk merged 6 commits into
fix/first-measure-default-budgetfrom
fix/budget-without-file-cache
Sep 30, 2026
Merged

sourcehawk merged 6 commits into
fix/first-measure-default-budgetfrom
fix/budget-without-file-cache

Conversation

@sourcehawk

@sourcehawk sourcehawk commented Sep 30, 2026 •

Copy link
Copy Markdown
Owner

Description

Fixes #59

The budget that --measure suggested 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 is CACHE_FLOOR_DIVISOR.

Changes

  • While a capped command runs, the one existing sampler also reads the cgroup's memory.stat and keeps the peak of anon + shmem + file_dirty + file_writeback + kernel. It falls back to the kernel fields that exist on older kernels.
  • The suggested budget is min(old suggestion, max(held + approximate margin, peak / 4 + margin)). Without the cap, it is the old suggestion.
  • The summary line and the row line gain held: row label=… cpus=… budget=NM peak=NM held=NM|- exact=… exit=….
  • The skill's description of the row line and of the suggested budget, and discovery step 5, say this.

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

Testing

TDD with fake memory.stat files. 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 its kernel line), 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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 Medium severity · 3 Low severity

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.

Comment thread skills/bounding-heavy-commands/SKILL.md Resolved
Comment thread skills/bounding-heavy-commands/SKILL.md Resolved
Copilot AI balanced review requested due to automatic review settings September 30, 2026 02:35
@sourcehawk

Copy link
Copy Markdown
Owner Author

Review round on ac75a60 (review 5360813901). No suppressed findings.

Comment gate: the comment above HELD_FIELDS did not change, and no other code comment changed in this round. Self-evaluated: this session could not dispatch an agent.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Kernel-specific memory accounting and the intentionally unvalidated cache-floor heuristic warrant final human review.

Review effort: Balanced
Findings: None

Resolved since last review (5)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 Low severity

Open (1)

Comment thread skills/bounding-heavy-commands/SKILL.md Resolved
Copilot AI balanced review requested due to automatic review settings September 30, 2026 08:57
@sourcehawk
sourcehawk force-pushed the fix/budget-without-file-cache branch from 56f1670 to 625017d Compare September 30, 2026 08:57
@sourcehawk

Copy link
Copy Markdown
Owner Author

Review round on 56f1670 (review 5363881606). No suppressed findings.

  • Document held=- as a valid value in the fixed form: applied in 625017d.

Comment gate: no code comment changed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The modern-kernel calculation includes reclaimable slab in held memory, potentially inflating budgets.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
Resolved since last review (1)

Copilot AI balanced review requested due to automatic review settings September 30, 2026 09:06
@sourcehawk
sourcehawk force-pushed the fix/budget-without-file-cache branch from 625017d to 8fa8e02 Compare September 30, 2026 09:06
@sourcehawk

Copy link
Copy Markdown
Owner Author

Review round on 625017d (review 5363991968). No suppressed findings.

  • Exclude slab_reclaimable from kernel memory accounting: fixed in 8fa8e02, with the updated fixture.

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The record workflow cannot correctly update budgets when held memory changes without the full peak changing.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
Resolved since last review (1)

Comment thread skills/bounding-heavy-commands/SKILL.md Resolved
Copilot AI balanced review requested due to automatic review settings September 30, 2026 09:15
@sourcehawk

Copy link
Copy Markdown
Owner Author

Review round on 8fa8e02 (review 5364113946). No suppressed findings.

  • Track held memory to detect budget changes at unchanged peak: applied in 1f53642. The update rule now compares the suggested budget.

Comment gate: no code comment changed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Platform-sensitive cgroup accounting and the intentionally unbenchmarked cache floor warrant final human validation.

Review effort: Balanced
Findings: None

Resolved since last review (1)

sourcehawk and others added 6 commits September 30, 2026 11:22
…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>
@sourcehawk
sourcehawk force-pushed the fix/budget-without-file-cache branch from 1f53642 to 0a8c95d Compare September 30, 2026 10:22
@sourcehawk
sourcehawk merged commit 48fd634 into main Sep 30, 2026
10 checks passed
@sourcehawk
sourcehawk deleted the fix/budget-without-file-cache branch September 30, 2026 10:23
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.

The suggested budget counts file cache, so commands that write many files get budgets far above their need

2 participants