Skip to content

Budget tracker drops test/test_extend costs due to wrong tuple index #508

@Serhan-Asad

Description

@Serhan-Asad

Summary

When cmd_test_main returns a 4-tuple (content, cost, model, agentic_success), the generic cost parser at sync_orchestration.py:1752 uses result[-2] to extract cost. For 4-tuples, result[-2] is the model name string — not the cost float — so isinstance(..., (int, float)) fails and cost falls back to $0.00.

Confirmed with debug logging

We instrumented the buggy code and ran pdd sync budget_test. The debug log shows:

generate (3-tuple — works by accident):

result[-2] = 0.0005551... (type=float)
cost extracted = $0.0006  

test_extend (4-tuple — bug):

result[-2] = 'gpt-4o-mini' (type=str)
cost extracted = $0.0000  
REAL cost at result[1] = 0.0007821...  

Root cause

cmd_test_main returns a 4-tuple: (content, cost, model, agentic_success)

For a 4-tuple, result[-2] = result[2] = model name (string). The actual cost is at result[1], but the parser never looks there.

The correct cost IS extracted later at line ~1777 for logging/fingerprints, but it's never added back to current_cost_ref[0].

Impact

  • Every test and test_extend operation's cost is silently dropped from budget tracking
  • The budget check if current_cost_ref[0] >= budget: break underestimates spend
  • Sync keeps running operations past the user's budget
  • With expensive models, overshoot could be 20-30%

Fix

# Before (line 1752):
cost = result[-2] if len(result) >= 2 and isinstance(result[-2], (int, float)) else 0.0

# After:
if operation in ('test', 'test_extend') and len(result) >= 4:
    cost = result[1] if isinstance(result[1], (int, float)) else 0.0
else:
    cost = result[-2] if len(result) >= 2 and isinstance(result[-2], (int, float)) else 0.0

Affected operations

  • test (line 1454 calls cmd_test_main)
  • test_extend (line 1488 calls cmd_test_main)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions