Skip to content

feat(memory): optimize persistent memory by pruning legacy tool calls - #812

Merged
haiphucnguyen merged 4 commits into
mainfrom
feature/optimize-memory-persistent
Nov 9, 2026
Merged

haiphucnguyen merged 4 commits into
mainfrom
feature/optimize-memory-persistent

Conversation

@haiphucnguyen

Copy link
Copy Markdown
Collaborator

⚠️ First-time contributor? This PR cannot be merged until you sign the CLA.
The CLA Assistant bot will post a comment below — reply to it with exactly:
I have read the CLA Document and I hereby sign the CLA
(Separate from this: all commits must also be signed off with git commit -s — see the Checklist.)

Summary

  • Prune redundant tool-call round-trip messages for finalized legacy turns
  • Persist memory cleanup back to database to prevent reloading bloat
  • Add comprehensive unit and Ollama integration tests

Related Issue(s)

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 💥 Breaking change
  • 📝 Documentation
  • ♻️ Refactor (no functional change)
  • 🧪 Tests
  • 🔧 Chore / tooling / CI

What Changed & Why

How to Test

./gradlew test

Screenshots / Recordings (if applicable)

Checklist

  • I have read the CONTRIBUTING guide
  • I signed the CLA (first-time contributors — reply to the CLA Assistant bot comment)
  • My branch is up to date with main
  • I ran ./gradlew spotlessApply and ./gradlew detekt locally
  • I ran ./gradlew test and all tests pass
  • I added/updated tests for my changes (if applicable)
  • I added/updated documentation (if applicable)
  • My commits are signed off (DCO) — git commit -s
  • This PR is focused on a single feature/fix

Additional Notes

- Prune redundant tool-call round-trip messages for finalized legacy turns
- Persist memory cleanup back to database to prevent reloading bloat
- Add comprehensive unit and Ollama integration tests
Copilot AI lite review requested due to automatic review settings November 9, 2026 06:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Two moderate test-coverage issues remain: one test prunes the tool-call unit before exercising forceCompact(), and another does not verify that the persisted state reflects the required cleanup.

2 open issues
What changed in this PR

This PR reduces persistent conversation-memory growth by pruning completed tool-call round trips while preserving unfinished interactions and cleaning legacy persisted sessions.

Changes:

  • Added per-turn and whole-history pruning for finalized tool-call messages.
  • Persisted cleaned memory state during legacy-session loading.
  • Added unit and Ollama integration coverage for pruning and summarization behavior.
File Description
shared-jvm/​src/​main/​kotlin/​io/​askimo/​core/​memory/​TokenAwareSummarizingMemory.kt Implements finalized tool-call pruning and persistence cleanup during loading.
cli/​src/​test/​kotlin/​io/​askimo/​core/​memory/​TokenAwareSummarizingMemoryTest.kt Adds unit coverage for finalized, unfinished, multi-round, and legacy tool-call histories.
cli/​src/​test/​kotlin/​io/​askimo/​core/​memory/​TokenAwareSummarizingMemoryOllamaIT.kt Adds Ollama-backed coverage for summarization and force-compaction behavior.

This pull request requires changes.

Review effort: Lite

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

A moderate active issue remains because pruning an empty terminal AI response can remove in-memory tool messages without persisting the cleanup or recalculating token pressure, allowing the history to return on the next session load.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Persist pruning when the terminal answer has no text

shared-jvm/​src/​main/​kotlin/​io/​askimo/​core/​memory/​TokenAwareSummarizingMemory.kt:335

This cleanup is not durable for a terminal AiMessage whose text is blank (for example, an image-only response): addMessageToDb() returns immediately for blank getTextContent(), so after this block removes the tool-call messages, the database still contains the old round-trip and _usedTokens/pressure are not recomputed. On the next session load there is no persisted terminal answer to trigger pruning, and the tool history comes back. Persist and call updatePressure() when this pruning removes messages even if the new answer has no text, or otherwise handle this blank-terminal path explicitly.

2 resolved since last review

Review effort: Lite

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

A moderate active finding shows the test assertion can pass even when the tool-call pair is incorrectly pruned, so the intended round-trip behavior remains unverified.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Test assertion passes when both tool-call messages are pruned

cli/​src/​test/​kotlin/​io/​askimo/​core/​memory/​TokenAwareSummarizingMemoryOllamaIT.kt:237

This assertion passes in both cases: when the tool-call pair survives (true == true) and when forceCompact() prunes both messages (false == false). Consequently the test does not verify the behavior promised by its name and would not catch the round-trip being removed entirely. Arrange the pair in the protected recent units or assert the intended survival outcome separately, while retaining a separate parity assertion for the non-splitting invariant.

Review effort: Lite

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The recorded review state identifies no active issues, and the change provides the intended memory-pruning and persistence improvements.

No open issues 🎉

Review effort: Lite

@haiphucnguyen
haiphucnguyen merged commit ab8ad09 into main Nov 9, 2026
8 of 15 checks passed
@haiphucnguyen
haiphucnguyen deleted the feature/optimize-memory-persistent branch November 9, 2026 07:42
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.

2 participants