Skip to content

fix: serialize compaction and preserve messages written mid-summarization - #1889

Merged
avoidwork merged 1 commit into
mainfrom
fix/compaction-race
Nov 18, 2026
Merged

avoidwork merged 1 commit into
mainfrom
fix/compaction-race

Conversation

@avoidwork

Copy link
Copy Markdown
Owner

Description

Fixes a race in compactAgentContext where messages written to the thread during the slow summarization step were wiped by the replace-all updateState, leaving the agent echoing its last statement. Compactions are now serialized per thread, and the state is re-read before the write so newly arrived messages are carried over.

Type of Change

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactor (no functional changes)
  • Performance improvement
  • CI / build / tooling

Testing

Added two unit tests in tests/unit/deepAgents.test.js: one verifying a message arriving mid-compaction is preserved, one verifying concurrent compactions on the same thread run in order. All 31 tests in the file pass. The narrowed window between the re-read and updateState remains, and the middleware-triggered path is not locked against a live run.

Coverage

  • Line coverage maintained

Checklist

  • npm run lint passes
  • Tests pass with maintained line coverage
  • No forbidden patterns used
  • Conventional Commit style applied

@avoidwork avoidwork added the bug Something isn't working label Nov 18, 2026
@avoidwork avoidwork self-assigned this Nov 18, 2026
@avoidwork
avoidwork merged commit a50d3d2 into main Nov 18, 2026
3 checks passed
@avoidwork
avoidwork deleted the fix/compaction-race branch November 18, 2026 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant