foley.runtime#
Runtime posture — local-first / offline mode as one verifiable contract (#12, report 12).
RuntimeConfig couples the three things “offline” must mean into a single frozen,
inspectable value, each a consumer of an existing SSOT (no parallel policy):
data egress —
data_egress_allowfilters the source registry by each adapter’s already-declaredconfig['data_egress'](foley.sourcesSSOT), so a network adapter is simply not available offline.telemetry —
telemetry=Falsedisables the observability run-artifact export (foley.obs), so nothing leaves the device.redaction —
redaction_moderoutes narration-derived fields through the readyfoley.obs.redact.REDACT_FIELDSredactor, so prompts/queries/narration never sit in even a local run store.
offline() (offline_scope) applies the posture for the duration of a with
block via a contextvars.ContextVar and restores the prior obs state on
exit — per-call granularity, not a process-global flip. Stdlib-only, so importing this
keeps import foley dol-only.
Module Attributes
The egress classes a source may declare ( |
Functions
The active |
|
Whether an offline runtime scope is currently active. |
|
|
Call |
|
Under an offline posture, forbid outbound connections in this context for the block. |
|
Alias of |
|
Apply a |
|
Raise |
|
Under an offline posture, raise |
|
Make |
Classes
|
A frozen runtime posture — the local-first / offline contract as data. |
Exceptions
Raised when a call would send data off the device under an offline posture. |
|
Raised under an offline posture when a model's weights are not on this machine. |
- exception foley.runtime.EgressBlocked[source]#
Bases:
PermissionErrorRaised when a call would send data off the device under an offline posture.
Every external path checks the active
RuntimeConfigthroughrequire_egress()— the source registry, the generate and pull façades, and the LLM resolver — sowith foley.offline():holds on every surface, not only in the MCP tools.
- foley.runtime.LOCAL: str = 'local'#
The egress classes a source may declare (
config['data_egress']SSOT).
- exception foley.runtime.ModelNotCached[source]#
Bases:
EgressBlockedRaised under an offline posture when a model’s weights are not on this machine.
foley never downloads weights inside
offline()(#86); the message names the model and how to fetch it beforehand, online.
- class foley.runtime.RuntimeConfig(offline=False, data_egress_allow=<factory>, telemetry=True, redaction_mode='hash', http_resilience=True)[source]#
Bases:
objectA frozen runtime posture — the local-first / offline contract as data.
- Parameters:
offline (
bool) – Whether this posture is offline/local-first.data_egress_allow (
frozenset[str]) – The egress classes a source may use to be available ({'local'}offline;{'local','external'}online).telemetry (
bool) – Whether the obs run-artifact export is on.redaction_mode (
str) –'hash'(default, salted),'off'(drop), or'full'(raw — local-debug only).http_resilience (
bool) – Whether HTTP source adapters are wrapped with the throttle/backoff/circuit-breaker (foley.sources.resilience).
- allows(data_egress)[source]#
Whether a source declaring
data_egressis available under this posture.An unknown/absent declaration is rejected (fail-closed): a source that does not say where its data goes is never used offline.
- Return type:
- classmethod default()[source]#
The online default: all egress allowed, telemetry on, hashed redaction.
- Return type:
- classmethod from_env()[source]#
Build from the environment:
FOLEY_OFFLINEin {1,true,yes} → offline-local.- Return type:
- foley.runtime.current_runtime()[source]#
The active
RuntimeConfig; outside any scope, the one$FOLEY_OFFLINEselects.- Return type:
- foley.runtime.is_offline()[source]#
Whether an offline runtime scope is currently active.
- Return type:
- foley.runtime.load_pretrained(loader, model_id, *, how_to_fetch=None, **kwargs)[source]#
Call
loader(model_id, **kwargs)— afrom_pretrained— honouring the posture.Online, it is a plain call. Under
offline()it passeslocal_files_only=True(no Hub request at all) and turns a cache miss (anOSError) intoModelNotCached; any other error passes through as is. foley’sfrom_pretrainedloads (CLAP, Stable Audio) go through here; loaders with no local-only switch (AudioSeal, whisperX) go throughno_download().
- foley.runtime.no_download(what, *, how_to_fetch)[source]#
Under an offline posture, forbid outbound connections in this context for the block.
For model loaders that have no local-only switch (AudioSeal, whisperX): inside the block a non-loopback connection or name lookup made from this context is refused, and an error whose cause is that refusal is re-raised as
ModelNotCachednamingwhatandhow_to_fetch. A cached model still loads (the libraries fall back to their cache when the network is refused); an unrelated error passes through unchanged. Online it does nothing. Threads a loader starts itself do not inherit the block (they start with a fresh context); the loaders guarded here make their first request from the calling thread.
- foley.runtime.offline(config=None)[source]#
Alias of
offline_scope()—with foley.offline(): ...for local-first runs.
- foley.runtime.offline_scope(config=None)[source]#
Apply a
RuntimeConfigfor thewithblock, restoring obs state on exit.Defaults to
RuntimeConfig.offline_local(). Disables telemetry export and sets the redaction mode for the scope; the prior obs enabled-state and redaction mode are captured on entry and restored on exit (so a scope never leaks its posture).- Parameters:
config (
RuntimeConfig|None) – The posture to apply (default: offline-local).- Yields:
The applied
RuntimeConfig.
- foley.runtime.require_egress(data_egress, *, what)[source]#
Raise
EgressBlockedunless the active runtime allowsdata_egress.- Parameters:
- Return type:
- foley.runtime.require_local_files(paths, *, what, how_to_fetch, min_bytes=None)[source]#
Under an offline posture, raise
ModelNotCachedunless every path exists.min_bytesmaps a path to the size below which the library would re-download it (a truncated download), so such a file counts as missing too.For model files a library downloads itself (PANNs fetches its checkpoint and label CSV with
wget, even at import), checked before that library is touched.- Return type:
- foley.runtime.runtime_scope(config)[source]#
Make
configthe current posture for the block — the ContextVar only.Unlike
offline_scope()it leaves the process-wide obs settings alone (safe to enter from many threads at once); telemetry still follows the posture, becausefoley.obs.is_enabled()readscurrent_runtime().