Skip to content

fix: session lifecycle and chat history reliability#49

Draft
cursor[bot] wants to merge 2 commits into
devfrom
cursor/critical-bug-investigation-0dc6
Draft

fix: session lifecycle and chat history reliability#49
cursor[bot] wants to merge 2 commits into
devfrom
cursor/critical-bug-investigation-0dc6

Conversation

@cursor

@cursor cursor Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Restores four critical correctness fixes that were identified on a prior automation branch but never merged to main.

Bugs fixed

1. Chat history clobber (data loss)

Impact: Live messages disappear when switching sessions or when loadHistory returns after newer session:output events.
Root cause: CentralPanel.loadHistory replaced the entire journal store with the DB snapshot instead of merging by seq.
Fix: Reintroduce mergeJournalBySeq — live entries win on seq conflicts.

2. Silent follow-up message loss

Impact: User sends a follow-up while the agent is still spawning; message appears in chat but is never delivered.
Root cause: send_message added the message to journal/DB then spawned, but do_spawn silently skipped when spawning_sessions already contained the session id.
Fix: Return an error when spawning_sessions is active.

3. Stop race overwrites Stopped → Completed

Impact: User stops a session; status briefly shows Stopped then flips to Completed when the CLI process exits.
Root cause: reader_loop unconditionally wrote Completed to DB on process exit.
Fix: Check session_status_allows_completion before finalizing.

4. Session output loss on DB lock

Impact: JSONL output lines silently dropped when SQLite BEGIN fails under contention.
Root cause: flush_batch cleared the buffer on BEGIN failure.
Fix: Keep buffer intact for retry on next flush.

Validation

  • npx vitest run ui/lib/journal-merge.test.ts — 4 tests pass
  • cargo test --lib should_not_finalize / should_finalize / should_reject_send_message — 3 tests pass
Open in Web View Automation 

cursoragent and others added 2 commits June 29, 2026 12:06
- Merge DB history with live journal by seq when switching sessions
- Reject send_message while spawning_sessions is active
- Skip Completed status in reader_loop when user stopped the session
- Retry flush_batch buffer on BEGIN failure instead of discarding rows

Co-authored-by: José Fernando <xinnaider@users.noreply.github.com>
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