Repository navigation
fix(trace): attribute commits made inside Bash calls - #3631
Conversation
PR validation — ✅ 3 passing
AI Session Checks — ⏭️ bypassed by labelAI Coding Session Check BypassedThis PR carries the Learn more about Chainloop Trace. Security Checks —
|
| Status | Policy | Messages |
|---|---|---|
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 13 files
Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.
View guided diff | Re-trigger cubic
d65514e to
26f4d6d
Compare
|
@jiparis can you take a look at this one? |
26f4d6d to
0b7e872
Compare
There was a problem hiding this comment.
All reported issues were addressed across 5 files (changes from recent commits).
Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.
View guided diff | Re-trigger cubic
|
Thanks for this fix. I tested the branch in real headless Claude Code sessions (Claude Code 2.1.301, Results
Scenarios and suggested approach1. Permission check on the rewritten command (blocker)Claude Code applies Suggested approach: do not rewrite the command. Use the snapshot files that this PR already writes (
There is no Notes:
2. Another hook that also returns
|
| Current PR | Minimal version | |
|---|---|---|
| Bash calls with a narrow allowlist | Denied, or a prompt on each call | No change in permissions |
| Another hook that rewrites the command | Trailer lost, with no warning | No conflict |
| Token in the transcript and in prompts | Yes, on each Bash call | No |
| Attribution precision | Exact call | Session. This is sufficient for the trailer. Line ranges can be less exact when calls overlap in one session. |
| Dependency | updatedInput (documented) |
CLAUDE_CODE_SESSION_ID (not documented, as far as we know). If Claude Code stops setting it, the behavior is the same as on the base commit. |
| Background Bash calls | Not attributed | Not attributed |
Estimated size of the change:
| Change | Size |
|---|---|
Delete TagShellCommand, ShellCommandTagger, RawToolInput, the ReadHookInput changes, EncodeShellCallKey/DecodeShellCallKey, and the ShellCallEnv export |
Approximately −100 lines |
Add store.OpenShellSnapshotKeys(sessionID). It lists the shell-index-* files in snapshots/<session>/ and makes each key from the file name. |
Approximately +30 lines |
In checkpointActiveShellAttribution, read the environment variable instead of the token, and do the checkpoint for each key. The diff and checkpoint logic does not change. |
Approximately +15 lines |
Tests: set CLAUDE_CODE_SESSION_ID instead of the token. Add one test with two overlapping calls in the same session. |
Small |
The snapshot, index, checkpoint and cleanup logic of this PR stays. Thus we expect the result to be smaller than the current PR.
Other items
- The
Chainloop AI PoliciesandChainloop PR Validationchecks fail. A possible cause is theAssisted-by: Vibhav's Pitrailer. We did not examine the failure details. - The repository rules require an update to the feature table and the compatibility matrix in
app/cli/internal/trace/README.mdwhen a Trace feature changes. This PR does not change that file.
Claude Code helped with this review.
|
Thanks @waveywaves, sorry for the last long ie-vibed response.
|
|
Thanks, this clarifies the scope. I agree that One correction on validation: I did not independently run this branch in Claude Code. I validated it with the automated Go lifecycle/race tests, lint, and build. The live headless Claude Code results in this thread are from @jiparis's testing, and I should not imply otherwise.
That said, you're right that invoking the Git binary from I will keep the existing regressions, especially the filter/line-ending case. If go-git cannot match Git's semantics there, I will report the concrete compatibility gap rather than hide a subprocess inside Provider scope is Claude-only in this PR because only Claude implements Thanks for the testing and clarification. I will make those GoGit-native and documentation changes next. |
There was a problem hiding this comment.
All reported issues were addressed across 4 files (changes from recent commits).
Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.
View guided diff | Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 8 files (changes from recent commits).
Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.
View guided diff | Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 3 files (changes from recent commits).
Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.
View guided diff | Re-trigger cubic
|
Thanks for the updates. The go-git changes and the README matrix row address my comments. One concern about scope. To stay in go-git, the PR now implements part of the git index logic in Go. That logic includes the effective index ( My concerns:
Can we reduce the scope of this PR?
If you think that one of these edge cases is necessary for #3625, please tell me which one. Then we can keep only that case. Claude Code helped with this comment. |
f4576c7 to
901e082
Compare
Tag the exact Claude Bash call so commit-msg can attribute staged content before PostToolUse runs. Assisted-by: Vibhav's Pi Signed-off-by: Vibhav Bobade <vibhav.bobde@gmail.com>
Honor the effective Git index, preserve recreated paths after staged deletions, and distinguish conflict-stage signatures. Assisted-by: Vibhav's Pi Signed-off-by: Vibhav Bobade <vibhav.bobde@gmail.com>
Read staged blob content from the exact object recorded in the index, even when refs/replace maps it to another object. Assisted-by: Vibhav's Pi Signed-off-by: Vibhav Bobade <vibhav.bobde@gmail.com>
Decode GIT_INDEX_FILE with go-git and keep staged, index, blob, and worktree comparisons inside GoGitClient without native git subprocesses. Assisted-by: Vibhav's Pi Signed-off-by: Vibhav Bobade <vibhav.bobde@gmail.com>
Mark same-call commit attribution as Claude-only and document the foreground Bash limitation. Assisted-by: Vibhav's Pi Signed-off-by: Vibhav Bobade <vibhav.bobde@gmail.com>
Exclude intent-to-add entries, honor effective attribute sources, retain tracked files below ignored directories, and avoid requeueing no-op filtered content. Assisted-by: Vibhav's Pi Signed-off-by: Vibhav Bobade <vibhav.bobde@gmail.com>
Guard transforming filters, exclude intent-to-add paths from tracked snapshots, and confine fallback reads to the checkout root. Assisted-by: Vibhav's Pi Signed-off-by: Vibhav Bobade <vibhav.bobde@gmail.com>
|
Thanks. I narrowed the PR to the scope in your review. What changed:
Follow-up issues:
Validation on the narrowed tree includes the focused and full affected race suites, CLI build, The earlier live headless Claude Code testing in this thread was performed by @jiparis. My validation here is automated Go testing plus CLI-level hook QA, not a separate live Claude Code run. The scope reduction is in Assisted-by: Vibhav's Pi |
|
Thanks for reducing the scope. I reviewed I found two items. 1. Repositories with a split index or a sparse index lose all shell attributiongo-git cannot decode a split index ( Index version 4 works. In How to reproduce:
Results:
A commit in these repositories does not fail. Only the attribution is lost. Suggested fix: if 2. Doc comments (minor)
Claude Code helped with this review. |
Use the Git client selected for the checkout and keep the worktree and HEAD snapshots when an index cannot be read. Assisted-by: Vibhav's Pi Signed-off-by: Vibhav Bobade <vibhav.bobde@gmail.com>
Preserve the Claude same-call path alongside the latest Trace provider and per-call file snapshots. Assisted-by: Vibhav's Pi Signed-off-by: Vibhav Bobade <vibhav.bobde@gmail.com>
Avoid a dynamic Git subprocess argument while preserving split and sparse index support. Assisted-by: Vibhav's Pi Signed-off-by: Vibhav Bobade <vibhav.bobde@gmail.com>
There was a problem hiding this comment.
All reported issues were addressed across 1 file (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
View guided diff | Re-trigger cubic
Read staged blob hashes through Git batch input so custom object directories work without dynamic subprocess arguments. Assisted-by: Vibhav's Pi Signed-off-by: Vibhav Bobade <vibhav.bobde@gmail.com>
|
@jiparis can you do a final review? Thanks! |
|
Thanks, I reviewed
I also ran the scenario from #3625 again in a headless Claude Code session. The commit has the trailer, and the session evidence is on disk. New item: time of
|
| Item | Time |
|---|---|
One Bash call changes and stages 301 files, then commit-msg runs |
10.6 s |
git ls-files --stage + git cat-file --batch for one file |
16.5 ms |
| The same two commands for 301 files | Approximately 5 s |
This can occur when a Bash call runs a code generator and then git add -A && git commit.
Suggested fix: read the blobs with the hashes from afterIndex. Use one git cat-file --batch process for all the paths, and do not run git ls-files for each file. For example, add a method that takes a list of hashes and returns their content.
I am OK if this change is in a follow-up issue.
Claude Code helped with this review.
Use snapshot hashes to read all changed staged blobs through one Git process instead of rescanning the index for each file. Keep the GoGit fallback on the same snapshot hashes. Assisted-by: OmO Signed-off-by: Vibhav Bobade <vibhav.bobde@gmail.com>
Rename the staged-blob test case so goconst no longer flags a third "exec" literal. Assisted-by: OmO Signed-off-by: Vibhav Bobade <vibhav.bobde@gmail.com>
|
Thanks, I reviewed Measurement: one Bash call stages and commits 301 files.
Please also batch the
|
Read pre-call base content with one git cat-file --batch process instead of three Git processes per changed file. Preserve missing paths and the GoGit fallback. Assisted-by: OmO Signed-off-by: Vibhav Bobade <vibhav.bobde@gmail.com>
There was a problem hiding this comment.
All reported issues were addressed across 5 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
|
Thanks for tracking this down! Added the batched base reads in e9b47a87, preserving missing-path behavior and the GoGit fallback. I repeated the same local before-and-after test on the real tektoncd/pipeline repository, pinned to upstream commit Before is Chainloop
The ratio of medians is approximately 50.9× faster, or a 98.03% reduction in handler elapsed time, in this workload. All six runs passed the session-trailer and fingerprinted-attribution checks for all 301 files, and produced the same staged tree hash. Baseline timings varied substantially. The three before samples ran first, followed by the three after samples; workstation load and filesystem caches were not controlled. Only the handler was timed, excluding checkout setup, pre-tool-use snapshots, editing, and staging. This is not a full The affected race-enabled tests, assisted by Vibhav's 🥧 |
|
Thanks @waveywaves . Please take a look at those cubic findings, in case they are legit. |
Recover readable paths after batched blob-read failures and use saved pre-call index blobs when restaging files. Assisted-by: Vibhav's Pi Signed-off-by: Vibhav Bobade <vibhav.bobde@gmail.com>
e3c3c12 to
f12ccf7
Compare
|
@waveywaves everything looks good, I've accepted the change. Please fix those merge conflicts and I'll be happy to drive the merge. Thanks! |
Merge current main while preserving approved same-call checkpoints and main's reflog attribution and Copilot filtering. Adapt generated-line assertions and blob-type checks to the merged APIs. Assisted-by: Vibhav's Pi Signed-off-by: Vibhav Bobade <vibhav.bobde@gmail.com>
Closes #3625
Problem
Claude Code can edit, stage, commit, and push within one foreground Bash tool call. The
commit-msghook runs before Claude'sPostToolUsehook, so the staged files previously had no recorded AI attribution and the commit lost itsChainloop-Trace-Sessionstrailer.Narrowed scope
This change now implements only the foreground Claude Bash path requested in the maintainer scope review:
tool_input;NewGitClient: Git handles split, sparse, and temporary indexes when available; GoGit handles ordinary indexes otherwise;commit-msg, so content staged before the call is not claimed;PostToolUsedoes not requeue committed attribution; andStagedFilesandSnapshotWorktreefollowmain. Broader Git-clean and index-edge-case parity remains in the follow-up issues below.Deferred behavior
git commit --only, intent-to-add, conflict stages, and replacement refsValidation
main, the race-enabledpkg/action,internal/trace/git,internal/trace/claude, andinternal/trace/statesuites pass;go vet ./...pass;golangci-lintcannot load the repository config because the installed binary was built with Go 1.26 while the repository targets Go 1.27.3. The current-headlint (cli)CI job is the authoritative lint result.The earlier live headless Claude Code testing in this thread was performed by @jiparis. The contributor validation above is automated Go testing plus CLI-level hook QA, not an independent live Claude Code run.
Assisted-by: Vibhav's Pi
Remaining policy gate
This PR still needs an approving review and AI-session evidence or a
skip-ai-sessionlabel. The available Chainloop login cannot upload evidence to the project, and the repository label API returned HTTP 403 when asked to apply this label to #3719 (admin rights required). A maintainer with admin access must add it here; code, test, DCO, and signing checks remain separate.