feat(core): JIT tool reference injection after pruning (#1740)#1771
Merged
feat(core): JIT tool reference injection after pruning (#1740)#1771
Conversation
This was referenced Mar 14, 2026
When soft compaction prunes a tool output that has an existing overflow
file, preserve the path as a reference instead of losing it:
[tool output pruned; full content at {path}]
This lets the agent re-fetch the content via the read tool if needed,
rather than repeating the tool call blindly — matching the Manus /
Anthropic just-in-time retrieval pattern.
Changes:
- Add OVERFLOW_NOTICE_PREFIX constant shared between writer and extractor
- Add extract_overflow_ref() to parse overflow path from body text
- Apply JIT reference in all three pruning paths: hard compaction loop,
prune_tool_outputs, and prune_stale_tool_outputs
- Update flatten_parts() and debug_dump to render body-aware reference
- 8 new unit tests covering parser, pruning paths, and rendering
aa39032 to
aa52129
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.
Summary
Implements the just-in-time tool result retrieval pattern from Manus / Anthropic context engineering research (#1740).
When soft compaction prunes a stale tool output that already has an overflow file on disk, instead of silently clearing the body, the reference is preserved:
This allows the agent to re-fetch the content via the
readtool if needed, rather than repeating the original tool call blindly.Changes
tool_execution/mod.rs: AddOVERFLOW_NOTICE_PREFIXconstant shared between the overflow writer and the new extractor — eliminates magic string couplingcontext/summarization.rs: Addextract_overflow_ref()helper; apply JIT reference in all three pruning paths: hard compaction loop,prune_tool_outputs,prune_stale_tool_outputsprovider.rs: Updateflatten_parts()to render body-as-reference when body is non-empty on a compactedToolOutputdebug_dump.rs: Same body-aware rendering for consistencyTest plan
extract_overflow_ref()unit tests: happy path, absent notice, empty body, prefix-at-startcontext/mod.rs: all three paths produce[tool output pruned; full content at {path}]when overflow file present[pruned]/ empty bodyflatten_parts()rendering test: non-empty body on compactedToolOutputrenders referencecargo +nightly fmt --check✓cargo clippy --workspace --features full -- -D warnings✓cargo nextest run --config-file .github/nextest.toml --workspace --features full --lib --bins✓ (5551 tests, +8 new)Follow-up issues
debug_dump.rspart_to_json_value()ToolOutput branch is untested — needs dedicated testextract_overflow_ref()edge case: prefix present but EM-DASH delimiter absent — missing testrfindoverfindinextract_overflow_reffor hardening against crafted tool outputCloses #1740