fix: prevent context-window crash from huge tool outputs#741
Open
pranav-afk wants to merge 2 commits into
Open
fix: prevent context-window crash from huge tool outputs#741pranav-afk wants to merge 2 commits into
pranav-afk wants to merge 2 commits into
Conversation
Contributor
Greptile SummaryThis PR adds recovery paths for large tool output hitting the model context window. The main changes are:
Confidence Score: 4/5The context-window recovery path needs fixes before merging.
strix/core/execution.py, strix/core/tool_output.py, strix/core/sessions.py Important Files Changed
Prompt To Fix All With AIFix the following 3 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 3
strix/core/execution.py:418-421
**Disabled Cap Still Truncates**
When `STRIX_MAX_TOOL_OUTPUT_CHARS=0`, `exec_command` output is left untruncated, but a later context-window retry rewrites the session with the default `65_536` cap anyway. That breaks the documented disable setting and can discard the full tool output the operator explicitly configured the run to keep.
```suggestion
truncated = await truncate_large_outputs_in_session(
session,
max_chars=max_chars,
)
```
### Issue 2 of 3
strix/core/tool_output.py:93
**Hard Cap Exceeds Limit**
When the first JSON record plus the truncation header is larger than `max_chars`, `_hard_cap` slices `max_chars` characters and then appends another marker. The stored tool output can exceed the configured cap, so a recovery meant to fit the next model request can still leave oversized history behind.
```suggestion
marker = "\n...[truncated]"
if max_chars <= len(marker):
return text[:max_chars]
return text[: max_chars - len(marker)] + marker
```
### Issue 3 of 3
strix/core/sessions.py:34-39
**Rewrite Can Erase Session**
During context-window recovery, this helper clears the persisted session before it knows the rebuilt items can be written back. If `add_items` fails twice after `clear_session()` succeeds, the agent loses its conversation history and the retry continues without the state it was trying to recover.
Reviews (1): Last reviewed commit: "fix: prevent context-window crash from h..." | Re-trigger Greptile |
d979355 to
438d0b1
Compare
44e87ca to
daf39a2
Compare
Cap exec_command results, recover by truncating session history instead of image-strip on ContextWindowExceededError, and surface scan failures as TUI toasts. Closes usestrix#579.
Respect disabled tool-output cap, keep hard-cap within max_chars, and restore session history if rewrite fails.
438d0b1 to
a9842bb
Compare
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.
Cap exec_command results, recover by truncating session history instead of image-strip on ContextWindowExceededError, and surface scan failures as TUI toasts. Closes #579.