Repository navigation
feat(contract): additive cost.reconciliation.v1 event and reconciliation projection #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,14 +32,15 @@ | |
| "com.signalops.ai.operation.terminal.v1", | ||
| "com.signalops.ai.attempt.started.v1", | ||
| "com.signalops.ai.attempt.terminal.v1", | ||
| "com.signalops.ai.provider.probe.v1" | ||
| "com.signalops.ai.provider.probe.v1", | ||
| "com.signalops.ai.cost.reconciliation.v1" | ||
| ] | ||
| }, | ||
| "subject": { | ||
| "type": "string", | ||
| "maxLength": 180, | ||
| "pattern": "^(operation|provider)/[A-Za-z0-9][A-Za-z0-9._:/-]*$", | ||
| "description": "Must exactly identify data.operation.id or, for probes, data.route.providerKey; the portable semantic validator enforces the cross-field equality." | ||
| "description": "Must exactly identify data.operation.id, or for probes and reconciliation events data.route.providerKey / data.provider.providerKey; the portable semantic validator enforces the cross-field equality." | ||
| }, | ||
| "time": { "$ref": "#/$defs/timestamp" }, | ||
| "datacontenttype": { "const": "application/json" }, | ||
|
|
@@ -111,6 +112,18 @@ | |
| "data": { "$ref": "#/$defs/providerProbeData" } | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "if": { | ||
| "properties": { "type": { "const": "com.signalops.ai.cost.reconciliation.v1" } }, | ||
| "required": ["type"] | ||
| }, | ||
| "then": { | ||
| "properties": { | ||
| "subject": { "type": "string", "pattern": "^provider/" }, | ||
| "data": { "$ref": "#/$defs/costReconciliationData" } | ||
| } | ||
| } | ||
| } | ||
| ], | ||
| "$defs": { | ||
|
|
@@ -277,17 +290,18 @@ | |
| "additionalProperties": false, | ||
| "required": ["amount", "currency", "source"], | ||
| "properties": { | ||
| "amount": { | ||
| "type": "string", | ||
| "pattern": "^(0|[1-9][0-9]*)(\\.[0-9]{1,12})?$", | ||
| "maxLength": 40 | ||
| }, | ||
| "amount": { "$ref": "#/$defs/decimalString" }, | ||
| "currency": { "type": "string", "pattern": "^[A-Z]{3}$" }, | ||
| "source": { | ||
| "enum": ["provider_reported", "catalog_estimate", "billing_reconciled"] | ||
| } | ||
| } | ||
| }, | ||
| "decimalString": { | ||
| "type": "string", | ||
| "pattern": "^(0|[1-9][0-9]*)(\\.[0-9]{1,12})?$", | ||
| "maxLength": 40 | ||
| }, | ||
| "resource": { | ||
| "type": "object", | ||
| "additionalProperties": false, | ||
|
|
@@ -416,6 +430,84 @@ | |
| "resource": { "$ref": "#/$defs/resource" }, | ||
| "attributes": { "$ref": "#/$defs/attributes" } | ||
| } | ||
| }, | ||
| "billingReconciledCost": { | ||
| "type": "object", | ||
| "additionalProperties": false, | ||
| "required": ["amount", "currency", "source"], | ||
| "properties": { | ||
| "amount": { "$ref": "#/$defs/decimalString" }, | ||
| "currency": { "type": "string", "pattern": "^[A-Z]{3}$" }, | ||
| "source": { "const": "billing_reconciled" } | ||
| } | ||
| }, | ||
| "reconciliationPeriod": { | ||
| "type": "object", | ||
| "additionalProperties": false, | ||
| "required": ["start", "end"], | ||
| "properties": { | ||
| "start": { "$ref": "#/$defs/timestamp" }, | ||
| "end": { "$ref": "#/$defs/timestamp" } | ||
| } | ||
| }, | ||
| "reconciliationBasis": { | ||
| "type": "object", | ||
| "additionalProperties": false, | ||
| "required": ["billSource"], | ||
| "properties": { | ||
| "billSource": { "$ref": "#/$defs/identifier" }, | ||
| "billReference": { "$ref": "#/$defs/identifier" }, | ||
| "units": { "type": "number", "minimum": 0 }, | ||
| "unit": { "$ref": "#/$defs/identifier" }, | ||
| "unitPrice": { "type": "number", "minimum": 0 } | ||
| } | ||
| }, | ||
| "reconciliationProvider": { | ||
| "type": "object", | ||
| "additionalProperties": false, | ||
| "required": ["providerKey", "providerVendor"], | ||
| "properties": { | ||
| "providerKey": { "$ref": "#/$defs/identifier" }, | ||
| "providerVendor": { "$ref": "#/$defs/identifier" } | ||
| } | ||
| }, | ||
| "costReconciliationData": { | ||
| "type": "object", | ||
| "additionalProperties": false, | ||
| "required": ["scope", "provider", "period", "cost", "basis", "resource"], | ||
| "properties": { | ||
| "scope": { "enum": ["provider_period", "route_period"] }, | ||
| "provider": { "$ref": "#/$defs/reconciliationProvider" }, | ||
| "period": { "$ref": "#/$defs/reconciliationPeriod" }, | ||
| "cost": { "$ref": "#/$defs/billingReconciledCost" }, | ||
| "basis": { "$ref": "#/$defs/reconciliationBasis" }, | ||
| "route": { "$ref": "#/$defs/route" }, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win Require the route to identify the declared provider. A 🤖 Prompt for AI Agents |
||
| "resource": { "$ref": "#/$defs/resource" }, | ||
| "attributes": { "$ref": "#/$defs/attributes" } | ||
| }, | ||
| "allOf": [ | ||
| { | ||
| "if": { | ||
| "properties": { "scope": { "const": "route_period" } }, | ||
| "required": ["scope"] | ||
| }, | ||
| "then": { | ||
| "required": ["route"], | ||
| "properties": { "route": { "$ref": "#/$defs/route" } } | ||
| } | ||
| }, | ||
| { | ||
| "if": { | ||
| "properties": { "scope": { "const": "provider_period" } }, | ||
| "required": ["scope"] | ||
| }, | ||
| "then": { | ||
| "required": [], | ||
| "properties": {}, | ||
| "not": { "required": ["route"] } | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| { | ||
| "specversion": "1.0", | ||
| "id": "phosphene:reconcile:missing-period-end:2026-08-22T00:00:00.000Z:v1", | ||
| "source": "urn:phosphene:production:billing-reconciler", | ||
| "type": "com.signalops.ai.cost.reconciliation.v1", | ||
| "subject": "provider/primary-fal", | ||
| "time": "2026-08-23T05:00:00.000Z", | ||
| "datacontenttype": "application/json", | ||
| "dataschema": "https://signalops.cc/schemas/ai-telemetry/v1", | ||
| "data": { | ||
| "scope": "provider_period", | ||
| "provider": { | ||
| "providerKey": "primary-fal", | ||
| "providerVendor": "fal" | ||
| }, | ||
| "period": { | ||
| "start": "2026-08-22T00:00:00.000Z" | ||
| }, | ||
| "cost": { | ||
| "amount": "0.105", | ||
| "currency": "USD", | ||
| "source": "billing_reconciled" | ||
| }, | ||
| "basis": { | ||
| "billSource": "fal.models.usage" | ||
| }, | ||
| "resource": { | ||
| "environment": "production", | ||
| "service": "billing-reconciler" | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| { | ||
| "specversion": "1.0", | ||
| "id": "phosphene:reconcile:provider-period-with-route:2026-08-22T00:00:00.000Z:v1", | ||
| "source": "urn:phosphene:production:billing-reconciler", | ||
| "type": "com.signalops.ai.cost.reconciliation.v1", | ||
| "subject": "provider/primary-fal", | ||
| "time": "2026-08-23T05:00:00.000Z", | ||
| "datacontenttype": "application/json", | ||
| "dataschema": "https://signalops.cc/schemas/ai-telemetry/v1", | ||
| "data": { | ||
| "scope": "provider_period", | ||
| "provider": { | ||
| "providerKey": "primary-fal", | ||
| "providerVendor": "fal" | ||
| }, | ||
| "period": { | ||
| "start": "2026-08-22T00:00:00.000Z", | ||
| "end": "2026-08-23T00:00:00.000Z" | ||
| }, | ||
| "cost": { | ||
| "amount": "0.105", | ||
| "currency": "USD", | ||
| "source": "billing_reconciled" | ||
| }, | ||
| "basis": { | ||
| "billSource": "fal.models.usage" | ||
| }, | ||
| "route": { | ||
| "providerKey": "primary-fal", | ||
| "modelKey": "flux-2-pro" | ||
| }, | ||
| "resource": { | ||
| "environment": "production", | ||
| "service": "billing-reconciler" | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| { | ||
| "specversion": "1.0", | ||
| "id": "phosphene:reconcile:route-period-missing-route:2026-08-22T00:00:00.000Z:v1", | ||
| "source": "urn:phosphene:production:billing-reconciler", | ||
| "type": "com.signalops.ai.cost.reconciliation.v1", | ||
| "subject": "provider/primary-fal", | ||
| "time": "2026-08-23T05:00:00.000Z", | ||
| "datacontenttype": "application/json", | ||
| "dataschema": "https://signalops.cc/schemas/ai-telemetry/v1", | ||
| "data": { | ||
| "scope": "route_period", | ||
| "provider": { | ||
| "providerKey": "primary-fal", | ||
| "providerVendor": "fal" | ||
| }, | ||
| "period": { | ||
| "start": "2026-08-22T00:00:00.000Z", | ||
| "end": "2026-08-23T00:00:00.000Z" | ||
| }, | ||
| "cost": { | ||
| "amount": "0.053", | ||
| "currency": "USD", | ||
| "source": "billing_reconciled" | ||
| }, | ||
| "basis": { | ||
| "billSource": "fal.models.usage" | ||
| }, | ||
| "resource": { | ||
| "environment": "production", | ||
| "service": "billing-reconciler" | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Reject periods whose end is not after their start.
The schema accepts equal or reversed timestamps. The snapshot then drops those records, although ingest accepted them as billing observations. Add a cross-field check in
schemas/ai-telemetry/v1/semantic-validation.mjsand an invalid fixture.🤖 Prompt for AI Agents