Strug Works ships autonomously, which means mission orchestration failures don't get caught by a human reviewing the queue — they silently corrupt the workflow. This week we fixed three failure modes that were orphaning tasks and lying about completion status.
The Early Completion Bug
An orchestrator parent task would mark itself completed the moment all its child tasks finished — even if its own run (the orchestration logic itself) was still executing. The aggregation logic checked children, saw they were done, and immediately wrote status=completed. The parent's own result hadn't been recorded yet.
The fix: never auto-finalize a parent whose own run is still live. We added a guard that checks whether the parent task's own execution has written its result before aggregating child outcomes. Without it, the mission panel would show "completed" while the orchestrator was still deciding what to do with the results.
The Orphaned Dependent Problem
A task whose dependency timed out would wait forever if the dependency was about to be retried. The original logic: if a dependency is status=failed and not older than 60 seconds, assume a retry is coming. The problem: a timeout writes status=failed immediately but re-queues only after the worker unwinds — workspace save, cleanup, all of it. That can take longer than 60 seconds. The dependent would see a "fresh" failed dependency and wait. And wait. And wait.
The fix: age alone can't tell "retry pending" from "dead." The row can. We now check is_retryable (False when retries are exhausted) and retry_count vs max_retries. If those say the task is done, it's done — regardless of age. And for the edge case where a worker dies between writing failed and re-queuing? A 3,600-second grace period backstops it. Long enough to cover the documented worst-case workspace save (1,500 seconds). Finite enough that orphans don't park forever.
The Budget-Paused Wait
wait_for_tasks would hold until its full timeout if any child was budget_paused. budget_paused is resumable — it's not in TERMINAL_STATUSES because it's waiting for a human to approve more spend. But the orchestrator doesn't care about that distinction. It just wants to know: is my child done, or do I need to surface this to a human?
The fix: return early when a child is budget_paused. The orchestrator gets the status immediately, can report it, and the human sees it instead of the parent task timing out 60 seconds later with no explanation.
The TDD Audit Rounds
Three audit rounds. 1,070 lines of new tests across 8 test modules. The first round caught the bugs. The second round caught the over-fixes (guards that would have made the fixes worse than the original bugs). The third round caught the fail-closed branches that no test was reading — log lines that would silently swallow errors.
One example: the dependency-cancellation logic now reads updated_at, retry_count, max_retries, and is_retryable from the database. But the original test suite mocked the dependency rows, so dropping any of those columns from the SELECT would leave every test green. We added a pin test that asserts the actual URL contains all four column names. If we ever drop one, the test fails before the silent orphaning starts.
What's Next
These three fixes shipped together because they share a root cause: orchestration state is distributed across multiple database rows, and the timing assumptions we made in single-task execution don't hold when tasks have parents and children. The next layer: surfacing budget_paused and cancelled_failed states in the UI so a human can see why a mission stopped, not just that it stopped.