[GH-ISSUE #162] AI Refactoring Its Own Code Shows Incorrect ai_deletions in Squashed Stats #58

Closed
opened 2026-03-02 04:11:33 +03:00 by kerem · 1 comment
Owner

Originally created by @AtnesNess on GitHub (Oct 28, 2025).
Original GitHub issue: https://github.com/git-ai-project/git-ai/issues/162

Summary

When AI refactors its own code across multiple commits and those commits are squashed, the squash-authorship command incorrectly counts deleted lines as ai_deletions even though the AI was both the author of the original code and the refactored code.

Expected Behavior

When AI refactors its own previously-written code in a squashed commit:

  • The deleted lines should not count as ai_deletions
  • Only the net result (final lines added/removed) should be reflected in statistics
  • ai_deletions: 0 in the squashed commit stats

Rationale: Since the AI wrote both the original and refactored code, this is code evolution/iteration, not deletion of AI contributions. From a productivity/contribution perspective, the AI has simply improved its own work.

Actual Behavior

The squash-authorship command shows ai_deletions: 8 for the deleted lines from the AI's first commit, even though those lines were authored by the same AI agent.

Steps to Reproduce

Detailed Scenario

  1. Commit 1: AI creates an iterative Fibonacci implementation (15 lines added)

    • 12 AI-authored lines
    • 3 structural lines (exports, etc.)
  2. Commit 2: AI refactors to recursive implementation (11 lines deleted, 2 added)

    • AI deletes 8 of its own lines from Commit 1
    • AI deletes 3 structural lines
    • AI adds 1 new line + 1 console.log
  3. Squash: The two commits are squashed into one

    • Net result: 6 lines added, 0 lines deleted (compared to base)
    • squash-authorship is run on the squashed commit

Actual Output

{
  "ai_deletions": 8,
  "ai_additions": 6,
  "tool_model_breakdown": {
    "mock_ai::unknown": {
      "ai_deletions": 8,
      "ai_additions": 6
    }
  }
}

Expected Output

{
  "ai_deletions": 0,
  "ai_additions": 6,
  "tool_model_breakdown": {
    "mock_ai::unknown": {
      "ai_deletions": 0,
      "ai_additions": 6
    }
  }
}

Root Cause Analysis

The squash-authorship command appears to:

  1. Track authorship information from individual commits correctly
  2. When squashing, it preserves deletion counts even when the deleted code was authored by the same AI agent
  3. It doesn't recognize that self-refactoring should net out deletions to 0

The logic should be: if the author of the deleted lines is the same as the author of the current change, don't count it as a deletion.

Impact

  • Statistics Accuracy: Misleading metrics about AI contributions
  • Productivity Tracking: AI appears to be "deleting" its own work rather than improving it
  • Tool Reliability: Users may lose trust in the squash-authorship feature if stats don't make sense
Originally created by @AtnesNess on GitHub (Oct 28, 2025). Original GitHub issue: https://github.com/git-ai-project/git-ai/issues/162 ## Summary When AI refactors its own code across multiple commits and those commits are squashed, the `squash-authorship` command incorrectly counts deleted lines as `ai_deletions` even though the AI was both the author of the original code and the refactored code. ## Expected Behavior When AI refactors its own previously-written code in a squashed commit: - The deleted lines should **not** count as `ai_deletions` - Only the net result (final lines added/removed) should be reflected in statistics - `ai_deletions: 0` in the squashed commit stats **Rationale**: Since the AI wrote both the original and refactored code, this is code evolution/iteration, not deletion of AI contributions. From a productivity/contribution perspective, the AI has simply improved its own work. ## Actual Behavior The `squash-authorship` command shows `ai_deletions: 8` for the deleted lines from the AI's first commit, even though those lines were authored by the same AI agent. ## Steps to Reproduce ### Detailed Scenario 1. **Commit 1**: AI creates an iterative Fibonacci implementation (15 lines added) - 12 AI-authored lines - 3 structural lines (exports, etc.) 2. **Commit 2**: AI refactors to recursive implementation (11 lines deleted, 2 added) - AI deletes 8 of its own lines from Commit 1 - AI deletes 3 structural lines - AI adds 1 new line + 1 console.log 3. **Squash**: The two commits are squashed into one - Net result: 6 lines added, 0 lines deleted (compared to base) - `squash-authorship` is run on the squashed commit ### Actual Output ```json { "ai_deletions": 8, "ai_additions": 6, "tool_model_breakdown": { "mock_ai::unknown": { "ai_deletions": 8, "ai_additions": 6 } } } ``` ### Expected Output ```json { "ai_deletions": 0, "ai_additions": 6, "tool_model_breakdown": { "mock_ai::unknown": { "ai_deletions": 0, "ai_additions": 6 } } } ``` ## Root Cause Analysis The `squash-authorship` command appears to: 1. Track authorship information from individual commits correctly 2. When squashing, it preserves deletion counts even when the deleted code was authored by the same AI agent 3. It doesn't recognize that self-refactoring should net out deletions to 0 The logic should be: **if the author of the deleted lines is the same as the author of the current change, don't count it as a deletion**. ## Impact - **Statistics Accuracy**: Misleading metrics about AI contributions - **Productivity Tracking**: AI appears to be "deleting" its own work rather than improving it - **Tool Reliability**: Users may lose trust in the squash-authorship feature if stats don't make sense
kerem closed this issue 2026-03-02 04:11:33 +03:00
Author
Owner

@svarlamov commented on GitHub (Nov 1, 2025):

Thanks for the report! Stats was definitely working right. Made a ton of updates in the latest release and added documentation for how each field is calculated in the docs here: https://usegitai.com/docs/reference#stats:~:text=in%20JSON%20format-,Output,-When%20using%20%2D%2Djson

When it comes to attributing the deletions that actually landed in the commit, I realized that this isn't possible to do with line count arithmetic. I opened #176 to track this enhancement. Please do let us know if you notice any lingering inconsistencies with the stats

<!-- gh-comment-id:3475523963 --> @svarlamov commented on GitHub (Nov 1, 2025): Thanks for the report! Stats was definitely working right. Made a ton of updates in the latest release and added documentation for how each field is calculated in the docs here: https://usegitai.com/docs/reference#stats:~:text=in%20JSON%20format-,Output,-When%20using%20%2D%2Djson When it comes to attributing the deletions that actually landed in the commit, I realized that this isn't possible to do with line count arithmetic. I opened #176 to track this enhancement. Please do let us know if you notice any lingering inconsistencies with the stats
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#58
No description provided.