> ## Documentation Index
> Fetch the complete documentation index at: https://docs.moda.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# A

# A — receipts and runtime

## Goal

Every call emits a valid `cost_call` receipt under the
[contract](../../../packages/cost-contract/README.md) and [architecture](../architecture.md).
During the owner/tenant rungs, adopt emitter/key prerequisites, not per-call
coverage redesign. The scoreboard holds current values.

## Metric

Share of AI provider-charge dollars whose rows carry required attribution fields
for their work level. This is an **interim readiness query**, not a full exit
proof. It checks the existing slim financial projection's attribution fields
over the last completed UTC hour, deduplicating metric identities. It does not
claim that legacy metric rows are already valid `CostCall` objects. Legacy scope
is conversation when `conversation_id` is present, tenant when only tenant is
present, otherwise company; missing company initiators remain uncovered. The
contract validator remains the authority for explicit work level, identity,
Unicode, timestamps, usage and prices after adoption. Price-book-only/unbilled
calls are outside this diagnostic's provider-charge denominator and need the
bill reconciliation gate; do not report this as coverage of all invoiced spend.
`occurrence_hash` is the projection's hash of the raw `idempotency_key`, and
`has_call_identity` preserves whether `source_event_id` was nonempty. The window
and provider-charge denominator are unchanged from the raw diagnostic. No raw
payloads or event-ID strings need to be scanned.

## Proof query

```sql theme={"dark"}
WITH charges AS (
  SELECT occurrence_hash,
    argMax(tuple(quantity,
      source!='' AND has_call_identity=1 AND stage!='' AND caller_app!='' AND credential_ref!=''
      AND multiIf(conversation_id!='', tenant_id!='' AND run_id!='',
        tenant_id!='', run_kind!='' AND run_id!='', initiator_kind!='' AND initiator_id!='')),
      tuple(event_revision,_ingested_at)) AS v
  FROM moda.cost_usage_financial
  PREWHERE event_date>=toDate(toStartOfHour(now('UTC'))-INTERVAL 1 HOUR)
    AND event_date<=toDate(now('UTC')) AND metric='provider_cost'
    AND resource_kind='llm' AND unit='usd'
    AND event_time>=toStartOfHour(now('UTC'))-INTERVAL 1 HOUR
    AND event_time<toStartOfHour(now('UTC'))
  GROUP BY occurrence_hash
)
SELECT sum(abs(v.1)) AS provider_charge_usd,
  sumIf(abs(v.1),v.2)/nullIf(sum(abs(v.1)),0) AS required_field_share,
  toUInt8(count()>0 AND sum(abs(v.1))>0 AND countIf(NOT v.2)=0) AS field_readiness_pass
FROM charges
SETTINGS readonly=2,max_threads=1,max_bytes_to_read=1000000000,max_result_rows=1000,
  max_execution_time=30,read_overflow_mode='throw',result_overflow_mode='throw'
```

## PRs to adopt now

From the [merged map](../pr-lane-map.md): #11538 (runtime labels), #11515
(account resolution/legacy retirement; coordinate C/E), #11321 (emitter config).
Adopt approved work rather than rewrite it. Coverage call-ID rework waits for
the run/message rungs; B's six parked coverage PRs are not runtime prerequisites.

## Stop-and-ask conditions

Ask before the `cost_call` migration, flipping any per-app flag, or any runtime
package change. Also stop on ambiguous scope, missing invoice coverage or a
proposal to substitute a random/default identity. Follow [standing rules](README.md).

## Exit check

The query's `field_readiness_pass` must pass with a nonempty dollar denominator;
unknown is fail. **Full lane exit is blocked until the `cost_call` table exists
and has a contract-level proof query.** It additionally requires `validateCostCall` to accept
the emitted receipts in both languages and approved per-app canary evidence.
Do not label the SQL prerequisite alone as full contract compliance.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.