Repository navigation
fix(cli): keep trace sessions when a commit is amended - #3480
Merged
Conversation
When you amend an AI-assisted commit with a new message, the new commit did not get the Chainloop-Trace-Sessions trailer, and the post-commit hook recorded it with no sessions. The pre-push hook then dropped the original commit record and skipped the attestation. - The commit-msg hook copies the trailer of HEAD when nothing is staged, because the new commit can then only replace HEAD. - A new post-rewrite hook copies the sessions of each rewritten commit to the record of the commit that replaces it (amend and rebase). Fixes PFM-7437 Assisted-by: Claude Code Signed-off-by: Jose I. Paris <jiparis@chainloop.dev> Chainloop-Trace-Sessions: d7cf52a4-d678-4f0c-907c-077d60025375
Contributor
AI Session Checks — ✅ 0 failing
|
| Status | Attribution | File | Lines |
|---|---|---|---|
| modified | ai | app/cli/pkg/action/trace_hook_handler_test.go |
+319 / -66 |
| modified | ai | app/cli/pkg/action/trace_hook_handler.go |
+183 / -36 |
| modified | ai | app/cli/internal/trace/git/merge_branch_test.go |
+29 / -0 |
| modified | ai | app/cli/internal/trace/git/gogit.go |
+20 / -0 |
| modified | ai | app/cli/cmd/trace_hook.go |
+17 / -0 |
| modified | ai | app/cli/internal/trace/hooks/hooks_test.go |
+8 / -8 |
| modified | ai | app/cli/internal/trace/git/exec.go |
+12 / -0 |
| modified | ai | app/cli/internal/trace/git/git.go |
+4 / -0 |
| modified | ai | app/cli/internal/trace/hooks/hooks.go |
+2 / -1 |
Policies (4)
| Status | Policy | Material | Messages |
|---|---|---|---|
| ✅ Passed | ai-config-ai-agents-allowed |
ai-coding-session-d7cf52 |
- |
| ✅ Passed | ai-config-no-dangerous-commands |
ai-coding-session-d7cf52 |
- |
| ✅ Passed | ai-config-no-secrets |
ai-coding-session-d7cf52 |
- |
| ✅ Passed | ai-config-mcp-servers-allowed |
ai-coding-session-d7cf52 |
- |
PR validation — ✅ 3 passing
| Status | Policy | Material | Messages |
|---|---|---|---|
| ✅ Passed | pr-min-approvals |
pr-info |
- |
| ✅ Passed | pr-description-required |
pr-info |
- |
| ✅ Passed | pr-user-story-linked |
pr-info |
- |
Powered by Chainloop and Chainloop Trace
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 5 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
For `git commit -a` and `git commit <path>`, git builds the commit from a temporary index and names it in GIT_INDEX_FILE. The regular index then shows nothing staged, so the commit-msg hook copied the trailer of HEAD onto a commit that is not an amend. Copy the trailer only when git commits the regular index. Assisted-by: Claude Code Signed-off-by: Jose I. Paris <jiparis@chainloop.dev> Chainloop-Trace-Sessions: d7cf52a4-d678-4f0c-907c-077d60025375
The commit-msg hook copied the trailer of HEAD when nothing was staged. This also matched `git commit --allow-empty`, and it missed amends with staged changes. During an amend, git exports the author date of HEAD in GIT_AUTHOR_DATE. Other commits carry the current time. The hook now compares this date with the author date of HEAD, and joins the sessions of HEAD with the sessions of the staged AI edits. The post-rewrite hook still carries the sessions for amends that change the author date. Also extend the hook tests to the post-rewrite hook, and make the amend lifecycle test exercise the post-rewrite hook. Assisted-by: Claude Code Signed-off-by: Jose I. Paris <jiparis@chainloop.dev> Chainloop-Trace-Sessions: d7cf52a4-d678-4f0c-907c-077d60025375
migmartri
approved these changes
Sep 28, 2026
jiparis
deleted the
jiparis/pfm-7437-chainloop-trace-amending-a-commit-drops-its-ai-session-and
branch
September 28, 2026 09:32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When you amend an AI-assisted commit with a new message,
chainloop tracelost the link between the commit and its AI session. The new message did not get theChainloop-Trace-Sessionstrailer, the post-commit hook recorded the commit with no sessions, and the pre-push hook skipped the attestation.This change:
commit-msghook keep the trailer of HEAD when the commit amends HEAD. During an amend, git exports the author date of HEAD inGIT_AUTHOR_DATE, and other commits (--allow-emptyincluded) carry the current time. The sessions of HEAD are joined with the sessions of the staged AI edits, so the trailer stays in the history.post-rewritehook, which runs aftercommit --amendandrebase. It copies the sessions of each rewritten commit to the record of the commit that replaces it. This keeps the attestation correct also when thecommit-msghook cannot see the amend, for example with--reset-author.Existing installations must run
chainloop trace initagain to install the newpost-rewritehook.Fixes PFM-7437
AI disclosure: this change was made with the assistance of Claude Code.