fix: enhance execution phase handling in ProjectStore

- Added logic to correct stale execution phases when a task reaches a terminal status (human_review, done, pr_created) but the persisted executionPhase is outdated.
- Improved the determination of execution progress to ensure accurate representation of task status, particularly for tasks that have transitioned from running to completed states.

These changes improve the reliability of task status updates and enhance user experience by ensuring accurate visual feedback on task execution phases.
This commit is contained in:
Test User
2026-02-05 22:18:43 +01:00
parent 01295eff99
commit 29d6c8cb14
+14 -5
View File
@@ -537,13 +537,22 @@ export class ProjectStore {
// because the task is no longer actively running
const isSettledState = xstateState && XSTATE_SETTLED_STATES.has(xstateState);
// Status-based override: if the task has reached a terminal status (human_review, done, pr_created)
// but the persisted executionPhase is stale (e.g. still "planning"), correct it.
// This happens when the XState machine didn't persist the final phase before being reset to backlog.
const STATUS_IMPLIES_COMPLETE: ReadonlySet<string> = new Set(['human_review', 'done', 'pr_created']);
const phaseIsStale = persistedPhase && persistedPhase !== 'complete' && persistedPhase !== 'failed'
&& STATUS_IMPLIES_COMPLETE.has(finalStatus);
const executionProgress = isSettledState
? this.inferExecutionProgressFromXState(xstateState) // Use XState for settled states
: persistedPhase
? { phase: persistedPhase, phaseProgress: 50, overallProgress: 50 } // Use persisted for running
: xstateState
? this.inferExecutionProgressFromXState(xstateState)
: this.inferExecutionProgress(plan?.status);
: phaseIsStale
? { phase: 'complete' as ExecutionPhase, phaseProgress: 100, overallProgress: 100 } // Fix stale phase
: persistedPhase
? { phase: persistedPhase, phaseProgress: 50, overallProgress: 50 } // Use persisted for running
: xstateState
? this.inferExecutionProgressFromXState(xstateState)
: this.inferExecutionProgress(plan?.status);
tasks.push({
id: dir.name, // Use spec directory name as ID