fix: prevent execution records from getting stuck in running state#140
Merged
fix: prevent execution records from getting stuck in running state#140
Conversation
Three independent issues left worker_execution rows orphaned in `running` state, causing downstream busy-checks (e.g. `/engine` command) to report workers as occupied when nothing was actually executing: 1. monitorExecution only updated the row on Done/Error output. When a process was killed, crashed, or signal-terminated the channel closed silently and the row stayed `running` forever. Add a fallback path that finalizes the row (status=failed, completed_at set) when the output channel closes without a terminal signal. 2. task cancel only attempted to stop a locally-tracked process; if the process had already exited the StopExecution error was logged but the row was never updated. Add a MarkAbandoned-on-failure path so the execution row is finalized even when the process is gone, and apply the same logic to the bulk clear-session cancel loop. 3. Server startup recovered tasks but not executions, so a crash or restart left every in-flight execution stuck in `running`. Add ExecutionStore.ResetRunningExecutions and call it alongside the existing recovery in app.BuildApp. Adds MarkAbandoned helper that only updates pending/running rows so terminal states are never clobbered, plus regression tests covering all three paths.
- Replace `error(nil)` with idiomatic `var stopErr error` - Extract duplicated MarkAbandoned + log pattern into finalizeCancelledExecution helper - Drop "Used by:" caller list from MarkAbandoned doc comment Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three independent issues left worker_execution rows orphaned in
runningstate, causing downstream busy-checks (e.g./enginecommand) to report workers as occupied when nothing was actually executing:monitorExecution only updated the row on Done/Error output. When a process was killed, crashed, or signal-terminated the channel closed silently and the row stayed
runningforever. Add a fallback path that finalizes the row (status=failed, completed_at set) when the output channel closes without a terminal signal.task cancel only attempted to stop a locally-tracked process; if the process had already exited the StopExecution error was logged but the row was never updated. Add a MarkAbandoned-on-failure path so the execution row is finalized even when the process is gone, and apply the same logic to the bulk clear-session cancel loop.
Server startup recovered tasks but not executions, so a crash or restart left every in-flight execution stuck in
running. Add ExecutionStore.ResetRunningExecutions and call it alongside the existing recovery in app.BuildApp.Adds MarkAbandoned helper that only updates pending/running rows so terminal states are never clobbered, plus regression tests covering all three paths.