agentprovision

package
v0.280.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation ¶

Overview ¶

Package agentprovision adapts a provision.Provisioner DRIVER to the LIFECYCLE interface the agent HTTP handlers depend on (api.Provisioner): seven methods over an agent's int64 database id, rather than over a provision.Ref and a provision.Spec.

🔴 IT IS THE LIFECYCLE HALF ONLY, AND THAT IS WHY IT CAN EXIST AT ALL. The consumer interface used to carry Chat and ChatWithTools as well, behind one nil and one wrapper, so nothing could wire provisioning without also claiming a model gateway this module has no implementation of. api.Provisioner and api.Gateway are now separate interfaces with separate nils and separate wrappers; this type satisfies the first and deliberately not the second, so a deployment gets working lifecycle routes and an honest 503 on the two chat ones. See internal/api/ext.go on api.Gateway.

🔴 WHAT THIS PACKAGE MUST NEVER DO, STATED BEFORE ANYTHING ELSE: it must never call agents.Store.SetKickedOff. That column answers "was the kickoff message HANDED TO A READY GATEWAY" — see agents.Agent.KickedOff and agents.Store.SetKickedOff — and this package has no gateway, so setting it would be a claim about a delivery that did not happen. That is the same class of lie the provisioner wrappers exist to prevent (a 200 over a pod that does not exist), one field down. It is not left to a reader's care: TestTheAdapterNeverClaimsAKickoffItCannotDeliver asserts it over the whole method set.

WHAT HAPPENS TO A PENDING KICKOFF INSTEAD: the instance is created, the note stays in agents.pending_note where it was written, and the non-delivery is RECORDED on the row via agents.Store.SetKickoffError — the field whose own doc calls it "evidence, not a verdict".

🔴 THAT IS NOW THE *DELIVERABLE* PATH ONLY, AND THE PARAGRAPH ABOVE IS KEPT RATHER THAN REWRITTEN BECAUSE EVERYTHING BELOW IT ARGUES FROM IT. When nothing in this process could deliver a kickoff, Dispatch(kickoff=true) no longer creates anything: it REFUSES. See Config.KickoffDeliverable, ErrKickoffUndeliverable and KickoffRefusalReason.

✅ AND THE DELIVERABLE ARM IS NOW CREATE-THEN-DELIVER, NOT CREATE-THEN-RECORD. internal/agentkickoff is the deliverer KickoffDeliveryWired waited for: cmd/muster-server runs it whenever it builds a gateway, so on a deployment that names one, Dispatch(kickoff=true) creates the instance, stores `provisioning`, and the deliverer hands the pending note to the instance once it is ready. Nothing is written to kickoff_error on that path unless a delivery actually fails. With no gateway named the dispatch is still REFUSED, as below.

WHY THE CREATE-THEN-RECORD BEHAVIOUR WAS THE WRONG ANSWER TO "I CANNOT DELIVER THIS": it answered a request this configuration cannot satisfy by performing the expensive, credential-holding, healthy-looking HALF of it. The surface an operator actually drives is a Dispatch button that always appears to work; the cost per click is a pod with a cloned repository and a model credential that will never be told what to do; and the only evidence was this pod's stdout plus a machine-tier field, both of which the paragraphs below correctly call unread. A request that cannot do the thing it was asked to do should say so, not do something else.

🔴 AND THE CONDITION IS CONFIGURATION, NOT A MISSING IMPLEMENTATION. internal/agentgateway is shipped and live-verified; MUSTER_AGENT_GATEWAY being unset is the whole of why nothing can deliver. Both the refusal text and the constant below say so, because the earlier wording ("this build cannot deliver") reads as an unimplemented feature and sends its reader to write code that exists.

🔴 AND NOTHING RENDERS THAT FIELD TO A HUMAN. THIS PARAGRAPH PREVIOUSLY CLAIMED IT DID, AND THE CLAIM WAS MEASURED FALSE — it is recorded here rather than quietly corrected, because it is the most load-bearing sentence in this doc. It read: "rendered into the agent's error line by agents.KickoffErrorSuffix. So the operator sees WHY the first turn never ran rather than a card that sits in `provisioning` with nothing written anywhere." Three things are wrong with that:

  • agents.KickoffErrorSuffix has NO caller anywhere in this module. Its only references are agents/reconcile_test.go and prose; the reconcile loop that would call it is explicitly OWED in reconcile.go's own header.
  • Agent.KickoffError reaches exactly ONE surface — GET /api/agents, which is hook-token-gated MACHINE tier (internal/api/machine_agents.go). No HTML view carries an agent error field at all.
  • the card does NOT "sit in provisioning". agents.ComputeStatus refines a live ready instance to `running`, so the card reads HEALTHY while the first turn never happened. That is worse than the state the sentence claimed to fix.

So: the field is where a MACHINE or an operator with a token can read it, and the boot banner names it — which is honest, because the banner names a field and not a screen. Nothing on any page says it. Do not restate the rendering claim without a caller to cite.

✅ THE FIRST AND THIRD BULLETS ARE CLOSED NOW, THE SECOND IS NOT — read which is which before quoting any of it. agents.KickoffErrorSuffix has a caller: internal/agentkickoff appends it to the error_message it writes when a first turn never arrives, so an undelivered kickoff DOES escalate to `error` once it has dwelt past agents.ProvisioningStuckTimeout — a red status DOT on the card, with the last send failure in error_message (machine tier only). And the card no longer reads healthy over an owed turn: agents.KickoffOwed renders a "kickoff owed" badge. What is unchanged is the second bullet: the REASON in kickoff_error reaches one hook-token-gated JSON route and no page.

Index ¶

Constants ¶

View Source
const (
	StepBuildSpec           = "build spec"
	StepApplyInstance       = "apply instance"
	StepScaleUp             = "scale up"
	StepCreateInstance      = "create instance"
	StepDestroyInstance     = "destroy instance"
	StepReadCredentials     = "read credentials"
	StepMintHooksToken      = "mint hooks token"
	StepStoreHooksToken     = "store hooks token"
	StepMintTurnCredential  = "mint turn credential"
	StepStoreTurnCredential = "store turn credential"
)

The step a failed lifecycle call names in the agent's error_message (fail: "<step>: <cause>", or "<step> <detail>: <cause>"). Exported because the officer wake loop classifies an instance in error by them (internal/api classifyInstanceError) to decide whether restarting it can help: a reader keyed on the same constant the writer uses cannot drift from it.

View Source
const AnonymousFetchMessage = "" /* 156-byte string literal not displayed */

AnonymousFetchMessage opens the error of a job whose checkout's own git configuration would rewrite the anonymous fetch URL or add a header or a credential to it.

View Source
const BaseFetchMessage = podagent.BaseFetchMessage

BaseFetchMessage opens the error of a job whose base_sha could not be fetched; the base follows it.

View Source
const BaseRefSuffix = "-base"

BaseRefSuffix is what a job's base ref adds to its pull-request ref: refs/muster-jobs/<job id>-base.

