Skip to content

sync_orchestration.py: cost extraction reads wrong tuple index for generate/crash/fix/verify operations #555

@Serhan-Asad

Description

@Serhan-Asad

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.0

Location 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 at result[4], model at result[5]
  • Operation generate: cost at result[2], model at result[3]
  • All other operations (example, test, test_extend, auto-deps): cost at result[1], model at result[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 generate entry will show "actual_cost": false and "model": "unknown"
  • The fix entry (if triggered) will show "actual_cost": 0.0 and "model" containing the source code string

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