Skip to content

fix(cost): worker crash incremenental case#3885

Merged
icecrasher321 merged 1 commit intostagingfrom
fix/worker-crash-case
Apr 1, 2026
Merged

fix(cost): worker crash incremenental case#3885
icecrasher321 merged 1 commit intostagingfrom
fix/worker-crash-case

Conversation

@icecrasher321
Copy link
Copy Markdown
Collaborator

Summary

Incremental cost tracking for crash case was incorrect. Only affects crash fallback.

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Apr 1, 2026 6:32pm

Request Review

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 1, 2026

PR Summary

Medium Risk
Touches incremental cost accumulation used for execution logging/billing, so incorrect parsing could under/over-report cost, but the change is small and covered by an updated test.

Overview
Fixes incremental cost tracking in LoggingSession.onBlockComplete by reading cost/tokens/model from the nested output.output payload (and validating cost.total there) instead of the top-level event.

Updates the affected unit test to pass cost data in the new nested shape so cost flush draining behavior is still exercised.

Written by Cursor Bugbot for commit b540775. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 1, 2026

Greptile Summary

This PR fixes a bug in onBlockComplete where the incremental cost accumulator (accumulatedCost) was reading cost, tokens, and model from the top level of the output parameter instead of the nested output.output field where those values actually live. Because accumulatedCost is the source of truth for the crash-fallback path (completeWithCostOnlyLog), this meant any execution that hit the fallback path would report only the base charge instead of the true cost.

Key changes:

  • logging-session.ts: introduces const blockOutput = output?.output and reads all cost fields from blockOutput, consistent with the already-correct success: !output?.output?.error usage on the same method.
  • logging-session.test.ts: updates the "drains fire-and-forget cost flushes" test to pass cost/tokens/model inside output.output rather than at the top level, so the test now genuinely exercises the cost-accumulation branch.

Confidence Score: 5/5

  • Safe to merge — targeted one-line structural fix with no logic side-effects and a correctly updated test.
  • The change is minimal and correct: it aligns the cost-extraction path with the pre-existing output?.output?.error pattern in the same method, fixing a silent no-op that only impacted the crash-fallback cost summary. No new API surface is introduced, existing tests are updated to match reality, and no other call-site changes are required.
  • No files require special attention.

Important Files Changed

Filename Overview
apps/sim/lib/logs/execution/logging-session.ts Fixed onBlockComplete to correctly read cost/tokens/model from output.output instead of output directly, matching the actual object shape passed at call sites and the existing success: !output?.output?.error pattern on line 293.
apps/sim/lib/logs/execution/logging-session.test.ts Updated the "drains fire-and-forget cost flushes before terminal completion" test to reflect the correct nested output.output shape for cost/tokens/model, ensuring the test actually triggers the cost-accumulation code path.

Sequence Diagram

sequenceDiagram
    participant Executor
    participant LoggingSession
    participant DB

    Executor->>LoggingSession: onBlockComplete(blockId, name, type, { endedAt, output: { cost, tokens, model, error } })
    Note over LoggingSession: Extract blockOutput = output?.output
    alt blockOutput.cost exists and > 0
        LoggingSession->>LoggingSession: accumulatedCost += cost/tokens/model
        LoggingSession-->>DB: flushAccumulatedCost() [fire-and-forget]
    else no cost
        LoggingSession-->>Executor: return (early exit)
    end

    alt Crash / completion failure
        Executor->>LoggingSession: safeComplete() / safeCompleteWithError()
        LoggingSession->>LoggingSession: completeWithCostOnlyLog() [fallback]
        Note over LoggingSession: Uses accumulatedCost (now correctly populated)
        LoggingSession->>DB: completeExecutionWithFinalization(costSummary)
    end
Loading

Reviews (1): Last reviewed commit: "fix(cost): worker crash incremenental ca..." | Re-trigger Greptile

@icecrasher321 icecrasher321 merged commit 2ede12a into staging Apr 1, 2026
12 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/worker-crash-case branch April 2, 2026 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant