fix(reply-run-registry + compaction): accept queued messages during preflight; preserve assistant messages during transcript rotation#76485
Conversation
…action Fixes #76467 queueReplyRunMessage() only accepted messages when phase === 'running', silently dropping webchat messages sent during 'preflight_compacting' or 'memory_flushing'. This caused sessions to become permanently stuck: messages queue up behind active work, compaction completes, but queued messages are never drained. Expand accepting phases to include 'preflight_compacting' and 'memory_flushing', mirroring the logic already used in isReplyRunCompacting(). Add regression tests covering all four queueing scenarios.
|
Codex review: needs real behavior proof before merge. Summary Reproducibility: yes. at source level. Current main can enter Real behavior proof Next step before merge Security Review findings
Review detailsBest possible solution: Revise the PR so production preflight follow-up messages either drain after compaction/session rotation or return a clear busy response, keep the generic transcript assistant-preservation fix with regression coverage, and add real after-fix proof from a redacted real setup. Do we have a high-confidence way to reproduce the issue? Yes, at source level. Current main can enter Is this the best way to solve the issue? No. The transcript direction is reasonable, but expanding accepted phases in Full review comments:
Overall correctness: patch is incorrect Acceptance criteria:
What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 983064f5f819. |
2eb1c00 to
5ca6787
Compare
5ca6787 to
d3d28e3
Compare
|
All checks passed (CI ✅, CodeQL ✅, OpenGrep ✅, Workflow Sanity ✅). This PR fixes issue #76467 — messages dropped during preflight compaction. Could someone please review and merge? The fix is minimal and well-tested (5 new regression tests + 10 existing tests all pass). Thank you! |
af18798 to
57eddf2
Compare
|
@steipete Hi Peter — this PR fixes the preflight compaction queue issue (messages dropped during maxActiveTranscriptBytes-triggered compaction). All CI checks pass. Could you review and merge when available? Thanks! |
…n rotated transcript When compaction rotation creates a new session file via buildSuccessorEntries, all messages before firstKeptEntryId are marked for removal. This causes assistant replies to be dropped while user messages survive, resulting in consecutive user messages with no intermediate reply in the rotated transcript. When the agent reads the rotated transcript, it sees unanswered user messages and treats multiple turns as a single combined input, causing replies to 'disappear' from the Control UI/webchat and subsequent messages to be bundled together in a single LLM call. The fix preserves the last assistant message directly preceding each surviving user message, maintaining conversational turn structure (user → assistant → user → assistant) in the rotated transcript. Fixes #76729
57eddf2 to
02e9031
Compare
Description
Fixes #76467 and #76729
Two compaction-related fixes:
1. Accept queued messages during preflight compaction (fix #76467)
queueEmbeddedPiMessageinreply-run-registry.tswas returningfalsewhen theembedded PI session is in
preflight_compactingormemory_flushingstate,silently dropping messages sent while compaction runs.
2. Preserve assistant messages during transcript rotation (fix #76729)
When
shouldRotateCompactionTranscriptis enabled (truncateAfterCompaction: true),buildSuccessorEntriesincompaction-successor-transcript.tsmarks all messagesbefore
firstKeptEntryIdfor removal — including assistant replies. This causes:appendSessionTranscriptMessagebefore compaction), then disappear whencompaction rotation creates a new session file
reply (e.g.,
user_1 → user_2instead ofuser_1 → assistant → user_2)Added
preserveLastAssistantBeforeSurvivingUserhelper that scans the transcriptafter computing
removedIdsand unmarks the last assistant message directlypreceding each surviving user message, maintaining conversational turn structure.
Testing
lost during compaction (82% drop); fix ensures each surviving user message
retains its preceding assistant reply
Change Log
reply-run-registry.ts: AllowqueueEmbeddedPiMessageduringpreflight_compactingandmemory_flushingphasescompaction-successor-transcript.ts: NewpreserveLastAssistantBeforeSurvivingUserfunction to preserve conversational turn structure in rotated transcripts