Skip to content

symfonic.capabilities.memory.work

work

The two surfaces the write coordinator borrows, and what a write reports.

Both are declared here rather than imported, for the same reason and with different consequences:

  • :class:BackgroundWorkPort mirrors symfonic.kernel.BackgroundRegistry.spawn exactly. The registry lives in kernel-runtime and the dependency matrix gives capability no edge to it, so the capability declares the shape and a composition root passes the registry straight in — structurally, with no adapter. test_the_kernel_background_registry_satisfies_the_port is the proof that the two have not drifted.
  • :class:MemoryDiscardPort is an optional capability of a lifecycle adapter: drop a scope's pending writes without committing them. The three declared memory ports cannot express a rollback — flush commits and forget erases the committed memories too — so an adapter that can do it says so by implementing this method, and one that cannot is not pretended to.

BackgroundWorkPort

Bases: Protocol

Somewhere to put owned work — structurally, T2.3.4's registry.

spawn

spawn(work: Coroutine[Any, Any, Any], *, owner: str, purpose: str, deadline_seconds: float | None = None) -> Any

Register and start one unit of run-owned work.

Source code in src/symfonic/capabilities/memory/work.py
def spawn(
    self,
    work: Coroutine[Any, Any, Any],
    *,
    owner: str,
    purpose: str,
    deadline_seconds: float | None = None,
) -> Any:
    """Register and start one unit of run-owned work."""
    ...

MemoryDiscardPort

Bases: Protocol

An optional capability: drop a scope's pending writes, uncommitted.

discard async

discard(scope: MemoryScope) -> LifecycleReceipt

Drop every uncommitted memory in scope and its descendants.

Source code in src/symfonic/capabilities/memory/work.py
async def discard(self, scope: MemoryScope) -> LifecycleReceipt:
    """Drop every *uncommitted* memory in ``scope`` and its descendants."""
    ...

WriteOutcome dataclass

WriteOutcome(request: WriteRequest, receipt: WriteReceipt | None = None, error: str = '')

What one background write did, once it finished.