Skip to main content

child_auth

How a background DAG child process obtains its credentials and configuration.

A background DAG run executes in a subprocess Prefect launches from a served deployment, so it inherits nothing from the pod. On the Docker path the credential costs nothing — BITFOUNT_API_KEY_ID / BITFOUNT_API_KEY are in the environment the Runner passes down, and _create_bitfount_session picks them up on its own.

The desktop path is the hard one. There the pod's own credential is a RefreshableJWT whose get_token is bound to a live multiprocessing.Queue back to the orchestrator, and neither a queue handle nor a bearer token can travel as a JSON deployment parameter — the first because it is not serialisable, the second because deployment parameters are persisted in the Prefect database in clear. The same is true of ehr_config, which carries a private key.

So the child asks the pod instead. It presents the nonce the pod left for it in the cache (cache.types.background_run_grants) to the pod control server's child-config endpoint, over loopback, and gets back a real token — or, for the "config" kind, the EHR configuration and the hook factories to re-register. A grant is redeemable repeatedly and for the life of the run, because a run that outlives its first token refreshes mid-flight.

The same grant buys the run the model memo's host cache key (the "cache_key" kind), so runs under one Compute host share the model weights an earlier run downloaded. The key is fetched lazily, once per process, by the PodCacheKeySource the run installs; any failure leaves the run with today's per-process weights, never a failed step.

Module​

Functions​

build_memo_key_source​

def build_memo_key_source(    pod_control_url: str | None, nonce: str | None, task_hash: str, project_id: str,) ‑> PodCacheKeySource | None:

Return the model memo's key source for this background run.

Nothing is asked of the pod here; the source asks at the memo's first lookup, so a run that loads no model never does.

Arguments

  • pod_control_url: Base URL of the pod control server, or None on a path that has no pod to ask.
  • nonce: The grant the pod recorded for this lineage, or None when it recorded none.
  • task_hash: The (pod, datasource) task hash the grant is scoped to.
  • project_id: The project the run belongs to.

Returns None when there is no pod to ask, a source reporting no_grant when the pod left no grant, otherwise a source that asks the pod.

pod_cache_key_source​

def pod_cache_key_source(    pod_control_url: str, nonce: str, task_hash: str, project_id: str,) ‑> Callable[[], ServedCacheKey]:

Return a fetch that redeems nonce for the model memo's host cache key.

Arguments

  • pod_control_url: Base URL of the pod control server on this machine.
  • nonce: The grant the pod recorded for this run's lineage.
  • task_hash: The task_hash half of the grant's key.
  • project_id: The project_id half of the grant's key.

Returns A callable that asks the pod for the model-memo purpose key.

Classes​

PodCacheKeySource​

class PodCacheKeySource(fetch: Callable[[], ServedCacheKey] | None):

The model memo's host cache key, asked of the pod that launched this run.

Asks at most once per instance, at the memo's first lookup, and remembers the answer for the life of the process, a refusal included: a run that could not get a key keeps its weights to itself rather than asking again at every model. Never raises, and never logs the key. Implements ModelMemoKeySource.

Create a source over fetch.

Arguments

  • fetch: Asks the pod for the key, or None when the pod left this run no grant to ask with.

Methods​


memo_key​

def memo_key(self) ‑> MemoKeyResult:

Return the model memo's host cache key, or why there is none.

Returns The key and its scope, or the reason this run has none. The same result on every call.

ServedCacheKey​

class ServedCacheKey(key: bytes, scope: str):

A host cache purpose key the pod served this run.

Attributes

  • key: The 32-byte purpose key. Kept out of repr.
  • scope: The <pid>-<create ms> scope of the host the key belongs to.

Raises

  • ValueError: If key is not 32 bytes or scope is not a valid scope. Neither value is echoed.

Variables​

  • key : bytes
  • scope : str