Skip to content

feat(core): JIT tool reference injection after pruning (#1740)#1771

Merged
bug-ops merged 1 commit intomainfrom
research-memory-just-in-time-t
Mar 14, 2026
Merged

feat(core): JIT tool reference injection after pruning (#1740)#1771
bug-ops merged 1 commit intomainfrom
research-memory-just-in-time-t

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented Mar 14, 2026

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:

[tool output pruned; full content at {path}]

This allows the agent to re-fetch the content via the read tool if needed, rather than repeating the original tool call blindly.

Changes

  • tool_execution/mod.rs: Add OVERFLOW_NOTICE_PREFIX constant shared between the overflow writer and the new extractor — eliminates magic string coupling
  • context/summarization.rs: Add extract_overflow_ref() helper; apply JIT reference in all three pruning paths: hard compaction loop, prune_tool_outputs, prune_stale_tool_outputs
  • provider.rs: Update flatten_parts() to render body-as-reference when body is non-empty on a compacted ToolOutput
  • debug_dump.rs: Same body-aware rendering for consistency

Test plan

  • extract_overflow_ref() unit tests: happy path, absent notice, empty body, prefix-at-start
  • Pruning path tests in context/mod.rs: all three paths produce [tool output pruned; full content at {path}] when overflow file present
  • Backward-compat: no-overflow case still produces [pruned] / empty body
  • flatten_parts() rendering test: non-empty body on compacted ToolOutput renders reference
  • cargo +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.rs part_to_json_value() ToolOutput branch is untested — needs dedicated test
  • extract_overflow_ref() edge case: prefix present but EM-DASH delimiter absent — missing test
  • SEC-JIT-04: use rfind over find in extract_overflow_ref for hardening against crafted tool output

Closes #1740

@github-actions github-actions bot added enhancement New feature or request size/L Large PR (201-500 lines) documentation Improvements or additions to documentation llm zeph-llm crate (Ollama, Claude) rust Rust code changes core zeph-core crate and removed size/L Large PR (201-500 lines) labels 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
@bug-ops bug-ops force-pushed the research-memory-just-in-time-t branch from aa39032 to aa52129 Compare March 14, 2026 18:58
@bug-ops bug-ops enabled auto-merge (squash) March 14, 2026 18:58
@github-actions github-actions bot added the size/L Large PR (201-500 lines) label Mar 14, 2026
@bug-ops bug-ops merged commit 7e74674 into main Mar 14, 2026
15 checks passed
@bug-ops bug-ops deleted the research-memory-just-in-time-t branch March 14, 2026 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core zeph-core crate documentation Improvements or additions to documentation enhancement New feature or request llm zeph-llm crate (Ollama, Claude) rust Rust code changes size/L Large PR (201-500 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

research(memory): just-in-time tool result retrieval — store large outputs, inject references (Manus/Anthropic pattern)

1 participant