Skip to content

Fix stale sessions condensed into every commit#418

Open
khaong wants to merge 5 commits intomainfrom
alex/fix-multi-session-vacuums-too-much
Open

Fix stale sessions condensed into every commit#418
khaong wants to merge 5 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.

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
Changes core PostCommit condensation gating; incorrect overlap logic could cause missed condensations or unintended checkpoint linking, though coverage is strengthened with new regression tests.

Overview
Fixes a PostCommit bug where stale ACTIVE sessions and ENDED/IDLE carry-forward sessions could be repeatedly condensed into unrelated commits.

This centralizes the condensation decision in shouldCondenseWithOverlapCheck, which intersects filesTouchedBefore with the commit’s actual changed files before running the existing content-aware overlap check, and applies it across both HandleCondense and HandleCondenseIfFilesTouched (with an ACTIVE-session fail-open when no files are known). Tests are updated/added to cover stale ACTIVE, ENDED carry-forward, and IDLE-with-no-files scenarios, plus a minor test adjustment to ensure FilesTouched includes newly created files.

Written by Cursor Bugbot for commit 014f53f. 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
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.

1 participant

Comments