Repository navigation
fix(runtime): flush transcript writes before persisting compaction - #4871
Conversation
Assisted-By: ChatGPT Signed-off-by: David Gageot <david.gageot@docker.com>
There was a problem hiding this comment.
🟢 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
left a comment
There was a problem hiding this comment.
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.
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 lintgo test -race ./pkg/runtime -run 'TestObserver|TestCompactionWaitsForPendingObserverWrites|TestClaude5.*CompactionLifecycle' -count=30