[GH-ISSUE #392] Bug Report: ai_accepted exceeds ai_additions causing logically impossible statistics #146

Closed
opened 2026-03-02 04:12:16 +03:00 by kerem · 2 comments
Owner

Originally created by @txf0096 on GitHub (Jan 22, 2026).
Original GitHub issue: https://github.com/git-ai-project/git-ai/issues/392

Issue Summary

The ai_accepted metric can exceed ai_additions in commit statistics, which is logically impossible. By definition, ai_additions = ai_accepted + mixed_additions, so ai_accepted should never be greater than ai_additions.

Environment

  • git-ai version: v1.0.36
  • Platform: macOS Darwin 25.2.0

Reproduction Data

From a real commit in production:

{
  "human_additions": 0,
  "mixed_additions": 0,
  "ai_additions": 223,
  "ai_accepted": 251,
  "total_ai_additions": 251,
  "total_ai_deletions": 0,
  "time_waiting_for_ai": 96,
  "git_diff_deleted_lines": 107,
  "git_diff_added_lines": 223
}

Problem: ai_accepted (251) > ai_additions (223)

This violates the fundamental invariant:

ai_additions = ai_accepted + mixed_additions
223 ≠ 251 + 0  // ❌ Impossible! 251 > 223

Since mixed_additions = 0, we expect ai_additions to equal ai_accepted, but instead ai_accepted exceeds it by 28 lines (12.5%).

Current Behavior

The calculation logic creates an inconsistency:

Step 1: Calculate ai_accepted (stats.rs:487-512):

for file_attestation in &log.attestations {
    for entry in &file_attestation.entries {
        let lines_in_entry: u32 = entry.line_ranges.iter()
            .map(|range| match range {
                LineRange::Single(_) => 1,
                LineRange::Range(start, end) => end - start + 1,
            })
            .sum();

        if let Some(prompt_record) = log.metadata.prompts.get(&entry.hash) {
            commit_stats.ai_accepted += lines_in_entry;  // ⚠️ No deduplication
        }
    }
}
// Result: ai_accepted = 251

Step 2: Calculate ai_additions (stats.rs:538-542):

commit_stats.ai_additions = std::cmp::min(
    commit_stats.mixed_additions + commit_stats.ai_accepted,
    git_diff_added_lines,
);
// Result: ai_additions = min(0 + 251, 223) = 223

The cap at git_diff_added_lines prevents ai_additions from matching the inflated ai_accepted, breaking the invariant.

Originally created by @txf0096 on GitHub (Jan 22, 2026). Original GitHub issue: https://github.com/git-ai-project/git-ai/issues/392 # Issue Summary The `ai_accepted` metric can exceed `ai_additions` in commit statistics, which is logically impossible. By definition, `ai_additions = ai_accepted + mixed_additions`, so `ai_accepted` should never be greater than `ai_additions`. ## Environment - git-ai version: v1.0.36 - Platform: macOS Darwin 25.2.0 ## Reproduction Data From a real commit in production: ```json { "human_additions": 0, "mixed_additions": 0, "ai_additions": 223, "ai_accepted": 251, "total_ai_additions": 251, "total_ai_deletions": 0, "time_waiting_for_ai": 96, "git_diff_deleted_lines": 107, "git_diff_added_lines": 223 } ``` **Problem**: `ai_accepted` (251) > `ai_additions` (223) This violates the fundamental invariant: ``` ai_additions = ai_accepted + mixed_additions 223 ≠ 251 + 0 // ❌ Impossible! 251 > 223 ``` Since `mixed_additions = 0`, we expect `ai_additions` to equal `ai_accepted`, but instead `ai_accepted` exceeds it by 28 lines (12.5%). ## Current Behavior The calculation logic creates an inconsistency: **Step 1: Calculate `ai_accepted`** (stats.rs:487-512): ```rust for file_attestation in &log.attestations { for entry in &file_attestation.entries { let lines_in_entry: u32 = entry.line_ranges.iter() .map(|range| match range { LineRange::Single(_) => 1, LineRange::Range(start, end) => end - start + 1, }) .sum(); if let Some(prompt_record) = log.metadata.prompts.get(&entry.hash) { commit_stats.ai_accepted += lines_in_entry; // ⚠️ No deduplication } } } // Result: ai_accepted = 251 ``` **Step 2: Calculate `ai_additions`** (stats.rs:538-542): ```rust commit_stats.ai_additions = std::cmp::min( commit_stats.mixed_additions + commit_stats.ai_accepted, git_diff_added_lines, ); // Result: ai_additions = min(0 + 251, 223) = 223 ``` The cap at `git_diff_added_lines` prevents `ai_additions` from matching the inflated `ai_accepted`, breaking the invariant.
kerem closed this issue 2026-03-02 04:12:16 +03:00
Author
Owner

@svarlamov commented on GitHub (Jan 24, 2026):

Great find -- we're actually going to be deprecating these stats in the prompt objects soon and moving to calculating on the fly based on diffs. Should be more stable, especially around rewrites

<!-- gh-comment-id:3793757336 --> @svarlamov commented on GitHub (Jan 24, 2026): Great find -- we're actually going to be deprecating these stats in the prompt objects soon and moving to calculating on the fly based on diffs. Should be more stable, especially around rewrites
Author
Owner

@svarlamov commented on GitHub (Feb 13, 2026):

This should be fixed as of 1.1.0 which uses the new diff-based accepted stats in the stats command output. Thanks for your patience!

<!-- gh-comment-id:3899717519 --> @svarlamov commented on GitHub (Feb 13, 2026): This should be fixed as of `1.1.0` which uses the new diff-based accepted stats in the `stats` command output. Thanks for your patience!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/git-ai#146
No description provided.