From 226579086f92ad101073dcb066e64ddbd279bff3 Mon Sep 17 00:00:00 2001 From: Lauren ten Hoor Date: Tue, 10 Feb 2026 22:56:05 +0800 Subject: [PATCH] fix: reset startTime on task assignment for accurate duration tracking Problem: Stale worker detection was reporting incorrect durations when sessions were reused. Workers showed total session lifetime rather than time since current task assignment. Example: - Session created 13 hours ago for issue #71 - Session reused 4 minutes ago for issue #106 - Status incorrectly showed: "DEV active on #106 (3.3h)" - Should show: "DEV active on #106 (4m)" Root Cause: In recordWorkerState(), startTime was only set when spawning a new session (sessionAction === 'spawn'). When reusing an existing session (sessionAction === 'send'), the old startTime persisted, causing stale worker detection to use total session age instead of task age. Solution: Always set startTime to current time when activating a worker, regardless of whether we're spawning a new session or reusing one. The startTime field now consistently represents "when did this worker start THIS specific task" rather than "when was the session created". Changes: - lib/dispatch.ts: Move startTime assignment outside spawn-only block - startTime now set unconditionally for both spawn and send actions - Maintains backward compatibility with existing health checks Impact: - Stale worker detection now accurately reflects task duration - Session reuse no longer causes false positive stale alerts - Duration shown in status matches actual time on current task Addresses issue #108 --- lib/dispatch.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/dispatch.ts b/lib/dispatch.ts index 5df90a8..4c5b0cb 100644 --- a/lib/dispatch.ts +++ b/lib/dispatch.ts @@ -244,12 +244,13 @@ async function recordWorkerState( workspaceDir: string, groupId: string, role: "dev" | "qa", opts: { issueId: number; tier: string; sessionKey: string; sessionAction: "spawn" | "send" }, ): Promise { - const params: { issueId: string; tier: string; sessionKey?: string; startTime?: string } = { - issueId: String(opts.issueId), tier: opts.tier, + const params: { issueId: string; tier: string; sessionKey?: string; startTime: string } = { + issueId: String(opts.issueId), + tier: opts.tier, + startTime: new Date().toISOString(), // Always reset startTime for new task assignment }; if (opts.sessionAction === "spawn") { params.sessionKey = opts.sessionKey; - params.startTime = new Date().toISOString(); } await activateWorker(workspaceDir, groupId, role, params); }