RFC: decouple agent identity from runtime — bindings, execution policies, quota-aware recovery
Problem
Today an agent is bound to exactly one runtime (agent.runtime_id) and carries its execution config (model, thinking_level, custom_env, custom_args) on the agent row. A large cluster of open requests traces back to this coupling:
- Availability: if the runtime is offline or the provider hits a quota/rate limit, the agent cannot run. There is no fallback (#1398, #3577, #3779, #6531), and provider-limit failures are intentionally non-retryable today.
- Team sharing: collaborators who want the same agent (instructions, skills, methodology) on their own machines must duplicate it, which forks the definition and fragments cost tracking (#4513, #4979, PR #2970).
- Scaling: no way to spread one agent's runs across several runtimes (#1900, #1981, #4205).
- Cost: a run's (provider, model) is only known after the fact via
task_usage; a shared agent burns one person's quota for the whole team (#4513).
When closing PR #6413 (provider-limit failover), the maintainer stated the platform direction: distinguish quota reset vs rate limit vs provider capacity, prefer pause/resume with an explicit recovery policy, and make any billing or identity transition visible and opt-in — this needs "a different platform design, not incremental changes" (#6413 closing comment). This RFC proposes that platform design. It is a design proposal, not an implementation report; the "Design decisions to validate" section lists the points where maintainer input is most needed.
Terminology
| Term | Meaning |
|---|---|
| Agent owner | Member who owns the agent's identity (instructions, workspace skills) and may delegate editing. |
| Binding | An (agent, runtime) execution config. Its owner is the member who created it — normally the runtime's owner — and whose account/quota its runs consume (the payer). |
| Originator | The user whose action triggered a run (existing originator_user_id / accountable_user_id chain). Responsibility ≠ payment: the originator is accountable for the run; the binding owner pays for it. |
| Task / attempt | A task is one unit of queued work. Each (re-)dispatch of that task through a selected binding is an attempt with its own record. |
| Quota pool | The provider account/credential whose rate/usage windows a binding draws from. Several bindings — even on different runtimes — may share one quota pool (same Claude account on two machines). |
Proposed model
1. Two layers: identity vs binding
Agent = identity (shared, governed): name, avatar, instructions, workspace skills (agent_skill), invocation permissions, agent-global concurrency cap. Instructions and workspace skills are already stored server-side and bundled to whichever machine executes, so they travel identically to any runtime. The agent owner edits this layer and can delegate editing to chosen members — answering the open governance objection in the #4513 thread (who decides the iteration of a shared agent).
Binding = execution config: new agent_binding entity — (agent_id, runtime_id, owner_id, model, thinking_level, service_tier, custom_env, custom_args, disabled_runtime_skills, priority, enabled). Everything provider-dependent moves off the agent into bindings. Each member fully owns their bindings; creating a binding is explicit consent that this agent may consume that runtime's quota. Runtime-local skills remain a per-binding concern: the UI surfaces the effective config per binding (skills present here but not there, differing models), and the nominal path for a locally useful skill is promotion to a workspace skill.
Per repository rules: no DB foreign keys; relationship integrity and cleanup are handled transactionally in application code (runtime deleted → its bindings removed and queued tasks re-resolved or unbound; member removed → their bindings disabled; agent archived → bindings inert). All new indexes use CREATE INDEX CONCURRENTLY, one per migration file.
flowchart LR
subgraph identity["Agent identity (shared, governed by owner)"]
A["Reviewer<br/>instructions · workspace skills<br/>permissions · policy · concurrency cap"]
end
subgraph alice["Alice's bindings (her quota)"]
B1["binding p1<br/>claude · opus"]
B2["binding p2<br/>codex · gpt"]
end
subgraph bob["Bob's binding (his quota)"]
B3["binding p1<br/>claude · opus"]
end
A --> B1 --> R1["runtime: alice-mac / claude"]
A --> B2 --> R2["runtime: alice-mac / codex"]
A --> B3 --> R3["runtime: bob-laptop / claude"]2. Execution snapshots and attempts
Bindings are mutable config; runs must be reproducible. Two consequences:
- Snapshot at dispatch: when an attempt starts, the effective execution config (binding id + resolved model/args/env/skill set) is frozen onto the attempt. Editing a binding affects future attempts only. "What ran" is always answerable from the attempt record, independent of later edits.
- Attempt history, not a single
binding_id: a task that was re-dispatched carries one record per attempt — requested binding, executed binding, selection reason (or rejection reason), timestamps. This is also what makes billing transitions visible: the history shows exactly which binding/runtime/account served each attempt.
A side benefit: (provider, model) becomes known at enqueue instead of being reconstructed from task_usage after the fact.
3. Selection: execution policy per agent
Selection is governed by an explicit per-agent policy — not inferred from binding count (adding a second binding must never silently enable fallback):
pinned— exactly one designated binding; if unavailable, the task waits or fails visibly. Today's behavior, and the migration default for existing agents.owner_first— among the originator's own bindings: local before remote, first candidate that is online and has quota headroom, ordered by the binding'spriority. The originator pays with their own quota. No cross-billing is possible under this policy. This is what #4979 (option A) and PR #2970 ask for, without a parallel per-user table — bindings already carryowner_id.shared_pool—owner_first, then bindings contributed by other members. Both consents are required: the binding owner opted in by creating the binding, and the agent opted in by selecting this policy. Every attempt served by someone else's binding is visible in run history and Inbox.
Invariants across all policies:
- Stickiness: work in progress (retries resuming a session, follow-ups on a live conversation) stays on the daemon that owns the worktree/session. Selection applies to fresh attempts, never to rebalancing an in-flight one.
- No silent transitions: every attempt records which binding served it and why the previous one was rejected.
- Deterministic ordering: candidates are ordered by (circle, binding priority, binding id) — no unspecified tie-breaking.
Selection lifecycle. Selection runs each time an attempt is created — neither once at enqueue (which freezes stale online/headroom data) nor at claim (which does not fit the runtime-sharded pull queue: daemons only see their own work and none can arbitrate for the others). The flow:
- Enqueue — the task is created with the agent and its policy; no binding is fixed yet. The only admission check is that at least one binding is plausibly available (otherwise a visible refusal, like today's
agent_runtime_required). - Selection (server-side) — the server creates an attempt by picking the best candidate binding at that moment, against fresh signals: policy circles, runtime online status (heartbeat), quota headroom (telemetry), binding health/cooldown, and the deterministic ordering above. The effective config is snapshotted onto the attempt.
- Stickiness short-circuits selection — if the task resumes existing work (retry with a session, follow-up on a live conversation), the binding is forced to the daemon holding the worktree/session; policy applies to fresh work only.
- Claim (daemon-side) — the attempt is visible only to its binding's runtime. The daemon is woken (existing
NotifyRuntimeMayHaveWork) or discovers it by polling, and claims it atomically. TodayClaimTaskmatches onagent_idonly, which can hand a task to a runtime other than the one that listed it; multi-binding makes a binding-constrained atomic claim a prerequisite, not an optimization. - Lease — if the runtime does not claim within a lease window (e.g. it just died but its heartbeat has not expired yet), the attempt expires and selection re-runs with the next candidate. The same loop handles failures before
provider_session_started: new attempt, next binding. After session start, selection never re-runs — only pause/resume in place (see failure handling).
In short: the server chooses the runtime at attempt creation on fresh data, the daemon only confirms via an atomic claim, and selection may replay as long as nothing has started — never after. (See "Worked examples" below for concrete walkthroughs.)
sequenceDiagram
participant U as Trigger (user / Autopilot)
participant S as Server
participant D as Daemon (binding's runtime)
U->>S: enqueue task (agent + policy)
S->>S: admission: any binding plausibly available?
S->>S: select binding (circles, online, headroom, health)<br/>snapshot effective config onto attempt
S->>D: attempt visible to this runtime only + wake
alt claimed within lease
D->>S: atomic claim (binding match + concurrency caps)
D->>D: run
else lease expires or pre-session failure
S->>S: mark attempt rejected (reason recorded)
S->>S: re-select with next candidate
end4. Concurrency model
Three limits of different natures compose; none replaces another:
- Agent-global cap (
max_concurrent_tasks, exists today, default 6) — stays on the identity layer and becomes a cap across all bindings: the agent never runs more than N attempts in parallel, wherever they execute. It is a property of the teammate (how much work it takes on), not of a machine. A parked attempt releases its slot — otherwise one exhausted quota window would freeze the agent's entire capacity. - Per-runtime cap (new, #4205, phase 5) — a property of the machine: how many parallel runs this host sustains, across all agents. Required before pooled execution: without it, load distribution can overwhelm a contributor's machine.
- Semantic serialization (exists today, unchanged) — never two active runs of the same agent on one issue or one chat session. This is ordering, not capacity: a conversation must not reply to itself in parallel.
All three are enforced at claim time, in one atomic transaction (the same FOR UPDATE SKIP LOCKED path as today): agent cap counted across runtimes, runtime cap, and attempt↔binding match. Since every daemon claims against the same PostgreSQL, counting active attempts across bindings at claim requires no distributed coordination.
5. Failure handling: per-class, progress-fenced
"Fall back to the next binding" is too coarse. Two orthogonal axes decide what happens:
Progress fence. The daemon reports structured attempt progress: provider_session_started, first_side_effect_observed (tool execution, file write, network call), retry_after hints, quota scope. An attempt is re-dispatchable to another binding only before provider_session_started. After that, side effects may exist and the only safe automatic actions are: pause/resume on the same binding, or surface to the user. We deliberately do not claim "zero replay risk" for any resumed session — resume minimizes but cannot eliminate re-execution; the fence bounds automatic behavior to the provably-unstarted case.
Failure class (mapped from the existing taskfailure classifier):
| Class | Before session start | After session start |
|---|---|---|
runtime_offline |
Re-dispatch per policy | Park; resume on same binding when runtime returns (existing recovery), or surface after timeout |
Quota window exhausted (provider_quota_limit with known reset) |
Deprioritize that quota pool; re-dispatch per policy | Park with resets_at, auto-resume on same binding (extends existing wait_reason/fire_at machinery; note fire_at promotion currently rides runtime polling, so parked-task wakeup for an offline runtime needs an explicit wake path) |
Rate limit / overload (provider_capacity_or_rate_limit) |
Brief backoff, then re-dispatch per policy | Backoff and retry same binding (bounded), else park |
| Auth / access / missing config | Skip binding, mark it unhealthy, notify binding owner | Fail visibly (user must act) |
| Model unavailable on this runtime | Skip binding | Fail visibly |
Parking semantics to define explicitly in design review: parked attempts release their concurrency slot; bounded number of park/resume cycles; cancellation always available; chat-session ordering preserved by the existing per-(session, agent) serialization.
stateDiagram-v2
[*] --> Queued: enqueue
Queued --> Dispatched: binding selected,<br/>snapshot frozen
Dispatched --> Queued: lease expired /<br/>pre-session failure → next binding
Dispatched --> Running: provider_session_started<br/>(progress fence — no re-selection past this point)
Running --> Parked: quota exhausted (resets_at) /<br/>runtime offline
Parked --> Running: resume on the SAME binding<br/>(reset reached / runtime back)
Parked --> Failed: cycles exhausted / cancelled
Running --> Completed
Running --> Failed: non-recoverable<br/>(auth, config — surfaced to user)
Completed --> [*]
Failed --> [*]Quota pools. Quota is scoped to a provider account, not to a binding: two bindings on the same account share one window. v1 treats quota telemetry as advisory, keyed by runtime (see Phase 1); a first-class quota-pool identity shared across bindings is listed as an open design decision. The telemetry source exists today: the daemon already parses Codex session events whose rate_limits block (used_percent, resets_at for the 5h and weekly windows) is currently discarded at unmarshal (#6000); #5950 asks for exactly this reset-aware requeue.
Headroom feeds selection before failure too: a binding whose quota pool is near exhaustion is deprioritized rather than selected and failed.
6. Cost and attribution
Unchanged: runs are attributed to the originator (existing attribution chain). Cost becomes queryable along both axes that matter:
- Payer view — by runtime/binding owner: already served by
task_usage_hourly(keyed by workspace, runtime, agent, project, provider, model). - Originator view — "what did this member's triggers cost across all runtimes": requires an originator dimension in usage rollups. This is a substantial workstream on its own (rollup schema, backfill, dashboard) and is scheduled as such, not as a side effect.
Worked examples
A. Cross-provider quota fallback (one member, one machine). Agent "Dev", policy owner_first, three bindings the member owns on their machine: priority 1 (claude, opus), priority 2 (codex, gpt), priority 3 (kimi, k2) — each CLI is a distinct runtime, so this needs no special mechanism. When the Claude quota window is exhausted, a fresh task skips the claude binding (headroom telemetry, or a provider_quota_limit failure before session start) and its next attempt runs on codex — same instructions and workspace skills, since those are server-side and travel identically. The attempt history reads claude/opus rejected (quota) → codex/gpt executed; usage is recorded under the actual (provider, model). The claude binding sits in cooldown until resets_at, then returns to priority 1. A task mid-flight on claude does not switch provider: it parks and resumes on claude at reset. Note that intra-provider model fallback (opus → sonnet, #6531) usually does not help against subscription quotas — the usage window is scoped to the account, not the model, so both exhaust together. Effective quota fallback is cross-provider, which is also why an account-scoped quota-pool identity (section 5) matters.
sequenceDiagram
participant S as Server
participant C as claude binding (p1)
participant X as codex binding (p2)
Note over C: Claude 5h window exhausted
S->>C: attempt 1
C-->>S: provider_quota_limit (resets_at 15:00)<br/>before session start
S->>S: cooldown claude binding until 15:00
S->>X: attempt 2 (fresh session, same instructions/skills)
X-->>S: completed — usage recorded as codex/gpt
Note over S: next fresh tasks go straight to codex until 15:00
Note over C: a task already MID-FLIGHT on claude parks<br/>and resumes here at 15:00 — it never switches providerB. Shared team agent, each member on their own quota. "Reviewer" is owned by Alice (identity: instructions + workspace skills), policy owner_first. Alice and Bob each created a binding on their own machine. When Bob assigns an issue to Reviewer, selection starts from Bob's bindings: the run executes on Bob's machine, on Bob's quota. Alice's edits to the instructions apply to everyone's next runs; Bob's binding config (model, env) affects only his. Cost dashboards answer both "what did Bob's triggers cost" (originator view) and "what did Bob's account pay" (payer view) — here they coincide, because owner_first never crosses billing boundaries.
C. Laptop + always-on remote (one member). Same member, two bindings: priority 1 on the laptop, priority 2 on an always-on server. A task triggered while the laptop is online runs locally. A task fired by Autopilot at 3 a.m. with the laptop closed selects the server binding — recorded in the attempt history, no manual re-pinning (#3779's scenario). If the laptop dies mid-run, the existing runtime_offline recovery parks the attempt; it resumes on the laptop's daemon when it returns (stickiness: the worktree and session live there), or surfaces to the user after a timeout — it does not silently restart elsewhere.
D. No runtime of your own: the shared pool. A PM with no daemon triggers "Reviewer", which uses shared_pool. The first circle (their own bindings) is empty, so selection falls through to pool bindings contributed by teammates — say Alice's server binding. The run is attributed to the PM (originator/accountable), executes on Alice's quota (payer), and both facts are visible: the run history names the executing binding, and Alice's payer view shows the consumption. Alice consented twice: by creating the binding, and because the agent's owner enabled shared_pool. Under owner_first this same trigger would be refused visibly ("no available binding") instead of silently spending Alice's quota.
E. Existing agent, untouched. An agent migrated from today's schema has one binding (its former runtime_id + model/env fields) and policy pinned. Behavior is byte-for-byte today's: runtime offline → task waits or fails visibly; quota exhausted → error surfaced. Nothing changes until someone deliberately adds a binding and switches the policy.
API compatibility
Installed desktop clients read agent.runtime_id and edit execution fields on the agent. Transition plan:
- The API keeps serving
runtime_id,model, etc. on the agent object, sourced from the agent's primary binding (pinned target, or highest-priority binding). Legacy writes to these fields are mapped to the primary binding. - New binding-aware endpoints are additive. Frontends parse them with zod schemas +
parseWithFallbackper the existing API-compatibility rules; a client that knows nothing about bindings keeps working with si
Source: multica-ai/multica