View Source
const ConfigRefNotOnDefaultBranchMessage = "" /* 134-byte string literal not displayed */

ConfigRefNotOnDefaultBranchMessage opens the error of a job whose config_ref is not reachable from the repository's default branch; the default branch's tip follows it.

View Source
const ConfigRefStrippedMessage = "" /* 179-byte string literal not displayed */

ConfigRefStrippedMessage opens the error of a job with a config_ref on an agent whose jobs get none of the repository's configuration (agentspec.StripsRepoConfig). The job API refuses such a job when it is submitted; this holds when the configuration moved since.

View Source
const DefaultAnonymousGitBase = "https://github.com/"

DefaultAnonymousGitBase is the anonymous fetch base: the public GitHub.

View Source
const DefaultBranchFetchMessage = "" /* 159-byte string literal not displayed */

DefaultBranchFetchMessage opens the error of a job whose config_ref is not on the checkout's origin/HEAD and whose default branch could then not be fetched anonymously to look for it there.

View Source
const DefaultOpTimeout = 5 * time.Minute

DefaultOpTimeout bounds one lifecycle operation.

🔴 IT EXISTS BECAUSE FOUR OF THE SEVEN METHODS TAKE NO context.Context. The consumer interface's Dispatch/Start/Stop/Destroy are called from handler goroutines that hand over nothing, so without a budget here a wedged backend call holds a goroutine for the life of the process — and the handler has already returned, so nothing is left to cancel it. The driver operations under it APPLY objects rather than wait for readiness (see the kubernetes driver's Create), so this is generous rather than tight on purpose: it is a leak guard, not a latency policy.

View Source
const DeployKeyRepoMismatchMessage = "" /* 159-byte string literal not displayed */

DeployKeyRepoMismatchMessage opens the error of a job whose repository is not the one its worker pool's deploy key is configured for.

View Source
const DeployKeyWritableMessage = podagent.DeployKeyWritableMessage

DeployKeyWritableMessage opens the error of a job whose worker pool's deploy key could open GitHub's receive-pack: it can push, so it was not used.

View Source
const KickoffDeliveryWired = true

KickoffDeliveryWired reports whether THIS MODULE contains production code that hands an agent's pending note to its model gateway — a kickoff DELIVERER.

✅ IT IS TRUE: internal/agentkickoff is that deliverer. cmd/muster-server builds it whenever a gateway is built and runs it as a background loop, which drives agents.DecideReconcile over owned, never-kicked-off rows and delivers through the same agentgateway.Gateway that POST /api/agents/{name}/messages calls, using Chat's two halves (Resolve before the delivered stamp, Send after it).

🔴 IT IS STILL ONLY THE SECOND HALF OF THE PREDICATE. Delivering a kickoff needs a gateway this process can reach AND code that calls it; cmd/muster-server passes `gw != nil && KickoffDeliveryWired` into Config.KickoffDeliverable. With MUSTER_AGENT_GATEWAY unset there is no gateway, so a dispatch asking for a first turn is still REFUSED — see KickoffRefusalReason. When this was false, the first conjunct alone had been passed and a deployment WITH a gateway created pods nobody ever told what to do; the two-conjunct form is what closed that.

âš  THIS PACKAGE DOES NOT READ IT AND MUST NOT. The adapter answers the question from what it is TOLD (Config.KickoffDeliverable); its only reader is cmd/muster-server/provisioner.go.

🔴 IT IS BOUND TO A MEASUREMENT, IN BOTH DIRECTIONS. internal/modulegate's TestKickoffDeliveryLedgerAgreesWithTheModule walks every non-test file for CALLS to the two store writes only a delivery makes (agents.Store.SetKickedOff, agents.Store.RecordKickoffDelivery) and fails when the measured set disagrees with this constant: deleting the deliverer without setting this false reddens it, and so does the reverse. A deliverer that exists but is not STARTED is the other half of that hazard, and cmd/muster-server's TestADeliverableAdapterAlwaysComesWithARunningDeliverer is what pins it.

View Source
const KickoffRefusalReason = KickoffRefusalSummary + " CAUSE: this deployment names no agent " +
	"gateway, and a DELIVERED kickoff is a model turn sent through one. REMEDY: set " +
	"MUSTER_AGENT_GATEWAY=hooks-sha256 together with MUSTER_AGENT_GATEWAY_MODEL (and the agent " +
	"runtime-config bundle boot requires with them) and restart muster; the kickoff deliverer " +
	"(internal/agentkickoff) then hands each dispatched agent's pending note to its instance once " +
	"the instance is ready. See cmd/muster-server/doc_seams.go entry 1. Do not go looking at the " +
	"spec or the credential on the way: the rendered spec declares the gateway port and the " +
	"instance receives the token the bearer is derived from."

KickoffRefusalReason is the operator-facing text of that refusal. It is logged, written to the agent row's error message, and carried in the returned error.

🔴 IT NAMES THE CAUSE *AND* THE REMEDY, WHICH IS THE PROPERTY THAT SEPARATES IT FROM UndeliveredKickoffReason. That constant is evidence about a thing that already happened and its reader can do nothing with it; this one is read by someone whose click was just refused, so it has to answer "why" and "what do I do". An error with no remedy is how an operator concludes the feature is broken and files a bug against the agent.

🔴 THE REMEDY NAMES THE VARIABLE AGAIN, AND THAT IS NOW TRUE RATHER THAN A REGRESSION. An earlier revision led with "set MUSTER_AGENT_GATEWAY", which was measured FALSE while KickoffDeliveryWired was false: the variable was set on the deployment reading it and the refusal fired anyway, because nothing called the gateway. The text then said in as many words that setting the variable was NOT sufficient. With the deliverer wired the refusal fires ONLY when no gateway was built, so the variable is exactly the remedy — and "create it stopped, then Start" (`muster agent create --start=false`) stays in the summary as the move that works without it.

⚠ THE SPEC AND CREDENTIAL CLAUSE SURVIVES AND IS STILL LOAD-BEARING. The text tells the operator NOT to go looking at the rendered port or the gateway token, because both were real blockers once and both are closed — and TestEveryCapabilityClaimTheRefusalMakesIsTRUE pairs each of those two sentences with a predicate that executes, so an unchanged sentence becoming false reddens.

âš  THE ENVIRONMENT VARIABLE IS SPELLED AS A LITERAL HERE AND THE BINARY HAS ITS OWN CONSTANT FOR IT. This package cannot import package main, so the two spellings are genuinely duplicated, and a duplicated name is a name that goes stale in one place. That is not left to care: TestTheKickoffRefusalNamesTheBinarysOwnGatewayVariable in cmd/muster-server asserts this string contains envAgentGateway, so renaming the variable there reddens here.

