Skip to content

fix: preserve total_additions for inherited prompts and prevent amend inflation#1081

Merged
svarlamov merged 2 commits intomainfrom
fix/total-additions-reset-inherited-prompts
Apr 14, 2026
Merged

fix: preserve total_additions for inherited prompts and prevent amend inflation#1081
svarlamov merged 2 commits intomainfrom
fix/total-additions-reset-inherited-prompts

Conversation

@svarlamov
Copy link
Copy Markdown
Member

@svarlamov svarlamov commented Apr 14, 2026

Summary

Fixes two related bugs in total_additions/total_deletions handling:

Root Cause

#1080: calculate_and_update_prompt_metrics unconditionally overwrote total_additions from the session_additions map. When a prompt was inherited from INITIAL with no new checkpoints, the session_id wasn't in the map, so unwrap_or(0) zeroed out the inherited value.

#1098: merge_prompts_picking_newest and merge_attributions_favoring_first summed total_additions across sources. Since total_additions is cumulative, when the same prompt appeared in both checkpoint VA (with inherited or delta values) and blame VA (with cumulative values), the sum inflated the total.

Fix

  1. Conditional update in calculate_and_update_prompt_metrics: Only overwrite total_additions/total_deletions when checkpoint data exists (if let Some)
  2. Cumulative session deltas: After metrics calculation, add_inherited_totals adds the inherited INITIAL base to session deltas, making all prompts carry cumulative values
  3. Max-based merge: Changed merge_prompts_picking_newest and merge_attributions_favoring_first from saturating_add to max, since the highest cumulative value is always the most current

Closes #1080
Closes #1098

Test plan

  • test_inherited_prompt_preserves_total_additions_when_no_checkpoint_data — inherited prompts preserve values, prompts with checkpoints get updated
  • test_empty_session_maps_preserve_existing_totals — empty maps (merge/rebase pattern) preserve values
  • test_merge_prompts_does_not_inflate_totals_for_same_prompt — same prompt in both sources doesn't double
  • test_merge_prompts_picks_higher_cumulative_total — higher cumulative value wins in merge
  • test_session_delta_plus_inherited_base_is_cumulative — session delta + inherited base = correct cumulative
  • Updated integration test test_merge_prompts_picking_newest_uses_max_totals_on_collision to expect max semantics
  • Full test suite passes (cargo test — all green)

🤖 Generated with Claude Code

svarlamov and others added 2 commits April 14, 2026 13:12
…t data

When a prompt is inherited from INITIAL attributions (e.g., from a
previous agent session), calculate_and_update_prompt_metrics would
unconditionally overwrite total_additions/total_deletions with
unwrap_or(0). If no new checkpoints existed for that session,
the inherited values were zeroed out, causing total_ai_additions
to be under-reported and acceptance rates to exceed 100%.

Only update total_additions/total_deletions when checkpoint data
actually exists for the session, preserving inherited values otherwise.

Closes #1080

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

@svarlamov svarlamov merged commit b2eb93e into main Apr 14, 2026
26 checks passed
@svarlamov svarlamov deleted the fix/total-additions-reset-inherited-prompts branch April 14, 2026 14:02
@svarlamov svarlamov changed the title fix: preserve total_additions for inherited prompts without checkpoint data fix: preserve total_additions for inherited prompts and prevent amend inflation Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant