cayu.environments.factory
Public Cayu API. Definitions are grouped by their public source module, and definitions from private implementation modules appear on their package’s page; adding a symbol does not move existing links. The import shown at each entry is a supported public namespace. Read the Python API overview and install the required extra.
copy_environment_factory_request
Section titled “copy_environment_factory_request”from cayu.environments import copy_environment_factory_requestcopy_environment_factory_request(request: EnvironmentFactoryRequest) -> EnvironmentFactoryRequestRelease source · Runtime guarantees · Capability guides
copy_environment_factory_result
Section titled “copy_environment_factory_result”from cayu.environments import copy_environment_factory_resultcopy_environment_factory_result(result: EnvironmentFactoryResult) -> EnvironmentFactoryResultRelease source · Runtime guarantees · Capability guides
DEFAULT_ENVIRONMENT_FACTORY_RELEASE_TIMEOUT_SECONDS
Section titled “DEFAULT_ENVIRONMENT_FACTORY_RELEASE_TIMEOUT_SECONDS”from cayu.environments import DEFAULT_ENVIRONMENT_FACTORY_RELEASE_TIMEOUT_SECONDSDEFAULT_ENVIRONMENT_FACTORY_RELEASE_TIMEOUT_SECONDS = 15.0Release source · Runtime guarantees · Capability guides
ENVIRONMENT_ALLOCATION_INTENT_SCHEMA_VERSION
Section titled “ENVIRONMENT_ALLOCATION_INTENT_SCHEMA_VERSION”from cayu.environments import ENVIRONMENT_ALLOCATION_INTENT_SCHEMA_VERSIONENVIRONMENT_ALLOCATION_INTENT_SCHEMA_VERSION = 1Release source · Runtime guarantees · Capability guides
EnvironmentAllocationContext
Section titled “EnvironmentAllocationContext”from cayu.environments import EnvironmentAllocationContextRuntime-owned durable coordinator passed to recoverable factories.
Bases: ABC.
intent (property)
Section titled “intent (property)”EnvironmentAllocationContext.intent() -> EnvironmentAllocationIntentReturn the current detached allocation intent.
state (property)
Section titled “state (property)”EnvironmentAllocationContext.state() -> EnvironmentAllocationStateReturn the last reconciled durable state.
dispatch_precluded (property)
Section titled “dispatch_precluded (property)”EnvironmentAllocationContext.dispatch_precluded() -> boolWhether cleanup atomically fenced a prepared, never-dispatched intent.
acknowledged_reconnect_metadata (property)
Section titled “acknowledged_reconnect_metadata (property)”EnvironmentAllocationContext.acknowledged_reconnect_metadata() -> dict[str, Any] | NoneReturn detached provider acknowledgement, when known.
prepare (method)
Section titled “prepare (method)”async EnvironmentAllocationContext.prepare(provider_metadata: Mapping[str, Any]) -> EnvironmentAllocationIntentPersist the final intent before provider dispatch.
mark_dispatched (method)
Section titled “mark_dispatched (method)”async EnvironmentAllocationContext.mark_dispatched() -> NoneFence recovery before the irreversible provider call.
acknowledge (method)
Section titled “acknowledge (method)”async EnvironmentAllocationContext.acknowledge(reconnect_metadata: Mapping[str, Any]) -> NonePersist the exact provider result before returning it.
mark_reaping (method)
Section titled “mark_reaping (method)”async EnvironmentAllocationContext.mark_reaping() -> boolFence cleanup against publication; false means publication already won.
mark_reaped (method)
Section titled “mark_reaped (method)”async EnvironmentAllocationContext.mark_reaped() -> NoneRecord positively completed cleanup after the durable cleanup fence.
Release source · Runtime guarantees · Capability guides
EnvironmentAllocationIntent
Section titled “EnvironmentAllocationIntent”from cayu.environments import EnvironmentAllocationIntentPortable identity prepared before one remote provider mutation.
Decorators: @dataclass(frozen=True).
Fields and attributes
Section titled “Fields and attributes”Defaults below are source expressions; Field(...) includes schema/validation settings and default_factory creates a fresh value. Inherited declarations are included. Constructor behavior follows the model or dataclass shown in the bases/decorators.
| Name | Type | Default |
|---|---|---|
allocation_id |
str |
required |
provider |
str |
required |
adapter_generation |
str |
required |
session_id |
str |
required |
environment_name |
str |
required |
requested_operation |
EnvironmentFactoryOperation |
required |
provider_metadata |
dict[str, Any] |
field(default_factory=dict) |
schema_version |
int |
ENVIRONMENT_ALLOCATION_INTENT_SCHEMA_VERSION |
scope (property)
Section titled “scope (property)”EnvironmentAllocationIntent.scope() -> EnvironmentAllocationScopewith_provider_metadata (method)
Section titled “with_provider_metadata (method)”EnvironmentAllocationIntent.with_provider_metadata(provider_metadata: Mapping[str, Any]) -> EnvironmentAllocationIntentto_payload (method)
Section titled “to_payload (method)”EnvironmentAllocationIntent.to_payload() -> dict[str, Any]from_payload (method)
Section titled “from_payload (method)”EnvironmentAllocationIntent.from_payload(payload: Mapping[str, Any]) -> EnvironmentAllocationIntentRelease source · Runtime guarantees · Capability guides
EnvironmentAllocationScope
Section titled “EnvironmentAllocationScope”from cayu.environments import EnvironmentAllocationScopeStable provider and adapter generation that own one allocation.
Decorators: @dataclass(frozen=True).
Fields and attributes
Section titled “Fields and attributes”Defaults below are source expressions; Field(...) includes schema/validation settings and default_factory creates a fresh value. Inherited declarations are included. Constructor behavior follows the model or dataclass shown in the bases/decorators.
| Name | Type | Default |
|---|---|---|
provider |
str |
required |
adapter_generation |
str |
required |
Release source · Runtime guarantees · Capability guides
EnvironmentAllocationState
Section titled “EnvironmentAllocationState”from cayu.environments import EnvironmentAllocationStateDurable progress of one remote allocation intent.
Bases: StrEnum.
Fields and attributes
Section titled “Fields and attributes”Defaults below are source expressions; Field(...) includes schema/validation settings and default_factory creates a fresh value. Inherited declarations are included. Constructor behavior follows the model or dataclass shown in the bases/decorators.
| Name | Type | Default |
|---|---|---|
UNPREPARED |
class attribute |
'unprepared' |
PREPARED |
class attribute |
'prepared' |
DISPATCHED |
class attribute |
'dispatched' |
ACKNOWLEDGED |
class attribute |
'acknowledged' |
REAPING |
class attribute |
'reaping' |
REAPED |
class attribute |
'reaped' |
Release source · Runtime guarantees · Capability guides
EnvironmentAllocationUnsupportedError
Section titled “EnvironmentAllocationUnsupportedError”from cayu.environments import EnvironmentAllocationUnsupportedErrorRaised before provider mutation when crash-safe allocation is unavailable.
Bases: RuntimeError.
This type’s implementation and inherited behavior are available in the linked release source.
Release source · Runtime guarantees · Capability guides
EnvironmentFactory
Section titled “EnvironmentFactory”from cayu.environments import EnvironmentFactoryCreates or attaches a concrete environment for a session.
Bases: ABC.
secret_resolution_scope (property)
Section titled “secret_resolution_scope (property)”EnvironmentFactory.secret_resolution_scope() -> Literal['static', 'dynamic']Declare the immutable secret capability of every CREATE/RECONNECT result.
Static factories must never expose a vault or credential proxy. Runtime snapshots this declaration at registration, fingerprints it for recovery, and rejects violating results before binding or tool dispatch. Undeclared factories remain dynamic, even when one result has no secret resolvers.
execution_profile_identity (property)
Section titled “execution_profile_identity (property)”EnvironmentFactory.execution_profile_identity() -> ExecutionProfileBehaviorIdentity | NoneReturn a stable application declaration, or None when non-portable.
egress_authority_identity (property)
Section titled “egress_authority_identity (property)”EnvironmentFactory.egress_authority_identity() -> EgressAuthorityIdentity | NoneReturn the immutable egress authority proposed for future invocations.
execution_admission_candidate (method)
Section titled “execution_admission_candidate (method)”EnvironmentFactory.execution_admission_candidate(request: EnvironmentFactoryRequest) -> ExecutionAdmissionCandidate | NoneReturn explicit pre-create evidence without allocating resources.
The default deliberately makes no capability claim. Implementations
must keep this hook side-effect free because Cayu calls it before
create.
construction_admission_candidate (method)
Section titled “construction_admission_candidate (method)”EnvironmentFactory.construction_admission_candidate() -> ExecutionAdmissionCandidate | NoneReturn side-effect-free configured capability evidence at app setup.
execution_environment_authority (method)
Section titled “execution_environment_authority (method)”EnvironmentFactory.execution_environment_authority() -> ExecutionEnvironmentAuthority | NoneReturn the exact security boundary every materialized runner preserves.
workload_authority (method)
Section titled “workload_authority (method)”EnvironmentFactory.workload_authority(name: str) -> RunnerWorkloadAuthority | NoneReturn configured authority for a workload every result must preserve.
configured_artifact_store (property)
Section titled “configured_artifact_store (property)”EnvironmentFactory.configured_artifact_store() -> ArtifactStore | NoneReturn the stable artifact store exposed by every factory result.
allocation_scope (method)
Section titled “allocation_scope (method)”EnvironmentFactory.allocation_scope(request: EnvironmentFactoryRequest) -> EnvironmentAllocationScope | NoneDeclare one crash-recoverable remote allocation boundary.
Returning None means the factory does not allocate a process-external
resource through this seam. Implementations that return a scope must also
override create_recoverable; Cayu will never fall back to
create after accepting a recoverable scope.
create_recoverable (method)
Section titled “create_recoverable (method)”async EnvironmentFactory.create_recoverable(request: EnvironmentFactoryRequest, allocation: EnvironmentAllocationContext) -> EnvironmentFactoryResultCreate or recover exactly one intent-owned remote allocation.
reap_allocation (method)
Section titled “reap_allocation (method)”async EnvironmentFactory.reap_allocation(request: EnvironmentFactoryRequest, allocation: EnvironmentAllocationContext) -> NoneReap abandoned setup without allocating, binding, or running guest work.
Validate the exact intent and adapter scope before taking the durable cleanup fence. Record REAPED only after disposal and dependent reference release are positively complete. Ambiguity must retain retryable ownership. Wrappers forwarding a recoverable factory must forward this hook too.
recover_finalization_disposal (method)
Section titled “recover_finalization_disposal (method)”async EnvironmentFactory.recover_finalization_disposal(request: EnvironmentFactoryRequest, state: dict[str, Any]) -> NoneIdempotently dispose an allocation whose publication durably finished.
This cleanup-only hook must validate the exact reconnect identity and disposal state, tolerate an already absent allocation, and never create a replacement or access/publish guest output. Factory wrappers must forward this hook when forwarding a factory that supports disposal.
is_allocation_disposed (method)
Section titled “is_allocation_disposed (method)”async EnvironmentFactory.is_allocation_disposed(request: EnvironmentFactoryRequest) -> boolPositively attest terminal disposal of the exact reconnect allocation.
Called for a new invocation after a completed or failed session, after
profile admission. When the environment’s workspace checkpoint policy
opts into allocation_replacement="restore", it is also called before
reconnecting an interrupted or recovering session; a proof there
authorizes a replacement allocation plus checkpoint restore. Return True only with durable provider ownership evidence;
absence or uncertainty is not proof. Do not dispose, reconnect, or create
resources here. The default preserves exact-allocation reconnect.
Wrappers must forward this hook to preserve this capability.
deferred_materialization (property)
Section titled “deferred_materialization (property)”EnvironmentFactory.deferred_materialization() -> boolWhether results defer runner creation to first use.
A deferred factory returns an environment built from a
cayu.environments.deferred.DeferredMaterialization: session start
binds nothing, and the first runner use creates and binds the runner.
Manifests and cayu inspect report this declaration.
release_deferred_materialization (method)
Section titled “release_deferred_materialization (method)”async EnvironmentFactory.release_deferred_materialization(request: EnvironmentFactoryRequest) -> boolRemove a resource a crashed run materialized for this exact allocation.
Called by recover_incomplete_session with RECONNECT authority for a
recovered session that has no pending completion finalization, so the
resource holds no output the runtime still has to publish. The session
keeps its allocation and materializes again on its next use. Return
whether a resource was removed. Absence is not an error. The default
manages nothing.
release_idle_resources (method)
Section titled “release_idle_resources (method)”async EnvironmentFactory.release_idle_resources() -> NoneTrim factory-held idle resources, such as warm spares.
Called by CayuApp.drain_environment_cleanups, which applications may
also call while idle. A later session may create such resources again.
It must never touch a resource a session owns. The default holds nothing.
close_idle_resources (method)
Section titled “close_idle_resources (method)”async EnvironmentFactory.close_idle_resources() -> NoneRelease factory-held idle resources for good, at application shutdown.
Called by CayuApp.close_idle_environment_resources (the server calls it
after its shutdown drain). Afterwards the factory creates no new idle
resources, and sessions that still materialize must work without them
(for example by starting cold). The default trims like
release_idle_resources.
create (method)
Section titled “create (method)”async EnvironmentFactory.create(request: EnvironmentFactoryRequest) -> EnvironmentFactoryResultReturn a concrete environment for the requested session.
Release source · Runtime guarantees · Capability guides
EnvironmentFactoryOperation
Section titled “EnvironmentFactoryOperation”from cayu.environments import EnvironmentFactoryOperationWhether a factory must allocate a new environment or reconnect one.
Bases: StrEnum.
Fields and attributes
Section titled “Fields and attributes”Defaults below are source expressions; Field(...) includes schema/validation settings and default_factory creates a fresh value. Inherited declarations are included. Constructor behavior follows the model or dataclass shown in the bases/decorators.
| Name | Type | Default |
|---|---|---|
CREATE |
class attribute |
'create' |
RECONNECT |
class attribute |
'reconnect' |
Release source · Runtime guarantees · Capability guides
EnvironmentFactoryRelease
Section titled “EnvironmentFactoryRelease”from cayu.environments import EnvironmentFactoryReleaseEnvironmentFactoryRelease = Callable[[EnvironmentFactoryReleaseAction], Awaitable[None]]Release source · Runtime guarantees · Capability guides
EnvironmentFactoryReleaseAction
Section titled “EnvironmentFactoryReleaseAction”from cayu.environments import EnvironmentFactoryReleaseActionHow an unadopted factory result must release its live resources.
Bases: StrEnum.
Fields and attributes
Section titled “Fields and attributes”Defaults below are source expressions; Field(...) includes schema/validation settings and default_factory creates a fresh value. Inherited declarations are included. Constructor behavior follows the model or dataclass shown in the bases/decorators.
| Name | Type | Default |
|---|---|---|
DISCARD |
class attribute |
'discard' |
PRESERVE |
class attribute |
'preserve' |
Release source · Runtime guarantees · Capability guides
EnvironmentFactoryRequest
Section titled “EnvironmentFactoryRequest”from cayu.environments import EnvironmentFactoryRequestDurable session context used to create or attach an environment.
Decorators: @dataclass(frozen=True).
Fields and attributes
Section titled “Fields and attributes”Defaults below are source expressions; Field(...) includes schema/validation settings and default_factory creates a fresh value. Inherited declarations are included. Constructor behavior follows the model or dataclass shown in the bases/decorators.
| Name | Type | Default |
|---|---|---|
session_id |
str |
required |
agent_name |
str |
required |
environment_name |
str |
required |
parent_session_id |
str | None |
None |
causal_budget_id |
str | None |
None |
labels |
dict[str, str] |
field(default_factory=dict) |
metadata |
dict[str, Any] |
field(default_factory=dict) |
reconnect_metadata |
dict[str, Any] |
field(default_factory=dict) |
operation |
EnvironmentFactoryOperation |
EnvironmentFactoryOperation.CREATE |
execution_requirements |
ExecutionRequirements |
field(default_factory=ExecutionRequirements.trusted) |
execution_profile_fingerprint |
str | None |
None |
interaction_id |
str | None |
None |
replacement_predecessor |
dict[str, Any] |
field(default_factory=dict) |
Release source · Runtime guarantees · Capability guides
EnvironmentFactoryResult
Section titled “EnvironmentFactoryResult”from cayu.environments import EnvironmentFactoryResultConcrete environment and pre-adoption release contract for a session.
release owns factory-created resources until workspace binding succeeds.
After successful binding, the binding owns the adopted environment lifecycle.
Decorators: @dataclass(frozen=True).
Fields and attributes
Section titled “Fields and attributes”Defaults below are source expressions; Field(...) includes schema/validation settings and default_factory creates a fresh value. Inherited declarations are included. Constructor behavior follows the model or dataclass shown in the bases/decorators.
| Name | Type | Default |
|---|---|---|
environment |
Environment |
required |
metadata |
dict[str, Any] |
field(default_factory=dict) |
reconnect_metadata |
dict[str, Any] |
field(default_factory=dict) |
release |
EnvironmentFactoryRelease | None |
None |
release_timeout_s |
float |
DEFAULT_ENVIRONMENT_FACTORY_RELEASE_TIMEOUT_SECONDS |