intelligence-radar/workplans/IR-WP-0006-billing-reconciliation.md
tegwick 2f5fe5faae Close IR-WP-0005 on the passed read-only key check.
Assistant: grok
Assistant-Session: 01a106a5-fc07-78c2-b64f-8e04cea25daf
2026-10-04 17:13:00 +02:00

80 lines
4.2 KiB
Markdown

---
id: IR-WP-0006
type: workplan
title: "Reconcile trial billing and establish campaign accounting"
domain: infotech
repo: intelligence-radar
status: blocked
flavor: implementation
owner: codex
topic_slug: custodian
origin: residual
origin_ref: IR-WP-0004
created: "2026-09-14"
updated: "2026-10-04"
state_hub_workstream_id: "b877f5e2-0c0e-5bca-9082-873eab857ada"
---
Created before closure of IR-WP-0004 at the user's request to separate credential
delivery from billing. Source files own the work; cross-repository owner plans
retain authority over native changes. Review baseline:
`docs/evidence/2026-09-14-ir-wp-0004-review.md`.
## Specify independent billing evidence and reconciliation contract
```task
id: IR-WP-0006-T01
status: done
priority: high
state_hub_task_id: "87b26b10-f4d6-5c53-9965-fae61ac0df11"
```
Inventory the append-only events for ir-openrouter-pilot-20260913. Preserve the USD 0.023712 pending reservation and USD 10 total authorization. Define how provider billing evidence matches the failed request, what is unknown, who reviews a settlement, and how discrepancies are retained. HTTP 401 alone is not zero-charge proof. Accounting design can proceed independently of credential delivery; provider evidence retrieval may require an admitted read-only path.
Done: contract specified in `docs/evidence/2026-09-27-ir-wp-0006-t01-reconciliation-contract.md` —
inventories the one pending reservation, defines valid billing evidence, the run_id-based match,
the five refusal conditions, and what a settlement record must (and must not) contain.
## Implement and verify auditable reconciliation
```task
id: IR-WP-0006-T02
status: done
priority: high
state_hub_task_id: "1637f2ee-2369-5e78-8893-9437d2d6b6fc"
```
Provide a reviewed append-only settlement procedure or command. Preserve original reservations; reject duplicate/conflicting settlement, unknown reservation, invalid amount, cross-campaign references and budget overrun. Retain source billing evidence and reviewer attribution without credentials. Test uncertain/partial evidence and restart behavior. Do not fabricate a completed model trial to settle a failed request.
Done: `intelligence_radar.trials.reconcile` (+ CLI `reconcile`) implements the T01 contract —
write-once settlement under the existing trials file lock, all five refusal conditions covered,
no `trials` record fabricated. Tests in `tests/test_trials.py`
(`test_reconcile_*`, 9 new cases) cover unknown reservation, duplicate/retry-after-success,
cross-campaign, invalid amount, budget overrun, and missing evidence/reviewer attribution.
Full suite (`make check`, 48 tests) passes.
## Reconcile the outstanding reservation and hand off budget readiness
```task
id: IR-WP-0006-T03
status: wait
depends_on: [IR-WP-0005-T02]
blocking_reason: "No authoritative provider billing evidence for the pending run yet; expected via the IR-WP-0005 admitted read-only path."
priority: high
state_hub_task_id: "441dc053-af7b-5a9c-866f-5b1eb804b94f"
```
Depends on T01/T02 and authoritative provider evidence. Resolve the USD 0.023712 reservation only to the supported actual amount, retaining any unresolved discrepancy explicitly. Rerender pilot/full plans for the same campaign and report spent, pending and remaining authorized budget. No campaign reset, additional authorization, or paid inference is implied. Completion requires reconciled evidence and a usable accounting handoff, not merely implementation tests.
Blocked: the mechanism is ready (T01/T02 done), but no authoritative provider billing evidence
exists for the pending run_id `29a46a1d6c2d9ef6cfce8de6efef75cddcfecee346c1b4babf57119f1a241d71`
yet. Applying `reconcile` here without that evidence would be exactly the fabrication this
workplan forbids. Waits on external evidence (likely via the IR-WP-0005 admitted read-only path).
Rechecked 2026-10-04: the ledger still has the one `reserved` event for
`29a46a1d6c2d9ef6cfce8de6efef75cddcfecee346c1b4babf57119f1a241d71` and no
provider billing artifact. IR-WP-0005-T02 passed on 2026-10-04: the pinned
recipient key check returned `authenticated` with HTTP 200. That check is not
a billing artifact for run
`29a46a1d6c2d9ef6cfce8de6efef75cddcfecee346c1b4babf57119f1a241d71`. `reconcile`
was not called. Stays wait.