-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix: clear terminalEventSeen on task restart to prevent stuck-after-planning (#1828) #1840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -177,6 +177,11 @@ export function registerTaskExecutionHandlers( | |
|
|
||
| console.warn('[TASK_START] Found task:', task.specId, 'status:', task.status, 'reviewReason:', task.reviewReason, 'subtasks:', task.subtasks.length); | ||
|
|
||
| // Clear stale tracking state from any previous execution so that: | ||
| // - terminalEventSeen doesn't suppress future PROCESS_EXITED events | ||
| // - lastSequenceByTask doesn't drop events from the new process | ||
| taskStateManager.prepareForRestart(taskId); | ||
|
|
||
| // Check if implementation_plan.json has valid subtasks BEFORE XState handling. | ||
| // This is more reliable than task.subtasks.length which may not be loaded yet. | ||
| const specsBaseDir = getSpecsDir(project.autoBuildPath); | ||
|
|
@@ -360,6 +365,9 @@ export function registerTaskExecutionHandlers( | |
| task, | ||
| project | ||
| ); | ||
|
|
||
| // Clear stale tracking state so a subsequent restart works correctly | ||
| taskStateManager.prepareForRestart(taskId); | ||
| }); | ||
|
|
||
| /** | ||
|
|
@@ -529,6 +537,9 @@ export function registerTaskExecutionHandlers( | |
| return { success: false, error: 'Failed to write QA fix request file' }; | ||
| } | ||
|
|
||
| // Clear stale tracking state before starting new QA process | ||
| taskStateManager.prepareForRestart(taskId); | ||
|
|
||
| // Restart QA process - use worktree path if it exists, otherwise main project | ||
| // The QA process needs to run where the implementation_plan.json with completed subtasks is | ||
| const qaProjectPath = hasWorktree ? worktreePath : project.path; | ||
|
|
@@ -703,6 +714,8 @@ export function registerTaskExecutionHandlers( | |
|
|
||
| // Auto-start task when status changes to 'in_progress' and no process is running | ||
| if (status === 'in_progress' && !agentManager.isRunning(taskId)) { | ||
| // Clear stale tracking state before starting a new process | ||
| taskStateManager.prepareForRestart(taskId); | ||
| const mainWindow = getMainWindow(); | ||
|
|
||
| // Check git status before auto-starting | ||
|
|
@@ -1133,6 +1146,8 @@ export function registerTaskExecutionHandlers( | |
| // Auto-restart the task if requested | ||
| let autoRestarted = false; | ||
| if (autoRestart) { | ||
| // Clear stale tracking state before restarting | ||
| taskStateManager.prepareForRestart(taskId); | ||
|
Comment on lines
+1149
to
+1150
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial
The call correctly clears This is a pre-existing design choice (outside the scope of this PR), but worth tracking separately. Would you like me to open a follow-up issue to add an appropriate 🤖 Prompt for AI Agents |
||
| // Check git status before auto-restarting | ||
| const gitStatusForRestart = checkGitStatus(project.path); | ||
| if (!gitStatusForRestart.isGitRepo || !gitStatusForRestart.hasCommits) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: AndyMik90/Auto-Claude
Length of output: 792
🏁 Script executed:
Repository: AndyMik90/Auto-Claude
Length of output: 50378
🏁 Script executed:
Repository: AndyMik90/Auto-Claude
Length of output: 120
🏁 Script executed:
# Look at the execution-handlers file to see the context around lines 368-370 wc -l apps/frontend/src/main/ipc-handlers/task/execution-handlers.tsRepository: AndyMik90/Auto-Claude
Length of output: 132
🏁 Script executed:
sed -n '360,380p' apps/frontend/src/main/ipc-handlers/task/execution-handlers.tsRepository: AndyMik90/Auto-Claude
Length of output: 467
🏁 Script executed:
# Find the taskMachine definition cat apps/frontend/src/shared/state-machines/task-machine.tsRepository: AndyMik90/Auto-Claude
Length of output: 7701
🏁 Script executed:
Repository: AndyMik90/Auto-Claude
Length of output: 343
🏁 Script executed:
Repository: AndyMik90/Auto-Claude
Length of output: 835
🏁 Script executed:
sed -n '175,190p' apps/frontend/src/main/ipc-handlers/task/execution-handlers.tsRepository: AndyMik90/Auto-Claude
Length of output: 828
🏁 Script executed:
sed -n '535,550p' apps/frontend/src/main/ipc-handlers/task/execution-handlers.tsRepository: AndyMik90/Auto-Claude
Length of output: 884
🏁 Script executed:
sed -n '710,730p' apps/frontend/src/main/ipc-handlers/task/execution-handlers.tsRepository: AndyMik90/Auto-Claude
Length of output: 1166
🏁 Script executed:
sed -n '1145,1160p' apps/frontend/src/main/ipc-handlers/task/execution-handlers.tsRepository: AndyMik90/Auto-Claude
Length of output: 768
🏁 Script executed:
Repository: AndyMik90/Auto-Claude
Length of output: 3268
🏁 Script executed:
Repository: AndyMik90/Auto-Claude
Length of output: 4367
🏁 Script executed:
Repository: AndyMik90/Auto-Claude
Length of output: 525
Remove
prepareForRestartfrom TASK_STOP handlerThe
prepareForRestart(taskId)call at line 370 is redundant and logically inconsistent. AfterhandleUiEvent(USER_STOPPED)transitions the actor to itsbacklogstate, clearingterminalEventSeenhere allows a stalePROCESS_EXITEDevent from the killed process to reach the actor—where it will be silently ignored since the backlog state doesn't define a handler for it. Every subsequent restart path already callsprepareForRestartbefore starting a new process (TASK_START line 183, TASK_UPDATE_STATUS line 718, TASK_RECOVER_STUCK line 1150), so the state is clean regardless. Delete the call and let the next start handler reset the tracking state at the right moment.🔧 Proposed fix
taskStateManager.handleUiEvent( taskId, { type: 'USER_STOPPED', hasPlan }, task, project ); - - // Clear stale tracking state so a subsequent restart works correctly - taskStateManager.prepareForRestart(taskId); });🤖 Prompt for AI Agents