Skip to content

Fix a bug that caused session conflicts#104

Merged
khaong merged 4 commits intomainfrom
soph/fix-strange-multi-session-bug
Jan 27, 2026
Merged

Fix a bug that caused session conflicts#104
khaong merged 4 commits intomainfrom
soph/fix-strange-multi-session-bug

Conversation

@Soph
Copy link
Collaborator

@Soph Soph commented Jan 26, 2026

This was reported by @dipree but also @georg might have seen variations of it. After digging through the entire/sessions logs and what data we had (and trying different theories) this is where we landed:

  The Bug Scenario

  1. Session A (914e68cc) starts
    - InitializeSession creates state with CheckpointCount: 0
  2. User runs a Task (subagent) in Session A
    - PreToolUse[Task] fires → createStartingAgentCheckpoint → SaveTaskCheckpoint
    - This creates a commit on the shadow branch (even with no file changes!)
    - CheckpointCount stays at 0
  3. User closes Claude without main agent making file changes
    - Stop hook fires but commitWithMetadata returns early ("No files were modified")
    - Session A state: CheckpointCount: 0, shadow branch has commits
  4. Session B (f9b37e51) tries to start
    - InitializeSession checks: state == nil || state.CheckpointCount == 0 → TRUE
    - Sees shadow branch with commits tagged 914e68cc
    - Loads Session A's state file (exists with CheckpointCount: 0)
    - Returns SessionIDConflictError
  5. User sees the error message about "orphaning existing work"
    - But working tree is clean (task changes were undone, committed, or never existed)

This is probably the important aspect:

  • This creates a commit on the shadow branch (even with no file changes!)

Since that commit caused then the other session to fail to start since there was a commit in the shadow branch but no local changes, so it gave the wrong instructions.


Note

Eliminates creation of "starting" subagent checkpoints and empty marker commits to prevent session conflicts and reduce noise.

  • PreToolUse[Task]: now only captures pre-task state; no checkpoint/commit is created
  • AutoCommitStrategy.commitTaskCodeToActive: skips commit when no file changes; removes TaskStart handling
  • Removes IncrementalTypeTaskStart, FormatSubagentStartMessage, and related tests; simplifies FormatIncrementalSubject
  • Updates integration/unit tests to expect a single completed checkpoint (no start checkpoint)
  • Docs updated to reflect new hook behavior and when checkpoints are created

Written by Cursor Bugbot for commit 49bda72. This will update automatically on new commits. Configure here.

Entire-Checkpoint: fd00dbbb51f1
@Soph Soph requested a review from a team as a code owner January 26, 2026 16:38
Copilot AI review requested due to automatic review settings January 26, 2026 16:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a session conflict bug where a new session would fail to start after a previous session ran a Task (subagent) that made no file changes. The bug occurred because the PreTask hook created a shadow branch commit even with no file changes, but didn't increment the session's CheckpointCount. This caused the session initialization logic to incorrectly detect a conflict.

Changes:

  • Removed createStartingAgentCheckpoint() function that created empty "starting agent" commits during PreTask hooks
  • Updated PreTask hook to only capture local state (for computing new files later) without creating shadow branch commits
  • Added clarifying comment that commits are only created when tasks actually result in file changes

Soph added 2 commits January 26, 2026 18:23
Entire-Checkpoint: c3851e15e4c2
Entire-Checkpoint: a7e6172c3842
Copilot AI review requested due to automatic review settings January 26, 2026 17:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

Remove documentation for the "Create Starting Checkpoint" step in
PreToolUse[Task] since TaskStart checkpoints no longer exist.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Entire-Checkpoint: 523d2b8bfaf3
Copy link
Contributor

@khaong khaong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - just updated some of the docs to align.

@khaong khaong enabled auto-merge January 27, 2026 00:35
@khaong khaong merged commit 371e1d7 into main Jan 27, 2026
4 checks passed
@khaong khaong deleted the soph/fix-strange-multi-session-bug branch January 27, 2026 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants