Skip to content

Fix convert capacity double-counting bug#185

Merged
fr1jo merged 5 commits intofrijo/release/PI-15from
frijo/fix/convert-capacity-double-count
Feb 14, 2026
Merged

Fix convert capacity double-counting bug#185
fr1jo merged 5 commits intofrijo/release/PI-15from
frijo/fix/convert-capacity-double-count

Conversation

@fr1jo
Copy link
Contributor

@fr1jo fr1jo commented Feb 11, 2026

Summary

  • Fixes a bug where convert capacity was double-counted when multiple converts occurred in the same block
  • calculateConvertCapacityPenalty() was returning cumulative values that applyStalkPenalty() added to storage again
  • Result: storage = old + (old + delta) = 2*old + delta instead of correct storage = old + delta

Example before fix:

  • 1st convert of 50: storage = 0 + (0 + 50) = 50 ✓
  • 2nd convert of 50: storage = 50 + (50 + 50) = 150 ✗ (should be 100)
  • 3rd convert of 50: storage = 150 + (150 + 50) = 350 ✗ (should be 150)

Changes

  • calculateConvertCapacityPenalty() now returns delta values instead of cumulative
  • calculatePerWellCapacity() now returns delta values and removes unused pdCapacityToken parameter
  • Added NatSpec documentation for pdCapacity return value
  • Added tests verifying sequential converts consume linear capacity

Test plan

  • New tests verify sequential converts consume capacity linearly
  • All 41 PipelineConvert tests pass
  • All 42 convert tests pass
  • Code compiles without errors

🤖 Generated with Claude Code

@fr1jo fr1jo changed the base branch from master to frijo/release/PI-15 February 11, 2026 17:42
@fr1jo fr1jo force-pushed the frijo/fix/convert-capacity-double-count branch from 7dc04fc to 052c51e Compare February 11, 2026 17:47
When multiple converts occurred in the same block, the convert capacity
tracking was double-counting usage because calculateConvertCapacityPenalty()
returned cumulative values that applyStalkPenalty() added to storage again.

Changes:
- calculateConvertCapacityPenalty() now returns delta values instead of cumulative
- calculatePerWellCapacity() now returns delta values and removes unused parameter
- Added NatSpec documentation for pdCapacity return value
- Added tests verifying sequential converts consume linear capacity

Before fix: storage = old + (old + delta) = 2*old + delta
After fix: storage = old + delta

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@fr1jo fr1jo force-pushed the frijo/fix/convert-capacity-double-count branch from 124f8ca to 694be8d Compare February 11, 2026 18:01
@fr1jo fr1jo force-pushed the frijo/fix/convert-capacity-double-count branch from eb9f17f to ff25c68 Compare February 11, 2026 18:45
Changed variable names in the convert capacity call chain to better reflect
that they now represent delta values (incremental amounts) rather than
cumulative totals after the double-counting fix:

- overallConvertCapacityUsed → overallCapacityDelta
- inputTokenAmountUsed → inputTokenCapacityDelta
- outputTokenAmountUsed → outputTokenCapacityDelta

This addresses the naming confusion identified in code review where
variables suggested cumulative semantics but actually contained deltas.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: frijo <fr1jo@users.noreply.github.com>
@fr1jo fr1jo merged commit 43d953a into frijo/release/PI-15 Feb 14, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants