MCPcopy Index your code
hub / github.com/CopilotKit/CopilotKit / abortRun

Method abortRun

packages/core/src/intelligence-agent.ts:277–302  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

275 }
276
277 abortRun(): void {
278 if (this.activeChannel && this.canonicalRunId) {
279 // Defer cleanup until the push is acknowledged so socket.disconnect()
280 // doesn't clear the push buffer before the stop signal is sent.
281 // The 5-second fallback handles the case where the socket is down and
282 // Phoenix never flushes the buffered push (its .receive("timeout") only
283 // fires for pushes that were actually sent but not replied to).
284 // detachActiveRun() gracefully tears down the connectAgent() pipeline;
285 // cleanup() follows as a safety net for the run() path.
286 const fallback = setTimeout(() => clear(), 5_000);
287 const clear = () => {
288 clearTimeout(fallback);
289 void this.detachActiveRun();
290 this.cleanup();
291 };
292
293 this.activeChannel
294 .push(STOP_RUN_EVENT, { run_id: this.canonicalRunId })
295 .receive("ok", clear)
296 .receive("error", clear)
297 .receive("timeout", clear);
298 } else {
299 void this.detachActiveRun();
300 this.cleanup();
301 }
302 }
303
304 /**
305 * Trigger the run via REST, then join the realtime thread channel and relay

Callers

nothing calls this directly

Calls 5

cleanupMethod · 0.95
receiveMethod · 0.65
pushMethod · 0.65
clearFunction · 0.50
detachActiveRunMethod · 0.45

Tested by

no test coverage detected