( taskId: string, setAppState: SetAppState, )
| 123 | * The lazy GC in generateTaskAttachments() remains as a safety net. |
| 124 | */ |
| 125 | export function evictTerminalTask( |
| 126 | taskId: string, |
| 127 | setAppState: SetAppState, |
| 128 | ): void { |
| 129 | setAppState(prev => { |
| 130 | const task = prev.tasks?.[taskId] |
| 131 | if (!task) return prev |
| 132 | if (!isTerminalTaskStatus(task.status)) return prev |
| 133 | if (!task.notified) return prev |
| 134 | // Panel grace period — blocks eviction until deadline passes. |
| 135 | // 'retain' in task narrows to LocalAgentTaskState (the only type with |
| 136 | // that field); evictAfter is optional so 'evictAfter' in task would |
| 137 | // miss tasks that haven't had it set yet. |
| 138 | if ('retain' in task && (task.evictAfter ?? Infinity) > Date.now()) { |
| 139 | return prev |
| 140 | } |
| 141 | const { [taskId]: _, ...remainingTasks } = prev.tasks |
| 142 | return { ...prev, tasks: remainingTasks } |
| 143 | }) |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Get all running tasks. |
no test coverage detected