fix: prevent silent message loss, stop race, and history clobber#48
Draft
cursor[bot] wants to merge 1 commit into
Draft
fix: prevent silent message loss, stop race, and history clobber#48cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
- Reject send_message while spawning_sessions is active (show error instead of adding the message to chat without delivering it to the agent) - Skip Completed status in reader_loop when session was stopped by user - Merge DB history with live journal by seq when switching sessions - Retry flush_batch buffer on BEGIN failure instead of discarding rows Co-authored-by: José Fernando <xinnaider@users.noreply.github.com>
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.
Summary
Critical bug sweep identified three pre-existing session-management bugs with concrete user-facing impact. This PR applies minimal, targeted fixes with tests.
Bugs fixed
1. Silent follow-up message loss (critical)
Impact: User sends a message while the agent is still processing; the message appears in chat but is never delivered to the CLI.
Root cause:
send_messagepushed the user entry to journal/DB/UI, then calleddo_spawn, which silently returned whenspawning_sessionsalready contained the session id (held for the entirereader_loop).Fix: Check
spawning_sessionsbefore recording the message; return an error so InputBar shows a clear failure instead of a false success.2. Stop → Completed status overwrite (high)
Impact: Stopping a running session could later show as "completed" after the CLI process exits.
Root cause:
reader_loopunconditionally wroteCompletedto DB on stdout EOF, racing withstop_sessionsettingStopped.Fix:
session_status_allows_completion()skips finalization when DB status is alreadyStopped.3. Chat history clobber on session switch (high)
Impact: Switching between sessions could drop recent live feed entries not yet flushed to SQLite.
Root cause:
CentralPanel.loadHistoryreplaced the in-memory journal with the DB snapshot.Fix:
mergeJournalBySeq()merges live and DB entries by seq (live wins on conflict).4. Output buffer discard on DB error (high)
Impact: SQLite
BEGINfailure during batched output flush permanently dropped pending JSONL rows.Fix: Stop clearing the buffer on
BEGINfailure; retry on the next flush cycle.Validation
cargo test should_not_finalize_stopped— passnpm test— 202 tests pass (includes 4 newjournal-mergetests)