Skip to content

fix(context): trim tool exchanges atomically - #292

Open
louiseboo wants to merge 2 commits into
EverMind-AI:mainfrom
louiseboo:fix/context_tool_exchange_trim
Open

fix(context): trim tool exchanges atomically#292
louiseboo wants to merge 2 commits into
EverMind-AI:mainfrom
louiseboo:fix/context_tool_exchange_trim

Conversation

@louiseboo

Copy link
Copy Markdown

Summary

Prevent context budget trimming from separating an assistant tool call from its matching tool result messages.

The existing canonicalization step closes selected history over tool exchanges, but the later budget loop removes one message at a time. That can leave an orphaned tool result in the provider request and cause OpenAI to reject a long-running session with HTTP 400.

This change treats an assistant tool-call message and all of its matching result messages as one structural unit during budget trimming. The regression test reproduces the previous orphaned-result case and verifies that the final prompt remains structurally valid.

Type

  • Fix
  • Feature
  • Docs
  • CI / tooling
  • Refactor
  • Other

Verification

  • uv run pytest tests/test_history_trimmer.py -q - 3 passed.

  • uv run ruff check raven/context_engine/history_trimmer.py tests/test_history_trimmer.py - passed.

  • uv run ruff format --check raven/context_engine/history_trimmer.py tests/test_history_trimmer.py - passed.

  • Relevant tests pass locally

  • Relevant lint / type checks pass locally

  • User-facing docs or screenshots are updated when needed

No user-facing documentation changes are required for this internal context-trimming fix.

Risk

Budget trimming may remove more than one history message when the selected message belongs to a tool exchange. This is intentional and preserves the provider message contract. Rollback is a revert of this change.

  • Security impact considered
  • Backward compatibility considered
  • Rollback path is clear for risky changes

Related Issues

Fixes #291

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] Budget trimming can orphan tool results and break long sessions with HTTP 400

1 participant