Skip to content

API Reference parrot_formdesigner.services.sandbox.router

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

parrot_formdesigner.services.sandbox.router

View source

Tier router: selects the cheapest executor and applies on_failure (FEAT-459 / M12).

Converges Track 2: given a SnippetBundle and a live FormEventContext (via the injected ContextProjector), routes to SubprocessWorkerPool (tiers 1-2) or GVisorWorkerPool (tiers 3-4), validates the returned EventResolution, rehydrates an AbortSignal into FormEventAbort, and applies the on_failure policy (TASK-3162's FormEventBinding.on_failure).

MUST NOT import or reference the FEAT-188 dispatch entry point module — this class is called FROM a TASK-3163 resolver closure, which that module's dispatch() (unmodified, G10) sees as an ordinary registered handler.

Alias AbortSignal

Re-exported from parrot_formdesigner.core.snippets.AbortSignal.

Alias CapabilityTier

Re-exported from parrot_formdesigner.core.snippets.CapabilityTier.

Alias EventResolution

Re-exported from parrot_formdesigner.core.events.EventResolution.

Alias FormEventAbort

Re-exported from parrot_formdesigner.core.events.FormEventAbort.

Alias SandboxContext

Re-exported from parrot_formdesigner.core.snippets.SandboxContext.

Alias SandboxOutcome

Re-exported from parrot_formdesigner.core.snippets.SandboxOutcome.

Alias SnippetBundle

Re-exported from parrot_formdesigner.core.snippets.SnippetBundle.

Class TierRouter

Routes a SnippetBundle to its cheapest satisfying executor.

Post-review correction (code review of this feature's first pass — both an independent Claude subagent and an adversarial codex cross-check, 2026-09-11): execute() originally took the LIVE FormEventContext and performed its own projection via an owned ContextProjector. That contradicted the spec's own declared TierRouter.execute(bundle, ctx: SandboxContext) interface AND services/snippets/base.py's actual resolver closure (TASK-3163), which already projects the live context via the INJECTED project_context callable before calling execute(bundle, sandbox_ctx). Passing an already-projected SandboxContext into a parameter that then tried to re-project it raised AttributeError at tier >= 2 (SandboxContext has no auth_context). Fixed by accepting the pre-projected SandboxContext directly and dropping the internal projection entirely — projection now has exactly ONE owner (the resolver closure), matching both the spec text and base.py's tested behavior.

Parameter Type Default Description
subprocess_pool SandboxProvider Serves CapabilityTier.PURE/HELPERS.
gvisor_pool SandboxProvider | None Serves CapabilityTier.BROKERED/TOOLKIT. May be None (e.g. gVisor unavailable); a bundle requiring it then raises RuntimeError rather than silently downgrading — the loader (TASK-3164) should already have refused such bundles at boot, so reaching this branch indicates a configuration bug, not routine unavailability.

Method TierRouter.execute

Run bundle against an already-projected ctx, returning the raw outcome.

execute(bundle: SnippetBundle, ctx: SandboxContext) -> SandboxOutcome

Parameter Type Default Description
bundle SnippetBundle The snippet to run.
ctx SandboxContext An ALREADY-PROJECTED SandboxContext — the caller (a TASK-3163 resolver closure) owns projection via its own injected ContextProjector before calling this method. This method does NOT project; passing a live FormEventContext here would fail at the pool boundary (SandboxContext and FormEventContext are distinct, unrelated Pydantic models).

Returns: SandboxOutcome — SandboxOutcome with exactly one of resolution/abort set, even on a worker-side failure — a raised exception (including a timeout, or a downstream Sandbox not yet exposing run_snippet) is caught and converted into SandboxOutcome(abort=AbortSignal(...)), so execute() itself never raises for an ordinary snippet failure; only execute_with_policy() decides whether that becomes a raised FormEventAbort or a logged continue.

Method TierRouter.execute_with_policy

Run bundle, applying on_failure to any failure outcome.

execute_with_policy(bundle: SnippetBundle, ctx: SandboxContext, *, on_failure: Literal['abort', 'continue']) -> EventResolution | None

Parameter Type Default Description
bundle SnippetBundle
ctx SandboxContext
on_failure Literal['abort', 'continue'] From FormEventBinding.on_failure (TASK-3162).

Returns: EventResolution | None — The EventResolution on success, or an empty EventResolution() when on_failure="continue" and execution failed.

Raises:

  • FormEventAbort — execution failed AND on_failure="abort" — this propagates up through the resolver closure (TASK-3163) and through dispatch() (unmodified) exactly as a hand-written handler's FormEventAbort would.

Attribute logger

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