0116: Fork shares persistent context
Status: Proposed — design default, pending the maintainer's confirmation
Context
Sibling agents need independent state and context tails without copying a potentially large shared conversation prefix.
Decision
Provide the plugin constructor Spawn.fork(state),
not new grammar (ADR-0006). Allocate a fresh child record and
deep-copy or promote its state into its own state block. Share the
parent's context root by incrementing its reference count.
Contexts are persistent lists of content-addressed blob
references; subsequent child appends create a separate tail and
never copy the parent prefix.
Fork cost is slab allocation, state copy/promotion, root refcount and enqueue, with no allocation proportional to context size. Confirm the M12 context-store representation against ADR-0113 before implementation.
Consequences
Sibling prefixes remain shared while each agent can extend its own context. Correct lifetime and reference counting are essential; copying state still costs proportionally to state size.
Alternatives
Copying the entire context at fork scales with conversation size. Sharing mutable state or a mutable tail would couple sibling behavior.
M13.2 implementation addendum
Status: Proposed, pending the maintainer's confirmation.
The original decision above remains identifiable as the
persistent-list proposal. For M13.2, the proposed implementation
instead uses the current exported plugin constructor
model.fork(input, detach) -> SpawnSpec, as
Action.Spawn(fork(...)). A child gets a fresh runner
record and inherits the parent's post-transition agent state with
value semantics: nested values are independent, including any
Context carried within that state. This requires no
explicit typed child-state variant and no language or native
changes.
Context remains an immutable vector of hashes, shared until
append; blobs reside in a Store keyed by hash, which
deduplicates them. The first append after fork copies the vector
in O(number of hashes), not O(blob bytes). This is a known
deviation from the refcounted persistent-list proposal above; it
does not introduce a bespoke refcounted store.
Alternatives considered
- A refcounted persistent list avoids copying the hash vector on append, but requires bespoke reference-counted storage beyond the current representation.
- Copying blob contents at fork or append would scale with context bytes and lose the existing deduplication benefit.
- Sharing mutable agent state or a mutable context tail would couple parent and child behavior.
- An explicit typed child-state variant is deferred as an open question pending the maintainer's decision; the current constructor is sufficient for the proposed inheritance behavior.