Commit 1b3708a
fix(processing): prevent double-billing race in LoggingSession completion
When executeWorkflowCore throws, its catch block fire-and-forgets
safeCompleteWithError, then re-throws. The caller's catch block also
fire-and-forgets safeCompleteWithError on the same LoggingSession. Both
check this.completed (still false) before either's async DB write resolves,
so both proceed to completeWorkflowExecution which uses additive SQL for
billing — doubling the charged cost on every failed execution.
Fix: add a synchronous `completing` flag set immediately before the async
work begins. This blocks concurrent callers at the guard check. On failure,
the flag is reset so the safe* fallback path (completeWithCostOnlyLog) can
still attempt recovery.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>1 parent 6540453 commit 1b3708a
1 file changed
+13
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
| 93 | + | |
92 | 94 | | |
93 | 95 | | |
94 | 96 | | |
| |||
267 | 269 | | |
268 | 270 | | |
269 | 271 | | |
270 | | - | |
| 272 | + | |
271 | 273 | | |
272 | 274 | | |
| 275 | + | |
273 | 276 | | |
274 | 277 | | |
275 | 278 | | |
| |||
341 | 344 | | |
342 | 345 | | |
343 | 346 | | |
| 347 | + | |
344 | 348 | | |
345 | 349 | | |
346 | 350 | | |
| |||
353 | 357 | | |
354 | 358 | | |
355 | 359 | | |
356 | | - | |
| 360 | + | |
357 | 361 | | |
358 | 362 | | |
| 363 | + | |
359 | 364 | | |
360 | 365 | | |
361 | 366 | | |
| |||
455 | 460 | | |
456 | 461 | | |
457 | 462 | | |
| 463 | + | |
458 | 464 | | |
459 | 465 | | |
460 | 466 | | |
| |||
467 | 473 | | |
468 | 474 | | |
469 | 475 | | |
470 | | - | |
| 476 | + | |
471 | 477 | | |
472 | 478 | | |
| 479 | + | |
473 | 480 | | |
474 | 481 | | |
475 | 482 | | |
| |||
540 | 547 | | |
541 | 548 | | |
542 | 549 | | |
| 550 | + | |
543 | 551 | | |
544 | 552 | | |
545 | 553 | | |
| |||
810 | 818 | | |
811 | 819 | | |
812 | 820 | | |
813 | | - | |
| 821 | + | |
814 | 822 | | |
815 | 823 | | |
| 824 | + | |
816 | 825 | | |
817 | 826 | | |
818 | 827 | | |
| |||
0 commit comments