Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/ADRs/0091-per-agent-runtime-model-effort.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ Config-layer addition, slotting in below per-run overrides:
> default
```

[ADR 0112](0112-task-grain-routing-policy-on-the-host.md) (decided, not yet
implemented) will add per-task `routing.rules` between the `FULLSEND_*`
variables and the `agents:` entry.

The repo-wide `runtime:` key is kept as the default for agents that set
none — deliberately not removed: existing configs, `fullsend github setup
--runtime` and the behaviour-test installs depend on it, and a default is
Expand Down
121 changes: 121 additions & 0 deletions docs/ADRs/0112-task-grain-routing-policy-on-the-host.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
title: "112. Runtime and model are routed per task by a config policy, on the host"
status: Accepted
relates_to:
- adaptive-agent-selection
- agent-architecture
- operational-observability
topics:
- config
- runtime
- routing
- cost
---

# 112. Runtime and model are routed per task by a config policy, on the host

Date: 2026-09-11

## Status

Accepted

<!-- ADRs are point-in-time records, but not fully frozen after acceptance.
Minor annotations are welcome: cross-references to related ADRs, short
notes linking to newer decisions, or clarifying remarks. However, do not
substantially rewrite the Context, Decision, or Consequences sections. If
the decision itself needs to change, write a new ADR that supersedes this
one. For evolving design narrative, use docs/architecture.md. -->

## Context

A repo can say *which* runtime, model, effort and persona model an agent uses
([ADR 0091](0091-per-agent-runtime-model-effort.md), [ADR
0104](0104-per-persona-model-resolution.md)) but not *when*.
Issues ask for cheaper runs on trivial changes (#5777, #2842, agents#497),
deeper review on security signals (agents#535) and a cost preview (#6560). The
deciding session's model is never downgraded (#6527), a listed model may be
unservable (#6964, agents#1225), and a learned policy keeps the constraints in
[adaptive-agent-selection.md](../problems/adaptive-agent-selection.md).

## Options

Rejected: **per-prompt routing in the sandbox** (#6361), which reads
author-controlled prompts and loses the prompt cache mid-loop, and a
**Route-job heuristic** (#6891), GitHub-only and a second decision point. An
**LLM gateway** stays only an optional provider that reports the model that
served.

## Decision

`fullsend run` resolves runtime, model, effort and persona models **per task,
on the host, before the sandbox exists**, from a `routing:` block in
`.fullsend/config.yaml`, declared in `repos.yaml` for repositories [ADR
0122](0122-declarative-repo-configuration.md) manages, where any change that
loosens routing is a relaxation under its safety gate. It configures a run that
dispatch has already authorized ([ADR
0098](0098-entity-first-harness-evaluation.md)) and never decides whether a run
happens.

1. **Shape.** `routing.rules[]` carry `agents:`, a CEL `when:`, an optional
`mode:` and a `set:` of the four fields an `agents:` entry holds. Matching
rules merge later-wins per field. While any matching escalation applies,
no field falls below the static choice or below the highest value an
escalation set, and a field with no order (runtime, a model of the same
model tier) keeps its static value. `routing.mode` is `off` (default),
`shadow` (rules are recorded, the static choice runs) or `enforce`, and a
rule may act less than its block, never more. A malformed block fails the
run before the sandbox exists. Rules override the agent's `agents:` entry
and the repo default; flags and `FULLSEND_*` variables still beat any
rule.
2. **Inputs are system-reported.** Rules see an allowlisted environment:
change stats and paths, actor, labels, attempt count and the linked
issue's number, state and labels. Author-written text is never visible;
paths and stats are author-chosen, a risk the reviewed policy accepts, but
a downgrade never applies to a change that touches agent-instruction or
policy files. A downgrade may key on a label or actor only through a
reviewed trust list that fails closed, and only on evidence the change's
author cannot supply. An escalation may key on anything visible.
3. **Guards.** A rule is an escalation only if it keeps the static runtime
and every other field it resolves is unchanged or above the static choice
(effort `low` to `max`; a changed model only on a higher catalog model
tier); anything else, including a runtime change or a swap to another
model of the same model tier, is a downgrade. Models come from
`routing.allowed_models` (empty by default) and the catalog. Agents in
`routing.never_downgrade` (default `triage`, `prioritize`, `review`; it
can only grow) keep their static runtime and keep their static model or
move to a higher model tier, and their personas never go below their
static model tier unless a persona file sets a lower `min_tier`;
escalations may raise both.
`routing:` and `min_tier:` come from the base branch or pinned harness,
never the change being routed. When `routing.mode` is not `off`, every
model is checked against its provider's served list before the sandbox
exists: a routed miss falls back to static, and a static miss fails the
run only when no model in its existing fallback chain is served.
4. **Echo.** The plan block, `metrics.json`, root span and status comment
name the rules that set each field and those a guard suppressed.
5. **Learning is offline.** A routing ledger on the root span ([ADR
0050](0050-distributed-tracing-instrumentation.md)), outcomes from later
forge events and a replay score candidate policies; a reviewed edit to
`routing:` is the only path to production, and a downgrade rule moves to
`enforce` only after replay shows it never downgraded a PR whose review
later requested changes.

## Consequences

- Docs-only downgrades and security escalations become reviewed config; a
downgrade of `review` reaches only its effort and opted-in personas, while
an escalation may also raise its model.
- For repos that turn routing on, the preflight ends the
retry-on-unavailable incident class on every provider that exposes a
served list; repos with routing `off` see no new failure mode.
- Implementing this adds a model tier to catalog entries and provenance fields
to ADR 0098's entity specification.

### Deferred

- **A routing advisor** that reads the diff (#6531) may fire an escalation
alone, but a downgrade rule may use its assessment only as one condition and
must still match with that condition removed; its classifier is an open
question in
[adaptive-agent-selection.md](../problems/adaptive-agent-selection.md).
1 change: 1 addition & 0 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ flowchart TB
**Decided (implementation):**

- The `fullsend run` runner delegates in-sandbox agent execution to a `runtime.Runtime` interface; production orgs default to Claude Code, with [pi](https://github.com/earendil-works/pi) available as an opt-in second runtime (`runtime: pi`, Claude-on-Vertex through the same WIF credential path) and [codex](https://github.com/openai/codex) as a third (`runtime: codex`, OpenAI-only through a custom model provider whose bearer token comes from a runner-seeded file, with the sandbox tool hooks behind a translating adapter — [ADR 0099](ADRs/0099-codex-agent-runtime.md) and [ADR 0100](ADRs/0100-codex-sandbox-hooks.md)). Runtime selection is configured per repo with `runtime:` in `.fullsend/config.yaml` (per-agent `runtime`/`model`/`effort`/`subagents` on the agent's `agents:` entry sit above it and below the `--runtime`/`--model`/`--effort` flags and `FULLSEND_*` variables, [ADR 0091](ADRs/0091-per-agent-runtime-model-effort.md)) and resolved via `runtime.ResolveForAgent()`. Test-only runtimes — **dummy** (scripted operations) and **dummy-playback** (playlist-based replay of canned results) — execute in the real OpenShell sandbox for behaviour tests without inference. Bootstrap uses a portable `BootstrapInput` interface with optional extensions such as `SandboxHooksBootstrap` for the runtime-neutral sandbox tool hooks ([ADR 0090](ADRs/0090-runtime-neutral-sandbox-hooks-contract.md)); runtimes declare further capabilities through small optional interfaces (`DebugLogNamer`, `ContextBridger`) rather than `Name()` checks in the runner. Transcript and debug artifact handling use a separate `TranscriptHandler` interface. See [runtimes.md](runtimes.md) for the per-runtime security feature matrix required when adding a new backend.
- Runtime, model, effort and persona models will be routed **per task** by a `routing:` policy in `.fullsend/config.yaml`, resolved by `fullsend run` on the host before the sandbox exists from allowlisted, system-reported task facts; a rule sits below the per-run flags and variables and above the agent's `agents:` entry, a downgrade rule moves to `enforce` only after `shadow` and replay evidence, and every rule is bounded by guards the ADR lists (decided in [ADR 0112](ADRs/0112-task-grain-routing-policy-on-the-host.md), not yet implemented).
- Plugins are runtime-scoped harness resources: a harness declares `plugins:` as one list of directories in its own repository (same trust and fetch path as skills), and each entry's format decides which runtime loads it — a `plugin.json` bundle is Claude Code's, a directory pi's `-e` loader resolves is uploaded and loaded after a tree-hash preflight computed from the host copy. Each runtime names and skips the entries in the other format, so the list survives a runtime switch. Because `--no-extensions` plus explicit `-e` closes the set of code that can register tools, no per-tool declaration is needed ([ADR 0094](ADRs/0094-pi-extensions-are-harness-resources.md)).

### Behaviour testing
Expand Down
1 change: 1 addition & 0 deletions docs/contributing/tier-conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ The term "tier" is used in multiple distinct contexts across this codebase. Alwa
| **credential delivery tier** | The four-tier model for how agents receive credentials: (1) prefetch + post-process, (2) providers + L7, (3) host-side REST server, (4) host files | [ADR 0025](../ADRs/0025-provider-credential-delivery-for-sandboxed-agents.md) |
| **intent authorization tier** | The four-tier model for change authorization: (0) standing rules, (1) tactical/issue, (2) strategic, (3) organizational | [intent-representation.md](../problems/intent-representation.md) |
| **configuration tier** | The three-tier inheritance model for agent configuration: upstream defaults -> org config -> per-repo overrides. The `customized/` overlay mechanism (ADR-0035) has been removed; use config-driven agent registration per [ADR 0064](../ADRs/0064-deprecate-customized-directory-overlay.md) | [ADR 0035](../ADRs/0035-layered-content-resolution.md) |
| **model tier** | The ordinal on a model catalog entry that per-task routing uses to tell an escalation from a downgrade and to floor persona models (decided, not yet implemented) | [ADR 0112](../ADRs/0112-task-grain-routing-policy-on-the-host.md) |

**Do not** use bare "Tier N" or "tier" without a prefix — the same number means different things in different contexts (e.g., "Tier 2" could be provider-based credential delivery or strategic intent authorization). External tier references (e.g., "GitLab Free tier", "GitHub plan tiers") are exempt from this convention.
5 changes: 3 additions & 2 deletions docs/problems/adaptive-agent-selection.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,10 @@ The experiment should actively pressure-test three assumptions:
- GA vs. Thompson Sampling — or both at different layers? TS for team/config selection, GA for workflow evolution is the leading hypothesis, but it needs validation.
- How fine-grained should context tuples be? A hierarchical split-on-variance approach avoids committing to a fixed schema, but adds implementation complexity.
- How do we handle model version changes — reset fitness data, apply a discount, or version-tag and keep history?
- Should the fitness function include a cost term from the start, or should cost optimization be a separate experiment after quality optimization is validated?
- Should the fitness function include a cost term from the start, or should cost optimization be a separate experiment after quality optimization is validated? (For runtime and model selection, [ADR 0112](../ADRs/0112-task-grain-routing-policy-on-the-host.md) scores candidate routing policies offline by replaying a ledger of routing choices against later forge outcomes, and a downgrade rule reaches `enforce` only after replay shows it never downgraded a PR whose review later requested changes; the composite fitness and cost-term questions remain open.)
- What is the right exploration budget, and how should it decay? Too high wastes runs on poor configurations; too low starves new options.
- Can fitness data transfer across repos with similar characteristics, and how do we measure "similar"?
- How should the adaptive layer interact with the deterministic safety model — is selection-only sufficient, or are there edge cases where the choice of configuration implicitly affects safety coverage?
- How should the adaptive layer interact with the deterministic safety model — is selection-only sufficient, or are there edge cases where the choice of configuration implicitly affects safety coverage? (Partially decided in [ADR 0112](../ADRs/0112-task-grain-routing-policy-on-the-host.md) for the runtime/model surface: selection only over four config fields, with a closed model set, a never-downgrade set that never lowers the deciding session's model and floors its personas unless they opt in (its effort may still drop), and no author-written text as a routing key; paths and change stats are author-chosen facts a policy may still key on.)
- What prevents a well-scoring configuration from being well-scoring only because it is assigned to a biased subset of tasks (selection bias in the evaluation)?
- Should there be a human-in-the-loop approval step before any configuration is retired, or is soft retirement with recovery probing sufficient?
- Can a decision model classify tasks for routing? [ADR 0112](../ADRs/0112-task-grain-routing-policy-on-the-host.md) defers a routing advisor that reads the diff and leaves its classifier open. A purpose-built decision model such as [Jev](https://typesafe.ai/blog/introducing-system-one-models-and-jev) or [Laya](https://www.layer3labs.io/guides/laya-explained) returns a probability for each label of a closed set rather than text, so a steered input can only pick a wrong label and fullsend could set its own abstention threshold from that distribution. Open: whether such a model matches a small fast LLM on labelled fullsend tasks, and whether it can sit on the repo's own inference path (an open-weight, self-hosted model can; a hosted decision API cannot unless it becomes a provider there).
2 changes: 1 addition & 1 deletion docs/problems/operational-observability.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ This works for early experimentation when the volume is low and the operators ar
- ~~How do we keep the triggering event and the agent run linked in the GitHub Actions UI for debugging?~~ Decided in [ADR 0041](../ADRs/0041-synchronous-workflow-call-event-dispatch.md) (synchronous `workflow_call` dispatch for the event path).
- How should trace access be controlled? (JSONL trace exposure decided in [ADR 0021](../ADRs/0021-jsonl-reasoning-trace-exposure.md): owner-scoped storage with credential scanning as defense-in-depth. Broader question of balancing security and transparency for non-JSONL observability data remains open.)
- What retention policy applies to traces? Indefinite retention supports audit requirements but increases storage cost and data sensitivity exposure. Time-bounded retention (e.g., 90 days) limits exposure but may lose traces needed for incident investigation.
- How do we measure "is the system getting better"? What metrics constitute a meaningful quality signal for an autonomous software factory? Merge revert rate? Human override rate? Time-to-review? Cost per decision? Some composite score? The choice of metric shapes what gets optimized. First-ship trend scores (trace fitness on wild runs, local `eval-measurements.jsonl`) are [ADR 0087](../ADRs/0087-eval-measurements-online-trace-scoring.md); richer quality signals remain open.
- How do we measure "is the system getting better"? What metrics constitute a meaningful quality signal for an autonomous software factory? Merge revert rate? Human override rate? Time-to-review? Cost per decision? Some composite score? The choice of metric shapes what gets optimized. First-ship trend scores (trace fitness on wild runs, local `eval-measurements.jsonl`) are [ADR 0087](../ADRs/0087-eval-measurements-online-trace-scoring.md); richer quality signals remain open. Routing decisions and the task facts behind them will be recorded as a routing ledger on the root span so outcomes can be compared across model choices (decided in [ADR 0112](../ADRs/0112-task-grain-routing-policy-on-the-host.md), not yet implemented).
- Should trace scoring cover run *health*, not just trace *health*? Trace *fitness* ([ADR 0087](../ADRs/0087-eval-measurements-online-trace-scoring.md)'s `trace_fitness`) checks that a run's telemetry is well-formed — span tree, identity, model, usage, cost, and exit present and coherent — but not whether the run *behaved* correctly. A separate class of failure is structurally decidable straight from the trace, with no model in the loop: a tool that returned an error the run then ignored, an errored result reused by a later side-effecting call, no-progress loops, or a job that reports success despite an in-trace failure (e.g. [#6621](https://github.com/fullsend-ai/fullsend/issues/6621)). Two questions follow. First, does the eval-measure layer grow a second scorer for these run-*health* defects — the deterministic complement to the statistical evals in [testing-agents.md](testing-agents.md), catching what is provable from a single trace rather than what needs repeated runs — or does behavioral correctness belong with the review and retro agents instead? Second, there is a prerequisite either way: the structured-trace ideal described above records each tool call's result, but tool *results* are only partly on the trace: `execute_tool` spans carry per-call error status (`error.type=tool_error` when a result is flagged `is_error`, [ADR 0108](../ADRs/0108-tool-call-span-topology.md)) only for id-bearing calls — Claude Code today; pi and codex emit no call ids ([#7414](https://github.com/fullsend-ai/fullsend/issues/7414)) — and result content is recorded only at opt-in Level 3 ([ADR 0050](../ADRs/0050-distributed-tracing-instrumentation.md)), again on Claude runs only. The highest-value rules therefore still depend on extending capture across runtimes and levels — itself a telemetry-contract decision. Prior discussion in [#7246](https://github.com/fullsend-ai/fullsend/issues/7246).
- At what scale does a dedicated LLM observability platform justify its operational overhead (Postgres, ClickHouse, Redis, S3 for something like Langfuse)? Is there a threshold of agent activity below which structured logging suffices? Score files are local JSONL ([ADR 0087](../ADRs/0087-eval-measurements-online-trace-scoring.md)); remote scores reuse `OTEL_EXPORTER_OTLP_*`. Platform choice remains open.
- ~~How do we handle the bootstrapping problem — the factory needs observability to improve, but building the observability infrastructure is itself work that competes with building the factory?~~ Decided in [ADR 0050](../ADRs/0050-distributed-tracing-instrumentation.md): zero-configuration baseline (local JSONL + summary files) eliminates infrastructure requirements for initial observability; OTLP export adds backends when the org is ready.
Expand Down
Loading