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
This commit is contained in:
@@ -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<void> {
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user