Skip to content

API Reference parrot.knowledge.retrieval.pin

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

parrot.knowledge.retrieval.pin

View source

WorkspacePin — the cross-repo unit of coherence (spec §3.4, TASK-2274).

A retrieval request is scoped not to a single (repo, rev) but to a frozen set of pins, resolved once at request admission. HEAD moving underneath a long-lived session does not change retrieval results; advancing is an explicit, separate action (a dev_loop reducer concern, out of scope here).

Alias CapabilityUnavailable

Re-exported from parrot.knowledge.graphindex.protocols.CapabilityUnavailable.

Class CoherenceReport

Result of a bounded pin-coherence check (spec §3.5.3).

A sampled check can false-pass: it corroborates that the index likely corresponds to the pin, it does not verify it exhaustively. This is strictly weaker than storing the build rev in L0, and is the accepted price of keeping L0 read-only (spec §1.2). The residual risk is removed entirely if/when L0 gains a one-column build_rev on the files table (out of scope here — see spec §3.5.3, RQ-1-adjacent).

Fields:

Field Type Default Description
repo str The repo this report is about.
sampled_paths tuple[str, ...] The source_uris that were sampled, in the deterministic order they were checked — same pin, same sample.
mismatched_paths tuple[str, ...] () The subset of sampled_paths whose content at the pinned rev did not hash to the stored sha1 (or could not be read at that rev at all).

Attributes:

Attribute Type Description
sampled int Number of files sampled.
mismatched int Number of sampled files whose content did not match.
coherent bool True iff no sampled file mismatched.

Attribute DEFAULT_PIN_VERIFICATION_SAMPLE

Attribute DEFAULT_STALE_PIN_WARNING_DAYS

Alias IndexPinMismatchError

Re-exported from parrot.knowledge.retrieval.exceptions.IndexPinMismatchError.

Alias SourceCoherencePersistence

Re-exported from parrot.knowledge.graphindex.protocols.SourceCoherencePersistence.

Alias StalePinError

Re-exported from parrot.knowledge.retrieval.exceptions.StalePinError.

Alias TenantContext

Re-exported from parrot.knowledge.ontology.schema.TenantContext.

Class WorkspacePin

A frozen, hashable set of repo→rev pins for one retrieval session.

Fields:

Field Type Default Description
primary str Name of the repo that anchors relative resolution (e.g. the repo the session was opened against).
pins MappingProxyType[str, str] repo -> concrete SHA for every repo in the workspace. Never symbolic refs. Coerced to an immutable mapping at construction so mutation after the fact raises, keeping the "frozen for the request's lifetime" guarantee real rather than nominal.
pinned_at datetime UTC timestamp the pins were resolved at.
weight_table_version str Version of the EdgeWeightTable (spec §5.3) in effect when this pin was created — stamped here so a replayed trace reproduces exactly.
package_map_version str | None None Version of the PackageRepoMap (spec §5.3.1, RQ-1) in effect, if cross-repo resolution is enabled. None when not applicable.

Method WorkspacePin.rev_of

Return the concrete SHA pinned for repo.

rev_of(repo: str) -> str

Parameter Type Default Description
repo str Repository name.

Returns: str — The concrete git SHA pinned for that repo.

Raises:

  • KeyError — If repo is not present in pins.

Method WorkspacePin.is_stale

Whether this pin is older than warning_days (spec §3.4).

A long-lived session pinned far behind HEAD gets correct staleness answers from the L1 wiki cache (it is indexed by (node, digest), not by rev), but regenerating most pages against old source is expensive — this is a warning signal, not an error.

is_stale(*, now: datetime | None = None, warning_days: int = DEFAULT_STALE_PIN_WARNING_DAYS) -> bool

Parameter Type Default Description
now datetime | None None Reference time to compare against (defaults to datetime.now(timezone.utc)).
warning_days int DEFAULT_STALE_PIN_WARNING_DAYS Age threshold in days.

Returns: bool — True if the pin is older than warning_days.

Function check_pin_coherence

Corroborate (not verify) that the GraphIndex corresponds to pin.

L0 does not record the rev it was built from, so exact verification is impossible without an L0 schema change (out of scope, spec §1.2). Instead: hash a bounded, deterministic sample of the files table's content at the pinned rev, using the exact hash function the builder used (plain sha1 of file bytes — NOT a git blob hash, which includes a "blob <len>\0" prefix and would never match).

check_pin_coherence(pin: WorkspacePin, persistence: SourceCoherencePersistence, ctx: TenantContext, repo: str, repo_path: Path, *, sample: int = DEFAULT_PIN_VERIFICATION_SAMPLE, allow_stale: bool = True) -> CoherenceReport

Parameter Type Default Description
pin WorkspacePin The WorkspacePin to corroborate.
persistence SourceCoherencePersistence A backend exposing sorted source URI and SHA-1 pairs.
ctx TenantContext Tenant context passed to the persistence backend.
repo str Which repo in pin this check is for.
repo_path Path Local filesystem path to that repo's working tree.
sample int DEFAULT_PIN_VERIFICATION_SAMPLE Maximum number of files to sample (bounded — never exhaustive; spec §3.5.3 explicitly rejects O(files) git calls).
allow_stale bool True If False and the check finds a mismatch, raises IndexPinMismatchError. If True (default, matches RetrievalBudget.allow_stale's default), mismatches are returned on the report instead of raised.

Returns: CoherenceReport — A CoherenceReport describing what was sampled and what, if anything, mismatched.

Raises:

  • CapabilityUnavailable — If the persistence backend does not expose source-coherence data.
  • IndexPinMismatchError — If a mismatch is found and allow_stale=False.

Attribute logger

Function read_at_rev

Read a file's exact content at a pinned rev, via git cat-file.

All content served by any retrieval policy flows through this function, so Evidence.digest (TASK-2273) always hashes bytes that provably match the pin — never the working tree, which may have moved.

read_at_rev(repo_path: Path, rev: str, path: str) -> bytes

Parameter Type Default Description
repo_path Path Local filesystem path to the repo's working tree.
rev str Concrete git SHA to read at.
path str Repo-relative file path.

Returns: bytes — The raw file bytes as they existed at rev.

Raises:

  • LookupError — If the path does not exist at that rev, or the object cannot be read (deleted file, corrupted repo, etc.).

Function resolve_workspace

Resolve every repo's ref to a concrete SHA and freeze it into a pin.

Resolution happens once, at admission — the resulting WorkspacePin is then held for the whole request/session (spec §3.4, OQ-1).

resolve_workspace(refs: Mapping[str, str], *, primary: str, weight_table_version: str, repo_paths: Mapping[str, Path], package_map_version: str | None = None) -> WorkspacePin

Parameter Type Default Description
refs Mapping[str, str] repo -> ref mapping (branch name, tag, HEAD, or an already-concrete SHA) to resolve.
primary str Name of the repo that anchors relative resolution.
weight_table_version str EdgeWeightTable version in effect.
repo_paths Mapping[str, Path] repo -> local working-tree path, used to run git rev-parse in the right repository.
package_map_version str | None None PackageRepoMap version in effect, if any.

Returns: WorkspacePin — A frozen WorkspacePin with every repo resolved to a concrete SHA.

Raises:

  • StalePinError — If any repo's ref cannot be resolved to a reachable commit. Per spec §3.4, this never silently falls back to HEAD.
  • KeyError — If repo_paths is missing an entry for a repo in refs.

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