Repository navigation
Conversation
Signed-off-by: Afloat <ShuffleMonkey@163.com>
chrisknvidia
left a comment
There was a problem hiding this comment.
I reproduced the allocation blow-up on main with the 22,922-byte, 2,000-function nested shell fixture: tracemalloc peak was 50.2 MB for the individual validator and 50.1 MB for the bundle preflight (about 11 s each), dropping to 3.9 MB and 2.3 MB on this branch, with both paths still ending incomplete and no embedding client constructed. That matches the numbers in the description.
Chunk output is unchanged for files within the budget. I chunked 649 files (every .md, .mdc, .py and .sh under tests/ plus a generated set of nested, CRLF, long-line, comment-only, unmatched-brace, unicode, syntax-error and fenced-markdown cases, with and without a line offset) on main and on this branch and the chunk lists are identical, text, ordering, line ranges and split groups included. For every file, max_chunks=N returns the same list, N-1 and 0 raise with the expected first-excess count, bool, negative, float and string budgets are rejected, chunk_shell still returns a list, and no shell generator is left alive after the early exit.
The incomplete-result contract holds too: across 20 validator and preflight scenarios (at budget, one over, far over, budget exactly consumed and then an empty or non-empty file, zero ceiling, reversed file order, shared member budgets at 3 and 4) status, error text, file_path and the zero embedding calls match main. The one visible difference is the reported actual / actual_chunks value, which is now limit + 1 rather than the eager total; see the inline note. Of the 13 new tests, the four scale regressions, the four exact-output tests and the zero-budget test fail on main's source and pass here; the two shared-budget pairs pass on both trees, which is fine as guards. tests/deduplication, tests/tier2 and the Tier 2 command tests pass on both trees with no new failures, and lint, format and git diff --check are clean.
A second note inline on the untested max_chunks type guard, also not blocking. I also did a separate differential run over about 1,100 generated files (shell with nested functions, heredocs, quoted braces, CRLF and unterminated functions, plus Markdown, MDC and Python) at two min_chars settings: every chunk field from chunk_file and chunk_shell is byte-identical between main and this branch. Open PR #394 rewrites the same chunk-count lines in plugin/commands.py, so whichever lands second needs a small rebase.
Signed-off-by: Afloat <ShuffleMonkey@163.com>
Summary
Nested shell functions produce overlapping raw bodies. Skill and bundle context deduplication currently materialize every body and every bounded piece before checking their chunk ceilings. Small nested scripts can therefore allocate many times their source size even though the scan ultimately stops as incomplete.
Pass each file the remaining skill or aggregate bundle budget and produce shell chunks on demand. Stop at the first excess bounded piece, preserve each caller's existing incomplete result and error, and never create embeddings for the oversized scan. Files within the budget retain the same complete chunk text, ordering, and source ranges. The public shell chunker retains its list return type.
Verification
make lint, changed-file formatting, andgit diff --checkpassed.make teston exact published headf9f39d1f4ab012de304b2f35339d1dd8750b2376: 45,554 passed, 338 skipped, 19 deselected under the project's existing defaults. No new skips or test exclusions were added.make build; wheel and source distribution built successfully. All three gates ran on a fresh Ubuntu 24.04 runner with Python 3.12.16 and locked all-extra dependencies: validation job.Release Impact
CHANGELOG.md.