Skip to content

Skip fully-condensed ENDED sessions in PostCommit#556

Open
evisdren wants to merge 2 commits intomainfrom
skip-fully-condensed-sessions
Open

Skip fully-condensed ENDED sessions in PostCommit#556
evisdren wants to merge 2 commits intomainfrom
skip-fully-condensed-sessions

Conversation

@evisdren
Copy link
Contributor

@evisdren evisdren commented Feb 28, 2026

Summary

  • PostCommit iterates ALL sessions for the worktree, including ENDED sessions that have already been fully condensed. Each session costs ~60ms just to exist in the pipeline (shadow resolve + hasNewContent + state machine + attribution), so 200 settled sessions add ~12s of pure overhead on every commit.
  • Adds a FullyCondensed flag to session state, set when an ENDED session is condensed with no remaining carry-forward files. PostCommit skips these sessions entirely on subsequent commits.
  • Sessions still persist in .git/entire-sessions/ for LastCheckpointID reuse (amend trailer restoration) — only the expensive per-session processing is skipped.

Changes

  1. session/state.go — Added FullyCondensed bool field (backward compatible: omitempty, defaults to false)
  2. strategy/manual_commit_hooks.go — Skip FullyCondensed sessions in PostCommit loop; set the flag after condensation when ENDED + no carry-forward

Benchmark results (2nd commit after sessions are condensed)

Scenario 1st Commit (all fresh) 2nd Commit (pruned) Speedup
100 sessions 6.4s 1.6s 3.9x
200 sessions 14.5s 3.3s 4.5x
500 sessions 46.8s 8.7s 5.4x

PostCommit specifically: 200 sessions dropped from 12.9s → 1.6s (8x).

Test plan

  • mise run fmt && mise run lint — clean
  • mise run test:ci — all unit + integration tests pass
  • Perf benchmark confirms speedup on 2nd commit
  • Verify backward compat: existing session state files without fully_condensed field deserialize as false (no behavior change)

🤖 Generated with Claude Code

PostCommit iterates all sessions for the worktree, including ENDED sessions
that have already been condensed with no remaining carry-forward files. Each
session costs ~60ms just to exist in the pipeline (shadow resolve +
hasNewContent + state machine + attribution), so 200 settled sessions add
~12s of pure overhead on every commit.

Add a `FullyCondensed` flag to session state that gets set when an ENDED
session is successfully condensed with no files remaining for carry-forward.
PostCommit skips these sessions entirely, reducing steady-state commit
overhead from seconds to milliseconds. The sessions still persist for
LastCheckpointID reuse (amend trailer restoration).

Benchmark results (2nd commit after sessions are condensed):
- 100 sessions: 6.4s → 1.6s (3.9x)
- 200 sessions: 14.5s → 3.3s (4.5x)
- 500 sessions: 46.8s → 8.7s (5.4x)
PostCommit specifically: 200 sessions dropped from 12.9s → 1.6s (8x).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Entire-Checkpoint: 28481f123e69
@evisdren evisdren requested a review from a team as a code owner February 28, 2026 00:34
Copilot AI review requested due to automatic review settings February 28, 2026 00:34
@cursor
Copy link

cursor bot commented Feb 28, 2026

PR Summary

Medium Risk
Moderate risk because it changes PostCommit session-processing control flow based on a new persisted state flag; mistakes could cause sessions to be skipped when they still have pending work or affect amend trailer restoration.

Overview
Speeds up post-commit by introducing a persisted State.FullyCondensed flag and skipping per-session processing for ENDED sessions that have already been condensed and have no remaining carry-forward files.

FullyCondensed is set after a successful condensation when the session is ENDED and FilesTouched is empty, and it is cleared when an ended session is reactivated via ActionClearEndedAt (ENDED → ACTIVE/IDLE).

Written by Cursor Bugbot for commit f9c6270. 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 reduces PostCommit hook overhead by skipping per-session processing for sessions that have already been condensed and have no remaining carry-forward work, while still retaining session state on disk for LastCheckpointID reuse (e.g., amend trailer restoration).

Changes:

  • Add FullyCondensed to persisted session state to mark ENDED sessions with no remaining carry-forward files.
  • Skip FullyCondensed sessions during the PostCommit per-session processing loop.
  • Set FullyCondensed = true after successful condensation when an ENDED session has no remaining files to carry forward.

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 Skips fully-condensed sessions in PostCommit and sets the flag after condensation when appropriate.
cmd/entire/cli/session/state.go Persists the new FullyCondensed flag in session state JSON (backward compatible via omitempty).
Comments suppressed due to low confidence (3)

cmd/entire/cli/strategy/manual_commit_hooks.go:786

  • The skip condition is documented as “fully-condensed ended sessions”, but it currently skips any session with FullyCondensed == true regardless of phase. To keep the invariant enforced in code (and avoid accidentally skipping an ACTIVE/IDLE session if state is corrupted or future logic sets the flag earlier), gate this continue with state.Phase == session.PhaseEnded (or !state.Phase.IsActive() plus PhaseEnded as appropriate).
		// Skip fully-condensed ended sessions — no work remains.
		// These sessions only persist for LastCheckpointID (amend trailer reuse).
		if state.FullyCondensed {
			continue

cmd/entire/cli/strategy/manual_commit_hooks.go:787

  • Skipping fully-condensed sessions here also means their shadow branch will never be retried for deletion if cleanup failed in a prior PostCommit run (the only deletion pass is driven by shadowBranchesToDelete, which is populated during per-session processing). Consider a low-cost best-effort cleanup path for fully-condensed sessions (e.g., check if the shadow ref exists and, if so, schedule it for deletion) so orphaned entire/* branches don’t accumulate after transient failures.
		// Skip fully-condensed ended sessions — no work remains.
		// These sessions only persist for LastCheckpointID (amend trailer reuse).
		if state.FullyCondensed {
			continue
		}

cmd/entire/cli/strategy/manual_commit_hooks.go:960

  • This change introduces new state (FullyCondensed) that alters PostCommit behavior across invocations, but there doesn’t appear to be coverage asserting (1) the flag is set only when an ENDED session is condensed with no carry-forward files, and (2) subsequent PostCommit runs skip that session. Adding a strategy/phase test around these cases would help prevent regressions (including backward-compat JSON load defaulting the field to false).
	// Mark ENDED sessions as fully condensed when no carry-forward remains.
	// PostCommit will skip these sessions entirely on future commits.
	// They persist only for LastCheckpointID (amend trailer restoration).
	if handler.condensed && state.Phase == session.PhaseEnded && len(state.FilesTouched) == 0 {
		state.FullyCondensed = true
	}

ENDED sessions can be reactivated via TurnStart (→ ACTIVE) or
SessionStart (→ IDLE). Clear FullyCondensed in ActionClearEndedAt
so reactivated sessions are not skipped by PostCommit.

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

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

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.

2 participants