Repository navigation
Closed
Milestone
Description
Problem
With session templates (#731) and a combined control plane (#750):
- A session pinned to a store build gets no seed. The session exchange (
exchange.ts) reads the
seed fromSH_SANDBOX_TEMPLATESonly, so a self-serve template (Let users create sandbox templates self-serve, gated by a machine-checked policy #737), which is in no env list,
starts in an empty workspace even though its build's spec carries a seed. - A client cannot read back what a session changed. Only
/v1/runssolve leaves return a patch;
a session's client has no exec on its workspace (the relay's exec route takes sandbox tokens only),
and tool results are clipped. A benchmark that grades a session's work has no way to get it. - No record ties a session to its build. A sandbox has
sandboxrecords on its build's chain (Record template provenance in a hash chain, verifiable offline #730);
a session has none. - Async turns lose the template (with feat(control-plane): async turn submission and turn records (#387) #704). The dequeue-time exchange
(turn-exchange.ts,exchangeTurnCredential, feat(control-plane): resolve an async turn's credential at dequeue (#388 M1) #713/fix(control-plane): #713 review follow-ups — correct the refusal docs, bound the dequeue turn id #714) returnssandboxTierfrom the live session
but none ofsandboxTemplate,sandboxSeed,sandboxSeedSource,sandboxBuildId, which the
session exchange returns. When the async consumer (Coding-agent subagents B4: async leaf worker on P6 (deploy/vm, compose) #389) drains a templated session's turn, it would
run on an untemplated worker, unseeded, with no patch.
Proposal
- The seed from the build: for a session pinned to a
sha256:build, the exchange takes the seed
from that build's ownspec.seedand sendssandboxSeedSource: build | declared; the turn result's
sandbox.seedreports{source, buildId}, so a client can check its workspace was seeded from the
build it pinned. A build with no seed sends none. - The baseline: right after the seed, the harness writes
git rev-parse HEADto.moca-baselinein
the workspace (best effort). - The patch, after every turn of a templated session that leased its sandbox, before the lease is
returned: one exec in the workspace, a throwaway index (GIT_INDEX_FILE),git read-tree $BASE,
git add -Aexcluding.moca-*and.sh-config,git diff --cached --binary $BASE(the agent's own
commits do not hide its work).TurnResult.workspace {baseline, patch | patchBase64, patchSha256, patchBytes}, also on the terminaldoneanderrorframes. OverSH_TURN_PATCH_MAX_BYTES(default
4 MiB, at most the transport's output cap) the patch is left out, never cut:patchRefused: too_largewith its sha256 and size. A capture that fails is{error}and never fails the turn. sessionrecords ontemplate/<id>: at create{sessionId, buildId, templateManifestHash, lease, state: created}and at delete{state: terminated, reason: deleted, endedAt}.- Async turns on a templated session (not in the branch yet; to add in this PR, the maintainers'
choice of the two):- preferred: pin the build on the turn record at submission and return
sandboxTemplate,
sandboxSeed,sandboxSeedSourceandsandboxBuildIdfrom the dequeue exchange, as feat(control-plane): async turn submission and turn records (#387) #704's own
note on live-versus-record fields suggests; - or, until then, refuse
POST /v1/sessions/{id}/turnson a templated session with a clear409, so
no turn runs on the wrong hands.
- preferred: pin the build on the turn record at submission and return
- mocactl (the client part, filed here):
mocactl run --jsonprintsworkspaceandsandbox.seed
from the result and the terminal frames;src/api/frames.ts,harness.ts,types.ts,
headless.ts,render/blocks.tscarry the fields.
What the PR will contain
One PR, about 900 added lines with tests, plus the async-turn part (sized when built) and the client part.
- control-plane:
src/exchange.ts(sessionSeed, the build seed),src/handlers.ts(thesession
records),src/provenance.ts(thesessionkind, if Record template provenance in a hash chain, verifiable offline #730 has not carried it),src/turn-exchange.ts
(the async part). - harness:
src/run-turn.ts(seedOrigin,SEED_BASELINE,captureTurnPatch,withWorkspacePatch),
src/turn-stream.ts;test/turn-seed.test.ts,test/turn-stream.test.ts. packages/k8s-sandbox/src/index.ts(exportsDEFAULT_OUTPUT_CAP).- knative-server:
src/turn-auth.ts,src/server.ts(sandboxSeedSource);test/server-process.test.ts. - mocactl: the files above;
test/harness.test.ts,test/headless.test.ts. - docs:
docs/api/harness-openapi.yaml(TurnResult,FrameDone,FrameError), the session templates
design §5-§5.1,docs/reference/configuration.md(SH_TURN_PATCH_MAX_BYTES).
Depends on
#731, #730, #750. Related: #704 (async turns), #713/#714 (the dequeue exchange), #389 (the consumer).
How to verify
pnpm -C harness test -- turn-seed turn-streampnpm -C packages/control-plane test -- session-templates activation provenancepnpm -C packages/knative-server test -- server-processpnpm -C packages/mocactl test -- harness headless- On a combined deployment: a session pinned to a self-serve build whose spec seeds a repository; the
first turn'ssandbox.seedis{source: build, buildId}; an agent edit and a commit in that turn
both appear inworkspace.patch, which applies cleanly to the seed's commit; deleting the session
writes itsterminatedrecord, and the template's export verifies offline.
Limits / out of scope
- A session has no defined end: one never deleted gets no
terminatedrecord (and keeps its build in
use for a retire). - The patch is per turn; a client takes the last turn's.
- An injected sandbox (a leaf's) is its caller's; leaves take their own patch, as today.
- A seed that leaves no git repository leaves no baseline, and the capture answers
{error}.
Assisted-By: Claude Code
Activity
fix(control-plane): an imported build's session records read as a san…
fix(control-plane): a pinned session's seed fails closed when the tem…
fix(harness): a templated session's workload run takes none of its te…
fix(harness): the turn patch leaves a promoted config out, ignores gi…
docs(reference): change-policy names the control plane's API 1.12.0
fix(control-plane): a pinned session's seed is its build's own spec.seed
feat(harness): a templated turn returns its workspace patch, and the …
feat(control-plane): the session provenance record, a session's span …
feat: a queued turn of a templated session runs on its template, seed…
docs(api): control-plane API 1.10.0 and harness API 1.3.0