Skip to content

API Reference parrot.tools.infographic_recipes.runner

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.tools.infographic_recipes.runner

View source

RecipeRunner — deterministic replay pipeline (Module 5, FEAT-324).

The heart of the feature: ONE runner behind all three triggers (chat tool, REST, scheduler — spec G6) executes the seven-step replay:

1. load recipe + resolve params (declared defaults + overrides + date resolvers)
2. fetch datasets (DatasetManager, invoker pctx honored)
3. fail-fast validation gate (spec G4)
4. execute the registered transform chain into a data_model dict
5. cross-check every layout ``{"path": ...}`` binding pointer against
   data_model keys, then assemble + catalog-validate the envelope
6. render via the resolved renderer profile
7. optionally deliver (persistence is a caller concern — see NOTE below)

Lives OUTSIDE parrot.outputs.a2ui (in parrot.tools.infographic_recipes) precisely so it may import DatasetManager (spec G8 one-way import rule).

pctx propagation (spec G8): DatasetManager reads its per-call PermissionContext from the module-level parrot.auth.context._pctx_var ContextVar — set by DatasetManager._pre_execute ONLY when a tool is invoked through the toolkit dispatch mechanism (ToolkitTool._execute). This runner calls fetch_dataset/get_dataset_entry directly (bypassing that dispatch path), so it sets _pctx_var itself around the data-fetch step and resets it afterwards — mirroring what _pre_execute/ _post_execute do, just invoked manually. Scheduled jobs pass whatever PermissionContext they resolved for schedule.principal as pctx (constructing/resolving that principal's context is TASK-1872's concern, not this runner's).

Persistence NOTE: this task's run() signature (spec §2 New Public Interfaces) takes no user_id/agent_id/session_id — the context ArtifactStore.save_artifact requires (parrot/storage/artifacts.py). Full envelope/artifact persistence therefore stays with whichever caller HAS that session context (chat tool TASK-1870, REST/scheduler TASK-1872); this runner's artifact_store constructor param is passed straight through to deliver_artifact(..., artifact_store=...) for its one VERIFIED use (the Slack public-URL lookup), not re-invented as a separate persist call.

Security review follow-up (post-merge hardening):

  • Every caller of run() MUST pass a real pctx — a missing/None pctx makes DatasetManager's PBAC/data-plane guards fail OPEN, not closed. Use parrot.auth.permission.build_principal_context() to build one from a bare user id/principal when no richer context is available.
  • run() accepts recipe_owner so replay loads the SAME owner scope a recipe was saved under (stores key by (name, owner) — omitting this silently makes owner-scoped recipes unrunnable via the tools meant to run them).
  • DataSourceSpec.sql {param} substitution is guarded against SQL injection (see :func:_reject_unsafe_sql_params) — TableSource executes sql close to verbatim and is NOT a security boundary by its own documentation; recipe params overrides are a new, less-trusted input to that path compared to TableSource's existing (LLM/agent- authored) callers.

Class RecipeRunException

Raised on every pipeline abort; carries the structured :class:RecipeRunError.

Parameter Type Default Description
error RecipeRunError

Class RecipeRunner

Executes the seven-step deterministic recipe-replay pipeline (spec §2).

Parameter Type Default Description
store AbstractRecipeStore Recipe store (:class:FileRecipeStore or :class:DBRecipeStore) recipes are loaded from.
dataset_manager DatasetManager The :class:DatasetManager instance used to fetch datasets.
artifact_store Any None Optional ArtifactStore-shaped object forwarded to deliver_artifact for its Slack public-URL lookup (see module docstring's Persistence NOTE).
owner Any None Optional NotificationMixin-bearing object (e.g. an agent) used as deliver_artifact's owner argument.
narrator Optional[Narrator] None Optional :class:Narrator (FEAT-420) used to render a recipe's declared narrative step as prose. None (the default) means every recipe replays deterministically with no narrative step attempted — a pure replay must never fail for lack of an LLM (spec criterion G-E). Injected at construction so run_scheduled_refresh (which takes a runner instance) needs no change to support narration.

Method RecipeRunner.run

Run the full seven-step replay pipeline for recipe name.

run(name: str, *, params: dict[str, Any] | None = None, pctx: Any | None = None, recipe_owner: Optional[str] = None, include_envelope: bool = False) -> RenderedArtifact

Parameter Type Default Description
name str Recipe name to load from self.store.
params dict[str, Any] | None None Override values for the recipe's declared params.
pctx Any | None None Invoker's PermissionContext (chat/REST) or the resolved context for schedule.principal (scheduled jobs). Propagated to DatasetManager via its _pctx_var ContextVar for the duration of the data-fetch step. Callers SHOULD always pass a real PermissionContext here (e.g. via parrot.auth.permission.build_principal_context) — a falsy pctx makes DatasetManager's PBAC/data-plane guards fail OPEN (no filtering applied), not fail closed.
recipe_owner Optional[str] None Owner scope to load the recipe under (must match the owner it was saved with — stores key by (name, owner)). None loads the shared/unscoped recipe. Named distinctly from the constructor's owner (the NotificationMixin- bearing delivery owner — an unrelated concept) to avoid confusion between the two.
include_envelope bool False When True, attach the assembled CreateSurface envelope dump (envelope.model_dump(by_alias=True, mode="json") — the same shape persist_envelope stores) at RenderedArtifact.metadata["source_envelope"] before returning. Lets a refresh caller (FEAT-492) obtain the envelope without a second ArtifactStore round-trip. Non-breaking: defaults to False, in which case the "source_envelope" key is never added.

Returns: RenderedArtifact — The rendered, persisted-if-configured :class:RenderedArtifact. When include_envelope=True, its metadata dict carries the reserved "source_envelope" key with the assembled envelope dump.

Raises:

  • RecipeRunException — On any pipeline abort (stage-tagged diagnostic).
  • ImportError — If the recipe's render profile names an uninstalled renderer backend (propagated from get_a2ui_renderer unchanged — "degrades with the existing actionable ImportError").

Method RecipeRunner.dry_run

Validate a recipe WITHOUT fetching data or rendering (freeze-path use).

Checks (spec: steps 1/3/5 only): - param references resolve (declared defaults / resolver names valid) - every TransformStep.transformer is registered - gate columns against dataset METADATA when available (no fetch) - every layout binding pointer's top-level key matches a declared output_key

dry_run(recipe: InfographicRecipe) -> list[RecipeRunError]

Parameter Type Default Description
recipe InfographicRecipe The (not-yet-persisted) recipe to validate.

Returns: list[RecipeRunError] — ALL problems found (empty list if the recipe is clean).

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally