fix: clear startTime when deactivating workers to prevent stale timestamps
Problem:
When workers were deactivated (task completed or fixed by health checks),
the startTime field was not being cleared. This caused:
- Inactive workers to retain stale timestamps
- Misleading duration data in projects.json
- Potential confusion in health checks and status displays
Example from projects.json:
{
"qa": {
"active": false,
"issueId": null,
"startTime": "2026-02-10T08:51:50.725Z", // Stale!
"tier": "qa"
}
}
Root Cause:
The deactivateWorker() function only set active: false and issueId: null,
but did not clear startTime. Similarly, health check auto-fixes that
deactivated workers also failed to clear startTime.
Solution:
Always set startTime: null when deactivating a worker to ensure clean state.
Changes:
1. lib/projects.ts:
- deactivateWorker() now sets startTime: null
- Updated function comment to document this behavior
2. lib/services/health.ts:
- All three auto-fix paths that deactivate workers now clear startTime:
* active_no_session fix (line 77)
* zombie_session fix (line 98)
* stale_worker fix (line 138)
Impact:
- Inactive workers now have clean state (startTime: null)
- Duration calculations only apply to active workers
- Health checks work with accurate data
- No stale timestamps persisting across task completions
- Complements fix from #108 (which ensures startTime is set on activation)
Together with #108:
- #108: Always SET startTime when activating worker
- #113: Always CLEAR startTime when deactivating worker
- Result: startTime accurately reflects current task duration
Addresses issue #113
This commit is contained in:
@@ -74,7 +74,7 @@ export async function checkWorkerHealth(opts: {
|
||||
fixed: false,
|
||||
};
|
||||
if (autoFix) {
|
||||
await updateWorker(workspaceDir, groupId, role, { active: false, issueId: null });
|
||||
await updateWorker(workspaceDir, groupId, role, { active: false, issueId: null, startTime: null });
|
||||
fix.fixed = true;
|
||||
}
|
||||
fixes.push(fix);
|
||||
@@ -95,7 +95,7 @@ export async function checkWorkerHealth(opts: {
|
||||
await revertIssueLabel(fix);
|
||||
const sessions = { ...worker.sessions };
|
||||
if (worker.tier) sessions[worker.tier] = null;
|
||||
await updateWorker(workspaceDir, groupId, role, { active: false, issueId: null, sessions });
|
||||
await updateWorker(workspaceDir, groupId, role, { active: false, issueId: null, startTime: null, sessions });
|
||||
fix.fixed = true;
|
||||
}
|
||||
fixes.push(fix);
|
||||
@@ -135,7 +135,7 @@ export async function checkWorkerHealth(opts: {
|
||||
};
|
||||
if (autoFix) {
|
||||
await revertIssueLabel(fix);
|
||||
await updateWorker(workspaceDir, groupId, role, { active: false, issueId: null });
|
||||
await updateWorker(workspaceDir, groupId, role, { active: false, issueId: null, startTime: null });
|
||||
fix.fixed = true;
|
||||
}
|
||||
fixes.push(fix);
|
||||
|
||||
Reference in New Issue
Block a user