Skip to content

fix(runtime): flush transcript writes before persisting compaction - #4871

Merged
dgageot merged 1 commit into
mainfrom
fix/native-compaction-lifecycle-boundary
Nov 9, 2026
Merged

dgageot merged 1 commit into
mainfrom
fix/native-compaction-lifecycle-boundary

Conversation

@dgageot

@dgageot dgageot commented Nov 9, 2026

Copy link
Copy Markdown
Member

Why

In the Windows run for PR #4870, a buffered UserMessageEvent was persisted after the directly persisted compaction summary, leaving the already compacted u2 in replay.

What

Add a stream-local, cancellation-aware observer barrier before compaction persistence, invisible to observers and the public stream. A deterministic synctest regression exercises an actual RunStream with a blocked write; additional tests cover cancellation and barrier invisibility.

Validation

  • task build, task test, task lint
  • go test -race ./pkg/runtime -run 'TestObserver|TestCompactionWaitsForPendingObserverWrites|TestClaude5.*CompactionLifecycle' -count=30
  • Windows runtime tests cross-compiled

Assisted-By: ChatGPT
Signed-off-by: David Gageot <david.gageot@docker.com>
@dgageot
dgageot requested a review from a team as a code owner November 9, 2026 12:56
Copilot AI balanced review requested due to automatic review settings November 9, 2026 12:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the change to flush observer writes before persisting compaction.

No open issues 🎉

What changed in this PR

This PR fixes transcript ordering during session compaction by waiting for pending observer writes before persisting the summary, preventing already-compacted messages from reappearing during replay.

Changes:

  • Adds a stream-local, cancellation-aware flush barrier hidden from observers and public event consumers.
  • Flushes pending observer events before persisting compaction.
  • Adds deterministic tests for write ordering, cancellation, and barrier invisibility.
File Description
pkg/​runtime/​session_compaction.go Flushes observer writes before persisting compaction and handles flush failures.
pkg/​runtime/​session_compaction_test.go Tests compaction ordering with a blocked transcript write through RunStream.
pkg/​runtime/​observer.go Implements the flush barrier and removes it from event delivery.
pkg/​runtime/​observer_test.go Tests flush waiting, cancellation, and barrier invisibility.
pkg/​runtime/​loop.go Attaches the stream-local flush mechanism to the runtime loop context.

Review effort: Balanced

@aheritier aheritier added area/runtime Runtime engine, agent loop execution, tool dispatch, loop detection kind/fix PR fixes a bug (maps to fix:). Use on PRs only. labels Nov 9, 2026

@aheritier aheritier left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed all five changed files against the stated scope: ordering transcript writes before compaction persistence, stream-local isolation, cancellation, barrier invisibility, and deterministic regression coverage. No findings. The linked #4870 Windows failure supplies background evidence, not additional delivery requirements.

CI: verified green for aba2c3c, including gate, Linux/Windows tests, lint, cross-compilation, TypeScript, licenses, image, and CodeQL. CI logs confirm the runtime suite passed on both platforms; the race job was skipped.
Prior threads: none; review history is complete.
Merge status: non-draft and conflict-free. Required review remains outstanding; this draft approval has not been submitted.

@dgageot
dgageot added this pull request to the merge queue Nov 9, 2026
Merged via the queue into main with commit 7e257fe Nov 9, 2026
18 checks passed
@dgageot
dgageot deleted the fix/native-compaction-lifecycle-boundary branch November 9, 2026 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/runtime Runtime engine, agent loop execution, tool dispatch, loop detection kind/fix PR fixes a bug (maps to fix:). Use on PRs only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants