Skip to content

fix: tolerate rewritten HEAD reflog during commit finalization#1384

Open
peckfly wants to merge 1 commit into
git-ai-project:mainfrom
peckfly:codex/fix-commit-reflog-note-finalization
Open

fix: tolerate rewritten HEAD reflog during commit finalization#1384
peckfly wants to merge 1 commit into
git-ai-project:mainfrom
peckfly:codex/fix-commit-reflog-note-finalization

Conversation

@peckfly
Copy link
Copy Markdown
Contributor

@peckfly peckfly commented May 16, 2026

Summary

  • keep raw worktree HEAD reflog regression errors visible at the low level
  • during commit trace finalization, ignore only rewritten worktree HEAD reflog offsets when branch ref changes or stable pre/post HEAD snapshots already prove the commit movement
  • preserve errors for non-commit commands, missing evidence, and amend-without-ref-change cases
  • add unit and daemon regression coverage

Testing

  • cargo fmt -- --check
  • cargo test worktree_head_reflog -- --test-threads 12
  • cargo test trace_normalizer --lib -- --test-threads 12
  • cargo test daemon_commit_writes_note_when_worktree_head_reflog_is_rewritten_before_finalization --test daemon_mode -- --test-threads 1

Open in Devin Review

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

@svarlamov
Copy link
Copy Markdown
Member

Thank you for the contribution @peckfly -- what bug/issue is this fixing?

@peckfly
Copy link
Copy Markdown
Contributor Author

peckfly commented May 19, 2026

Thank you for the contribution @peckfly -- what bug/issue is this fixing?

This fixes a daemon post-commit attribution bug.

I hit a case where an AI edit was checkpointed correctly, but after git commit the commit had no refs/notes/ai note, so stats/blame treated the added lines as unknown. The daemon log showed:

worktree HEAD reflog cut regressed (1889 < 19738)

The issue is that commit trace finalization reads the worktree HEAD reflog delta using offsets captured at trace start/end. If .git/logs/HEAD is rewritten or truncated during the commit, that supplemental reflog read fails. Previously that failure aborted normalization for the whole commit, so the post-commit authorship note was never written.

The fix keeps the low-level error intact, but narrowly tolerates it for ordinary git commit only when branch ref changes or stable pre/post HEAD snapshots already prove the commit movement. Other cases still return the error.

I added unit tests for the allowed and disallowed cases, plus a daemon regression test that reproduces the bug by truncating .git/logs/HEAD in a post-commit hook and verifies the authorship note/blame still preserve the AI attribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants