barrel_mcp_task_relay (barrel_mcp v3.0.1)

View Source

The process a task-supporting tool reports to while it is not yet known whether its call is answered synchronously or as a task.

tasks.md "Task Creation": a task-supporting tool may still answer synchronously when it can, and an MRTR round before the work starts is synchronous too. So the worker is started before the task, with this relay as its reply_to. Whatever arrives within the inline window goes to the request process and is answered in place. When the window closes the request process holds the relay, drains its own mailbox, and if nothing came creates the task and redirects the relay to the task's collector. A message in flight at that moment is held and released on redirect, so none is ever lost between the two.

The collector watches the relay rather than the worker: the relay ends when the worker has, with the worker's reason, after forwarding everything the worker sent. Being the same sender, its exit can never overtake a result.

Summary

Functions

Create the task for a held relay's worker and redirect the relay to the task's collector. The task exists before this returns, so a tasks/get for the handle resolves at once (tasks.md "Task Creation"). Returns the CreateTaskResult for the caller's era.

Stop forwarding and wait for the acknowledgement, after which nothing more lands in the caller's mailbox. A relay that has already ended (its worker finished and it forwarded everything) counts as held: what it forwarded is in the caller's mailbox.

How long a task-supporting tool may take before its call becomes a task.

Start a relay reporting to the calling process. Linked: a request process that dies takes an unanswered relay with it.

The call was answered in place; the relay is not needed.

Tell the relay which worker to watch. undefined when the tool could not be started; its failure is already on its way.

Functions

escalate(Relay, Worker, Owner, ToolName, Params, Ctx)

-spec escalate(pid(), pid() | undefined, term(), binary(), map(), map()) ->
                  {ok, map()} | {error, too_many_tasks}.

Create the task for a held relay's worker and redirect the relay to the task's collector. The task exists before this returns, so a tasks/get for the handle resolves at once (tasks.md "Task Creation"). Returns the CreateTaskResult for the caller's era.

hold(Relay)

-spec hold(pid()) -> ok.

Stop forwarding and wait for the acknowledgement, after which nothing more lands in the caller's mailbox. A relay that has already ended (its worker finished and it forwarded everything) counts as held: what it forwarded is in the caller's mailbox.

inline_ms()

-spec inline_ms() -> non_neg_integer().

How long a task-supporting tool may take before its call becomes a task.

start()

-spec start() -> pid().

Start a relay reporting to the calling process. Linked: a request process that dies takes an unanswered relay with it.

stop(Relay)

-spec stop(pid()) -> ok.

The call was answered in place; the relay is not needed.

worker(Relay, Worker)

-spec worker(pid(), pid() | undefined) -> ok.

Tell the relay which worker to watch. undefined when the tool could not be started; its failure is already on its way.