Skip to content

Version coexistence

Two blocks in one workflow can need versions of a library that cannot be installed together: one block needs numpy<2, the next needs numpy>=2.1. In one Python environment that is a conflict with no answer. In Xratu each block gets its own resolved closure and runs in its own cell, so each block imports the version it declared, and the two exchange data through the typed interface between them.

How it works

  1. Each block declares its own requirement. Block A declares numpy>=1.26,<2 and block B declares numpy>=2.1, each in its own @xratu.
  2. Each block's closure is resolved on its own. A's requirement and B's requirement are solved separately, so each gets a binding that satisfies it.
  3. Each closure runs in its own cell. A's cell environment view mounts only A's selected NumPy component and maps the numpy module to it. B's view does the same with B's component. Each cell's search path holds one NumPy.
  4. Data crosses as typed values. A returns its result in the form B's interface declares, such as a record or a buffer. The kernel carries that value into B's cell, and B's NumPy builds its own array from it. A's array object stays in A's cell.
flowchart LR
  subgraph K["Xratu kernel"]
    direction LR
    A["Block A cell<br/>numpy 1.26.4<br/>from the foundation"]
    B["Block B cell<br/>numpy 2.1.3<br/>closure-local component"]
  end
  A -->|"typed value defined<br/>by the interface"| B

A worked example

The foundation carries NumPy 1.26.4 in its component store.

@xratu(["numpy>=1.26,<2"])
class Features:
    ...

@xratu(["numpy>=2.1"])
class Scorer:
    ...

Features is satisfied by the foundation's NumPy, and its binding selects it with the reason compatible_foundation_preferred. Scorer is not, so the resolver builds a closure-local component. The foundation's NumPy is recorded as considered and rejected, and excluded from Scorer's closure (trimmed, digests shortened):

{
  "requirement_id": "python:numpy",
  "requirement_scope": "reusable_block",
  "requirement_specs": ["numpy>=2.1"],
  "source": "closure_local",
  "selected_version": "2.1.3",
  "considered_candidates": [
    {
      "candidate_id": "foundation:scientific-python:numpy",
      "source": "foundation",
      "version": "1.26.4",
      "disposition": "version_mismatch",
      "reason_code": "declared_specifier_mismatch"
    },
    {
      "candidate_id": "python:numpy:2.1.3:wheel-linux-amd64",
      "source": "closure_local",
      "version": "2.1.3",
      "disposition": "selected",
      "reason_code": "highest_precedence_compatible_candidate"
    }
  ],
  "excluded_foundation_component_digests": ["sha256:f00d…"]
}

In Scorer's cell, module_ownership maps numpy to the closure-local component, and that component is the only NumPy mounted. In Features' cell, numpy maps to the foundation component. See Candidate dispositions and conflict.

A replacement is whole

When a block's selection replaces a foundation component, the whole foundation distribution leaves that block's closure, including its metadata, package data and native bundle. The block's own component stands in for it entirely. A package tree assembled from files of two distributions is refused.

The replacement applies to that block's closure only. The foundation keeps its component, and every sibling closure that selected it keeps it too. A replacement that would break a native dependency another selected foundation component relies on makes that candidate incompatible, with the reason foundation_native_closure_broken_by_override.

Native libraries

Native libraries follow the same rule through the native loader view. Two blocks that need incompatible builds of one native library get two loader views in two cells. Within one closure, a native, ABI, SONAME or driver conflict refuses the closure or produces a separately selected one, so the library a cell loads is the same whatever order libraries load in. See Native loader view.

What the two cells share

Two cells that select the same component map the same immutable bytes, by digest, and each keeps its own process, live objects, writable state and lifecycle. Two cells that select different versions share only the foundation rootfs, its exported baseline, and the project-wide system components.

Coexistence is per block

Within one block, every requirement and every transitive dependency resolves to one version. A candidate whose transitive dependencies clash with the rest of the block's graph is recorded as conflicting, and when no candidate set satisfies every requirement in the block, the build is refused. Split the work into two blocks when two parts of it need incompatible versions.

Related: Cells covers what crosses between cells, and Requirements are declared per block covers why one block's requirement never changes another's.