fix(logs): record a run's cost before it reads finished, and hold sync execute responses until the log is final - #8473
Conversation
…c execute responses until the log is final
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
All reported issues were addressed across 5 files
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
All reported issues were addressed across 5 files
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
…t the ledger lock
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
…early completion failures
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
Summary
completeWorkflowExecutioncommitted a run's terminal status andcost_total, and only then read the payer's usage and wrote itsusage_logledger. In that window a finished run had no ledger rows, andbuildCostLedgerreports that ascost.items: null, which the logs contract defines as "this run has no ledger" (GET /api/v2/logs/{runId}can return an unfinished log right after a sync execute completes #8354)cost_totalkeeps its current final value: when the ledger write sets the exact reconciled sum, the terminal commit leaves it alone; otherwise it applies the sameGREATESTas beforerecordExecutionUsagenever throws, so a failed threshold read no longer needs a second attempt/api/workflows/{id}/executenon-SSE sync path now waits for the background log finalizer before responding, so a caller that reads the log right after the response sees it final. fix(v2): await run log finalization before sync execute responds #8369 does the same for v2 sync execute; together they closeGET /api/v2/logs/{runId}can return an unfinished log right after a sync execute completes #8354Type of Change
Testing
completion-ledger-order.integration.ts: across 20 real completions, a concurrent reader never sees a finished run without its ledger, and the ledger andcost_totalboth match the charge. On the original code it fails in all 20 runs (a local diagnostic saw the gap last up to 15 ms)lib/logs,lib/billing, execute routes (internal + v2),lib/workflows/executor,background— 1718 passedusage-threshold-email,usage-log,usage-reservation,pause-persistence,start-execution,secret-provenance,execution-archive-provenance,reporting-usage-cache,usage-analytics-queries,organization-activity,service-store— 99 passedbun run type-check,bun run lint, block-registry check,bun run check:audits,docs-manifest:checkChecklist
test-auditauthoring gate)