magus v0.4.3 is out. See what's new
¶ View markdown source · ✎ Suggest an edit
3 min read

ADR 0015: a call runs where its line says

Decision proposed on .

Context

A worker forked with job fork --checkout owns a linked checkout, but the host decides where its shell starts. A subagent's call can begin in the parent's directory, and a cd does not persist from one Bash call to the next (Bash tool behavior). The lease rules read one location, the directory the host's envelope named, so a worker that typed ./magus run go-test . was graded, and its run was cached and written, in the parent's tree. The same envelope made a holder's cd <checkout> && magus affected ci look like a gate from the wrong checkout.

Shells also differ by host: Codex, Cursor and OpenCode each report a working directory in their own way, and some report none.

Decision

The guard places each magus call by its line

A shared resolver answers where a magus call runs: the directory the line has reached through a leading cd, moved by the call's own -C, --root and --root=, then the workspace root holding it. One that cannot be read without running the line (a variable, a substitution, ~, a call inside a conditional or loop) is placed where the host started, which is what every rule did before.

Item State
placeMagusCalls places every magus call on a line (internal/guard/lease.go) done
gatesInHeldCheckout and the Buzz gatesInHeldCheckout judge a holder's gate where the call runs done
actingIntegrator and denyWorkerCheckOnly's row judge read the workspace the line runs in done
background.go, bootstrap.go and the brief judge read the workspace each line runs in done
lease-checkout denies a holder's magus call that resolves outside its row's Worktree.Root, default deny done
magusCdTargets (shell.go) stays: it resolves same-line variable assignments and serves sibling-checkout done

lease-checkout

The holder of a row with a standing worktree is denied a magus call that resolves outside that worktree. The refusal quotes the line to run: <Root>/magus -C <Root> <args>, with the call's own -C dropped. A plan, a dry run, a graph and help pass. The rule is silent with no lease, a row with no worktree, the root session, and a line that runs no magus.

The CLI's root rules do not change

-C, --root and the nearest magus.yaml resolve the workspace as before. Only the guard reads the line.

Principles checked

  • No silent defaults: relied on. A call the line cannot place falls back to the envelope and the rule says nothing, rather than guessing a checkout.
  • A record of refusals: relied on. The lease-implied root is added as a refusal.

Alternatives

  • Rewriting the command through the host's updatedInput. Lost: the guard would edit what the model asked for, and the outer harness's own rewriting stays outside magus. The deny names the line to run and leaves the edit to the caller.
  • A MAGUS_ROOT environment variable, or a CLI root implied by the lease. Lost: a run's root would depend on state the line does not show, which is a silent default. A reader of the transcript could not tell which tree a command ran in. Reopen if a host can carry a working directory per subagent.
  • Judging with the binary the line names. Lost: there is one build per base, so the binary beside the checkout is the one that judges it already, and a second choice would run a different build over the same tree.
  • A WorktreeCreate hook template. Lost: host-only, so it does not reach the other hosts. Reopen with a mapping from a host's spawn to a job.

Consequences

  • A worker names its checkout on every magus line. The leases guide and the Claude Code page say so.
  • A cd <checkout> && magus affected ci passes for the holder from any directory, and a gate aimed at another checkout is refused.

Open questions

  • Whether a host reports a subagent's starting directory reliably enough to drop the fallback to the envelope.
adrdecisionguardleasesagentscheckouts
Last updated (2df714e8)
Earlier changes on this page (1)

Full history ↗ · Blame source ↗

Glossary

Workspace

The magus root directory that owns a set of projects and shared config; the unit magus operates over. Workspace in full.

Target

A named operation (build, test, ...) you invoke with magus run <target>; it may compose a spell's tool-native operations and depend on other targets. Target in full.

Op

A single tool-native command a target composes (long form: operation); the middle of the work hierarchy (Spell to Op to Target). Op in full.

Buzz

The language magusfiles are written in (the .buzz engine). Buzz in full.

Cache

The content-addressed store magus consults before running a target, so unchanged work is skipped. Cache in full.

Affected

The set of projects touched by a change; magus affected <target> runs a target only over them. Affected in full.

CI

An ordinary target you compose yourself with ctx.needs; magus does not hardcode its stages. It is the anchor magus affected ci keys off, and ci strips the rw charm. CI in full.

Agent

A model working through an agent host such as Claude Code, Codex, Cursor or OpenCode. magus treats an agent as one more caller of its CLI, MCP tools and console, held to the same checks as a person. Agent in full.

Tool

An action a model can call through its host: a name, a description, a typed input and a result. magus serves its tools over MCP, each a read of the workspace model or a run of the CLI it already has. Tool in full.

Harness

The deterministic scaffolding around the work on a change, for a person or an agent: compiler errors, formatters, linters, checks, gates, leases and hooks, placed at points a person chose. Around an agent's loop, magus supplies one and keeps it outside. Harness in full.

Session

An agent host's conversation, by the id the host delivers to its hooks. magus never mints one: a record with no session is unattributed, and the OS user it carries says whose account ran it. Session in full.

Job

The unit of delegated work, and one row of the job store: what an orchestrating agent handed out, with its goal, the checkpoint it was cut against, the paths it may write or must not touch, and the one check it runs. A job's holder is either a session, for work an orchestrator handed out, or the daemon, for its own maintenance. The store records; the agent guard is what reads those facts back when grading a write. Job in full.

Run

One target executing under one magus invocation, such as magus run test web or magus affected ci. A run keeps its captured output behind an output reference. Every magus run is a run whether or not any job asked for it; see Job for how the two relate. Run in full.

Lease

The grant a holder takes on a job: the write and read paths that job declared, enforced in the checkout that took it with magus job exec. A job is the piece of work; a lease is permission over it. Lease in full.

Conventions

Placeholders

Angle brackets mark a value you replace with your own; never type the brackets:

magus run <target>
magus completion <shell>    # e.g. bash, zsh, fish

<target>, <path>, <shell>, <name> and the like are stand-ins, not literal text.