Skip to content

fix: clear tool output and attachments during compaction prune#16162

Closed
guazi04 wants to merge 1 commit intoanomalyco:devfrom
guazi04:fix/prune-clear-output
Closed

fix: clear tool output and attachments during compaction prune#16162
guazi04 wants to merge 1 commit intoanomalyco:devfrom
guazi04:fix/prune-clear-output

Conversation

@guazi04
Copy link

@guazi04 guazi04 commented Mar 5, 2026

Problem

When compaction prunes old tool outputs, only the time.compacted timestamp was being set — the actual output string and attachments array remained in storage indefinitely. This caused unbounded storage growth.

Evidence:

  • Database size: 774 MB after 3 weeks of usage
  • Storage breakdown: 81% part data (unpruned outputs), 0.07% summaries
  • Duplicate tool invocations accumulating due to incomplete pruning

Solution

This PR clears the actual data when marking parts as compacted:

  1. compaction.ts (2 lines):

    • Clear output and attachments array in prune() when setting time.compacted
  2. prompt.ts (2 calls):

    • Add prune() calls before both compaction triggers to reduce context before LLM summarization
    • Reduces token count and storage footprint simultaneously
  3. Tests (new coverage):

    • Verify prune clears output/attachments when compaction.enabled=true
    • Verify prune respects compaction.enabled=false (skips clearing)
    • Test integration with both compaction trigger points

Testing

  • Unit tests: prune() behavior with/without config
  • Test fixtures cover clearing behavior verification
  • No breaking changes to existing API

Fixes part of #16101

When compaction prunes old tool outputs, only the `time.compacted` timestamp
was being set — the actual output string and attachments array remained in
storage indefinitely. This caused unbounded storage growth (observed 774 MB
database in 3 weeks, with 81% being part data).

Changes:
- Clear output and attachments when prune marks parts as compacted
- Add prune() calls before both compaction triggers in prompt.ts to reduce
  context before LLM summarization
- Add tests for prune clearing behavior and config respect

Fixes part of anomalyco#16101
@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Mar 5, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found related PRs that address similar issues:

Potentially Related PRs:

  1. PR fix: resolve memory leak issues across multiple subsystems #14650 - "fix: resolve memory leak issues across multiple subsystems"

  2. PR fix: clear tool output and attachments when pruning to prevent memory leak #7049 - "fix: clear tool output and attachments when pruning to prevent memory leak"

  3. PR feat(opencode): prune old tool outputs before compaction #14827 - "feat(opencode): prune old tool outputs before compaction"

Note: PR #7049 appears to be addressing the same core problem (clearing tool output and attachments to prevent memory/storage leaks). You should verify if this is a duplicate or if PR #16162 is an update/fix to the previous approach.

@guazi04
Copy link
Author

guazi04 commented Mar 5, 2026

Superseded by #16175 which includes this fix plus the full MVP (CLI commands, VACUUM support, cross-project cascade fix).

@guazi04 guazi04 closed this Mar 5, 2026
@guazi04 guazi04 deleted the fix/prune-clear-output branch March 5, 2026 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:compliance This means the issue will auto-close after 2 hours. needs:issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant