Skip to content

Compact execution history before scratchpad persistence#21

Merged
v3g42 merged 3 commits intomainfrom
codex/implement-context-optimization-strategy
Mar 10, 2026
Merged

Compact execution history before scratchpad persistence#21
v3g42 merged 3 commits intomainfrom
codex/implement-context-optimization-strategy

Conversation

@v3g42
Copy link
Copy Markdown
Contributor

@v3g42 v3g42 commented Mar 5, 2026

Motivation

  • Prevent unbounded context growth by keeping full-fidelity execution payloads in storage while sending only compact, high-signal information back into the rolling scratchpad used for prompt construction.
  • Honor tool-provided metadata (e.g., per-part save: false) and enforce a central policy so ephemeral/large tool outputs are not repeatedly injected into LLM calls.

Description

  • Add ExecutionResult::compact_for_history() which truncates long text, summarizes/compacts large JSON, preserves artifact references, and replaces inline images with lightweight placeholders to reduce prompt bloat.
  • Ensure ToolResponse.parts_metadata (save: false) is applied during compaction so ephemeral parts are removed before re-injection into history.
  • Wire compaction into ExecutorContext::store_execution_result() so all execution results persisted to the scratchpad are the compacted versions.
  • Add a unit test test_compact_for_history_filters_save_false_and_truncates_large_parts validating truncation, JSON compaction, and save:false filtering.

Testing

  • Ran unit tests for the new behavior with cargo test -p distri-types compact_for_history -- --nocapture, which passed.
  • Attempted cargo check -p distri-core but it failed in this environment due to an external rusty_v8 archive download error (build script returned HTTP 403), not related to the compaction change.

Codex Task

@v3g42 v3g42 merged commit fa7e235 into main Mar 10, 2026
@v3g42 v3g42 deleted the codex/implement-context-optimization-strategy branch March 10, 2026 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant