Skip to content

fix(context): prevent tiny-budget overflow - #12

Open
vibe-cy wants to merge 1 commit into
vixues:mainfrom
vibe-cy:fix/context-budget-overflow
Open

fix(context): prevent tiny-budget overflow#12
vibe-cy wants to merge 1 commit into
vixues:mainfrom
vibe-cy:fix/context-budget-overflow

Conversation

@vibe-cy

@vibe-cy vibe-cy commented Jul 20, 2026

Copy link
Copy Markdown

Problem

When the remaining context budget is smaller than the truncation suffix, pinned context blocks can still be truncated and kept. In that case, the resulting truncated block may exceed the available budget instead of being dropped.

Solution

Apply the same minimum remaining-budget guard used by candidate blocks to pinned blocks. If the remaining budget cannot fit both content and the truncation notice, the pinned block is dropped and recorded in the budget ledger with final_cost=0.

Changes

  • Guard pinned block truncation when remaining <= len(TRUNCATION_SUFFIX).
  • Add regression coverage for tiny pinned budgets.
  • Add coverage ensuring truncated pinned blocks stay within the remaining budget.

Testing

  • uv run pytest tests/test_context/test_budget_cost.py -q
  • uv run pytest tests/test_context -q
  • uv run ruff check leagent/context/budget.py tests/test_context/test_budget_cost.py

Notes for Reviewer

This keeps pinned block behavior aligned with the existing candidate block path. Pinned blocks are still preserved whenever the remaining budget can fit a truncation notice plus at least one body character.

@vibe-cy
vibe-cy requested a review from vixues as a code owner July 20, 2026 08:05
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.

1 participant