✅ WHERE AN OPERATOR READS IT, MEASURED RATHER THAN ASSUMED: the boot banner, this pod's log, the agent row's status becoming `error` (which agents.ComputeStatus treats as terminal, so the card can no longer be refined to `running` by a live instance that does not exist), agents.error_message on the hook-token-gated GET /api/agents — and, since the change that added Adapter.KickoffUndeliverableReason, THE HTTP RESPONSE OF THE POST THAT ASKED. That last one was the open half and this paragraph used to say so: "IT DOES *NOT* REACH THE HTTP RESPONSE OF THE POST THAT ASKED … CLOSING CONDITION: a pull request in which POST /agents with action=dispatch answers 4xx carrying this text." That form is gone (docs/design/chief-dispatch.md phase 2); internal/api's handleAPIAgentCreate, POST /api/agents with start: true, asks Adapter.KickoffUndeliverableReason BEFORE the row is created and answers 409 with KickoffRefusalSummary, which is this string's own prefix. ⚠ ONE CALLER IS STILL ASYNCHRONOUS AND THAT IS DELIBERATE: handleChiefProvision reaches Dispatch through createAndDispatchAgent inside safeGo, so its refusal is recorded on the row rather than returned. It has no "create stopped" affordance to be sent to; the row it creates can be brought up with Start, which is the same escape by a different door.

View Source
const KickoffRefusalSummary = "dispatch REFUSED and NOTHING was provisioned: this deployment " +
	"cannot deliver an agent's first turn, so beginning the work is impossible and creating the " +
	"instance would only produce a pod that reads healthy and was never told what to do. " +
	"Create it with `muster agent create --start=false`, then Start it from its page, which brings " +
	"the instance up without claiming a first turn."

KickoffRefusalSummary is the SHORT operator-facing form of the refusal: what happened, and what to do instead. KickoffRefusalReason is this string plus the mechanism, and nothing else.

