[Bug]: Incorrect AI percentage calculation for mixed commits (human + AI changes)
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 74/100
Research direction
Start in src/authorship/stats.rs at accepted_lines_from_attestations(), especially lines 619-629, and reproduce the behavior with git-ai stats HEAD using an invalid attestation hash such as ai_agent. Ensure hashes absent from metadata.prompts are not counted as AI lines and are instead categorized as unknown additions, while valid prompt hashes still produce the expected authorship percentages.
Written by the indexing model from the issue text.
Description
What broke?
Description
When a commit contains both human-authored and AI-generated changes, git-ai incorrectly calculates the AI authorship percentage. Lines that cannot be matched to valid prompt records are incorrectly counted as AI-generated instead of being treated as human/unknown.
Why This is a Problem
In our test case, the git notes contained:
src/array.ts
ai_agent 2
"ai_agent"is aCheckpointKindmarker, not a valid prompt session hash- The entry is parsed as a valid attestation with hash="ai_agent"
- But
"ai_agent"doesn't exist inmetadata.prompts - Despite this, the code counts these 2 lines as AI modifications ❌
Environment
- git-ai version: 1.4.11
- OS: macOS (Darwin 24.6.0)
- Scenario: Mixed human + Claude Code editing session
Impact
This bug affects the accuracy of AI authorship statistics for any commits that:
- Contain human-authored changes without explicit checkpoint tracking
- Have invalid or missing attestation hashes in git notes
- Mix human edits with AI-generated code in the same commit
Steps to reproduce
Steps to Reproduce
- Create a git repo with git-ai initialized
- Use Claude Code or similar to generate some lines (e.g., utils.ts with 20 lines)
- Manually edit another file and add 1 line (e.g., array.ts)
- Stage and commit both files together
- Run
git-ai stats HEAD - Observe that the commit is incorrectly marked as 100% AI instead of ~95% AI
Expected vs actual behavior
Expected Behavior
For a commit with:
- 1 line human modification (manual edit)
- 20 lines AI-generated (from Claude)
Expected: 5% human + 95% AI
Actual Behavior
Shows: 0% human + 100% AI ❌
Root Cause
File: src/authorship/stats.rs
Function: accepted_lines_from_attestations()
Lines: 619-629
The function unconditionally counts all non-h_-prefixed attestation entries as AI modifications, regardless of whether the hash exists in metadata.prompts:
for entry in &file_attestation.entries {
if entry.hash.starts_with("h_") {
// Handle known-human modifications
continue;
}
let accepted = /* calculate line count */;
// ❌ BUG: Lines are counted as AI before checking if hash is valid
total_ai_accepted += accepted;
// This check only affects statistics grouping, not the count above
if let Some(prompt_record) = log.metadata.prompts.get(&entry.hash) {
let tool_model = format!("{}::{}", ...);
*per_tool_model.entry(tool_model).or_insert(0) += accepted;
}
}
Diagnostics (git-ai debug)
## Solution
Move the hash validation check BEFORE counting the lines as AI:
for entry in &file_attestation.entries {
if entry.hash.starts_with("h_") {
// Handle known-human modifications
let accepted = /* calculate */;
known_human_accepted += accepted;
continue;
}
// ✅ FIX: Only count as AI if the hash exists in metadata
if let Some(prompt_record) = log.metadata.prompts.get(&entry.hash) {
let accepted = /* calculate */;
total_ai_accepted += accepted;
let tool_model = format!("{}::{}", ...);
*per_tool_model.entry(tool_model).or_insert(0) += accepted;
}
// Otherwise, lines are not counted here and will be categorized as
// unknown_additions in stats_from_authorship_log()
}
Extra context (optional)
- Dominant language
- Rust
- Stars
- 2.8k
- Forks
- 296
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 43
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from git-ai-project/git-ai
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
git-ai-project/git-ai#2119 ·
-
agent-support enhancement help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
git-ai-project/git-ai#1213 · 1 comment ·
-
integration nightly triage
Difficulty 3/5 1-2 days Newbie friendliness 48/100
git-ai-project/git-ai#2365 ·
-
integration nightly triage
Difficulty 3/5 1-2 days Newbie friendliness 48/100
git-ai-project/git-ai#2363 ·
-
[Bug]: hand-typed commits attributed to an agent session running in an unrelated repository (1.7.4) Open
Difficulty 4/5 3-5 days Newbie friendliness 52/100
git-ai-project/git-ai#2362 · 3 comments ·
All issues in git-ai-project/git-ai
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
gitbutlerapp/gitbutler#15998 · 1 comment ·
-
bug triage:deciding
Difficulty 1/5 Under an hour Newbie friendliness 88/100
open-telemetry/otel-arrow#4132 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100