Skip to content

fix: prevent silent message loss, stop race, and history clobber#48

Draft
cursor[bot] wants to merge 1 commit into
devfrom
cursor/critical-bug-identification-9889
Draft

fix: prevent silent message loss, stop race, and history clobber#48
cursor[bot] wants to merge 1 commit into
devfrom
cursor/critical-bug-identification-9889

Conversation

@cursor

@cursor cursor Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

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_message pushed the user entry to journal/DB/UI, then called do_spawn, which silently returned when spawning_sessions already contained the session id (held for the entire reader_loop).

Fix: Check spawning_sessions before 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_loop unconditionally wrote Completed to DB on stdout EOF, racing with stop_session setting Stopped.

Fix: session_status_allows_completion() skips finalization when DB status is already Stopped.

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.loadHistory replaced 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 BEGIN failure during batched output flush permanently dropped pending JSONL rows.

Fix: Stop clearing the buffer on BEGIN failure; retry on the next flush cycle.

Validation

  • cargo test should_not_finalize_stopped — pass
  • npm test — 202 tests pass (includes 4 new journal-merge tests)
Open in Web View Automation 

- 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant