latent.serve.knowledge_fetch¶
Fetch the knowledge bundle an agent version pins, before the pod serves.
A version that pins a bundle sets AGENT_KNOWLEDGE_DIGEST (with
AGENT_KNOWLEDGE_BUCKET, AGENT_KNOWLEDGE_PREFIX and
AGENT_KNOWLEDGE_DIR). latent serve then, before the HTTP server listens
and before it registers:
- GETs
s3://<bucket>/<prefix>/<hex>.tar.zstwith the node's credentials (60 s per attempt, 3 attempts with backoff); - hashes the bytes as they stream in and refuses a digest mismatch;
- unpacks into a staging directory inside the knowledge directory, which
must be empty or missing, refusing absolute paths,
.., symlinks, hard links and special files; - reads
manifest.jsonand refuses an unknownformat_versionor awriter_contractthe image does not read ([knowledge] contracts_read, see :func:latent.config.read_knowledge_contracts); - moves the files into place and writes the marker
.knowledge-complete(the digest andformat_version) last.
A container restarted inside the same pod finds its emptyDir already holding the bundle. When the marker names the pinned digest, the files are reused without a download, after the manifest checks run again.
Every refusal raises, so the process exits non-zero and never serves with an empty, partial or image-baked knowledge directory. With the digest unset the pod starts as before, on the image's own knowledge.
Needs latent[knowledge] (boto3, zstandard) only when a digest is set.
Classes¶
BundleManifest¶
manifest.json at the bundle root. Fields beyond these are the writer's.
DigestMismatch¶
FetchedKnowledge¶
The bundle a pod fetched at startup: what it reports and stamps on turns.
KnowledgeDirNotEmpty¶
KnowledgeFetchError¶
A pinned bundle the pod must not serve with.
UnknownFormat¶
UnsafeArchive¶
WriterContractMismatch¶
Functions¶
fetch_bundle¶
fetch_bundle(digest: str, bucket: str, prefix: str, target: Path, contracts_read: frozenset[int]) -> BundleManifest
Fetch, verify and unpack the bundle digest into target.
target is created when missing, and reused without a download when its
marker names digest (see the module docstring). Raises
:class:KnowledgeDirNotEmpty, :class:DigestMismatch,
:class:UnsafeArchive, :class:UnknownFormat or
:class:WriterContractMismatch; S3 errors propagate once the attempts are
spent.
fetch_knowledge_from_env¶
Fetch the bundle the environment pins, or None when no digest is set.