On this page

0169: Structured workspace ownership and vc finalization

Status: Accepted — per-agent prerequisite explicitly authorized 2026-11-05

Context

ADR-0117 implemented invocation cleanup but left agent finish/cancel/detach open. The vc plan requires each agent's work and actual settled usage to survive its finish. Action-result task IDs are not agent owners; root and child zero can collide numerically. Generic impls are unsupported, and pure runner clients use the CLI platform without the agent-only Ws capability.

Decision

Keep one platform-neutral generic runner with a single DriverState containing RunState, host, ownership/attempt evidence and terminal flags. RunHost callbacks supply lifecycle effects; existing ToolPort clients use a concrete no-workspace host. The agent-only workspace_run module supplies a concrete lease table and WorkspaceToolPort; concrete application hosts forward to reusable helpers. Do not add generic impl syntax, duplicate the scheduler or keep a mutable host root outside transition-arena carry. Only Agent.step remains eligible for parallel execution; lifecycle/tool effects run in deterministic action order.

WorkspaceOwner distinguishes Root from Child(TaskId). Bind a distinct Ws before a child steps, and pass that exact handle to its tool port. Ws.fork inherits the pinned original source/backend, using fresh sibling directories. VC forks only from protected history; unlanded parent edits are not stacked. Preserve the existing flat native layout and add explicit runner/recovery ownership rather than rewriting descriptor confinement into nested paths.

Add explicit workspace_backend=vc plus Ws.fork and Ws.commit(provenance,message) on both execution backends. Auto behavior stays unchanged. A trusted absolute HARNESS_VC_BIN is canonicalized/pinned at acquisition; generated C contains no installation path. Native calls use direct argv, fixed child environment, bounded process lifetime and child-only vc directory selection. Existing Io represents vc command failures; non-vc commit validates its live handle then succeeds as a no-op. No new error union variant or crate is needed.

Pin original store and branch privately. Public vc-tree files are tool-writable, so checking them before spawn alone is insufficient. Keep protected private command state beside each workspace, outside delegated tool Fs. Privileged status/commit/fork use vc --directory plus --state-directory; a fork retains its parent's pinned store even if original-source metadata changes. The CLI binds one immutable command context, never mutating a native host's cwd/environment. Public metadata inconsistencies remain errors. Read/write/fork/commit/release all reject replaced directory identities on C and interpreter.

After scoped children and synchronous effects settle, every explicit Finish outcome checkpoints that owner's vc branch, then releases its files. A clean checkpoint is an empty-commit-free no-op. No automatic landing occurs. Cancel performs no checkpoint; dirty or unverifiable vc work is retained and reported. Detached leases survive parent finish in returned driver state and resume via explicit draining without resetting counters/owners or finalizing root twice.

Provenance sums actual BudgetSettled records joined to explicit owner/attempt bindings. Workspace mode records unbudgeted actual settlements; legacy journal payloads and enum variants stay unchanged. Missing/ambiguous/duplicate coverage, unknown fields, overflow or no settlements yield unknown. Returned parent budget spend is not direct-owner usage. Journal failure prevents lifecycle effects and later actions, retaining leases for recovery.

VC release/drop/atexit/stale sweep refuse to erase dirty or unverifiable work. Protected recovery sidecars and private state survive process death. Successful branch commits remain rooted after file cleanup. This provides retained current work and explicit CLI recovery, not reconstruction of native capabilities from arbitrary paths or serialized pointers.

Consequences

This completes the ownership/VC portions left open by ADR-0117; its invocation cleanup remains the fallback for legacy callers. Host forwarding is explicit because generic impls are unavailable. Recovery artifacts can consume disk until an operator resolves them, which is preferable to deleting agent work on error. The administrative root and toolchain executable remain trusted; same-uid direct store mutation is not an OS security boundary. Existing sandbox platform limits are unchanged. Networking, auto-land and migration away from Git remain separate.

Alternatives

Measured startup cost

The generic carrier adds one initial-state deep promotion before the transition loop: 616 allocated bytes and 79 copied bytes (queue 584, initial text16, empty provider 16). Instrumented 1,000- and 100,000-transition runs have the identical startup delta; serial/parallel totals and stdout match. The existing bounded memory tests remain unchanged. Its exact allocation-report golden is refreshed for this intentional fixed cost, not relaxed into a looser threshold. The carrier itself is 768 bytes; it is not a new per-transition allocation.