🔴 IT EXISTS BECAUSE THE FULL REASON IS ~900 CHARACTERS AND THE SURFACE THAT NOW SHOWED IT WAS A TOAST. internal/api answers POST /api/agents with start: true 409 + this text (it answered the deleted dispatch form's POST /agents the same way, which a toast printed verbatim); the full mechanism paragraph is a wall of text an operator scrolls past. It is a PREFIX of KickoffRefusalReason rather than a second sentence of its own, so the two cannot drift into saying different things — pinned by TestTheShortRefusalIsAPrefixOfTheLongOne.

âš  ONE CLAUSE OF THE TEXT BELOW IS NOW WEAKER THAN WHEN IT WAS WRITTEN, AND IT IS FLAGGED HERE RATHER THAN SILENTLY REWORDED. "a pod that reads healthy" was literally true while nothing on any page reported an undelivered first turn; agents.KickoffOwed now renders a "kickoff owed" badge beside the status dot, so such a pod would read `running` AND owed. The REMEDY and the cause are untouched and still exactly true, which is why the operator-facing bytes are left alone: this text is pinned by TestTheRemedyDoesNotPromiseADeliveryTheDispatchPathCannotMake, whose own doc records three regressions caused by editing it, and rewording it is a product decision about copy rather than part of surfacing the signal. If it is reworded, re-read that test's four properties first.

View Source
const NoDefaultBranchMessage = "" /* 155-byte string literal not displayed */

NoDefaultBranchMessage opens the error of a job whose repository's default branch could not be resolved.

View Source
const NotOnPullRequestMessage = "the job's sha is neither the pull request's head nor an ancestor of it, so it was not checked out; nothing was run"

NotOnPullRequestMessage opens the error of a job whose sha is not on its pull request; the pull request's head follows it.

View Source
const PullFetchMessage = podagent.PullFetchMessage

PullFetchMessage opens the error of a job whose pull request could not be fetched (podagent's, which the key holder's script fails with too).

View Source
const RemoveTrackedMarker = "muster-job-remove:tracked"

RemoveTrackedMarker is what removeScript prints when it leaves a tracked file.

View Source
const SymlinkOverlayMessage = "" /* 184-byte string literal not displayed */

SymlinkOverlayMessage opens the error of a job refused because the default branch carries a symlink among the overlaid paths; the paths follow it.

View Source
const TerminalReleaseTimeout = 10 * time.Second

TerminalReleaseTimeout bounds one terminal release. It is its own budget, on a context DETACHED from the attach's: by the time a release runs, the attach's context has usually just been cancelled — that is what ended it.

View Source
const TerminalSizeTimeout = 3 * time.Second

TerminalSizeTimeout bounds the window-size query an attach makes first. A slow answer is "size unknown", never a slow terminal.

View Source
const UndeliveredKickoffReason = "kickoff NOT delivered: this deployment names no agent gateway " +
	"(MUSTER_AGENT_GATEWAY), so nothing can hand the pending note to the instance's model gateway. " +
	"The instance WAS created and the note is still in agents.pending_note. Name a gateway, restart " +
	"muster and Start this agent again: the kickoff deliverer hands the note over once the instance " +
	"is ready. This is a property of the deployment, not a failure of this agent: see " +
	"cmd/muster-server/doc_seams.go entry 1."

UndeliveredKickoffReason is written to agents.kickoff_error when a START brings up an instance that owes a first turn on a deployment with no gateway. (A DISPATCH asking for one there is refused instead and creates nothing.)

⚠ "Start this agent again" IN THE REMEDY IS LOAD-BEARING: Start rewrites the row's status, which restarts the dwell clock agents.DecideReconcile bounds the first-turn retry by. A row last started more than agents.ProvisioningStuckTimeout before a gateway was named is otherwise ERRORED by the deliverer's first tick rather than delivered — that is the table's verdict on a ready instance that never got its turn, and the remedy routes around it rather than hiding it.

🔴 IT NAMES THE DEPLOYMENT, NOT THE AGENT, BECAUSE THE CONDITION IS A PROPERTY OF THE DEPLOYMENT. An operator reading it on a card must not go looking at the agent's pod, its model or its credentials — none of them is why the turn did not run. Same reasoning as api.ProvisionerUnwiredField being a field rather than a sentence: the reader has to be able to tell a permanent property of the deployment from a transient failure of this agent.

View Source
const UnshallowBackoffNote = "muster: not unshallowing the checkout yet: it failed recently"

UnshallowBackoffNote is what the worktree script prints (to stderr) when it skips the unshallow because the last attempts failed.

View Source
const UnshallowFailedFile = "muster-unshallow-failed"

UnshallowFailedFile is the file in the checkout's git directory counting the unshallow's consecutive failures (its mtime is the last one's time). While it exists the unshallow is skipped for unshallowBackoffBaseSeconds × 2^(n−1) seconds (n capped at unshallowBackoffDoublings + 1: 1 h, 2 h, … 16 h); a success removes it.

View Source
const UnshallowFailedNote = "" /* 132-byte string literal not displayed */

UnshallowFailedNote is what the worktree script prints (to stderr) when the one-time unshallow of a shallow checkout failed; the job proceeds.

View Source
const UnshallowMaxBudget = 10 * time.Minute

UnshallowMaxBudget bounds the one-time unshallow of a shallow checkout (jobOverlayScript, "THE UNSHALLOW"); unshallowBudget also caps it at a third of what is left of the job's own deadline.

Variables ¶

View Source
var ErrFileTooLarge = errors.New("the file is larger than the limit")

ErrFileTooLarge is ReadWorkspaceFile's answer for a file over its limit.

View Source
var ErrKickoffUndeliverable = errors.New("agentprovision: kickoff undeliverable")

ErrKickoffUndeliverable is returned by Adapter.Dispatch when it is asked to begin work — kickoff=true — in a process that has no gateway to begin it with.

🔴 IT IS A REFUSAL, NOT A FAILURE, AND THE DIFFERENCE IS WHAT IT PROTECTS. A failure means the request was reasonable and something broke. This means the request can NEVER succeed on this configuration, so doing half of it is the wrong answer: the half that works (create the pod, clone the repository into it, hand it a model credential) is exactly the half that costs money and holds a secret, while the half that matters — telling the agent what to do — cannot happen at all.

⚠ THIS SENTENCE SAID "and reads HEALTHY on every page", AND THAT CLAUSE IS NO LONGER TRUE — the clause is removed rather than kept, because unlike the retracted paragraphs in this file's header it was not load-bearing for anything else. Both tiers now show agents.KickoffOwed, so such a pod reads `running` AND `kickoff owed`. It does NOT weaken the refusal: the cost, the secret and the impossibility of the asked-for turn are each sufficient on their own, and a badge naming the gap is not a reason to create the gap.

âš  IT IS A SENTINEL SO A CALLER CAN TELL IT FROM A DRIVER ERROR. Nothing in this module matches on it yet: the only consumer of Dispatch's error is a background goroutine in internal/api that logs it (see KickoffRefusalReason's own note on what that costs and who owes the rest). It is exported now because the caller that WILL match on it must not have to reach for a string.

View Source
var ErrNoAccountRebinder = errors.New("agentprovision: the agents store cannot move an agent to another Claude account")

ErrNoAccountRebinder is Rebind's refusal when the agents store cannot move an agent's account (a store without RebindCCAccount): fail closed, nothing is re-applied.

View Source
var JobOverlayRootFiles = []string{"CLAUDE.md", "CLAUDE.local.md", "AGENTS.md", ".mcp.json"}

JobOverlayRootFiles are the files at a job worktree's root that are replaced by the repository's default branch's (or removed, when the default branch has none). Together with every `.claude` directory (jobOverlayScript) they are what the overlay covers, and nothing else is.

  • CLAUDE.md, CLAUDE.local.md, AGENTS.md: the instructions the CLI loads at launch from the project root (CLAUDE.local.md is its personal memory file, loaded beside CLAUDE.md).
  • .mcp.json: the project's MCP servers. The CLI STARTS each server's command, so it is code the commit would otherwise run.

Functions ¶

func AnonymousFetchURL ¶

func AnonymousFetchURL(base, repo string) string

AnonymousFetchURL is the URL a commit job's pull request is fetched from for repository owner/name: base + owner/name (base empty: DefaultAnonymousGitBase).

func ChiefLLMRouted ¶ added in v0.178.0

func ChiefLLMRouted(ctx context.Context, ag agents.Agent, rule func(ctx context.Context, owner int64) (bool, error)) (bool, error)

ChiefLLMRouted is THE predicate for whether agent ag runs on the LLM route under rule (Config.ChiefLLMRoute): a claude-code agent with the reserved chief slug whose owner the rule routes; false for every other agent, and for every agent when rule is nil. The spec builder asks it (chiefLLMRoute) and so does the LLM proxy on Kubernetes (api.ChiefLLM.Routed, wired from the same rule), so the proxy serves exactly the chief the pod was built for.

Types ¶

type AccountRebinder ¶ added in v0.114.0

type AccountRebinder interface {
	RebindCCAccount(ctx context.Context, id int64, from, to string) (bool, error)
}

AccountRebinder is the agents store's conditional account move (agents.PGStore.RebindCCAccount), asserted rather than added to agents.Store: the account failover is its only caller.

type Adapter ¶

type Adapter struct {
	// contains filtered or unexported fields
}

Adapter implements the consumer-side lifecycle interface over a driver.

⚠ IT DOES NOT NAME THAT INTERFACE IN A COMPILE-TIME ASSERTION, and the omission is deliberate: internal/api declares it consumer-side precisely so this direction of the dependency does not exist. The binding is checked where it is used — cmd/muster-server assigns an *Adapter to api.Extensions.Provisioner, which is a compile error if the method set drifts — and internal/api's own TestTheLifecycleAdapterSatisfiesTheConsumerInterface pins it from the side that owns the interface.

func New ¶

func New(cfg Config) (*Adapter, error)

New validates the configuration and builds the adapter.

func (*Adapter) AttachTerminal ¶

func (a *Adapter) AttachTerminal(ctx context.Context, ag agents.Agent, readOnly bool, stdin io.Reader, stdout io.Writer, resize <-chan provision.TermSize) error

AttachTerminal attaches a terminal to the agent's live session: the kind's attach command (agents.TerminalCommand — ErrNoTerminal for a kind without one) run on a pty through provision.ExecTTY, which refuses a driver that cannot exec. readOnly is passed straight to the command; there is no default here for a caller to inherit.

🔴 IT RETURNS ONLY AFTER THE ATTACH IS RELEASED, ON EVERY EXIT PATH. Ending the exec stream does not end the process it started in the container — the runtime keeps it and its pty, and tells it nothing — so every attach that may have started is followed by releaseTerminal, a second exec that ends exactly that attach's tmux client (agents.TerminalReleaseCommand). One place, after ExecTTY returns, whatever made it return: the browser closing the socket, a dropped connection the keepalive noticed, a mode switch (which is a close and a new attach), a stream error, the client exiting on its own, or muster's shutdown cancelling every terminal (api.Server.EndTerminals). Only a refusal BEFORE any stream (terminalMayHaveStarted) skips it. A muster that dies without running this (a crash, SIGKILL) leaves its clients attached until the pod restarts; see agents.TerminalCommand on sizing.

func (*Adapter) Destroy ¶

func (a *Adapter) Destroy(ctx context.Context, agentID int64) error

Destroy removes the instance and then the stored row.

🔴 THE ROW IS DELETED ONLY WHEN THE BACKEND HOLDS NOTHING, AND THIS IS WHERE THIS ADAPTER IS STRICTER THAN THE IMPLEMENTATION IT REPLACES. Upstream tore down best-effort and deleted the row unconditionally, which was safe there because its teardown could only fail transiently. The driver contract has two failures that are NOT transient-and-harmless, and both of them mean nothing was removed:

  • provision.ErrNotManaged — something under this instance's name is not muster's, so Destroy refused BEFORE deleting anything and the contract calls the refusal terminal. Deleting the row here would leave whatever is running with no record in this service at all: unlistable, unstoppable, and invisible to the very refusal that was trying to protect it.
  • provision.ErrBlind — the backend could not be reached, so the driver knows nothing. Deleting the row on no information is the same loss with a different cause.

A nil error and provision.ErrNotFound both mean the backend holds nothing, and only those two reach the delete.

func (*Adapter) Dispatch ¶

func (a *Adapter) Dispatch(ctx context.Context, agentID int64, kickoff bool) error

Dispatch provisions an instance for the agent when kickoff is true, and creates NOTHING when it is false.

🔴 kickoff=false CREATES NO INSTANCE, AND AN EARLIER REVISION OF THIS METHOD CREATED ONE. That revision mirrored the upstream implementation, which installs its release either way and then stores `stopped` — and carrying that across turned a consumer-side comment into a falsehood and bypassed a guard. The caller is internal/api's createAndDispatchAgent, where `kickoff` is `start` on POST /api/agents (it was `action == "dispatch"` on the deleted dispatch form): the OTHER value creates the agent stopped (the form's "Save for later"), and the gate check before it refuses a dispatch of a `gate:<reason>`-tagged task while allowing a save, giving as its reason that a save "provisions nothing". That was TRUE for as long as this module had no provisioner at all. Wiring one made it false in the worst direction: a save on a task explicitly gated from being worked created a pod, cloned the repository into it, and handed it a model credential — one per click, with the gate's own check passing.

