Patch Changes
-
ca510d4Thanks @threepointone! - Tighten internal peer dependency floors to reflect the current monorepo set we actually test against:agents(>=0.8.7→>=0.11.7),@cloudflare/codemode(>=0.0.7→>=0.3.4), and@cloudflare/shell(>=0.2.0→>=0.3.4). Upper bounds (<1.0.0) are unchanged.No runtime change in
@cloudflare/thinkitself. The visible effect for consumers: pairing the latest@cloudflare/thinkwith a staleagents(<0.11.7),@cloudflare/codemode(<0.3.4), or@cloudflare/shell(<0.3.4) now produces a peer warning where it previously did not. That's the intended signal — those older combinations are no longer tested in the monorepo. -
#1411
2fa68beThanks @threepointone! - Addoptions.signaltoThink.saveMessagesandThink.continueLastTurnfor external cancellation of programmatic turns, plus protectedabortRequest(id)/abortAllRequests()methods to replace bracket access into the private_abortsregistry (#1406).saveMessagesandcontinueLastTurnaccept a secondSaveMessagesOptionsargument:const result = await this.saveMessages(messages, { signal: controller.signal, }); if (result.status === "aborted") { // Inference loop terminated mid-stream; partial chunks persisted. }
The signal is linked to Think's per-turn
AbortControllerfor the duration of the call. When it aborts:- the inference loop's signal aborts (the same path
chat-request-canceltakes); - partial chunks already streamed are persisted to the resumable stream;
saveMessagesresolves with{ status: "aborted" };onChatResponsefires withstatus: "aborted".
Pre-aborted signals short-circuit before any model work runs. Listeners are detached cleanly when the turn finishes, so passing the same long-lived
AbortSignalto many turns (e.g. a parent chat-turn signal driving multiple sub-agent calls) is safe and leak-free.abortRequest(id, reason?)andabortAllRequests()are protected entry points for DO subclasses (e.g. RPC-driven helpers) that want to cancel turns without tracking ids — they replace the historical(this as unknown as { _aborts: ... })._aborts.destroyAll()workaround used by helper-as-sub-agent implementations.SaveMessagesResult.statusnow includes"aborted"alongside"completed"and"skipped". Existing callers that only switch on"completed"are unaffected.Limitations.
AbortSignalcannot cross Durable Object RPC. Construct the controller inside the DO that callssaveMessages. To bridge a parent's intent into a child DO, return aReadableStreamfrom the child whosecancelcallback aborts a per-turn controller —examples/agents-as-toolsshows the canonical pattern.- The signal lives in memory only. If the DO hibernates mid-turn and
chatRecoveryis enabled, the recovered turn callscontinueLastTurn()internally without the original signal — an abort fired after restart has no effect on the recovered turn.
See
cloudflare/agents#1406for the motivating use case. - the inference loop's signal aborts (the same path