fix(KB-111): implement invalid transition handling in executor

- Detect and handle invalid column transitions during task step updates
- Reorder error checks to catch invalid transitions before paused status
- Improve log messages with actual column names for better debugging
- Add comprehensive tests for invalid transition error scenarios
- Include changeset for the invalid transition fix
This commit is contained in:
gsxdsm
2026-03-30 07:40:41 -07:00
parent 863395b43c
commit 2de1f8c419
3 changed files with 117 additions and 0 deletions

View File

@@ -513,6 +513,17 @@ export class TaskExecutor {
// Dependency added mid-execution — discard worktree and move to triage
this.depAborted.delete(task.id);
await this.handleDepAbortCleanup(task.id, worktreePath);
} else if (err.message?.includes("Invalid transition")) {
// Task was moved by user/process while executor was running — already in desired state
// This check must come before pausedAborted since it's more specific
const transitionMatch = err.message.match(/Invalid transition: '([^']+)' → '([^']+)'/);
const fromColumn = transitionMatch?.[1] ?? "unknown";
const toColumn = transitionMatch?.[2] ?? "unknown";
const logMessage = `Task already moved from '${fromColumn}' — skipping transition to '${toColumn}'`;
executorLog.log(`${task.id} ${logMessage}`);
await this.store.logEntry(task.id, logMessage, err.message);
// Task finished successfully (just already moved), so call onComplete
this.options.onComplete?.(task);
} else if (this.pausedAborted.has(task.id)) {
// Task was paused mid-execution — move to todo, don't mark as failed
executorLog.log(`${task.id} paused — moving to todo`);