fix(cli, conversation): Defer replay trim to turn-start commit#862
Merged
Conversation
`jp query --replay` and the bare `--no-edit` replay-last-request path used to remove the trailing request event from the conversation stream while the request was still being built — during editor composition, MCP boot, or attachment loading. An interrupt or an empty query in that window persisted the removal without ever writing the replacement, silently dropping the last turn. The removal is now described by a `PendingStreamTrim` and only applied inside the same lock scope that appends the new turn, so the stream goes from "old turn present" to "old turn replaced" in one write. Building the request is otherwise read-only: `ConversationStream` gains `last_turn_event` to peek at the trailing event without popping it, and `ConversationLock`/`ConversationMut` gain `with_events` for read-only access that never marks the conversation dirty. Inline, piped, and replayed queries now also write their composed request to the conversation's recovery file before the turn starts, matching the existing editor-session behavior: an interrupt during MCP boot or model resolution no longer discards the request, and the next `jp query --edit` seeds its buffer from it. The file is still removed once the turn completes successfully. The `--cfg` config delta is now recorded only after the empty-query check, so a query that turns out empty no longer leaves a stray config event in the stream. Signed-off-by: Jean Mertz <git@jeanmertz.com>
37442e9 to
39d1d98
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
jp query --replayand the bare--no-editreplay-last-request path used to remove the trailing request event from the conversation stream while the request was still being built — during editor composition, MCP boot, or attachment loading. An interrupt or an empty query in that window persisted the removal without ever writing the replacement, silently dropping the last turn.The removal is now described by a
PendingStreamTrimand only applied inside the same lock scope that appends the new turn, so the stream goes from "old turn present" to "old turn replaced" in one write. Building the request is otherwise read-only:ConversationStreamgainslast_turn_eventto peek at the trailing event without popping it, andConversationLock/ConversationMutgainwith_eventsfor read-only access that never marks the conversation dirty.Inline, piped, and replayed queries now also write their composed request to the conversation's recovery file before the turn starts, matching the existing editor-session behavior: an interrupt during MCP boot or model resolution no longer discards the request, and the next
jp query --editseeds its buffer from it. The file is still removed once the turn completes successfully.The
--cfgconfig delta is now recorded only after the empty-query check, so a query that turns out empty no longer leaves a stray config event in the stream.