So the two arguments now differ in WHAT IS BUILT, not only in what is stored:

kickoff=true  -> WITH something in the process that could deliver it
                 (Config.KickoffDeliverable): create the instance and store
                 `provisioning` (a first turn is owed); internal/agentkickoff
                 delivers it once the instance is ready. WITHOUT: REFUSE —
                 create nothing, store `error` carrying KickoffRefusalReason,
                 and return ErrKickoffUndeliverable.
kickoff=false -> create nothing, store `stopped` (only tests call this now:
                 createAndDispatchAgent inserts a save `stopped` and no
                 longer dispatches it — see the branch). The status is now TRUE
                 rather than a statement about what this service is waiting
                 for, which is also what makes the model-change roll in
                 internal/api correct for such an agent: it branches on the
                 STORED status, so a `stopped` row over a running instance
                 made it skip a roll the instance needed.

âš  Start IS WHAT PROVISIONS A SAVED AGENT, and it already does: its provision.ErrNotFound branch creates the instance the save deliberately did not. So "save, then start later" works without this method creating anything.

func (*Adapter) Driver ¶

func (a *Adapter) Driver() string

Driver returns the backend's short name, for the boot banner and for error messages that have to say which set of capability losses applies.

func (*Adapter) Instances ¶

func (a *Adapter) Instances(ctx context.Context) ([]provision.Instance, error)

Instances returns every instance the driver manages, for status reconciliation.

âš  IT PASSES THE DRIVER'S ERROR THROUGH RATHER THAN DEGRADING TO AN EMPTY SLICE. An empty slice is a positive claim that nothing is running, and api.Server.instanceIndex distinguishes a nil index ("live state was not observed", keep the stored status) from an empty one ("observed, nothing is running", every agent is stopped). Swallowing the error here would collapse those two and report a whole board stopped on one unreachable backend.

func (*Adapter) InstancesOf ¶ added in v0.251.0

func (a *Adapter) InstancesOf(ctx context.Context, ags []agents.Agent) ([]provision.Instance, error)

InstancesOf returns the instances of ags only: one driver Get per agent, never a List of the whole fleet. The officer loop reads its pool's instances this way (api's officerFleet.Instances).

🔴 ITS COST IS THE AGENTS ASKED ABOUT, NOT THE FLEET. On the Kubernetes driver's least-privilege layout List reads every agent namespace on its own (three requests each), so a caller that wanted three instances paid for every instance in the cluster — per officer, per pass — and a deployment with a few dozen agents spent the client's whole request budget on it.

