Cap persisted tool results before rehydration#1089
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 318e64e828
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Greptile SummaryThis PR adds a
Confidence Score: 5/5Safe to merge — the change is additive and all production rehydration paths now apply a consistent byte cap with no missed call sites. Every callsite that converts persisted session JSON to ChatMessages for provider consumption is updated. The core truncation is delegated to the already-tested sanitize_tool_result helper. The intentional exception (provider_values_to_chat_messages) is clearly documented and left unbounded by design. Unit and integration tests cover the new code path end-to-end, including char-boundary safety and orphan-filter preservation. No files require special attention.
|
| Filename | Overview |
|---|---|
| crates/agents/src/model/convert.rs | Adds values_to_chat_messages_with_tool_result_limit and maybe_limit_tool_result_content; applies capping to both tool and tool_result roles, preserves orphan filtering and char-boundary safety. |
| crates/agents/src/model/mod.rs | Exports new public API and adds seven well-structured unit tests covering string, JSON, error, char-boundary, orphan-filter, and provider-path scenarios. |
| crates/chat/src/compaction_run/llm_replace.rs | Threads max_tool_result_bytes through to the summary-input conversion; new integration test correctly distinguishes the provider byte cap from tool_prune_char_threshold. |
| crates/chat/src/compaction_run/structured.rs | Threads max_tool_result_bytes into the structured summary-prompt build and adds a parallel integration test; recency-preserving path stays JSON-native and is correctly left unchanged. |
| crates/chat/src/run_with_tools.rs | Applies the capped conversion at both initial chat-history load and retry-after-compaction reload, sourcing the limit from persona config each time. |
| crates/chat/src/service/chat_impl.rs | Updates silent memory turn and prompt-inspection paths; minor refactor avoids calling discover_and_load() twice by storing the config in a local binding. |
| crates/chat/src/streaming.rs | Switches the streaming history-to-messages conversion to the capped variant; single-line, low-risk change. |
| crates/gateway/src/session/summary.rs | Session summary memory write now uses the bounded conversion; straightforward call-site update. |
| crates/gateway/src/session/title.rs | Title-generation history conversion switched to the capped variant; no logic change, just call-site update. |
| crates/chat/src/compaction_run/runner.rs | Threads max_tool_result_bytes into structured::run and llm_replace::run; recency_preserving::run correctly omits it since it operates directly on raw JSON values. |
Reviews (2): Last reviewed commit: "Cap persisted tool results before rehydr..." | Re-trigger Greptile
318e64e to
869fe56
Compare
|
Addressed the review feedback in
Verification:
|
|
@greptile Pls review |
|
@codex advise tests set, docs |
|
To use Codex here, create an environment for this repo. |
|
@codex advise tests set, docs |
|
To use Codex here, create an environment for this repo. |
Summary
toolandtool_resultcontent when session history is rehydrated into provider-boundChatMessagesTesting
cargo test -p moltis-agents model::tests::convert_caps_persisted_string_tool_result_when_limit_is_set -- --nocapturefailed before implementation with missingvalues_to_chat_messages_with_tool_result_limitcargo test -p moltis-agents model::testscargo test -p moltis-agentscargo test -p moltis-chatcargo fmt --checkgit diff --check