Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions apps/frontend/src/main/task-state-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,17 +362,22 @@ export class TaskStateManager {

const phase = XSTATE_TO_PHASE[xstateState] || 'idle';

// Emit execution progress with the phase derived from XState
// Emit execution progress with the phase derived from XState.
// IMPORTANT: Do NOT use Date.now() as sequenceNumber here — doing so would
// permanently block all subsequent agent execution-progress events, because
// the agent uses small sequential integers (1, 2, 3…) that are always less
// than a timestamp. Instead emit with sequenceNumber=0 so the agent's own
// events can continue updating phaseProgress once the phase is established.
safeSendToRenderer(
this.getMainWindow,
IPC_CHANNELS.TASK_EXECUTION_PROGRESS,
taskId,
{
phase,
phaseProgress: phase === 'complete' ? 100 : 50,
overallProgress: phase === 'complete' ? 100 : 50,
phaseProgress: phase === 'complete' ? 100 : 0,
overallProgress: phase === 'complete' ? 100 : 0,
Comment on lines +377 to +378
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

rg -nP "XSTATE_TO_PHASE" --type ts -C 10

Repository: AndyMik90/Auto-Claude

Length of output: 20638


Handle 'failed' phase state in progress calculation.

The phase === 'complete' ? 100 : 0 logic only recognizes 'complete' as a finished state. Terminal states map mostly correctly to 'complete' ('done', 'pr_created', 'creating_pr', 'human_review'), but the 'error' state maps to 'failed', causing the progress bar to reset to 0% when a task errors out. Either extend the condition to include 'failed' (e.g., ['complete', 'failed'].includes(phase) ? 100 : 0) or define explicit progress values for each terminal phase.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/frontend/src/main/task-state-manager.ts` around lines 377 - 378, The
progress calculation resets to 0 for error states because phaseProgress and
overallProgress use phase === 'complete' ? 100 : 0; update the logic in the code
that sets phaseProgress and overallProgress (the lines that compute these
values) to treat terminal failure as complete—either change the condition to
include 'failed' (e.g., check ['complete','failed'].includes(phase)) or replace
with an explicit mapping for terminal phases (e.g., map
'complete','done','pr_created','creating_pr','human_review','failed' to 100) so
error states show 100% instead of 0%.

message: `State: ${xstateState}`,
sequenceNumber: Date.now() // Use timestamp as sequence to ensure it's newer
sequenceNumber: 0
},
Comment on lines +365 to 381
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

rg -n "updateExecutionProgress|incomingSeq|currentSeq|sequenceNumber" --type ts --type tsx -C 3 apps/frontend/src/renderer/

Repository: AndyMik90/Auto-Claude

Length of output: 92


🏁 Script executed:

rg -n "updateExecutionProgress|incomingSeq|currentSeq" apps/frontend/src/renderer/ -C 3

Repository: AndyMik90/Auto-Claude

Length of output: 8389


🏁 Script executed:

sed -n '416,460p' apps/frontend/src/renderer/stores/task-store.ts

Repository: AndyMik90/Auto-Claude

Length of output: 1875


Sequence guard doesn't filter sequenceNumber: 0 mid-task—progress bar will reset.

The renderer's sequence guard at line 435 of apps/frontend/src/renderer/stores/task-store.ts only drops updates when incomingSeq > 0 && currentSeq > 0 && incomingSeq < currentSeq. When the main process sends sequenceNumber: 0 (as this fix does), the condition incomingSeq > 0 is false, so the guard is bypassed entirely. The update proceeds to merge at line 451-454, applying phaseProgress: 0 to the task state.

This means every XState mid-task transition (e.g., planning → coding while the agent is running) will reset the progress bar to 0%, which is the exact regression the PR commit message claims to avoid. The sequence guard has no logic to treat sequenceNumber: 0 as a special sentinel that should be dropped when currentSeq > 0.

Either update the renderer's guard to explicitly drop sequenceNumber: 0 when currentSeq > 0:

if ((incomingSeq === 0 && currentSeq > 0) || (incomingSeq > 0 && currentSeq > 0 && incomingSeq < currentSeq)) {
  return t; // Skip update
}

Or use a distinct sentinel value (e.g., sequenceNumber: -1) with explicit renderer handling.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/frontend/src/main/task-state-manager.ts` around lines 365 - 381, The
renderer's sequence guard (the check using incomingSeq and currentSeq in the
task-store update path that merges IPC_CHANNELS.TASK_EXECUTION_PROGRESS
payloads) must treat sequenceNumber=0 as a special sentinel so mid-task updates
don't reset progress; update that guard (the condition that currently reads
incomingSeq > 0 && currentSeq > 0 && incomingSeq < currentSeq) to also skip when
incomingSeq === 0 && currentSeq > 0 (or alternatively change the main-process
sender safeSendToRenderer for IPC_CHANNELS.TASK_EXECUTION_PROGRESS to use a
distinct sentinel like -1 and update the renderer's guard to handle that
sentinel), ensuring variables referenced (incomingSeq/currentSeq and the
TASK_EXECUTION_PROGRESS handler that merges phaseProgress/overallProgress) are
adjusted accordingly.

projectId
);
Expand Down
Loading