Skip to content

fix: bound prompt truncation loop - #80

Merged
Upper9527 merged 1 commit into
mainfrom
codex/fix-truncate-loop
Aug 17, 2026
Merged

fix: bound prompt truncation loop#80
Upper9527 merged 1 commit into
mainfrom
codex/fix-truncate-loop

Conversation

@Upper9527

Copy link
Copy Markdown
Collaborator

Summary

  • bound the oldest-message truncation loop by the number of non-system messages
  • preserve system messages and the newest non-system message when the prompt cannot fit
  • log the remaining over-budget condition instead of spinning forever
  • avoid recalculating the original/result token estimates for logging

Closes #77.

Verification

  • pytest -q tests/test_prompt_truncation.py — 2 passed
  • uvx ruff@0.12.2 check .
  • uvx ruff@0.12.2 format --check .
  • full suite: 1 pre-existing dashboard failure, 132 passed, 1 skipped

@Upper9527
Upper9527 merged commit 2e42449 into main Aug 17, 2026
1 check passed
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.

Bug: _truncate_messages infinite loop pegs CPU at 100% when system message alone exceeds max_prompt_tokens

1 participant