Protected Readonly_Protected Readonly_Protected Readonly_The ID of the user each task was created for. Kept beside the task rather than on it, because the task is the wire shape returned to clients.
Protected Readonly_Whether durable MJ: Tasks persistence is enabled on this store instance.
Configured retention window in milliseconds.
Optional human-readable identifier surfaced in shutdown logs and used for
de-duplication when Register is called repeatedly with the same instance
but no name. Falls back to the constructor name.
Use Size.
Cancel an in-flight task, aborting its registered AbortController (if any) and
notifying any active SSE subscribers immediately.
Cancels a task owned by contextUser across both local in-flight execution and durable MJ: Tasks storage.
In durable mode, the replica running the task polls stored status (default 5 s, WatchCancellation)
and aborts its local work when it observes Cancelled, or stops on its next save via MergeStoredA2ATask.
Returns false when the task is not the caller's, or the cancellation could not be saved.
OptionalcontextUser: UserInfoOptionalprovider: IMetadataProviderDrops a task from this process's cache (and its listeners and abort controller).
The task with this ID when it belongs to userId, otherwise undefined. A task that belongs
to someone else is indistinguishable from one that does not exist, so a caller cannot learn
another user's task IDs, nor read, continue or cancel their tasks.
Loads an A2A Task for contextUser, consulting MJ: Tasks when persistence is enabled
so cross-replica updates/cancellations are observed immediately, and falling back to the
local L1 cache when persistence is disabled or the row does not exist yet. A row that is not
the caller's A2A task reads as missing.
OptionalcontextUser: UserInfoOptionalprovider: IMetadataProviderNotify all subscribers of a task state change. Automatically cleans up listeners and abort controllers once the task reaches a terminal state.
Notifies any in-process SSE subscribers and persists the updated task state to MJ: Tasks.
OptionalcontextUser: UserInfoOptionalprovider: IMetadataProviderRegister an AbortController for an in-flight task so CancelTask can propagate
cancellation down to AgentOperations / AgentRunner.
Persists an A2A Task into both the local L1 cache and the MJ: Tasks entity. Returns false when
the task could not be written — no authenticated owner, someone else's task, a row that is not an
A2A task, a failed save, or a row too contended to settle — so the caller can report it rather
than carry on with a task that exists only in this process's memory.
OptionalcontextUser: UserInfoOptionalprovider: IMetadataProviderStores a task.
OptionalownerUserId: stringThe user the task was created for. Only that user can retrieve it through GetForUser; a task stored without an owner is retrievable by no one. Omit it when replacing a stored task, to keep its owner.
Stop the sweep timer and drop all tasks, listeners, and abort controllers. Idempotent.
Begin the periodic sweep. Idempotent; calling twice is safe. Uses unref()
so the sweep timer doesn't hold the process alive on its own.
Subscribe to event-driven updates for a specific task ID (replaces 500ms polling). Returns an unsubscribe function.
In durable mode, subscribes to task updates across replicas by combining in-process events
with periodic polling of the stored row in MJ: Tasks (S10).
Polling stops when the task reaches a terminal status, or when its stored row has not changed for
staleAfterMs (a task orphaned by a replica that died stays in_progress forever); onStale is
then called so the caller can end its stream and say why. A task this replica is still running
(it holds a live abort controller for it) is never stale.
OptionalonStale: () => voidDrop terminal-state tasks that haven't been updated in retentionMs.
Returns the count evicted (useful for tests and diagnostics).
In durable mode, periodically checks the stored status of an in-flight task while this replica is running it. When stored status is observed as 'cancelled' (e.g. cancelled on another replica), aborts local work via the registered AbortController (S10).
A cleanup function to stop polling when the task finishes locally.
Durable
MJ: Tasks-backed implementation of IA2ATaskStore (WS-4.5b).Combines the in-process L1 cache and SSE subscriber notifications of TaskStore with durable persistence through
MJTaskEntity('MJ: Tasks'). Enables horizontal scaling (multiple A2A server replicas behind a load balancer) and zero-data-loss rolling restarts: any replica can serveGET /a2a/tasks/:taskId, continue a multi-turn task onPOST /a2a/tasks/send, or cancel a task onPOST /a2a/tasks/:taskId/cancel.Only A2A rows.
MJ: Tasksalso holds task-graph steps, conversation tasks and people's to-dos, and a caller who owns one of those knows its ID. The store reads and writes a row only when it is filed under the A2A_TASK_TYPE_NAME type, carries the A2A_TASK_PROTOCOL payloads and belongs to the caller; any other row is "not found". Without that,tasks/sendon a task-graph step's ID overwrote its payloads (its envelope, failure policy and continuation) and status, and could complete a pending Human step.Concurrent writers. Two replicas can save the same task at once (two sends, or a cancel and the owning replica's completion). Each save re-reads the row and merges (MergeStoredA2ATask), checks
__mj_UpdatedAthas not moved before writing, and reads the row back afterwards; a row that moved, or that came back without what this save wrote, is merged and written again.BaseEntity.Save()has no conditional update, so this narrows the lost-update window to the gap between the check and the write rather than closing it; the read-back makes the losing writer repair it.