What it answers matches what List would have said about the same agents:

  • provision.ErrNotFound (the backend was reached and has no instance) is NOT an error: the agent is simply absent from the result, as it would be from List's. That includes a stranger's co-named Deployment, which a by-name read reports as ErrNotFound AND ErrNotManaged (provision's sentinel doc) and which List does not list either; ErrNotFound is therefore tested FIRST.
  • ErrNotManaged or ErrDivergentSpec ALONE (on the Kubernetes driver: a namespace RoleBinding muster refuses to use) is reported as the instance in PhaseUnknown with the refusal as its Reason — what List reports for the same namespace. Failing the read on it would blind the caller over one agent; omitting it would read as "not running" and have the caller start it again every pass.
  • Any other error (ErrBlind: the backend could not be read) fails the whole call, never a partial answer: a missing instance in a partial answer reads as "not running".

func (*Adapter) JobBypassDecision ¶

func (a *Adapter) JobBypassDecision(ctx context.Context, ag agents.Agent) (bypass bool, veto string)

jobBypassVeto is why ag's job lanes must not run with permissions bypassed although its pool is listed (MUSTER_AGENT_CC_BYPASS_POOLS), or "".

🔴 AN AGENT HOLDING AN APPROVED GRANT THAT REACHES GITHUB IS NEVER BYPASSED. With such a grant ccd routes the pod's git through muster's proxy, which adds a GitHub App token with contents:write and pull_requests:write in the default write mode (internal/githubapp; read-only only under MUSTER_GITHUB_APP_ACCESS=read, and a stored github.com connector is never limited by it), so a prompt-injected lane running unapproved could push and merge. The approval doors already refuse such a grant to every pool worker (internal/api refusePoolWorkerGitHubGrant), so this is the third door: it is asked every time the spec is built — Dispatch, Start and ReapplyProfiles — and it FAILS CLOSED: an unreadable grant state, or no lookup wired, is a veto too. Each veto is logged naming the agent. JobBypassDecision is what this adapter decides for ag's job lanes the next time its spec is applied: bypass, or not and the veto ("" when its pool is simply not listed). It asks the same two questions buildSpec does (agentspec.JobBypassListed and jobBypassVeto), over the deployment's spec configuration, so the wiring that feeds them is observable from outside.

func (*Adapter) KickoffUndeliverableReason ¶

func (a *Adapter) KickoffUndeliverableReason() string

KickoffUndeliverableReason answers, for THIS process, why an agent's first turn cannot be delivered — and "" when it can. It is the question Adapter.Dispatch answers by refusing, asked WITHOUT performing the refusal, so a caller can answer its own request before creating anything.

âš  IT RETURNS THE SHORT FORM, KickoffRefusalSummary, AND THE DIFFERENCE IS THE AUDIENCE RATHER THAN A LOSS. Its one consumer puts the string straight into an HTTP response body that internal/ui shows a human as a toast; the ~900-character mechanism paragraph in KickoffRefusalReason is what a toast gets scrolled past for. The full text still reaches the log, the agent row's error_message and the returned error on the Dispatch path, and the short form is a literal PREFIX of it, so neither surface can come to say something the other contradicts.

🔴 IT EXISTS SO THE REFUSAL REACHES THE HUMAN WHO ASKED, WHICH Dispatch CANNOT DO. internal/api calls Dispatch inside a background goroutine after the row exists, so the returned ErrKickoffUndeliverable is logged into this pod's stdout and the operator's POST has already answered 200 — a card that turns red with the reason in a machine-tier field. This method is what lets the create handler refuse SYNCHRONOUSLY, before the row, and hand back KickoffRefusalSummary with a 409.

🔴 IT IS A SECOND READ OF ONE FACT, NOT A SECOND PREDICATE, AND THAT IS THE WHOLE POINT OF ITS SHAPE. It returns the same field Adapter.Dispatch branches on, so the pre-flight answer cannot disagree with what the dispatch would actually do. A caller computing deliverability from its own copy of the configuration is the hazard: two expressions over one condition, disagreeing for every input the two were written against at different times. Guarded by internal/api's TestTheCreateHandlersPreflightAgreesWithWhatDispatchWouldDo.

⚠ "" MEANS DELIVERABLE, AND THE ZERO VALUE OF THIS RETURN IS THEREFORE THE PERMISSIVE ONE — the opposite polarity from Config.KickoffDeliverable, whose zero value refuses. That is not an oversight and it does not reopen the hole that field's doc closes: a struct field can be FORGOTTEN by a wiring, which is why its zero value has to fail closed; a method cannot be forgotten, because omitting it is a compile error against the interface that names it. What an implementer can still do is return the wrong answer, and no polarity protects against that — the guard above is what does.

func (*Adapter) PoolRepoRefusal ¶ added in v0.217.0

func (a *Adapter) PoolRepoRefusal(ag agents.Agent) error

PoolRepoRefusal is agentspec.PoolRepoRefusal with this adapter's configuration: why ag's spec would be refused for working on a repository other than its pool's deploy key's, or nil.

func (*Adapter) PrepareJobWorktree ¶

func (a *Adapter) PrepareJobWorktree(ctx context.Context, ag agents.Agent, jobID int64, repo string, pr int, sha, configRef, baseSHA string) (string, error)

PrepareJobWorktree creates job jobID's worktree of ag's repository at sha, which must be pull request pr's head of repo (owner/name) or an ancestor of it — fetched anonymously, or, for an agent of a pool with a deploy key, through the pod's key holder (jobFetchWithKey) — with the overlay taken from configRef ("" = the default branch's tip; else a full commit id the default branch must reach), and returns its absolute path in the instance. On a pool with a deploy key the repository's agent configuration is removed and none restored (agentspec.StripsRepoConfig), and a configRef is refused. With baseSHA that commit is fetched the same way into refs/muster-jobs/<jobID>-base. ag's own checkout is not moved. On an error a partly made worktree may be left; RemoveJobWorktree removes it either way.

func (*Adapter) ReadWorkspaceFile ¶

func (a *Adapter) ReadWorkspaceFile(ctx context.Context, ag agents.Agent, jobID int64, rel string, max int) ([]byte, error)

ReadWorkspaceFile returns the contents of rel byte for byte, refusing a file over max bytes with ErrFileTooLarge rather than truncating it. rel is relative to job jobID's worktree for a positive jobID (PrepareJobWorktree), and to the directory ag's CLI works in (agentspec.ClaudeCodeWorkingDir) for zero.

func (*Adapter) ReapplyProfiles ¶

func (a *Adapter) ReapplyProfiles(ctx context.Context, agentID int64) error

ReapplyProfiles re-renders the agent's spec from its current row and reconciles the live instance to it, which rolls the instance.

🔴 IT SATISFIES api.ProfileReapplier, WHICH IS A TYPE ASSERTION AND THEREFORE THE ONE FORM OF OPTIONAL DEPENDENCY THAT LEAVES NO TRACE WHEN IT IS NOT SATISFIED. cmd/muster-server/doc_seams.go entry 3 exists for exactly that: an adapter without this method compiles, wires, and takes the else branch for ever with no nil anywhere to notice. So it is implemented rather than omitted, and internal/api's TestTheLifecycleAdapterSatisfiesTheConsumerInterface asserts the assertion succeeds — "it compiles" is not that test, because a method added to the wrong type compiles just as well.

âš  ROLLING THE INSTANCE RE-DELIVERS A KICKOFF ONCE A GATEWAY EXISTS, and agents.kickoffLost's own doc says so and calls it intended: a roll has already killed whatever turn was running, so the choice is between re-delivering the task and silently doing nothing. It is capped by agents.MaxKickoffAttempts. âš  STILL LATENT: internal/agentkickoff delivers FIRST turns only and never acts on a kicked-off row, so agents.ActionResendKickoff has no driver and a roll re-sends nothing today.

func (*Adapter) Rebind ¶ added in v0.114.0

func (a *Adapter) Rebind(ctx context.Context, agentID int64, from, to string, prepare func(context.Context, agents.Agent) error) (RebindResult, error)

Rebind is an ACCOUNT FAILOVER's lifecycle half (internal/ccfailover): move claude-code agent agentID from Claude account from to account to, then re-apply its spec, so its pod restarts with to's setup-token as CLAUDE_CODE_OAUTH_TOKEN. The agent's name, namespace, volume and identity are kept: only the per-agent Secret's token changes, and since the spec fingerprint covers the Secret's values the Deployment rolls (a persistent workspace rolls with Recreate, so the running CLI session restarts).

prepare, when non-nil, runs after the move and before the re-apply (the officer runtime re-arms an instance's first turn there); its error is logged and does not stop the rebind.

🔴 IT RUNS UNDER THE SAME PER-AGENT LANE AS Start, Stop AND Destroy (lockAgent), AND RE-READS THE ROW INSIDE IT. So a Stop or Destroy that wins the lane first leaves a row that is not live (or none), and the rebind does nothing; one that arrives after waits for the re-apply and then stops or deletes the restarted pod. A rebind therefore never brings back a stopped agent nor re-creates a deleted one. The lane is this process's; across processes the conditional move (RebindCCAccount: WHERE cc_account = from) still makes the move itself happen once.

func (*Adapter) RemoveJobWorktree ¶

func (a *Adapter) RemoveJobWorktree(ctx context.Context, ag agents.Agent, jobID int64) error

RemoveJobWorktree removes job jobID's worktree of ag's repository (jobRemoveScript). A worktree that is not there is not an error.

func (*Adapter) RemoveUntrackedWorkspaceFile ¶

func (a *Adapter) RemoveUntrackedWorkspaceFile(ctx context.Context, ag agents.Agent, rel string) (removed bool, err error)

RemoveUntrackedWorkspaceFile deletes rel — a path relative to the directory ag's CLI works in, validated as ReadWorkspaceFile validates it — unless the repository checked out there tracks it. removed reports whether it deleted (or found nothing to delete); false with a nil error means the file is tracked and was left in place. It is for a job WITHOUT a commit, whose turn ran in the agent's own working directory; a commit job's whole worktree is removed instead (RemoveJobWorktree).

func (*Adapter) RotateCredentials ¶ added in v0.227.0

func (a *Adapter) RotateCredentials(ctx context.Context, agentID int64) (rotated bool, err error)

RotateCredentials gives agent agentID NEW credentials — a new hooks token (its muster identity) and, for a claude-code agent, a new turn credential — and, when the agent is live (stored running or provisioning), re-applies its spec so the instance holds them. The old token is refused by muster the moment the store holds the new one (agents.Store.GetByHooksToken).

rotated reports whether the NEW credentials were committed: true with a non-nil err is a rotation whose re-apply failed (the old token is dead, the instance does not hold the new one yet); false with err is a rotation that changed nothing.

It is the remedy for a credential printed where it should not be: a team's agent is steered into printing its token into the team's chat (the team trust model, docs/chief.md), and rotation is what makes that copy worthless.

🔴 BOTH CREDENTIALS ARE WRITTEN IN ONE TRANSACTION (agents.CredentialsWriter): neither changes unless both do, so a failed write never leaves the agent on a new token beside its old turn credential. A store without the method is refused before anything is minted. For a TEAM owner the credentials land in agent_secrets ONLY: migration 0131's agents_team_no_secret trigger blanks the shared row's legacy columns on every write. A person's agent is still dual-written, as every mint is.

⚠ A STOPPED AGENT IS NOT RE-APPLIED HERE: its next Start re-applies the spec (always for claude-code, and for every kind once credentials resolve per owner — startLocked), so it comes up holding the new credentials. A gateway agent on a deployment with no credential resolver is the one case whose Start only scales; it would come up on the old token, which muster now refuses (a loud 401, not a silent one) until its next re-apply.

func (*Adapter) Start ¶

func (a *Adapter) Start(ctx context.Context, agentID int64) error

Start scales a stopped instance back up, creating it first when the backend does not have it.

🔴 THE MISSING-INSTANCE BRANCH KEYS ON provision.ErrNotFound, NOT ON "Scale FAILED". Upstream fell back to a full re-provision on ANY scale error, which treats an unreachable backend (provision.ErrBlind — the driver knows nothing) as evidence that nothing is there, and answers it by creating. The sentinels exist to keep those apart: "the backend says there is nothing" is a reason to create, "I cannot see the backend" is a reason to stop and say so.

🔴 START IS *NOT* REFUSED WHEN NO KICKOFF CAN BE DELIVERED, AND THAT ASYMMETRY WITH Dispatch IS THE DECISION, NOT AN OVERSIGHT. The refusal belongs where a NEW PROMISE IS MADE. Dispatch(kickoff=true) is the one call that means "begin this work now" — it is what the UI's Dispatch button sends — and on a deployment with no gateway that promise cannot be kept at all, so making it is the defect. Start promises something narrower and entirely deliverable: bring this instance up. This build genuinely can, and does — the pod runs, its logs stream, and a human with a reachable instance can talk to it.

So refusing here would DELETE WORKING CAPABILITY to signal a missing one. Three concrete operations would stop: restarting a stopped agent, recovering an agent whose instance was evicted, and provisioning an agent that was deliberately SAVED for later — which is the very escape route KickoffRefusalReason tells the operator to take, so refusing it would make the remedy text a lie. Guarded by TestStartStillWorksWhenNoKickoffCanBeDelivered.

⚠ NOTHING IS HIDDEN BY THAT CHOICE. The !ag.KickedOff branch below still records the non-delivery through recordUndeliveredKickoff, so a first turn that is owed and cannot be delivered is written to agents.kickoff_error and logged exactly as before — and here that field is honest, because an instance really does exist for a retry to act on. The difference between the two methods is whether an instance SHOULD come into being, not whether the missing gateway is reported.

func (*Adapter) StartIfLive ¶ added in v0.158.0

func (a *Adapter) StartIfLive(ctx context.Context, agentID int64, live func() (bool, error)) (bool, error)

StartIfLive is Start, only when live reports the agent live, with the check and the start both under the agent's lifecycle lock (lockAgent): a Stop cannot land between them, so a Stop is never undone by a start that read the agent as live before it. It reports whether it started. The Compose chief's boot re-apply is the caller (internal/api reapplyComposeChief); live reads its spec's replicas.

func (*Adapter) Stop ¶

func (a *Adapter) Stop(ctx context.Context, agentID int64) error

Stop scales the instance to zero replicas, keeping its declaration.

func (*Adapter) StreamLogs ¶

func (a *Adapter) StreamLogs(ctx context.Context, ag agents.Agent, emit func(string)) error

StreamLogs follows the agent's instance output, calling emit per line.

func (*Adapter) StripsRepoConfig ¶ added in v0.110.0

func (a *Adapter) StripsRepoConfig(ag agents.Agent) bool

StripsRepoConfig reports whether ag's jobs get none of the repository's agent configuration (agentspec.StripsRepoConfig, with this adapter's configuration). The job API asks it before recording a job with a config_ref.

func (*Adapter) SweepJobWorktrees ¶ added in v0.252.0

func (a *Adapter) SweepJobWorktrees(ctx context.Context, ag agents.Agent) ([]string, error)

SweepJobWorktrees removes every job worktree of ag's checkout and every refs/muster-jobs/* ref (jobSweepScript), and returns what it removed, one line each. Call it only while no job of ag can be running but the caller's own, whose worktree is already removed: it does not ask which jobs run.

func (*Adapter) UseBeforeStop ¶ added in v0.198.0

func (a *Adapter) UseBeforeStop(f func(ctx context.Context, ag agents.Agent))

UseBeforeStop installs f, handed the agent's row on every Stop and Destroy BEFORE the driver scales the instance to zero or removes it — while its pod can still answer. internal/api's consumer usage collector is the one caller (its last push of the instance's Claude usage). f must be bounded and must not fail the stop: it returns nothing, and it runs under the agent's lifecycle lock. Call it before the adapter serves.

func (*Adapter) UseChiefPluginSections ¶ added in v0.241.0

func (a *Adapter) UseChiefPluginSections(f func(ctx context.Context, owner int64) ([]agentspec.PluginSection, error))

UseChiefPluginSections installs f, which reads an owner's APPROVED plugin instruction sections (internal/plugins ApprovedChiefSections): a claude-code chief's CLAUDE.md renders them after every core rule (agentspec.PluginSectionsBlock). Call it before the adapter serves.

func (*Adapter) UseClaudeCodeSession ¶ added in v0.106.0

func (a *Adapter) UseClaudeCodeSession(f func(agents.Agent) (agentspec.ClaudeCodeSession, bool))

UseClaudeCodeSession installs the source of claude-code agents' per-agent session settings (agentspec.ClaudeCodeSession). internal/api's officer runtime is the one caller: an officer instance's own tools pre-allowed, its configured model and every tool allowed (BypassPermissions); every other agent answers ok=false.

func (*Adapter) UseGitHubGrants ¶

func (a *Adapter) UseGitHubGrants(f func(ctx context.Context, agentID int64) (string, error))

UseGitHubGrants wires the lookup jobBypassVeto asks. Call it before the adapter serves; without it every agent in a bypass-listed pool is started WITHOUT bypass (fail closed).

func (*Adapter) UseTeamOwner ¶ added in v0.227.0

func (a *Adapter) UseTeamOwner(f func(ctx context.Context, owner int64) (name string, team bool, err error))

UseTeamOwner installs f, which reports whether an owner is a TEAM and its name (internal/users TeamNames, under System). A chief whose owner is a team gets the team section of its instructions (agentspec.TeamChiefSection): several people talk to it in one shared room, and it acts as the team. Call it before the adapter serves.

type Config ¶

type Config struct {
	// Driver is the provisioning backend. REQUIRED.
	Driver provision.Provisioner
	// Store resolves an agent id to its row and is where every status write
	// lands. REQUIRED.
	Store agents.Store
	// Spec is the deployment-wide half of every built spec — image repository,
	// the base URL instances phone home to, model, resources. REQUIRED, and
	// agentspec.Build refuses the two fields that have no defensible default.
	Spec agentspec.Config
	// KickoffDeliverable declares whether THIS PROCESS holds something that could
	// hand an agent's pending note to its model gateway.
	//
	// 🔴 "SOMETHING THAT COULD" IS A CONJUNCTION OF TWO FACTS AND THIS DOC USED TO
	// NAME ONLY ONE OF THEM. It read "— in cmd/muster-server, whether buildGateway
	// returned a gateway rather than nil", and that is what the binary passed: a
	// reachable gateway, with nothing asserted about whether any code CALLS one on
	// the dispatch path. On the deployment that runs this, with
	// MUSTER_AGENT_GATEWAY set, the first fact was true and the second false, so
	// this field was true, the refusal below was skipped, and a Dispatch click
	// produced the pod-that-was-never-told-what-to-do this whole file argues
	// against. The binary now passes `gw != nil && KickoffDeliveryWired` — see
	// [KickoffDeliveryWired] for the second conjunct and the ledger that keeps it
	// honest.
	//
	// 🔴 IT IS EXTERNAL KNOWLEDGE AND IT HAS TO BE, WHICH IS WHY IT IS A FIELD
	// RATHER THAN A METHOD ON THIS TYPE. This adapter is the LIFECYCLE half by
	// construction and must never grow a gateway (see the package header), so it
	// cannot answer the question by looking at itself. The answer lives in the
	// binary's configuration, and passing it in is what makes the refusal below
	// conditional on the ACTUAL resolved configuration instead of on a build tag or
	// an assumption about what this build contains.
	//
	// 🔴 THE ZERO VALUE IS "NO GATEWAY", SO IT FAILS CLOSED. A wiring that forgets
	// this field refuses kickoffs it could have delivered — visible, annoying and
	// fixable. The other polarity, defaulting to deliverable, silently restores the
	// create-a-pod-and-strand-the-note behaviour this field exists to remove, and
	// would do so with no error anywhere. Prefer the loud direction.
	KickoffDeliverable bool
	// Logger is optional.
	Logger *log.Logger
	// OpTimeout defaults to [DefaultOpTimeout].
	//
	// ⚠ NOTHING SETS IT TODAY — not buildProvisioner, not any test — and it was
	// kept over a round-0 deletion candidate for one reason: the alternative is a
	// package whose only timeout is a constant, which cannot be shortened by a
	// test that needs to observe the expiry. If no such test exists by the time the
	// reconcile loop lands, collapse this to the constant.
	OpTimeout time.Duration
	// Credentials resolves the model-provider credentials of an agent's OWNER
	// for every spec this adapter builds (internal/credentials.Plane). nil
	// keeps Spec's deployment-wide credentials for every agent — the shape
	// every pre-accounts test builds; cmd/muster-server always sets it
	// (TestTheAgentPlaneResolvesCredentialsPerOwner).
	Credentials CredentialResolver
	// AnonymousGitBase is where a commit job's pull request is fetched from,
	// anonymously: the repository is AnonymousGitBase + "owner/name".
	// Empty is [DefaultAnonymousGitBase], the only production value; tests
	// point it at a local directory (file://…/).
	AnonymousGitBase string

	// ChiefLLMRoute is set when a chief may run on the LLM route
	// (cmd/muster-server chiefllm.go: the docker compose install's chief
	// runtime, or MUSTER_CHIEF_LLM=openrouter on Kubernetes). For a claude-code
	// chief (the reserved slug) it answers whether the chief runs on the LLM
	// route — the server's OpenRouter key through muster's proxy — instead of
	// the Claude subscription token its account holds, or an error naming what
	// to add. On Compose it is the same rule the api's Account page and refusal
	// read (api.ComposeChief.Credential), so the two cannot disagree. nil:
	// every agent's credential comes from Credentials, as before.
	ChiefLLMRoute func(ctx context.Context, owner int64) (route bool, err error)
}

Config is everything the adapter needs. Every field without a stated default is required, and New says which one is missing rather than producing an adapter that fails at the first dispatch.

type CredentialResolver ¶

type CredentialResolver interface {
	ClaudeToken(ctx context.Context, owner int64, account string) (string, error)
	OpenRouterKey(ctx context.Context, owner int64) (string, error)
}

CredentialResolver answers which credentials an OWNER's agent is built with.

🔴 EVERY SPEC BUILD ASKS, FOR THE AGENT ROW'S OWN owner_id. A member's agent is built with that member's setup-token and OpenRouter key and nothing else; the deployment-wide values in Config.Spec (the admin's environment pool and key) are REPLACED, not merged, so a member's pod can never be handed the admin's credential by falling through to them.

type RebindResult ¶ added in v0.114.0

type RebindResult struct {
	// Rebound: this call moved the agent from its `from` account to `to` and
	// re-applied its spec (Err may still report the apply failing).
	Rebound bool
	// Current is the account the agent is on after the call.
	Current string
	// PrevInstance is the backend's id of the instance that was running before
	// the re-apply ("" when none was seen), so a caller can wait for its
	// replacement (ccfailover.Service.AwaitRebound).
	PrevInstance string
	// Skipped says why nothing was moved: the agent is not on `from` any more
	// (another failover moved it), or it is not live (stopped, in error, gone).
	Skipped string
}

RebindResult is what Adapter.Rebind did.

Directories ¶

Path Synopsis
Package scrubexec is the ONE way agentprovision reaches a provisioning driver: a wrapper whose every exec into an agent's container runs with the container's turn credentials removed from its environment.
Package scrubexec is the ONE way agentprovision reaches a provisioning driver: a wrapper whose every exec into an agent's container runs with the container's turn credentials removed from its environment.
Package worktreetest builds, for tests only, the repository a machine job's worktree is made from: an origin whose default branch carries benign agent configuration, and a commit under review that carries hostile configuration of its own — a SessionStart hook, an MCP server, instructions, a nested `.claude/` — each of which, if it reached the CLI, would leave a marker file.
Package worktreetest builds, for tests only, the repository a machine job's worktree is made from: an origin whose default branch carries benign agent configuration, and a commit under review that carries hostile configuration of its own — a SessionStart hook, an MCP server, instructions, a nested `.claude/` — each of which, if it reached the CLI, would leave a marker file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL