Repository navigation
fix(sed): budget pattern/hold growth against live-intermediate limit - #2698
Merged
Merged
Conversation
The per-cycle step budget resets on N while N preserves pattern space,
so :a;N;100~100{h;G};ba doubles pattern+hold every 100 lines without
tripping the step limit (~13 MB from ~3 KB of input at 1500 lines,
unbounded beyond).
Pattern and hold spaces are now BudgetedStrings charged against the
live-intermediate budget before growth; every command charges aggregate
work plus cancellation/deadline checkpoints. Growth refusal aborts via
the sink error slot (exit 1) instead of warn-and-continue.
Legit input-driven loops ($!N;P;D dedup, G;D, s///, y) are unaffected:
same-size rewrites drop the old charge first, and restart/step guards
keep their input-progress resets.
Tests: PoC regression (1 MB cap), per-command work cap, aggregate input
cap, and deterministic cancel/checkpoint unit tests. Mutation battery:
removing the budgeted type, step/input-progress resets, restart cap, or
per-command work/input charges flips the corresponding test; growth-error
propagation and explicit checkpoints overlap with the framework's
fail-closed lease allocator (poison + sink park), verified still bounded.
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
bashkit | bcd8ed2 | Commit Preview URL Branch Preview URL |
Oct 12 2026, 06:59 AM |
The no_debug_fmt_in_builtin_source static scan (CI failure on the
previous push) requires test-only {:?} in builtins to carry a
// debug-ok: reason on the same line. All flagged sites are #[cfg(test)]
assertion details, never user-facing stderr.
- mod.rs maps Machine::new failure to sed exit 1 (fail closed). - PoC test asserts sed's own status (no pipe) plus a default-budget finite control; work/input knob tests cover aggregate metering.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Closes the sed loop-budget reset finding: the per-cycle step budget resets on
NwhileNpreserves pattern space, sosed -n ':a;N;100~100{h;G};ba'doubles pattern+hold every 100 input lines without tripping the step limit. Growth model: ~13 MB of pattern from ~3 KB of input at 1500 lines, unbounded beyond (419 MB at 2000 lines).Fix
BudgetedStrings charged against the live-intermediate budget before growth (same primitive the output sink already used).sed: <error>, exit 1) instead of warn-and-continue with a truncated pattern.s///,y,Ddrain) drop the old charge first so legit scripts near the limit are not double-counted; restart/step guards keep their input-progress resets, so input-driven loops ($!N;P;Ddedup,G;D) stay unbounded.Before / After
Before (1 MB live cap, PoC): exit 0, amplification succeeds (~13 MB allocated, no refusal) — reproduced by the new test failing pre-fix.
After: refused in ~0.04 s with a bounded diagnostic (
live intermediate bytes …), nonzero status, no OOM. Ordinary loops,s///,y,w,r/Routput paths all still pass (55 sed integration + 79 lib tests green).Tests
pattern_hold_doubling_stops_at_live_intermediate_budget(PoC regression, written failing first)sed_commands_stop_at_work_budget,sed_lines_stop_at_input_budget(aggregate metering)Verification
cargo fmt --checkclean,cargo clippy -p bashkit --all-targets0 warningscargo testrunningProduced by yolop