fix(v2): await run log finalization before sync execute responds

LA
1mo ago
+39-0

Summary

Fixes #8354. The v2 sync execute route could return completed while the run's log row was still being finalized: executeWorkflowCore defers status/endedAt/cost persistence into the logging session's post-execution promise, and the sync path in executeWorkflowService returned without awaiting it. A GET /api/v2/logs/{runId} right after the response could still show status: "running", a null endedAt, and missing cost items.

The sync response now waits for the post-execution promise to settle before it is returned, so a terminal response doubles as a durable receipt. Async (queued) runs are unaffected: they already return before execution starts.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Other: ___________

Testing

  • New route test holds the sync response until post-execution logging finalizes: gates waitForPostExecution on a manually released promise and asserts the response is not sent before release. Verified it fails without the fix and passes with it.
  • vitest run app/api/v2/workflows/[workflowId]/execute/route.test.ts: 39/39 pass.
  • biome check on the changed files: clean.
  • Reviewers can focus on the finally in runSynchronousWorkflow (apps/sim/lib/workflows/executor/execute-service.ts): the await covers both the success and error terminal results, and is a no-op whenever the core never set a post-execution promise.

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)

Screenshots/Videos

N/A - server-side API behavior change, covered by the new test.