feat: Flexprice integration#96
Conversation
|
| Filename | Overview |
|---|---|
| app/api/v1/routes/evaluators.py | Adds requested-run billing for evaluator dispatches, but the emitted quantity can exceed the number of queued tasks. |
| app/api/v1/routes/playground.py | Adds playground billing events, but evaluation metric counts are still hardcoded to zero on the changed paths. |
| app/services/billing/flexprice_service.py | Introduces Flexprice event wrappers and shared event ingestion behavior. |
| app/workers/tasks/evaluate_call_import_row.py | Adds call-import evaluation delta billing based on completed-row watermarks. |
Reviews (3): Last reviewed commit: "feat: updating logs" | Re-trigger Greptile
| background_tasks.add_task( | ||
| record_evaluator_run_requested, | ||
| organization_id, | ||
| uuid4(), | ||
| workspace_id=workspace_id, | ||
| quantity=len(request.evaluator_ids), | ||
| ) |
There was a problem hiding this comment.
The dispatch loop catches per-evaluator queue failures and continues, but this event bills len(request.evaluator_ids) instead of the number of tasks that were actually queued. A request where one evaluator queues and another raises in run_evaluator_task.delay(...) returns success with one task while recording usage for both requested evaluators.
| background_tasks.add_task( | |
| record_evaluator_run_requested, | |
| organization_id, | |
| uuid4(), | |
| workspace_id=workspace_id, | |
| quantity=len(request.evaluator_ids), | |
| ) | |
| background_tasks.add_task( | |
| record_evaluator_run_requested, | |
| organization_id, | |
| uuid4(), | |
| workspace_id=workspace_id, | |
| quantity=len(task_ids), | |
| ) |
| record_playground_call_evaluated, | ||
| organization_id, | ||
| call_short_id, | ||
| workspace_id=workspace_id, | ||
| metric_count=0, | ||
| ) |
There was a problem hiding this comment.
| record_playground_call_evaluated, | ||
| organization_id, | ||
| call_short_id, | ||
| workspace_id=workspace_id, | ||
| metric_count=0, | ||
| ) |
There was a problem hiding this comment.
| organization_id, | ||
| uuid4(), | ||
| workspace_id=workspace_id, | ||
| quantity=len(request.evaluator_ids), |
There was a problem hiding this comment.
Partial Dispatch Overbills When one evaluator queues successfully and a later evaluator fails inside the dispatch loop, the endpoint still returns success because
task_ids is non-empty. This line then records the full requested count, so Flexprice bills evaluators that were never queued and can never produce results. Use the count of successfully queued tasks for this event.
| quantity=len(request.evaluator_ids), | |
| quantity=len(task_ids), |
| organization_id, | ||
| call_short_id, | ||
| workspace_id=workspace_id, | ||
| metric_count=0, |
There was a problem hiding this comment.
Metric Count Dropped This records every custom websocket evaluation with
metric_count=0, but the worker can evaluate the organization’s enabled agent metrics for the call. Since the later completion event does not include the actual count, any Flexprice meter or analytics using this property will report these evaluated calls as zero-metric runs. Move the metered event to the worker where the metric count is known, or compute the same selected metric count before enqueueing.
| organization_id, | ||
| call_short_id, | ||
| workspace_id=workspace_id, | ||
| metric_count=0, |
There was a problem hiding this comment.
Reevaluation Count Dropped Re-evaluations still send
metric_count=0 immediately after queueing the worker. A re-evaluated call can run the enabled agent metrics, and no later event sends the real count, so these runs are reported as zero-metric evaluations. Emit this after metric execution or pass the actual selected metric count into the billing call.
What Changed?
Adding flexprice changes
Why?
Explain the problem this solves and why this approach was chosen.
How to Test?
List clear steps for reviewers to verify the change.
Release Label
Select one semantic version bump intent for this PR:
major- breaking change, next release bumps major versionminor- backward-compatible feature, next release bumps minor versionfix- backward-compatible bug fix, next release bumps patch versionIf you do not have permission to apply labels, mention the intended release label here and a maintainer will set it.
Checklist
CONTRIBUTING.mdguide.