Skip to content

add post commit cache#500

Merged
evisdren merged 3 commits intomainfrom
postcommitcache
Feb 25, 2026
Merged

add post commit cache#500
evisdren merged 3 commits intomainfrom
postcommitcache

Conversation

@evisdren
Copy link
Contributor

Entire-Checkpoint: 0e42eb4462d9

@evisdren evisdren requested a review from a team as a code owner February 25, 2026 21:38
Copilot AI review requested due to automatic review settings February 25, 2026 21: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 introduces a post-commit cache optimization to reduce redundant Git object reads during the PostCommit hook execution. The implementation pre-resolves HEAD and parent trees once, then threads them through multiple per-session functions that previously performed duplicate reads.

Changes:

  • Added caching fields to postCommitActionHandler to store pre-resolved Git trees (headTree, parentTree, shadowRef, shadowTree)
  • Refactored PostCommit to extract per-session processing into postCommitProcessSession function
  • Updated multiple functions to accept optional pre-resolved tree parameters (condenseOpts, overlapOpts, attributionOpts)

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
cmd/entire/cli/strategy/postcommit_bench_test.go Added benchmark tests for PostCommit hook with single and multiple sessions
cmd/entire/cli/strategy/phase_postcommit_test.go Updated test calls to pass nil parameters to filesChangedInCommit
cmd/entire/cli/strategy/manual_commit_hooks.go Refactored PostCommit to pre-resolve trees and extract session processing logic
cmd/entire/cli/strategy/manual_commit_condensation.go Added caching support for shadow ref/tree resolution in CondenseSession and attribution
cmd/entire/cli/strategy/content_overlap.go Added optional tree parameters to overlap detection functions
.claude/worktrees/cached-spinning-nebula Added Git subproject commit reference
Comments suppressed due to low confidence (1)

cmd/entire/cli/strategy/content_overlap.go:110

  • The comment "Check each file in filesTouched" appears to be orphaned after the refactoring. The code that builds the touchedSet map was removed, but this comment remains. The loop below doesn't need this comment as it's self-explanatory. Consider removing this line.
	// Check each file in filesTouched

Comment on lines 372 to 376
} else if shadowRef == nil {
// Cache provided a shadow tree but shadowRef is nil — this shouldn't happen
// in practice, but handle gracefully: use HEAD as shadow.
logging.Debug(logCtx, "attribution: using HEAD as shadow (no shadow ref, ignoring cached tree)")
shadowTree = headTree
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

The logic at lines 372-377 handles an unexpected state where shadowTree is cached but shadowRef is nil. However, this condition cannot occur in the calling code (line 826-827 in postCommitProcessSession) because both fields are set together from the same resolution. This defensive code adds unnecessary complexity. Consider removing this branch or adding a comment explaining the specific edge case it protects against.

Suggested change
} else if shadowRef == nil {
// Cache provided a shadow tree but shadowRef is nil — this shouldn't happen
// in practice, but handle gracefully: use HEAD as shadow.
logging.Debug(logCtx, "attribution: using HEAD as shadow (no shadow ref, ignoring cached tree)")
shadowTree = headTree

Copilot uses AI. Check for mistakes.
@cursor
Copy link

cursor bot commented Feb 25, 2026

PR Summary

Medium Risk
Touches post-commit condensation/attribution decision paths; while behavior is guarded by equivalence tests, incorrect cache plumbing or nil/initial-commit handling could cause missed or extra condensation/carry-forward.

Overview
Improves PostCommit performance by caching and reusing resolved git objects (HEAD tree, parent tree, and per-session shadow ref/tree) instead of repeatedly re-reading them across overlap detection, carry-forward detection, condensation, and attribution.

Refactors the post-commit loop into postCommitProcessSession, threads optional cache opts through filesOverlapWithContent, filesWithRemainingAgentChanges, filesChangedInCommit, CondenseSession, calculateSessionAttributions, and sessionHasNewContent, and adds tests/benchmarks to validate cache equivalence (including partial/initial-commit cases) and measure end-to-end PostCommit timing.

Written by Cursor Bugbot for commit 1835022. Configure here.

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

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

evisdren and others added 3 commits February 25, 2026 14:40
Entire-Checkpoint: 0e42eb4462d9
…tion

Tests verify that pre-resolved git objects (cache hit) produce identical
results to fallback resolution (cache miss) for filesOverlapWithContent,
filesWithRemainingAgentChanges, and filesChangedInCommit. Also covers
partial cache (some trees nil) and initial commit (no parent) edge cases.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Entire-Checkpoint: 3a8a8ee935de
shadowRef and shadowTree are always resolved together from the same
repo.Reference call, so the cached-tree-but-nil-ref state cannot occur.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Entire-Checkpoint: 88a7d2762f60
@evisdren evisdren merged commit f43adb2 into main Feb 25, 2026
3 checks passed
@evisdren evisdren deleted the postcommitcache branch February 25, 2026 22:46
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