Conversation
… upsert Three P1 findings from FleetReview on d7fdcac: - turn_api_calls PRIMARY KEY(turn_id, seq) accepted NULLs (SQLite allows NULL in non-INTEGER PK columns, and NULLs never collide) -> NOT NULL on both columns plus a boundary reject in insert_api_call. - sweep() cascaded call rows only through the selected turns, so a call whose parent insert_turn never landed outlived retention forever -> bounded parentless delete on the call's own ts, same transaction. - insert_turn used INSERT OR REPLACE, which deletes the row first and NULLed served_subs_json/attribution on any re-finalize -> INSERT ... ON CONFLICT DO UPDATE over the TurnRecord-owned columns only.
… not OR REPLACE The probe matched the literal 'INSERT OR REPLACE INTO turns', so the upsert rewrite made its mutation inert (caught by the probe's own self-check). Match the turns INSERT regardless of conflict strategy.
Parentless turn_api_calls rows are the normal state of an in-flight turn (calls are appended as they happen; the parent turns row only lands at finalize). Sweeping them on the retention cutoff alone deletes a live turn's call ledger whenever retention is short or the turn outruns it. Orphan deletion now requires the row to be past BOTH retention and _ORPHAN_GRACE_S (24h): orphan_cutoff = now - max(grace, retention). Verified: scripts/run_tests.sh tests/plugins/blackbox -q -> 15 files, 156 tests passed, 0 failed, EXIT=0. Mutation gate: replacing orphan_cutoff with the retention cutoff fails exactly test_orphan_sweep_respects_grace_period_independent_of_retention (1 failed, 12 passed).
Capture pooled response identity beside each completion's usage, append zero-token failure attempts before retry classification, and preserve per-turn sequence ownership across delegated/concurrent turns.\n\nVerified: 187 scoped tests passed; Blackbox 156 passed; Anthropic adapter 108 passed; direct and streaming wiring/stub mutations went red.
51621f9 to
8425583
Compare
|
Superseded by merged #913 (52ba20d). That PR explicitly cherry-picked this PR's accumulator commit Verified on current fork main at |
Summary
Stacked on #799. Records every Hermes-managed upstream completion attempt in the C1
turn_api_callsledger, pairing raw relay identity headers with the exact call usage object.Acceptance coverage
build_api_kwargsecho probe with mutation control.Verification
scripts/run_tests.sh tests/agent/test_api_call_attribution.py tests/agent/test_stream_surrogate_splicer.py tests/plugins/blackbox -q→ 187 passed, 0 failed.scripts/run_tests.sh tests/agent/test_anthropic_adapter.py -q→ 108 passed, 0 failed.git diff --check→ clean.Stack
Base branch is
daedalus-opus/t_75b1f823-api-calls/ #799. Retarget this PR tomainafter #799 lands.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.