Appearance
0002. Workspace placement as a closed enum ​
Status: Accepted (2026-09-29). Closes the open question of ADR 0001, decision 10. Adoption of the runs of a lost worker is not part of this decision (see Consequences).
Status note 2026-09-29: the coder Helm chart (0.2.0) sets the placement. workspace.placement (shared, affinity, isolated; a2a-only is refused) is passed as WORKSPACE_PLACEMENT, and WORKER_ID is the pod name for the pinning placements. replicaCount above 1 is allowed once a placement is set. The decision itself is unchanged.
Amended 2026-10-11 by ADR 0037, not built yet: a child run inherits its parent's owner when it is created, so a subagent under a pinning placement runs on the worker that holds its root's workspace. Until then a child is created with no owner and the first pinned claim takes it.
Context ​
The owner's words, 2026-09-29: "A worker can do the work, it can own a folder, it can have an isolated pvc, it can use only a2a. The guy doing the deployment will decide."
ADR 0001 decided that the deployer picks the workspace placement, and left the exact enum and the mechanism open. The reason it cannot stay open is a silent failure that exists today.
A run moves between workers at every step. The worker loop commits a run that Continues, releases its lease, and the next claim may go to any worker (crates/adam-runtime/src/worker.rs, the doc of run_worker). The Postgres claim has no owner filter, and the release clears lease_owner (crates/adam-store-postgres/src/lib.rs, claim_due and release_lease). The worker id is random per process (worker-<uuid>, crates/adam-runtime/src/runtime.rs), and adam-coder never sets it. Verified 2026-09-29: read those files at commit a1bcb1e.
The coder keeps a worktree per run under a local root. With two workers on two local disks, a run can land on a worker that has no worktree for it. The chain, in code:
open_existingreturnsNone, and the tool answers "call prepare_workspace first" (crates/adam-coder/src/tools/mod.rs,worktree).prepareclones the repository again (crates/adam-workspace/src/workspace.rs).- The branch
agent/<short>is already pushed, sobranch_is_availablesays no andpick_branchtakesagent/<short + 4 characters>. - The run notes lived under
<root>/coder, on the other disk, and are lost. - The pull-request lookup goes by head branch (
crates/adam-coder/src/github.rs), so it finds nothing and opens a second pull request.
No error is raised anywhere. The run forks silently. Verified 2026-09-29: read each function named above. Even with one shared volume there is a smaller gap: the lock that serialises work on a repository's mirror is in-process only (Workspaces::lock_for), so two worker processes can run git fetch on one mirror at the same time and fail with "could not lock".
Decision ​
Placementis a closed enum inadam-host, besideRole, with no#[non_exhaustive]for the reason of ADR 0001 decision 3: a new placement must be a compile error in every host that matches on it.Placement Meaning Runs pinned to a worker Needs a workspace shared(default)one volume, mounted by every worker (RWX); any worker may resume any run no yes affinitya run is stepped only by the worker that first claimed it; each worker owns a folder <root>/<worker id>yes yes isolatedas affinity, and the worker's root is a volume of its own (a PVC per worker), used as it isyes yes a2a-onlythe host has no filesystem work, its agents only call remote agents no no Placement::pins_runs()is true foraffinityandisolated.Placement::needs_workspace()is false only fora2a-only. The name is the deployer's word; the host reads it from its own variable (adam-coder:WORKSPACE_PLACEMENT).The store learns to pin.
Store::claim_duetakes a closedClaimScope:Any: what it did before. The owner is neither read nor written.Pinned: a run is claimable only if it has no owner or its owner is this worker, and the first claim sets the owner. Releasing a lease leaves the owner alone, so the run comes back to the same worker.
The owner is a column (
runs.owner, Postgres) or a field (owner, MongoDB, a missing field counts as none), not a part of the run state, because the pure state machine never sees it. Postgres schema version goes to 2 (ALTER TABLE .. ADD COLUMN IF NOT EXISTS owner TEXT, then the version row is raised); MongoDB needs no migration for a missing field, and its version number goes to 2 as well so both stores say the same.The runtime chooses the scope.
RuntimeBuilder::claim_scope(ClaimScope), defaultAny.adam-coreandadam-runtimedo not depend onadam-host; the host mapsPlacement::pins_runs()toClaimScope::Pinneditself. A pinned worker needs a stable worker id (a StatefulSet pod name), or the owner it set is never seen again.The mirror lock crosses processes. Under the in-process async lock,
adam-workspacetakes an exclusive advisory lock on<mirror>.lockwithstd::fs::File::lock(flock(2)on Linux), throughspawn_blocking. It makes a shared root safe for many worker processes. The lock file sits next to the mirror, never inside it, and it is released when the file is closed, so a crashed process frees it. Verified 2026-09-29:File::lockandTryLockErrorare stable since Rust 1.89; a test program built with 1.94.1 showed that a second handle to the same file, in the same process, getsWouldBlockfromtry_lockand succeeds afterunlock.adam-coderreads two variables.WORKSPACE_PLACEMENT(defaultshared) andWORKER_ID. A pinning placement withoutWORKER_IDis a configuration error (exit 78) that names the variable, because a random id would silently strand every run at the next restart.a2a-onlyis also a configuration error for the worker roles ofadam-coder, whose tools all need a workspace.affinityjoins<worker id>underWORKSPACE_ROOT;isolatedandshareduseWORKSPACE_ROOTas it is.
Consequences ​
- A pinned run whose owner is gone is stranded. If the worker that owns a run never comes back (a scaled-in pod, a deleted PVC), no other worker claims it, and nothing reports it, because a cheap check does not exist: a claim cannot tell "owner is busy" from "owner is gone". This is a known limitation of this decision. Adoption (a way to move a run to another owner, with its workspace) is future work. Until then a deployer who uses
affinityorisolatedkeeps worker ids stable and does not scale the workers in. - Isolated storage loses the workspace with the volume, and with it the pinned runs. That is the price of the placement, and it is the deployer's choice.
- flock on network volumes is unverified. The mirror lock relies on
flock(2)being honoured by the volume. Unverified 2026-09-29 for NFS and for Longhorn RWX; the deployer who pickssharedon such a volume should test two workers against one repository before relying on it. a2a-onlyexists for other hosts.adam-coderrejects it. A host whose agents only call remote agents, such as theanother-agentic-systemorchestrator, uses the same vocabulary and needs no workspace at all.Store::claim_duechanges signature (a breaking change for anyone who implementsStore). The testkit gets conformance cases so a third-party store proves the pinning.PlacementandClaimScopeare two closed enums that deployments and hosts depend on. Adding a variant is a breaking change on purpose.
Alternatives considered ​
- A worker id derived from the host name, with no configuration. A pod that restarts under a new name would strand its runs with no error. Rejected: the deployer must say the id is stable.
- Pin inside the run state. The pure
transitionwould have to know about workers. Rejected (ADR 0001 keeps the core pure). - Keep runs on one worker with a bare lease that never expires. It breaks crash recovery, the reason leases exist. Rejected.
- Make the run workspace-independent (push the worktree state on every step). It costs a commit and a push per step and loses the run notes anyway. Rejected as a default; a
Sharedvolume already covers the case. #[non_exhaustive]onPlacementorClaimScope. Rejected for the reason of ADR 0001.