MCPcopy Index your code
hub / github.com/AI45Lab/Code / cancel

Method cancel

core/src/subagent_task_tracker.rs:129–156  ·  view source on GitHub ↗

Fire the registered token and mark the snapshot as `Cancelled`. Returns `true` if a token was found (caller can interpret as "cancellation initiated"), `false` if the task id was unknown or the task already finished. The eventual `SubagentEnd` event won't overwrite the Cancelled status — see `record_event`.

(&self, task_id: &str)

Source from the content-addressed store, hash-verified

127 /// the task already finished. The eventual `SubagentEnd` event won't
128 /// overwrite the Cancelled status — see `record_event`.
129 pub async fn cancel(&self, task_id: &str) -> bool {
130 let token = self.cancellers.write().await.remove(task_id);
131 match token {
132 Some(token) => {
133 token.cancel();
134 let now = now_ms();
135 let transitioned = {
136 let mut tasks = self.tasks.write().await;
137 if let Some(entry) = tasks.get_mut(task_id) {
138 if entry.status == SubagentStatus::Running {
139 entry.status = SubagentStatus::Cancelled;
140 entry.updated_ms = now;
141 true
142 } else {
143 false
144 }
145 } else {
146 false
147 }
148 };
149 if transitioned {
150 self.mark_terminal_and_evict(task_id).await;
151 }
152 true
153 }
154 None => false,
155 }
156 }
157
158 /// Apply a single agent event to the tracker. Non-subagent events are ignored.
159 pub async fn record_event(&self, event: &AgentEvent) {

Calls 4

removeMethod · 0.80
writeMethod · 0.80
now_msFunction · 0.70

Tested by

no test coverage detected