Skip to content

API Reference parrot.tools.working_memory.task_memory.repl

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

parrot.tools.working_memory.task_memory.repl

View source

Generation-bound REPL materialization of exact evidence (FEAT-538).

Recovering a task must not silently drag its data back into a worker. This module is the only way an artifact version becomes a live variable again, and it is deliberately narrow:

  • Explicit only. Nothing here runs as a side effect of recall, of a descriptor read, or of listing artifacts. Recall is read-only and bounded (AC10); if describing a binding could materialize one, a single recall could pull megabytes back into a worker.
  • Exact versions only. :meth:ReplBindingResolver.load takes an artifact_id and a version. A bare alias is mutable and is not evidence, so there is no alias-shaped entry point.
  • Verified before bound. The materialized payload is re-fingerprinted and compared with the descriptor's recorded fingerprint before the value is injected. Binding content that no longer matches what was fingerprinted would break the evidence chain the whole feature exists to protect.
  • Strict transport only. DataFrames travel as Arrow IPC and JSON/text as safe JSON, via the strict paths TASK-2992 added. There is no pickle fallback for task evidence, and a value the strict path refuses is refused here too.
  • Never a namespace restore. One named variable per explicit request. Arbitrary namespaces are never reconstructed and saved code is never replayed.

Stale bindings versus lost bytes

These are different failures and this module never conflates them. A worker restarting invalidates its binding — the variable is gone from that process — but the artifact is still perfectly locatable in the store. Every refusal therefore reports artifact_locatable, so a caller can tell "rebind this into the new worker" from "this evidence is actually gone".

Class BindingStatus

Outcome of a resolve or load request.

Class ReplBindingResolver

Materializes exact artifact versions into a live REPL worker.

Parameter Type Default Description
artifacts ArtifactStore The artifact store to resolve versions from.
config Optional[TaskMemoryConfig] None Byte-ceiling configuration. Defaults to :class:TaskMemoryConfig's own defaults.

Method ReplBindingResolver.describe

Report whether a binding would be valid, without materializing.

This is what a descriptor read or a recall may call. It performs no injection and loads no payload, so it can never become a way for a read path to pull data back into a worker.

describe(scope: TaskScope, artifact_id: str, version: int, worker_session_id: Optional[str] = None, *, task_id: Optional[str] = None) -> ReplLoadResult

Parameter Type Default Description
scope TaskScope Trusted runtime scope.
artifact_id str Artifact identity.
version int Exact version.
worker_session_id Optional[str] None The worker generation the caller believes holds the binding. None asks only about the artifact.
task_id Optional[str] None Owning task, scoping the lookup.

Returns: ReplLoadResult — class:ReplLoadResult that never carries a payload.

Method ReplBindingResolver.load

Materialize one exact version into worker, on explicit request.

The order of checks is the guarantee. Scope, existence, availability, kind, verifiability and the byte ceiling are all settled before anything is loaded; the fingerprint is verified before anything is injected; and the binding is published only after the worker has acknowledged the injection.

load(scope: TaskScope, artifact_id: str, version: int, worker_session_id: Optional[str] = None, *, worker: WorkerLike, variable_name: Optional[str] = None, task_id: Optional[str] = None, max_bytes: Optional[int] = None, fencing_token: Optional[int] = None) -> ReplLoadResult

Parameter Type Default Description
scope TaskScope Trusted runtime scope. A version belonging to another scope reads as absent.
artifact_id str Artifact identity.
version int Exact version. There is no alias entry point: a bare alias is mutable and is not evidence.
worker_session_id Optional[str] None The worker generation the caller expects. When it does not match worker.generation the request is reported as :attr:BindingStatus.BINDING_INVALID and nothing is injected — the caller then retries against the live generation to rebind. None binds to whatever generation worker currently is.
worker WorkerLike The live worker to bind into.
variable_name Optional[str] None Name to bind under. Defaults to the artifact's alias, then to its id.
task_id Optional[str] None Owning task, scoping the lookup.
max_bytes Optional[int] None Caller's byte ceiling. Clamped by the configured hard ceiling — a caller may lower it, never raise it.
fencing_token Optional[int] None Monotonic token carried in the envelope so a superseded owner's late reply can be rejected.

Returns: ReplLoadResult — class:ReplLoadResult. On success it carries a generation-bound :class:ReplBinding.

Class ReplLoadRefusal

Why a load was refused.

A plain str subclass, matching :class:PayloadRefusal, so the reason survives JSON and reaches a tool result without a second enum to keep in sync.

Class ReplLoadResult

The result of a resolve or load request.

Fields:

Field Type Default Description
status BindingStatus Whether the value was bound, the binding is stale, or the load was refused.
ref EvidenceRef The exact version requested.
binding Optional[ReplBinding] None The generation-bound binding, present only on :attr:BindingStatus.BOUND.
refusal Optional[str] None A :class:ReplLoadRefusal reason, when refused.
artifact_locatable bool False Whether the artifact itself can still be found in the store. True for a stale binding — a worker restart loses the variable, not the evidence. This is the field that stops the two failures being conflated.
byte_size Optional[int] None Recorded payload size, reported even on refusal so a caller can see how far over a ceiling it was.
guidance Optional[str] None What the caller should do instead, when refused.

Attributes:

Attribute Type Description
ok bool Whether the value is live in the worker.

Class WorkerLike

The worker surface this resolver needs.

Both :class:~parrot.tools.repl_worker.handle.WorkerHandle and :class:~parrot.tools.repl_worker.inprocess.InProcessHandle satisfy it. Depending on the protocol rather than either class keeps the resolver usable in both execution modes without branching.

Attributes:

Attribute Type Description
generation str Stable identity of this worker generation.

Method WorkerLike.inject_dataframe

Bind a DataFrame into the worker namespace.

inject_dataframe(name: str, df: Any, *, strict: bool = False, envelope: Any = None, max_bytes: Optional[int] = None) -> None

Parameter Type Default Description
name str
df Any
strict bool False
envelope Any None
max_bytes Optional[int] None

Method WorkerLike.set_var

Bind one namespace variable.

set_var(name: str, value: Any) -> None

Parameter Type Default Description
name str
value Any

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