Skip to content

fix(cli): keep trace sessions when a commit is amended - #3480

Merged
jiparis merged 3 commits into
chainloop-dev:mainfrom
jiparis:jiparis/pfm-7437-chainloop-trace-amending-a-commit-drops-its-ai-session-and
Sep 28, 2026
Merged

jiparis merged 3 commits into
chainloop-dev:mainfrom
jiparis:jiparis/pfm-7437-chainloop-trace-amending-a-commit-drops-its-ai-session-and

Conversation

@jiparis

@jiparis jiparis commented Sep 27, 2026 •

Copy link
Copy Markdown
Member

When you amend an AI-assisted commit with a new message, chainloop trace lost the link between the commit and its AI session. The new message did not get the Chainloop-Trace-Sessions trailer, the post-commit hook recorded the commit with no sessions, and the pre-push hook skipped the attestation.

This change:

  • Makes the commit-msg hook keep the trailer of HEAD when the commit amends HEAD. During an amend, git exports the author date of HEAD in GIT_AUTHOR_DATE, and other commits (--allow-empty included) 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.
  • Adds a post-rewrite hook, which runs after commit --amend and rebase. It copies the sessions of each rewritten commit to the record of the commit that replaces it. This keeps the attestation correct also when the commit-msg hook cannot see the amend, for example with --reset-author.

Existing installations must run chainloop trace init again to install the new post-rewrite hook.

Fixes PFM-7437

AI disclosure: this change was made with the assistance of Claude Code.

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
@chainloop-platform

chainloop-platform Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

AI Session Checks — ✅ 0 failing

Avg score Sessions Failing policies Attribution Files Lines Total Duration
- 1 ✅ 0 100% AI / 0% Human 9 +594 / -111 57m17s

100% AI — ✅ All policies passing

Sep 27, 2026 23:11 UTC · 57m17s · $17.34 · 470 in / 252.3k out · claude-code 2.1.283 (claude-opus-5-5)

View session details ↗


File Attribution

████████████████████ 100% AI / 0% Human

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 -

View attestation ↗


Powered by Chainloop and Chainloop Trace

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 5 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread app/cli/pkg/action/trace_hook_handler_test.go
Comment thread app/cli/pkg/action/trace_hook_handler.go Outdated
Comment thread app/cli/internal/trace/hooks/hooks_test.go
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
@jiparis
jiparis merged commit 63ef0c9 into chainloop-dev:main Sep 28, 2026
17 checks passed
@jiparis
jiparis deleted the jiparis/pfm-7437-chainloop-trace-amending-a-commit-drops-its-ai-session-and branch September 28, 2026 09:32
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