Skip to content

fix(session): bound compacted history hydration - #39930

Open
brauliobo wants to merge 1 commit into
anomalyco:devfrom
brauliobo:compacted-history
Open

fix(session): bound compacted history hydration#39930
brauliobo wants to merge 1 commit into
anomalyco:devfrom
brauliobo:compacted-history

Conversation

@brauliobo

@brauliobo brauliobo commented Jul 31, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #35570

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

filterCompactedEffect currently hydrates every message part before discarding history older than the latest completed compaction. This change finds that boundary from lightweight message rows first, then hydrates only the retained messages in batches. Retained tails, incomplete compactions, forks, and the existing stream behavior are unchanged.

On one compacted session this reduced the hydrated window from 609 messages / 11.4 MB of parts to 51 messages / 0.81 MB.

Related to #31638. That PR scans already-hydrated pages; this implementation avoids hydrating oversized parts on the boundary page by separating row discovery from part hydration, as proposed in #35570.

How did you verify your code works?

  • bun test --timeout 30000 test/session/messages-pagination.test.ts test/session/compaction.test.ts test/session/prompt.test.ts test/session/snapshot-tool-race.test.ts
  • bun typecheck from packages/opencode
  • repository pre-push bun turbo typecheck
  • Prettier and targeted oxlint (0 errors)

Screenshots / recordings

N/A - backend memory fix.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

Copy link
Copy Markdown
Contributor

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 Jul 31, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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

Potential Duplicate Found:

This PR appears to address the same issue—avoiding full history hydration after compaction. Both PRs focus on optimizing memory usage by limiting what gets hydrated from prompt history during session compaction iterations. You should verify whether PR #31638 is already merged or if it needs to be reconciled with the current PR #39930.

@brauliobo
brauliobo force-pushed the compacted-history branch from 086e5ab to 94c5234 Compare July 31, 2026 19:02
@brauliobo brauliobo changed the title fix(opencode): bound prompt history hydration fix(session): bound compacted history hydration Jul 31, 2026
@brauliobo

Copy link
Copy Markdown
Author

Addressed the follow-up comments:

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Jul 31, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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.

perf(core): avoid hydrating discarded compacted session parts

1 participant