-
Notifications
You must be signed in to change notification settings - Fork 53
Description
Bug description
In pdd/sync_orchestration.py, the sync loop extracts cost and model from operation results by always reading result[1] as cost and result[2] as model. This is incorrect because each operation returns a different tuple format.
Affected code
File: pdd/sync_orchestration.py
Location 1 — line 1857-1858 (cost accumulation):
# Cost is always at index 1 in both 3-tuple and 4-tuple returns
cost = result[1] if len(result) >= 2 and isinstance(result[1], (int, float)) else 0.0Location 2 — lines 1889-1890 (log entry):
actual_cost = result[1] if isinstance(result[1], (int, float)) else 0.0
model_name = result[2] if len(result) >= 3 and isinstance(result[2], str) else 'unknown'Return formats per operation
Each function returns a different tuple. The correct cost and model indices are:
- generate (
code_generator_main, line 1207): returns(content, was_incremental, cost, model)— 4-tuple, cost at index 2, model at index 3 - crash (
crash_main, line 389): returns(success, final_code, final_program, attempts, cost, model)— 6-tuple, cost at index 4, model at index 5 - fix (
fix_main, line 545): returns(success, fixed_unit_test, fixed_code, attempts, total_cost, model_name)— 6-tuple, cost at index 4, model at index 5 - verify (
fix_verification_main, line 689): returns(success, final_program, final_code, attempts, total_cost, model_name)— 6-tuple, cost at index 4, model at index 5 - example (
context_generator_main, line 205): returns(content, cost, model)— 3-tuple, cost at index 1, model at index 2 (correct as-is) - test/test_extend (
cmd_test_main, line 420): returns(content, cost, model, agentic_success)— 4-tuple, cost at index 1, model at index 2 (correct as-is)
Why the isinstance check doesn't catch it
Python's bool subclasses int, so isinstance(False, (int, float)) returns True. For generate, result[1] is was_incremental=False, which passes the type check and cost becomes 0 (the integer value of False).
Expected behavior
_extract_cost_from_result(operation, result)should return the cost from the correct index based on which operation produced the result_extract_model_from_result(operation, result)should return the model name from the correct index based on which operation produced the result- The bool check should explicitly exclude bool:
isinstance(cost, (int, float)) and not isinstance(cost, bool)
Fix approach
Create two helper functions that dispatch on the operation name:
- Operations
crash,fix,verify: cost atresult[4], model atresult[5] - Operation
generate: cost atresult[2], model atresult[3] - All other operations (
example,test,test_extend,auto-deps): cost atresult[1], model atresult[2]
Replace the inline result[1] reads at both locations (line 1858 and lines 1889-1890) with calls to these helpers.
Reproduction
Run pdd sync on any prompt and inspect .pdd/meta/<basename>_sync.log:
- The
generateentry will show"actual_cost": falseand"model": "unknown" - The
fixentry (if triggered) will show"actual_cost": 0.0and"model"containing the source code string