Skip to content

Comments

Fix stale sessions condensed into every commit#418

Merged
gtrrz-victor merged 8 commits intomainfrom
alex/fix-multi-session-vacuums-too-much
Feb 20, 2026
Merged

Fix stale sessions condensed into every commit#418
gtrrz-victor merged 8 commits intomainfrom
alex/fix-multi-session-vacuums-too-much

Conversation

@khaong
Copy link
Contributor

@khaong khaong commented Feb 19, 2026

Summary

Fixes zombie sessions being re-condensed into every commit indefinitely.

Root cause: After condensation, carry-forward sets FilesTouched with uncommitted files. On subsequent commits, sessionHasNewContent returns true (shadow branch has content), and the condensation handlers condense the session again without checking whether the committed files actually relate to the session. This cycle repeats on every commit.

A second bug was that FilesTouched was updated to wrong files due to another bug in the logic which wanted to prevent issues when FilesTouched was empty.

Affected code paths:

  • HandleCondense (ACTIVE/IDLE sessions) — skipped the overlap check entirely for ACTIVE sessions (hasNew=true unconditionally)
  • HandleCondenseIfFilesTouched (ENDED sessions) — had zero overlap checking, only checked len(FilesTouched) > 0 && hasNew

Impact: In one real case, 6 zombie sessions accumulated over 11 days (Feb 8–19), polluting 12 checkpoints with 18 duplicate condensation events.

Fix: Extract shouldCondenseWithOverlapCheck() as a shared method that intersects session files with actually-committed files before calling filesOverlapWithContent. Both HandleCondense and HandleCondenseIfFilesTouched now use this method, ensuring ALL condensation paths verify file overlap.

Commits

1. bee7df26 — fix stale ACTIVE sessions being condensed into every commit

  • Add filesTouchedBefore field to postCommitActionHandler, populated from state.FilesTouched (IDLE/ENDED) or transcript extraction (ACTIVE)
  • Extract shouldCondenseWithOverlapCheck() method: intersects filesTouchedBefore with committedFileSet, then calls filesOverlapWithContent on the intersection
  • Both HandleCondense and HandleCondenseIfFilesTouched now use this shared method
  • Add TestPostCommit_StaleActiveSession_NotCondensed regression test

2. 744c4f3f — fix ENDED sessions with carry-forward re-condensed into every commit

  • Apply the same overlap check to HandleCondenseIfFilesTouched (ENDED sessions), which previously had zero overlap checking
  • Add TestPostCommit_EndedSessionCarryForward_NotCondensedIntoUnrelatedCommit regression test
  • Fix TestHandleTurnEnd_PartialFailure to include second.txt in FilesTouched so the overlap check passes

3. 014f53f2 — fix IDLE sessions with empty FilesTouched incorrectly condensed

  • Address review feedback: shouldCondenseWithOverlapCheck() was fail-open when filesTouchedBefore was empty, causing IDLE sessions with no files (e.g., conversation-only) to be condensed into unrelated commits
  • Add isActive parameter: ACTIVE sessions fail-open (handles mid-turn multi-session commits), IDLE/ENDED sessions return false
  • Add TestPostCommit_IdleSessionEmptyFilesTouched_NotCondensed regression test

Test plan

  • TestPostCommit_StaleActiveSession_NotCondensed
  • TestPostCommit_EndedSessionCarryForward_NotCondensedIntoUnrelatedCommit
  • TestPostCommit_IdleSessionEmptyFilesTouched_NotCondensed
  • TestPostCommit_ActiveSessionAlwaysCondenses — ACTIVE sessions with no files still condense (multi-session)
  • TestHandleTurnEnd_PartialFailure — updated for overlap check
  • All existing PostCommit tests pass (OldIdleSession, OldEndedSession, CarryForward, etc.)
  • Integration tests pass
  • mise run fmt && mise run lint clean

🤖 Generated with Claude Code

When an agent is killed without the Stop hook firing, its session
remains in ACTIVE phase permanently. PostCommit unconditionally set
hasNew=true for ACTIVE sessions and skipped the file overlap check,
so stale ACTIVE sessions got condensed into every subsequent commit.

Apply the file overlap check to ALL sessions (including ACTIVE) by
intersecting filesTouchedBefore with the actually-committed files
before calling filesOverlapWithContent.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Entire-Checkpoint: 8642696e40dd
Copilot AI review requested due to automatic review settings February 19, 2026 04:08
@khaong khaong requested a review from a team as a code owner February 19, 2026 04:08
@cursor
Copy link

cursor bot commented Feb 19, 2026

PR Summary

Medium Risk
Touches git hook condensation decisions and checkpoint metadata generation; logic changes can affect when checkpoints are created/linked, but the behavior is heavily covered by new unit and integration regression tests.

Overview
Prevents stale manual-commit sessions (ACTIVE zombies, ENDED carry-forward, and IDLE conversation-only) from being repeatedly condensed into unrelated commits by requiring a content-aware overlap between the session’s tracked files and the files changed in the commit before condensing.

Tightens CondenseSession files_touched handling so the “fallback to committed files” only applies when the session had no tracked files (true mid-session commit), avoiding overwriting metadata for unrelated sessions. Adds extensive unit + integration regression coverage for multi-session carry-forward, stale ACTIVE sessions, ENDED carry-forward, IDLE empty FilesTouched, and the mid-session fallback behavior.

Written by Cursor Bugbot for commit 5f515e0. Configure here.

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 bug where stale ACTIVE sessions (agent killed without the Stop hook firing) were incorrectly condensed into every subsequent commit. The fix extends the file overlap check to ALL sessions, including ACTIVE ones, by intersecting the session's touched files with the actually-committed files before calling filesOverlapWithContent.

Changes:

  • Modified HandleCondense in manual_commit_hooks.go to apply content overlap checking to ACTIVE sessions
  • Added filesTouchedBefore field to postCommitActionHandler and filter logic to check only committed files
  • Added comprehensive regression test TestPostCommit_StaleActiveSession_NotCondensed
  • Updated TestHandleTurnEnd_PartialFailure to include second.txt in FilesTouched for accurate overlap checking
  • Refactored test constant testNewActiveSessionID for consistency

Reviewed changes

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

File Description
cmd/entire/cli/strategy/manual_commit_hooks.go Fixed condensation logic to apply overlap check to ALL sessions including ACTIVE, preventing stale sessions from being incorrectly condensed
cmd/entire/cli/strategy/phase_postcommit_test.go Added regression test for stale ACTIVE sessions, updated existing test for correct FilesTouched tracking, and refactored constant

@khaong khaong marked this pull request as draft February 19, 2026 04:11
khaong and others added 3 commits February 19, 2026 16:02
The overlap check from the previous commit only applied to HandleCondense
(ACTIVE/IDLE sessions). ENDED sessions go through HandleCondenseIfFilesTouched,
which had no overlap check at all — it only checked len(FilesTouched) > 0.

Carry-forward sets FilesTouched with remaining uncommitted files after
condensation. On the next commit, sessionHasNewContent returns true (shadow
branch has content), and HandleCondenseIfFilesTouched condenses the session
again. This cycle repeats on every commit indefinitely.

Extract shouldCondenseWithOverlapCheck as a shared method and use it in both
HandleCondense and HandleCondenseIfFilesTouched. This ensures ALL condensation
paths verify that committed files actually overlap with session files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Entire-Checkpoint: 2fbfa77cb815
…n-vacuums-too-much

# Conflicts:
#	cmd/entire/cli/strategy/manual_commit_hooks.go
shouldCondenseWithOverlapCheck() was fail-open when filesTouchedBefore
was empty, causing IDLE sessions with no files (e.g., conversation-only
sessions) to be condensed into unrelated commits. Now only ACTIVE
sessions fail-open (to handle mid-turn commits before files are saved
to state); IDLE/ENDED sessions with no files return false.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Entire-Checkpoint: 058ec85be074
@khaong
Copy link
Contributor Author

khaong commented Feb 19, 2026

bugbot run

@khaong khaong requested a review from Copilot February 19, 2026 05:43
@khaong khaong changed the title Fix stale ACTIVE sessions condensed into every commit Fix stale sessions condensed into every commit Feb 19, 2026
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 2 out of 2 changed files in this pull request and generated 2 comments.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

- Update comment to reference SaveStep/SaveTaskStep instead of
  nonexistent SaveChanges
- Remove unused newHead computation in idle empty-files test

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Entire-Checkpoint: 2ac81686c7e4
@khaong khaong marked this pull request as ready for review February 19, 2026 06:08
Soph added 2 commits February 19, 2026 11:19
Entire-Checkpoint: 4e61e28fd507
@Soph
Copy link
Collaborator

Soph commented Feb 19, 2026

bugbot run

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Entire-Checkpoint: 1a2c8fa29e67
@gtrrz-victor gtrrz-victor merged commit 228eb24 into main Feb 20, 2026
3 checks passed
@gtrrz-victor gtrrz-victor deleted the alex/fix-multi-session-vacuums-too-much branch February 20, 2026 02:25
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