Syntropy.TaskScheduler.Support (syntropy v0.3.0)

Copy Markdown

Shared helpers for the task scheduler pipeline.

Holds the small contracts used across the scheduler submodules: agent reference maps, attempt duration arithmetic, agent failure normalization, and the process-dictionary LLM usage context that ties provider calls back to the originating task and stage.

Summary

Functions

Builds the minimal cross-node agent reference carried by runs and events.

Reads the LLM usage context for the calling process.

Millisecond duration between two datetimes, floored at zero.

Normalizes an agent execution failure into a stable error map with a machine-readable code and operator-facing message.

Runs fun with the LLM usage process context set to task_id/stage, restoring any previous context afterwards.

Types

agent_ref()

@type agent_ref() :: Syntropy.TaskScheduler.agent_ref()

Functions

agent_ref(map)

@spec agent_ref(map()) :: agent_ref()

Builds the minimal cross-node agent reference carried by runs and events.

current_llm_usage_context(source_review?)

@spec current_llm_usage_context(boolean()) :: map()

Reads the LLM usage context for the calling process.

duration_ms(started_at, finished_at)

@spec duration_ms(DateTime.t() | nil, DateTime.t() | nil) :: non_neg_integer() | nil

Millisecond duration between two datetimes, floored at zero.

Returns nil when either endpoint is missing.

normalize_agent_failure(reason)

@spec normalize_agent_failure(term()) :: map()

Normalizes an agent execution failure into a stable error map with a machine-readable code and operator-facing message.

with_llm_usage_context(task_id, stage, fun)

@spec with_llm_usage_context(String.t(), String.t(), (-> result)) :: result
when result: var

Runs fun with the LLM usage process context set to task_id/stage, restoring any previous context afterwards.

The context is read back by current_llm_usage_context/1 when provider calls are dispatched, so token usage lands on the right task and stage.