@mastra/core
Version:
46 lines • 2.4 kB
TypeScript
/**
* Cross-process abort transport for durable agents.
*
* `abort()` runs in the caller's process, but a durable run's steps may execute
* in a different process entirely (a load-balanced server replica, or an Inngest
* worker). Flipping a local `AbortController` is therefore invisible to the code
* that is actually driving the model call.
*
* These helpers carry the abort *intent* over pubsub so the executing process
* can flip its own controller and unwind gracefully — emitting the usual
* `finish` event with reason `abort`. That matters: hard-cancelling the
* underlying workflow run would tear execution down before the terminal stream
* event is ever published, leaving stream consumers hanging forever.
*/
import type { PubSub } from '../../events/index.js';
import type { Mastra } from '../../mastra/index.js';
export { publishAbortRequest, requestAcknowledgedAbort, subscribeToAbortRequests } from '../streams/abort-transport.js';
/**
* Make the current process responsive to abort requests for `runId`.
*
* Called by durable steps as they start work. The step may be running on a
* worker that never saw the caller's `abort()`, so this is where that process
* grows an `AbortController` of its own — the same one every downstream call
* already reads off the run registry (`registryEntry.abortSignal`), so nothing
* downstream needs to know abort arrived from elsewhere.
*
* Idempotent: a run executes many steps in the same process, and each of them
* calls this. The subscription is torn down with the registry entry, whether
* that happens on explicit cleanup or TTL eviction.
*/
export declare function ensureRemoteAbortListener(pubsub: PubSub, runId: string, mastra?: Mastra, deadline?: RunDeadline): Promise<void>;
/**
* Request-context key the caller sets to the run's absolute total deadline for one execution
* segment (stream or resume), so every worker can stop at it on its own clock.
*/
export declare const RUN_DEADLINE_KEY = "__mastra_runDeadline";
/** The run's total deadline: when it fires (epoch ms) and the budget it enforces. */
export type RunDeadline = {
at: number;
timeoutMs: number;
};
/** The run deadline a step's request context carries, if any. */
export declare function readRunDeadline(requestContext?: {
get(key: string): unknown;
}): RunDeadline | undefined;
//# sourceMappingURL=abort-transport.d.ts.map