improvement(logs): object storage backed tracespans#4787
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryHigh Risk Overview Billing and cost display shift to the The log details UI shows an itemized Reviewed by Cursor Bugbot for commit 0014218. Configure here. |
Greptile SummaryThis PR moves heavy
Confidence Score: 5/5Safe to merge. The write path ordering is correct, the GREATEST guard prevents cost regression on resume, and all read-path routes properly materialize externalized data. The externalization, advisory-locked ledger reconciliation, and GREATEST-guarded cost_total projection are internally consistent and correct. All API routes and data-drain paths that need full execution payload call materializeExecutionData. The migration batching procedure and CONCURRENTLY indexes follow standard PostgreSQL patterns. apps/sim/lib/billing/core/usage-log.ts (inArray empty-array guard), apps/sim/scripts/backfill-trace-spans.ts (orphan-on-tx-failure for one-shot script) Important Files Changed
Sequence DiagramsequenceDiagram
participant Exec as Execution Engine
participant Session as LoggingSession
participant Logger as ExecutionLogger
participant DB as PostgreSQL
participant ObjStore as Object Storage
participant UsageLog as usage_log ledger
Exec->>Session: completedRun(traceSpans, finalOutput)
Session->>Session: calculateCostSummary(traceSpans)
Session->>Logger: completeExecutionWithFinalization(costSummary, traceSpans)
Logger->>Logger: stripSpanCosts(traceSpans)
Logger->>ObjStore: externalizeExecutionData(executionData)
ObjStore-->>Logger: slim row (traceStoreRef + markers)
Logger->>DB: "UPDATE executionData=slim, costTotal=GREATEST(...), modelsUsed"
Logger->>DB: BEGIN advisory lock (pg_advisory_xact_lock)
DB->>UsageLog: SELECT SUM already-billed for executionId
UsageLog-->>DB: alreadyBilled map
DB->>UsageLog: INSERT delta entries (onConflictDoNothing)
DB->>DB: "UPDATE costTotal=exact ledger sum"
Logger->>DB: COMMIT
Exec->>Logger: GET /api/logs/execution/:id
Logger->>DB: SELECT executionData (slim row)
Logger->>ObjStore: materializeExecutionData
ObjStore-->>Logger: full executionData
Logger-->>Exec: WorkflowExecutionLog (with traceSpans)
Reviews (6): Last reviewed commit: "incorrect type cast" | Re-trigger Greptile |
|
bugbot run |
|
@greptile |
|
bugbot run |
|
@greptile |
Drops the 0219_robust_shard SQL, its snapshot, and the journal entry so the trace-spans/cost schema migration can be regenerated on top of the latest staging migration chain (avoids a number collision with staging's migrations). Co-authored-by: Cursor <cursoragent@cursor.com>
Per-member/per-user usage in the org-member routes now adds the usage_log ledger to the currentPeriodCost baseline (which is no longer incremented), via a shared getOrgMemberLedgerByUser helper to avoid repeating the subscription→period→ledger lookup across the admin and member-facing routes. Co-authored-by: Cursor <cursoragent@cursor.com>
|
bugbot run |
|
@greptile |
|
bugbot run |
|
@greptile |
|
bugbot run |
|
@greptile |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 0014218. Configure here.
Summary
Object storage backed execution log trace spans to keep table lean
Type of Change
Testing
Tested manually
Checklist