Skip to content

API Reference parrot.tools.working_memory.task_memory.validators

github-actions[bot] edited this page Nov 10, 2026 · 4 revisions

parrot.tools.working_memory.task_memory.validators

View source

Evidence-bound completion validation (FEAT-538).

A tool succeeding is not evidence that a step is done. This module is where that principle is enforced: before a step may be marked complete, its declared evidence is resolved to exact immutable versions and checked against code-registered validators.

Two completion modes, and recall must always be able to tell them apart:

validated Every validator named by the step's policy must pass, and every expected output alias must bind to an exact artifact_id@version.

agent_asserted At least one accessible evidence reference plus the required note. This is the weaker source, and it is labelled as such everywhere it appears — an asserted completion is a claim, not a proof.

The subtle rule this module exists to get right is the difference between an overwrite and a mutation:

  • An overwrite moves an alias to a new version. The old version is untouched and remains perfectly valid evidence. Completions that cite it stay valid.
  • A mutation changes the content behind a version that is already bound as evidence. That invalidates the evidence and must block the completion — and, once recorded, reopen anything already completed against it.

Getting these two confused in either direction is a correctness failure: treating an overwrite as mutation would spuriously invalidate sound work, and treating a mutation as an overwrite would let a step stay "complete" against content that no longer exists as it was verified.

Validation runs outside any long-held lock, then commits against the same task revision and the same evidence generation it validated. If either moved underneath it, the result is discarded and the caller retries — never a stale completion.

Class CompletionValidationError

A completion was refused because its evidence does not support it.

Attribute CompletionValidator

Class EvidenceBinding

One resolved piece of evidence.

Parameter Type Default Description
ref EvidenceRef The exact version.
descriptor ArtifactDescriptor Its descriptor.
alias Optional[str] None The alias resolved from, if any.

Attributes:

Attribute Type Description
ref The exact version.
descriptor Its read projection at resolution time.
alias The alias it was resolved from, when it was.

Class EvidenceMutated

Content changed behind a version that is already bound as evidence.

Distinct from an overwrite, which is normal and harmless. This is the case where the same version no longer matches the fingerprint it was verified with, so anything completed against it must be reopened.

Parameter Type Default Description
ref EvidenceRef The mutated version.
expected Optional[str] Fingerprint recorded at binding time.
actual Optional[str] Fingerprint observed now.

Attributes:

Attribute Type Description
ref The version whose content changed.
expected The fingerprint recorded when the evidence was bound.
actual The fingerprint observed now.

Attribute VALIDATORS

Type: Dict[str, CompletionValidator]

Attribute VALIDATOR_NAMES

Type: Tuple[str, ...]

Class ValidationOutcome

The result of validating one step's completion.

Parameter Type Default Description
passed bool Whether completion may proceed.
source Optional[CompletionSource] The completion source to record.
results Sequence[Tuple[str, bool]] () Per-validator outcomes.
bound Sequence[EvidenceRef] () Exact versions bound as evidence.
failures Sequence[str] () Reasons for refusal.
invalidated Sequence[EvidenceRef] () Versions mutated in place.

Attributes:

Attribute Type Description
passed Whether the completion may proceed.
source How the completion would be recorded. agent_asserted is always the weaker label.
results Tuple[Tuple[str, bool], ...] Per-validator (name, passed) pairs, recorded in the journal so replay consumes them rather than re-running them.
bound Tuple[EvidenceRef, ...] The exact versions the completion binds.
failures Tuple[str, ...] Human-readable reasons, when it did not pass.
invalidated Tuple[EvidenceRef, ...] Versions found to have been mutated in place.

Function resolve_evidence

Resolve evidence to exact versions, once.

Aliases are resolved a single time and pinned to the version they named at that moment. Resolving twice would open a window in which an overwrite between the two reads silently changed what was validated.

resolve_evidence(artifacts: ArtifactStore, scope: TaskScope, *, task_id: str, refs: Sequence[EvidenceRef] = (), aliases: Sequence[str] = ()) -> List[EvidenceBinding]

Parameter Type Default Description
artifacts ArtifactStore The artifact store.
scope TaskScope Trusted runtime scope.
task_id str The owning task, which also scopes the alias namespace.
refs Sequence[EvidenceRef] () Exact versions supplied by the caller.
aliases Sequence[str] () Aliases to resolve and pin.

Returns: List[EvidenceBinding] — The resolved bindings, in the order requested: refs first, then aliases.

Raises:

  • CompletionValidationError — If a reference or alias cannot be resolved in this scope.

Function validate_completion

Decide whether a step's completion is supported by its evidence.

Runs outside any long-held lock. The caller commits the result against the same task revision and the same evidence it validated; :func:assert_unchanged re-checks both.

validate_completion(artifacts: ArtifactStore, scope: TaskScope, state: TaskState, step_id: str, *, evidence_refs: Sequence[EvidenceRef] = (), note: Optional[str] = None) -> ValidationOutcome

Parameter Type Default Description
artifacts ArtifactStore The artifact store.
scope TaskScope Trusted runtime scope.
state TaskState The task projection at validation time.
step_id str The step being completed.
evidence_refs Sequence[EvidenceRef] () Exact versions the caller offers as evidence.
note Optional[str] None The completion note.

Returns: ValidationOutcome — class:ValidationOutcome. passed is False with populated failures rather than raising for an unsupported completion — a refusal is an ordinary answer, not an exception.

Raises:

  • UnknownValidatorError — If the policy names a validator that is not code-registered. Never treated as a vacuous pass.
  • EvidenceMutated — If content changed behind an already-bound version. This is not an ordinary refusal: it means existing completions must be reopened.
  • CompletionValidationError — If evidence cannot be resolved.

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