Repository navigation
fix(trace): re-record rebased commits from their trailer - #3839
Conversation
A rebase outside the clone with the Trace hooks gives the branch commits new SHAs with no commit record, so the next pre-push dropped the old records as orphans and sent none of the rebased commits. Before the orphan filter, record each branch commit that has a Chainloop-Trace-Sessions trailer and no record, with the trailer sessions that have a local session record. Merge commits are skipped. Fixes chainloop-dev#3838 Refs PFM-8286 Assisted-by: Claude Code Signed-off-by: Jose Ignacio Paris Prieto <jiparis@chainloop.dev> Chainloop-Trace-Sessions: 7fa5c0ca-dc5c-428e-83d2-5f528e3bd327
PR validation — ✅ 3 passing
AI Session Checks — 🟡 84% · ✅ 0 failing
|
| Status | Attribution | File | Lines |
|---|---|---|---|
| created | ai | app/cli/pkg/action/trace_rebased_commits_test.go |
+249 / -0 |
| modified | ai | app/cli/pkg/action/trace_hook_handler.go |
+90 / -6 |
| modified | ai | app/cli/internal/trace/git/gogit.go |
+43 / -13 |
| modified | ai | app/cli/internal/trace/git/exec.go |
+54 / -1 |
| modified | ai | app/cli/internal/trace/git/exec_test.go |
+55 / -0 |
| modified | ai | app/cli/internal/trace/git/git.go |
+15 / -1 |
| modified | ai | app/cli/pkg/action/trace_hook_handler_test.go |
+3 / -0 |
| modified | ai | app/cli/internal/trace/README.md |
+1 / -0 |
Policies (4)
| Status | Policy | Material | Messages |
|---|---|---|---|
| ✅ Passed | ai-config-ai-agents-allowed |
ai-coding-session-7fa5c0 |
- |
| ✅ Passed | ai-config-no-dangerous-commands |
ai-coding-session-7fa5c0 |
- |
| ✅ Passed | ai-config-no-secrets |
ai-coding-session-7fa5c0 |
- |
| ✅ Passed | ai-config-mcp-servers-allowed |
ai-coding-session-7fa5c0 |
- |
Security Checks — ⚠️ 1 failing
⛔ The AI Security Analysis check blocks this merge. An active finding at or above the high severity floor was found on the current head. Where this check is required in branch protection, the merge stays blocked until the finding is resolved or the required check is bypassed.
⚠️ AI Security Analysis
[1 finding · 1 high] The grounded audit checked this change against the project's security context and flagged code a past fix guards against.
app/cli/pkg/action/trace_hook_handler.go:544 ▶ · fails-to-guard · logic flaw · CWE-840 · CVSS 6.4 · confidence: high
-
Trailer-only commit recovery bypasses session ownership checks
Why it matters — An attacker can include an unrelated commit and its code changes in a signed evidence document for an earlier AI session, falsely attributing that work to the session.
Precondition: An attacker needs local commit/push capability in a repository with Chainloop trace hooks enabled and residual trace state from an earlier AI session (or a stale session record). By touching a file that old session once edited, or by relying on a finished session that still looks active, they could trigger commit-msg/post-commit/pre-push to reuse that session ID on unrelated work.Show detail — the change · how to fix · related fixes
The change
func recordRebasedCommits(client tracegit.Client, store *state.Store, repoRoot string, records []*state.CommitRecord, sessionRecords map[string]*state.SessionRecord, log zerolog.Logger) []*state.Commi … if len(sessionRecords) == 0 { return records } // One read of the commits that carry a trailer: an unrecorded commit // without one is never recorded, and the branch can hold the whole // history when no base branch is found. candidates, err := client.BranchCommits(repoRoot, state.TrailerKey+":") if err != nil { log.Debug().Err(err).Msg("could not enumerate branch commits, skipping rebased commit recovery")
How to fix — Require a verified replay match against a previously recorded session-owned commit, such as an orphan record, before saving recovered ownership. If equivalence cannot be verified, skip recovery rather than persisting ownership derived solely from a known session trailer.
Related fixes & locations
06ec131— Only uncommitted, still-owned AI edits may credit a commit or session evidence document; once those edits land, are superseded, or the session has ended and nothing remains to attest, that session must stop being attached to later unrelated commits and pushes.
View in Chainloop ↗ · How this works ↗
✅ secret-scan
| Status | Policy | Messages |
|---|---|---|
| ✅ Passed | secrets-detection |
- |
✅ sast-scan
| Status | Policy | Messages |
|---|---|---|
| ✅ Passed | owasp-top10-2025 |
- |
| ✅ Passed | sast |
- |
| ✅ Passed | cwe-top25 |
- |
| ✅ Passed | cwe-top26-40-cusp |
- |
Scans not applied (3)
| Scan | Reason |
|---|---|
vulnerability-scan |
no manifest/lockfile changed |
github-actions-scan |
no workflow files changed |
iac-scan |
no IaC files changed |
Powered by Chainloop and Chainloop Trace
There was a problem hiding this comment.
All reported issues were addressed across 8 files
Tip: Get a Slack DM when cubic finishes reviewing your PRs. Connect Slack
View guided diff | Re-trigger cubic
Fixes the goconst lint findings of the new test. Refs chainloop-dev#3838 Assisted-by: Claude Code Signed-off-by: Jose Ignacio Paris Prieto <jiparis@chainloop.dev> Chainloop-Trace-Sessions: 7fa5c0ca-dc5c-428e-83d2-5f528e3bd327
A rebase replays its commits in the same second, so the committer dates of the re-recorded commits tie and the session sort could put them out of order. Walk the branch oldest first, give each new record a timestamp after the previous one, and sort the session commits with a stable sort. Refs chainloop-dev#3838 Assisted-by: Claude Code Signed-off-by: Jose Ignacio Paris Prieto <jiparis@chainloop.dev> Chainloop-Trace-Sessions: 7fa5c0ca-dc5c-428e-83d2-5f528e3bd327
There was a problem hiding this comment.
All reported issues were addressed across 4 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
View guided diff | Re-trigger cubic
|
On the AI Security Analysis finding at
The server-side fix in PFM-8286 should validate the trailer against the repository and branch of the PR, which covers the cross-repository case. |
Rebased commit recovery ran one git log per unrecorded branch commit on each push, which is the whole history when no base branch is found. Replace CommitInfo with BranchCommits, which lists in one read the branch commits whose message contains the trailer, with their parent count, so the merge check needs no extra call either. Refs chainloop-dev#3838 Assisted-by: Claude Code Signed-off-by: Jose Ignacio Paris Prieto <jiparis@chainloop.dev> Chainloop-Trace-Sessions: 7fa5c0ca-dc5c-428e-83d2-5f528e3bd327
There was a problem hiding this comment.
All reported issues were addressed across 6 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
A rebase that runs outside the clone with the Chainloop Trace hooks (for example the GitHub "Update branch" button, or a rebase in another clone) gives the branch commits new SHAs that have no commit record. The next
pre-pushthen dropped the old records as orphans and sent none of the rebased commits, so the session lost their files and AI line attribution, or was not sent at all.Before the orphan filter, the push now records each commit of the branch that carries a
Chainloop-Trace-Sessionstrailer and has no record. It keeps only the trailer sessions that have a local session record, because the commit author controls the trailer text. Merge commits are skipped, as inpost-commit, and existing records are not changed. The next push then sends all the commits of the session with their new SHAs, with or without a new commit.The git client gets a
CommitInfomethod to read the message and committer date of any commit. The Trace README feature table documents the new behavior.This is the client part of PFM-8286. A rebase on GitHub that is not followed by a push from a clone with the hooks still needs the server-side fix.
Fixes #3838
AI disclosure: this change was produced with the assistance of Claude Code.
🤖 Generated with Claude Code