Local apps as execution surfaces
Delegating a planner Task to an app the user already pays for, running on
a machine they own, with MemQL's tools reachable from inside that app over
MCP. Epic memql#4358;
design record
docs/superpowers/specs/2026-08-22-local-apps-as-execution-surfaces-design.md.
The engine drives exactly two apps today — Claude Code (claude-code) and
Codex (codex) — and that set is closed in the engine on purpose. See
Why the app set is closed.
The shape of it
planner Task the user's machine executionSurface=containerExecutor executorBackend=cockpit-app:claude-code │ ▼ cockpit-app backend ────── app gate ───────► refused, with a reason (agent node) naming which gate │ │ AppSessionStart {credential, mcpEndpoint, workspace, prompt} ▼ WorkerService.Stream ═══════════════════════► memql (the Cockpit) │ │ │ ◄══ AppSessionChunk (stdout/stderr/event) ══ │ runs `claude -p` │ ═══ AppSessionControl (cancel / renew) ════► │ │ ◄══ AppSessionEnd {exitCode, usage, ...} ═══ │ ▼ │ v1:worker:appSession │ MCP over HTTPS v1:router:call (billing=subscription) ▼ mcp.<domain>/mcp ◄── the app, acting as the userThe engine cannot dial the machine. It is behind NAT. The stream the cockpit opened outward is the only channel, so it is the transport, and MCP is the back-channel the app uses to reach back in.
The cockpit installs as the
memqlcommand (memql#4553). The engine builds abin/memqltoo, but that one only ever runs inside a pod; these two never share a PATH.
Why the app set is closed
claude-code and codex are the only ids the engine will open a session for.
A cockpit may report others — they are stored on
v1:worker:registration.apps and are never given a routing label, so they are
visible in the console and unroutable.
This is the direction that fails safe. A cockpit ships on its own cadence; if
an unknown id could be driven, a newer cockpit reporting a third app would make
the engine attempt a protocol it does not have, at dispatch time, inside
somebody's plan. Growing the set is a value change in
component/worker/apps.go — not a wire change.
Why a machine must be BOTH allowed and signed in
An app:<id> routing label is derived only from an entry that is:
allowed | the machine's own policy.yaml apps.allow lists it |
signedIn | the app's auth state, as the cockpit can observe it |
Either one false means no label, which means the router cannot select that machine. The alternative — selecting on presence and discovering the refusal on the far side — commits a plan to a machine that then rejects it, and the resulting failure names the wrong thing.
What the machine measures
signedIn used to mean only that the app's credential files exist, so an expired
login read as signed in. Each machine now checks on a schedule that its apps can
really answer, and reports readiness on the same entry:
readiness | What it means | Selectable |
|---|---|---|
ready | signed in with usage left, as of the last check or real turn | yes |
signed_out | no login, or an expired one. signedIn is false too | no |
out_of_usage | signed in with no usage left. usageResetsAt says until when, if the app did | no |
unknown | the machine has not checked yet, or its check could not tell. readinessDetail says why | no |
| absent | a Cockpit that predates the checks | yes, as the one exception |
Selection admits only ready. An app that is offline, signed out, out of usage or
unchecked cannot be reached, and Ask's Apps route reads as not ready when no app can
answer.
A Cockpit that predates the checks is the one exception. It sends no word at all,
and refusing it would take every current machine out of routing until it upgraded. So
it keeps the file-based answer it always had, reads as Not checked in Fleet, and a
call it refuses moves on to the next app. A Cockpit that measures always sends a word,
unknown before its first check, so this cannot admit an app a machine could not vouch
for. The exception can be removed once no machine in a fleet reports silence.
The answer lives on the registration row, so a replica without the machine's stream reads the same thing, and selection reads the row again rather than trusting a door built a moment earlier. The engine compares no clock: the machine re-checks at a reset and reports the change.
Codex's check spends nothing and runs every 5 minutes. Claude Code has no free way to ask, so it is pinged hourly while it works, for about 600 tokens, at most 30 times a day per machine, and never with anything that could bill API credit. An app that is not working is asked every 15 minutes, because a refused ping is free. A running session suppresses the check, and every real turn counts as one, so a busy machine never pings. One check that cannot tell keeps the last answer and is repeated within a minute, so a timeout on a busy machine does not take a working app away. The machine side has the details.
An exhausted app stays out until its machine says otherwise. The state is durable: the machine's check keeps asking, and its reset time and credits decide when the app comes back. A reset passing does not send anybody's real call to find out, and neither does a timer. Buying credits or a reset shows within that app's check interval.
Signing into an app takes effect on the next heartbeat, not the next
reconnect: an inventory change is applied to the live registry immediately and
persisted outside the 60-second lastSeenAt throttle, because it is a routing
change. Persisting it there is also what lets a planner node answer "is a
machine with this app online" — that node holds no worker streams at all, so
the row and its derived labels are the only thing it can read.
When an app refuses a call
An app the machine last measured as working can still turn a call away, because the login expired or the plan ran out since that check, and a Cockpit that predates the checks measures nothing. The call moves to the next app only when nothing ran: no model served it, it has no result, no action was recorded or dropped, no tokens were reported, and the only text is the refusal itself. Any other failure may have caused effects, so it is returned rather than run again.
| What the app said | What the rest of the call skips | How long that machine's app is skipped |
|---|---|---|
| Out of usage | that app on every machine, because a limit belongs to the account | until a check on that machine says it can answer |
| Signed out or expired | that app on that machine, because a login belongs to one machine | until a check on that machine says it can answer |
A Cockpit that predates the checks has only the clock: a limit lasts until the reset the app names, or 15 minutes if it names none, and a login lasts 15 minutes. The next call after that is what finds out, and a refusal then moves on to the next app.
A call pinned to one app stays on that app and may only move to another machine. When nothing is left, the call fails with the app's own sentence.
Codex names its reset in the machine's time zone without saying which, so the engine reads the earliest time it could mean. An app can come back up to a day before its real reset; the next call then costs one more refusal and no tokens.
Signing in from Fleet
A machine's Apps page in Fleet offers Sign in when an app reads as signed out. It
works when you are not at the machine, because the page opens in your own browser and
none opens there. Only the machine's owner can start one, and the app must already be
allowed for this cluster in the machine's own policy.yaml.
The login stays on the machine. The app writes it there, and no token crosses to the cluster. What crosses is the sign-in page's address, a device code to enter on it (Codex), or a code the page shows that you paste back (Claude Code). A pasted code goes to the app waiting on the machine and is written to no row and no log line. It is useless without the verifier that process holds.
The address and the device code are on a v1:worker:appSignIn row only the machine's owner
can read, with no cluster-owner access, and are cleared when the sign-in ends. It runs on
the agent holding the machine's stream, whichever replica took your call
(fleetAppSignIn forwards it). A machine whose Cockpit predates this gets the older
Connect instead, a setup goal in Ask.
There is no button to retry an app, because the machine checks on its own. A ready
measured after a refusal ends the block that refusal started.
When an app stops partway
A step that has already done work cannot simply be run again, because its actions have effects. So when an app runs out of usage or loses its login partway through a step, the next ready app takes over: it gets the same step, the record of what ran, and where the work is, and it carries on.
- The machine has to say so. The app's own protocol must report the limit or the login. Any other failure, a crash or a timeout included, may have left an action half done and is never taken over. A Cockpit that predates this reports nothing, so the step fails as before.
- The record has to be complete. The journal of what ran is what the next app is told as fact, and what the first app wrote travels as its own account, not as evidence. If an action was dropped, or an output did not reach the Library, nothing takes over and the step fails saying why.
- The next app is on the same machine if it can be, in the same working directory, with the files as they were left. Otherwise another of your machines carries on, with what reached the Library delivered to its working directory.
- A choice stays a choice. An app you pinned, or an Only strategy, stays that app.
- You can see it. The run gets a note naming both apps, each session's record stays on its own child run, and the next app says that it took over.
A chat turn with no step has no record to hand over. One that ran no action sends the same prompt to the next app, unless part of an answer was already shown. If nothing else is ready, the step fails with the app's own sentence, and the work so far is kept.
Which machine, and on which replica
Selection is the Fleet router
(epic memql#4349), asked for
the app:<id> label as a requirement. It applies the owner's routing policy,
orders by their chosen strategy, and knows which replica holds each machine's
stream. Nothing in this feature picks between machines itself — a second
selector would disagree with the first, and the plan would commit to a machine
that then refused.
A session runs only on the replica holding that machine's stream, and a
call can be forwarded there. A machine's WorkerService stream terminates on
exactly one agent replica. The planner holds no streams at all, and with two
agent replicas the one serving a turn is the one holding the laptop about half
the time. So an app-door call made anywhere else is forwarded to the agent
holding the machine (AppCallForward on NodeService.Stream, the
ModelForward shape):
- Planner prompts can now use app Sources. When a Route (the one a Rule
picks) or an Ask pin puts
app:claude-codeorapp:codexahead of a local model, the planner's triage, compile and compose calls are answered by that app on the owner's machine. The planner resolves the Source once, picks the machine from the persisted registration (connectedNodeId) and forwards the RESOLVED call -- never the prompt for a second resolution, so there is one router and one decision record per call. - The holding agent decides whether it runs. It verifies the forwarded authority, that the machine is the verified subject's own and not revoked (app sessions are never lent -- sharing lends a machine's models, not its signed-in apps), the app gate (the owner's own pin or a Rule's Route, and the kill switch when it is engaged), and that it still holds the stream with the app allowed and signed in. It never forwards again.
- A refusal moves the Route on. A holder that is not reachable, that no
longer holds the stream, or whose gate refuses answers with a named reason and
"nothing started", so the Route tries its next Source. The app gate's
refusal comes back under its own code (
kill_switch_engaged,app_not_named_by_owner) exactly as on the agent itself. - Cancellation and loss cross the hop. A caller that has already given
up -- typically because a slower first Source used up the triage's deadline
-- sends nothing at all. A caller that gives up mid-call sends a cancel and
the session on the machine is stopped. The holder registers every forwarded
call before it runs it, so a cancel that arrives right behind its request,
or even ahead of it, still stops it: the call is refused before anything
opens (
caller_cancelled). The call also carries the caller's remaining deadline, so a cancel that never arrives still ends the session when the caller stopped waiting, not at the ten-minute ceiling. A holder that goes away mid-call is noticed when its stream ends, not waited out; the session may have run there, so the call is not re-run on a second machine -- the Route moves on to its next Source instead. An answer that arrived just before the stream ended is still the answer. - The same app, whichever node asks.
app:*follows the owner's delegation policyappOrderon the planner exactly as on the agent, so one Route never picks Claude Code in triage and Codex in the reply. - A vision call keeps its refusal. When the holder cannot land a vision
call's images, the refusal comes back as
app_vision_staging_failed, not as "no machine can run this app", and no other machine is tried: the images land in the holder's storage, which the next machine would share.
Only the chat door forwards. A chat, structured or vision turn is one call
and crosses; a tool-needing STEP (the session door, below) does not -- it runs
as a session subrun on the replica whose delegate opens it. On a node that does
not hold the stream, a tool turn therefore passes an app Source over with
"a step handover opens its session on the agent holding the machine's stream"
and takes the next Source in the Route. A goal whose owner chose Apps avoids
that pass-over at dispatch: an agent holding no eligible stream leaves the run
to the agent that does
(choosing the execution replica).
Auto and a Route with other Sources keep ordinary arbitration, so a tool turn
there can still pass an app over. System work with no acting user never
gets an app door on any node: a session's credential names a person. The
inference-status row (appEligible, runnableApps) asks the chat door's
question, so a replica that can forward to the laptop reports the app door
open -- which is what its chat and structured calls find.
A cockpit that reports no apps at all is normal — that is what a build older than the app protocol does, and what a machine with neither binary on PATH does. It is not an error state.
Sessions, not dispatches
A ToolDispatch carries one timeout and returns one result. A headless
claude -p can run for an hour and emits output the whole way, so an app run
is a session:
| Message | Direction | Carries |
|---|---|---|
AppSessionStart | server → worker | app, kind, prompt, inputs, workspace, credential, mcpEndpoint, limits, responseSchema, level |
AppSessionChunk | worker → server | stream (stdout / stderr / event), data, seq |
AppSessionControl | server → worker | cancel or renew_credential |
AppSessionEnd | worker → server | exitCode, usage, appSessionRef, producedArtifactIds, result, model, effort |
The level goes out; the model comes back. level is one of the closed four
(fast, strong, reasoning, embeddings) and says how much intelligence the run
needs rather than which model serves it. THE COCKPIT owns the translation into the
app's own knobs -- Claude Code's --model and --effort, Codex's model flag and
reasoning-effort key -- from one table per app the machine's owner may override in
policy.yaml, because the knob names are the app's and only the machine knows which
app, at which version, is installed. An EMPTY level is what every session had before
the field: the app runs at its own defaults. embeddings is always refused -- an
embedding must come from the embedder of the index it is written into, and no app
exposes one.
model and effort on the end are what the app REPORTED, never what was asked for.
Empty means it did not say, which is recorded as unknown: a report copied from the
request would record as measured something nobody measured. Claude Code's headless
output states no effort at all, so an empty effort is the ordinary case.
Three kinds:
run— headless and autonomous. The engine reads the output.open— launch the app for the HUMAN with the workspace and prompt loaded. Ends when the window closes, or immediately with a failure if the app cannot be opened.attach— stream a run the human started, named byapp_session_ref.
A tool-needing call resolved to an app door now opens a
runsession (epic memql#5391, design D7). It used to be passed over: MemQL drives a tool loop and an app is an agent that drives itself, so the app could not serve the TURN -- which meant that on a cluster whose only open door is a signed-in Claude Code, Ask stayed dark. The app does not serve the turn; it takes the whole STEP, drives its own loop, reaches MemQL's tools back over MCP, and answers once. The step records achildRunIdnaming the subrun, and a call carrying no step is REFUSED at resolution rather than falling through to the vendor behind it. A call made inside a run takes its run and step KEY from the run context when it did not name them, so every work turn -- an Ask'sreasonstep included, pinned or not -- carries one; only a call outside any run is refused this way.runis still the only kind anything initiates today. The protocol carries all three and the runner accepts all three;openandattachhave no engine-side caller yet, because a planner Task is autonomous by definition — they are for a console hand-off and a resume, neither of which exists. Said plainly here rather than implied, because the same section of CLAUDE.md spent two years describing a coding agent nothing ran. The cockpit half implements all three (memql-cockpit#347 / #350); the engine-side initiator is the missing piece.
Chunk seq is monotonic, and out-of-order or duplicate chunks are dropped.
A transcript is a record; silently interleaving a replayed chunk corrupts it in
a way no later reader can detect.
A session is RECORDED as rows of the work spine (epic memql#5396). The
stream on each chunk decides where it goes: an event is a completed action
the cockpit normalized -- a command, a file read or write, a fetch, a call back
into MemQL -- and becomes one v1:work:step plus one v1:work:observation in
the session's recording run, which the row names as sessionRunId. stdout
and stderr are the model's prose and become one content-addressed
v1:library:file at end, named as transcriptFileId. The row used to carry a
flattened 256 KiB transcript string with the stream and the sequence
discarded; transcript and transcriptBytes are retired.
Three things an operator reads off that:
recordedStepsanddroppedActions. A hole in the action sequence is recorded as anoteobservation on the run AND counted on the row, because anything lifted from an incomplete recording is incomplete and a silent gap lets that happen unnoticed. A refused repeat is not counted: the first copy was recorded.- File contents are content-addressed. Two identical writes are one Library
file referenced twice, so a later branch from a recorded step costs no copy.
A content above the per-file cap is referenced BY DIGEST with
contentOmittedrecorded, and a Library failure never fails the session. - An app's MCP calls are recorded by the MCP node, not by the replica
running the session -- the harness sees an opaque result and the session's
replica never sees the call at all.
submitandnext_taskare excluded: they are the session's protocol rather than its work.
A node with no recorder wired runs the session and records nothing, exactly as
it did before; sessionRunId is then empty, which is not the same answer as a
session that did nothing.
A caller context that dies cancels the run on the machine. Otherwise a plan that was cancelled leaves a headless agent working on somebody's laptop. A worker disconnect ends every live session with a named error rather than leaving callers parked until their own deadlines expire.
Only the replica holding a session ends its row, so a sweep ends the rest.
While a replica holds a session it re-writes the row's heartbeatAt every
two seconds -- including after the app's output stops, while the transcript
is stored -- and keeps the recording run's heartbeat fresh too (unless the run
belongs to a delegated step, whose own journal beats it). A heartbeat names no
status: the row is promoted to running once, on the first chunk, so a row
the sweep has failed stays failed until the holder's own terminal write.
workerAppSessionStaleSweep runs every two minutes on the cron leader and
fails a starting or running row whose heartbeat is older than 90 seconds
(the holder is gone), or whose session started more than 4.5 hours ago (longer
than any session may run). It writes only the status, exit code, error and end
time: no result, so an answer the app submitted over MCP survives the close,
and no usage or billing, so a holder that ended the row first keeps its
account. The machine being online is not the
test: after a pod restart it re-registers on another replica within seconds,
while the session the dead pod held is orphaned. Both graces are
globalVariables an operator can widen without a release:
MEMQL_APP_SESSION_STALL_GRACE_SECONDS and MEMQL_APP_SESSION_MAX_AGE_SECONDS.
A recording run is its driver's, not the dispatcher's. The recording (and
every other Go-written journal) carries triggeredBy: journal:<template>, and
the work dispatcher never adopts a run with that prefix. Before it did, every
agent replica claimed each recording a millisecond after it opened, could not
load a template called appSession, and failed it automation_not_runnable
over the session's own outcome.
The back-channel credential
At session start the engine mints a class="app_session" JWT and sends it
with mcpEndpoint = https://mcp.<domain>/mcp. The cockpit writes the app's MCP
configuration naming both, runs the app, and deletes that file at end.
Its sub is the owning user's id. That single choice is the security
story: the app reads over MCP as that user, so row authz applies to it
exactly as it does to their browser. The machine-credential interceptor pins
the surface to read/query and stamps role=system rather than owner, so the
credential reaches no credential mutation and no cluster-owner gate.
Why it has a class of its own (memql#4857)
It was minted as class="service_account" until then, and the collapse cost a
capability the design had already granted on paper.
Every other machine class names a machine: a node token's subject is a
binary, a service account's is a CI job. This one's subject is a person.
component/server/http_access.go refuses to resolve an HTTP actor for a
machine class, and it is right to — the Library's byte routes stamp ownership
from actor.userId, so resolving one for a binary would invent somebody to own
the bytes. With one class name covering both kinds of subject, that rule could
not be stated for one and not the other, and the cockpit's Library.Pull and
Library.Push 401'd against the user's own rows.
With the class separated, the rule is sayable and narrow:
| Surface | service_account | app_session |
|---|---|---|
gRPC MemqlService.Stream | read/query pin | the same pin |
POST /artifacts, GET /artifacts/{id}/content, the chunked session family | refused | admitted, as the user it names |
POST /sites/{id}/bundles | admitted | refused |
Over HTTP the token carries no role claim, so the actor resolves to
reader plus the real user id. That is enough for the byte routes — they gate
on the actor resolving to a USER and never on a role — and short of every admin
gate. Nothing else about the credential widened.
It is not revocable, and this doc will not pretend otherwise
The verify path is JWKS-only and DB-free — that is what lets it work on every node without a lookup — so there is no row to strike. Revoking one issued token means rotating the cluster's signing key, which invalidates every other token in the cluster. That is not a per-session operation.
Three things stand in for revocation:
- The lifetime is short and hard-capped at 8 hours by the identity service, whatever the delegation policy asks for.
- The cockpit deletes the MCP configuration file at session end, which is where the bearer actually lives.
- A run that outlives its credential is handed a replacement
(
AppSessionControl{renew_credential}) rather than a longer-lived bearer up front, so no single bearer is ever long-lived.
Residual exposure: the unexpired remainder of one short-lived, user-scoped, read-surface-pinned bearer. That is the trade the DB-free verify path buys.
The mint widens the bootstrap secret
POST /node/bootstrap with tokenClass="app_session" is the mint surface —
the request field and the resulting class claim now agree, which they did not
before memql#4857. Before this path existed, that secret bought only the
machine principal node; it now also buys a user-scoped one.
Narrowing it:
- the named user must exist (a forged subject would verify and then act as a user nobody can point at in an audit);
- the TTL is clamped at the identity service;
- the surface stays read/query-pinned;
- the session id is the token label, so a leaked bearer traces back to the run it was handed to.
An operator who does not want this path at all leaves
MEMQL_NODE_BOOTSTRAP_TOKEN unset, which darkens the whole endpoint exactly
as it does today.
Consent
An app session has its own gate, not the computer-use gates workerHost
takes. Those answer "may this agent run this command on this user's
computer"; an app session is the owner's own app, on their own machine, doing
work that was routed to it. Every app session asks the same gate
(integrations/agent/worker/app_gate.go) — a step handed over through the
session door and a turn through the chat or structured app door alike, and a
delegated Task through the same executor:
-
apps.allowon the machine — the app is allowed in that machine'spolicy.yamland somebody signed into it. The cockpit enforces it, the registration reports it, and theapp:<id>routing label reflects it. -
The machine is the owner's — an app session runs only on the machines of the person it runs for. There is no sharing opt-in for app sessions: the session's back-channel credential names a person.
-
A decision named the app — and the router reaches an app door two ways:
- A routing rule's chain. The chain names
app:<id>because the cluster's AI routing configuration wrote it there. That configuration is one document for the whole cluster, not a per-owner policy; what makes the session the owner's is items 1 and 2 — the door resolves only against their own machines, where their ownapps.allowconsented to it. - An explicit pin — a provider named on the request itself, which skips
every rule. A pin opens a session only when the person the session runs
for made it: their own request naming the app, their own step
override. A pin anybody else made — another user's agent whose record
stores
app:<id>, a prompt author's@defaultProvider, a deploy-time env var — is refused asapp_not_named_by_owner. The router carries which of the two a door was, and who made a pin, to the gate.
A delegated Task reaches an app because the owner's delegation policy routed its kind there, and carries no pin.
- A routing rule's chain. The chain names
-
The kill switch, when it is explicitly engaged —
v1:identity:user.preferences.computerUseEnabled == falsecloses every app session. Unset is not engaged. A preference read that fails is neither, and refuses askill_switch_unreadable: it neither opens a machine the owner may have switched off nor tells them they switched it off. -
The goal's execution destination, for a session inside a work goal. The destination says where a goal's tools run, and an app session on your machine counts as moving the work to your computer: it is refused as
execution_destination_requires_permissionunless you chose the Apps route for that goal or approved the move for that run. One exception: a tool-free turn (no images, no inputs) in a goal set to Auto runs the app with no tools, so it is a model call like a local model, and it is admitted on a machine whose Cockpit declares that it runs such a turn without tools (inferenceOnlyon its app descriptor). That is what lets a goal nobody is present to approve -- a pipeline's diagnosis of a failed run -- use your apps. A goal explicitly set to Workbench, a turn with images or inputs, and a whole step handed to an app keep the refusal.
No agentAuthorization row and no computerUseScope is read, and there is no
per-task approval or classifier pass: a cluster where no agent was ever granted
a shell still opens the sessions routed to its owners' apps.
A refusal names which gate refused it (app_not_named_by_owner,
kill_switch_engaged, kill_switch_unreadable, "is not allowed and signed
in", "is not <owner>'s machine"). The pin and the kill switch are asked before
a machine is chosen — and on the session door before the step's child run is
opened — so a refused call never opens anything, on the machine or in the
Work feed.
Delegation is a preference with a fallback
v1:worker:delegationPolicy, one row per user. MemQL OS → Fleet → Apps
edits the caller's delegation preferences and shows app sessions. It reads
the policy on demand, reports when it was read, and saves the complete form.
Opening the editor does not enable delegation. Fleet → Machines also shows
apps reported by a machine.
| Field | Meaning |
|---|---|
preferSubscriptionApps | the master switch. False (the default, and the state of an absent row) means never delegate |
eligibleKinds | task kinds that may be delegated. An empty list allows nothing — opting in does not opt every kind in with it |
appOrder | which apps to try, in order. An app not listed is never selected even on a machine that has it |
maxConcurrentSessions | live sessions across every machine. 0 reads as the default of 1, never as "none" |
workspaceRoot | where the engine names a directory for a handed-over step or Task: one per run. An inference turn (chat or structured) never gets one — it is one session, and the machine chooses. Unset lets the machine choose for every session — AppSessionStart.workspace is sent empty and the machine runs it in a scratch directory under its own roots. The cockpit still gets to veto a path outside its own roots |
credentialLifetimeSeconds | default 4h, clamped to 8h at the mint |
Older Cockpit releases. The machine-side implementation lives in the monorepo's
cockpit/internal/worker/appsession/. Cockpit releases up to v0.16.0 refuse an emptyAppSessionStart.workspace("no workspace in AppSessionStart"). Those releases require a step or Task whose owner set aworkspaceRoot; inference turns through the app door require a published Cockpit release with scratch-directory support.
If no machine with an allowed, signed-in app is online, the task runs in-process. A plan never waits for a laptop to wake up: a delegation design that can block turns "my laptop was asleep" into "my plan hung", which is worse than the cost it was trying to save.
task.delegationReason records the outcome on both branches:
| Reason | Means |
|---|---|
delegated | a machine was found |
delegation_not_enabled | the master switch is off |
kind_not_eligible | the kind is not in eligibleKinds |
no_apps_configured | appOrder is empty |
no_machine_with_app_online | nothing online has an allowed, signed-in app from appOrder |
max_concurrent_sessions_reached | the cap |
task_has_no_owner | a machine-touching backend cannot run unattributed |
The reasons are checked cheapest-first so the recorded one points at the real cause: somebody with delegation switched off is told that, rather than "no machine online" — which would send them to check a laptop that was never going to be consulted.
Accounting
Every session writes one v1:router:call row, including failures: a run
that burned an hour of somebody's subscription and then crashed still spent it,
and a cost surface that records only successes understates what work cost.
billing∈metered | subscription | unknownexecutionSurface=cockpit-app:<appId>door=appfor a chat turn an app answered,sessionfor a whole STEP an app was handed and drove its own loop through (they are different answers, so they are different values)servedModel/servedEffort= what the app reported, empty when it said nothingplan.tokenSpentSubscriptionaccumulates the covered spend separately fromplan.tokenSpent
The dollar ceiling excludes subscription tokens; the loop caps include the call. The two caps want opposite answers, so they are counted in different places. Counting covered tokens against the ceiling would park a plan over money nobody was charged — and the more a user leans on the subscription they already pay for, the sooner their plans would stop, which is backwards. A cap blind to those calls, meanwhile, is a hole the cheapest path walks straight through.
Everything a session produced carries producedBy. {app, model, effort, sessionId} is stamped on each v1:library:artifact the session pushed -- the
transcript included -- and on the backing v1:library:file row, by the session runner
at end. model and effort are the app's own report and may be empty; sessionId
is the v1:worker:appSession row the run is readable at. A lifted construct's source
reads this stamp, which is what lets its provenance say "recorded from claude-code,
model X, effort Y, session Z".
It is ABSENT on anything a person uploaded, and the absence is the answer. A stamp
naming no app would read as "an app produced this and reported nothing", which is a
different fact from "nobody delegated this". The upload route physically cannot write
one: its params struct has no field for it, and the two stamping mutations are
@serverOnly. Caller-scoping is not the alternative there -- the party who would
write a false stamp is the row's own OWNER, and actor.userId answers whose row it is
rather than whether the claim on it is true.
Cost is never synthesised. MemQL knows its own providers' per-token prices,
not the prices inside somebody's subscription. totalCost carries what the app
reported (claude --output-format json gives total_cost_usd) and nothing
when it reported nothing. billing falls to unknown whenever the app's usage
report or the machine's subscription signal is silent — the number the owner
asked for is only worth having if silence stays visible as silence.
Operating it
# Is the machine reporting apps at all?psql "$MEMQL_DATABASE_DSN" -c \ "select payload->>'name', payload->'apps' from memory_nodes where concept='v1:worker:registration' order by created_at desc limit 5;" # Which sessions are live right now?psql "$MEMQL_DATABASE_DSN" -c \ "select id, payload->>'app', payload->>'status', payload->>'billing' from memory_nodes where concept='v1:worker:appSession' and payload->>'status' in ('starting','running');" # Did the agent node install the executor?kubectl logs -n memql deploy/agent | grep 'cockpit-app container executor installed'Symptoms
| What you see | What it means |
|---|---|
cockpit-app: the backend is registered but not wired on this node | the Task reached a node with no WorkerService. Only an agent node serves one |
cockpit-app: no credential minter configured | MEMQL_IDENTITY_VERIFIER_BASE_URL or MEMQL_NODE_BOOTSTRAP_TOKEN is unset on the agent. The run is REFUSED rather than started with a blank bearer — an app with no credential reaches nothing over MCP and reports that as "MemQL's tools are broken" |
no machine online with claude-code allowed and signed in | check Fleet -> Machines page; the badge says which half is missing |
Failed to authenticate: OAuth session expired, Not logged in, 401 Unauthorized | the app's login on that machine is missing or expired, even though Fleet may show it signed in. Press Sign in on that machine's Apps page in Fleet, or run claude auth login or codex login on the machine. The call has already moved on where another app could take it |
You've hit your usage limit | that app's plan is out of usage. It is skipped until the reset it names, and the call moved on where another app could take it |
executorBackend "..." is not registered at task creation | the name was validated against RegisteredExecutors(). With an empty registry the message says so |
app_holder_unreachable / "the agent holding its stream (...) is not reachable from this node" | the registration names an agent replica this node cannot reach (restarted, or the row is stale). Nothing started; the route moved on. The machine re-registers on a live replica within a heartbeat |
app_holder_gone | the agent holding the machine went away while the session ran. The session may have run on the machine; the call is not re-run elsewhere and the route moved on |
caller_cancelled | the caller gave up -- a cancel, or its deadline passed -- before the session opened on the machine. Nothing ran. Common when a slower first Source in the Route used up the call's deadline |
| "a step handover opens its session on the agent holding the machine's stream" | a TOOL turn resolved on a node that does not hold the machine's stream. Chat and structured calls forward; a step does not. Expected on the planner and on the replica without the laptop |
| "No agent replica is holding this session any more" | the node holding the session died, or the session outlived the longest any session may run. workerAppSessionStaleSweep closed the row a few minutes after its last heartbeat. Whatever the app already did on the machine stays there; ask again to start a new session |
Environment
No new variables. The path reuses MEMQL_IDENTITY_VERIFIER_BASE_URL,
MEMQL_NODE_BOOTSTRAP_TOKEN and MEMQL_MCP_PUBLIC_URL.
The cockpit half
Implemented in the monorepo's
cockpit/ module
for memql#4364: app detection (claude / codex on PATH, versions, auth state),
apps.allow in policy.yaml, the session runner (process supervision,
streaming, cancel, resume by app session id), the MCP config writer and its
cleanup, the Library pull/push with the session credential, and the open kind
per platform.
Related
- Workers runbook — the tool surface, whose computer-use gates app sessions do not take
- MCP connect — the endpoint the back-channel dials
- LLM cost control — the layered spend guardrails
- Service-account JWTs — the credential class
See inference cost estimates for the distinction between app-reported usage, a dated API-equivalent estimate and actual billing. A subscription or zero legacy cost report does not establish that work was free.