(taskId, setAppState)
| 1085 | name: 'RemoteAgentTask', |
| 1086 | type: 'remote_agent', |
| 1087 | async kill(taskId, setAppState) { |
| 1088 | let toolUseId: string | undefined; |
| 1089 | let description: string | undefined; |
| 1090 | let sessionId: string | undefined; |
| 1091 | let killed = false; |
| 1092 | updateTaskState<RemoteAgentTaskState>(taskId, setAppState, task => { |
| 1093 | if (task.status !== 'running') { |
| 1094 | return task; |
| 1095 | } |
| 1096 | toolUseId = task.toolUseId; |
| 1097 | description = task.description; |
| 1098 | sessionId = task.sessionId; |
| 1099 | killed = true; |
| 1100 | return { |
| 1101 | ...task, |
| 1102 | status: 'killed', |
| 1103 | notified: true, |
| 1104 | endTime: Date.now(), |
| 1105 | }; |
| 1106 | }); |
| 1107 | |
| 1108 | // Close the task_started bookend for SDK consumers. The poll loop's |
| 1109 | // early-return when status!=='running' won't emit a notification. |
| 1110 | if (killed) { |
| 1111 | emitTaskTerminatedSdk(taskId, 'stopped', { |
| 1112 | toolUseId, |
| 1113 | summary: description, |
| 1114 | }); |
| 1115 | // Archive the remote session so it stops consuming cloud resources. |
| 1116 | if (sessionId) { |
| 1117 | void archiveRemoteSession(sessionId).catch(e => |
| 1118 | logForDebugging(`RemoteAgentTask archive failed: ${String(e)}`), |
| 1119 | ); |
| 1120 | } |
| 1121 | } |
| 1122 | |
| 1123 | void evictTaskOutput(taskId); |
| 1124 | void removeRemoteAgentMetadata(taskId); |
| 1125 | logForDebugging(`RemoteAgentTask ${taskId} killed, archiving session ${sessionId ?? 'unknown'}`); |
| 1126 | }, |
| 1127 | }; |
| 1128 | |
| 1129 | /** |
nothing calls this directly
no test coverage detected