Repository navigation
feat(server): record an interactive run's owner from the request that starts it - #2968
Conversation
… starts it A run's owner was read from the session's owner at every run entry. It is now recorded once, when the run is minted, from the verified caller on the request that starts it, and persisted beside the run ID on the session snapshot. Every resume (approval, run ask, plan ask, retry, authorization continuation) reads it back, so a run keeps the owner it started with, across restarts and whatever the session's owner value is later. A RunTeam run takes its owner from the RunTeam caller. Scheduled runs keep their session's owner (#2569). The engine gains Session.BeginRunFor and Session.RunOwner, and sessnap a "run_owner" key; an older snapshot restores a run with no owner, whose gateway calls fail closed. Closes #2947 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ous team run has no owner Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…an proceed run A retried run keeps the owner it started with after the session's owner changes, and the run an approved plan starts on a detached context records the approving caller. The probe tool reports a second execution instead of blocking the run. The mint-site comment no longer lists RetryFailedRun, which continues the stored run. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
- BeginRunFor records no owner for an empty run ID or an identity that is not well framed, so a saved snapshot always restores. - Docs say "verified caller", as the neighbouring Owner docs do; the domain model notes a continuation keeps the run's recorded owner. - The RunTeam run takes its owner through newRunOwner, the one place a run owner is chosen. - Tests: a scheduled run keeps its session's owner; a plan proceed run is owned by its approver, not the plan run's owner; parkRun is shared with driveServiceToAwaiting instead of copied. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
jhrozek
left a comment
There was a problem hiding this comment.
Thanks, this reads well, and the rule that a resume keeps the run's original owner holds up. I traced every resume path: none of them starts a new run or falls back to the session owner. A few comments inline. I'd like two of them fixed before merge: starting a run again with the same ID, and the test with no owner.
One more that has no line in the diff to attach to:
A remote session store driver drops run_owner. adapters/grpcdriver/server.go decodes the snapshot on Save (sessnap.Unmarshal) and encodes it again on Load (sessnap.Marshal). A driver built before this PR has no field for the owner, so it silently drops it. That also applies to a driver built from the published adapters module, which still requires engine v0.19.0. It drops the owner even for runs started after the harness upgrade.
Nothing reaches this today: only mecak8s runs the identity broker, and mecak8s has no --session-store-url. If it did happen, the run's gateway calls would be refused, not allowed. But anyone who later puts the broker in front of a remote driver will lose owners with no error.
Could you add a line to the upgrade implications? It should say that the driver, and the adapters module's engine requirement, must be upgraded together with the harness. It should also say that a missing owner must not be filled in from the session owner.
Beginning the current run again with its ID now changes nothing, so a resume cannot rewrite who started the run; a new run ID still records its own owner. A team run with no run of its own now clears any run the caller's context carries, as rootedRunContext does. The no-verified-caller test resumes as another caller, proving a run with no recorded owner does not take the resuming caller. The domain model names the run owner the host recorded. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes #2947
An interactive run's owner is now recorded once, when the run starts, from the verified caller on the request that starts it. It is stored with the run ID and read back on every resume, instead of being read from the session's owner at each run entry.
What changed
session.SessiongainsBeginRunFor(runID, owner)andRunOwner(). The owner is an inert label beside the existing run ID, copied in and out.BeginRun(runID)records no owner for a new run. Beginning the current run again with its ID changes nothing, so a resume cannot rewrite who started the run.BeginRunForrecords none for an empty run ID or an identity that is not well framed, so a saved snapshot always restores.sessnappersists it under an optional"run_owner"key and checks its framing on restore, like"owner". API snapshot andengine/CHANGELOG.mdupdated (Added, minor).startRunContentLocked) records the owner throughnewRunOwner: the verified caller (session.PrincipalFromContext, the company identity fromsub_idin mecak8s).rootedRunContext, which every engine entry and resume passes through, readssess.RunOwner()instead ofsess.Owner. Retries, approval and run-ask resumes, plan-ask resumes, and MCP authorization continuations mint nothing, so they keep the stored run and owner.RunTeam. The team run takes its owner from theRunTeamcaller, through the samenewRunOwner. A team with no run of its own clears any run on the caller's context, asrootedRunContextdoes.implementation.mdgains a "Run owner checks" bullet for the mecak8s side.domain-model.mdnotes that a continuation keeps the run's recorded owner.Decisions
run-owner.mddefines the run owner as "the person who started a run", with one initiator per run. The broker also records a run's owner on its first call and refuses a later call for that run that reports another. An OAuth callback that resumes an authorization continuation may carry no verified caller at all.RunTeamsupersedes Runs, delegations, and the run owner #2557's sign-off item 1. That item recorded the team run as "owned by the root session's owner" because that is what the code did.run-owner.mdmakes it the caller, as the original Runs, delegations, and the run owner #2557 proposal said. Nothing changes while ownership is enforced, since team lookup admits only the team's owner. With ownership off, another caller's team run reports that caller, and the broker refuses its members' delegation. A team run with no verified caller has no run, so members fail closed. Before, both borrowed the root owner's grant.newRunOwner.agent-definitions.md: "An unfinished run whose owner cannot be restored denies calls."API compatibility
BeginRunFor,RunOwner,sessnap.Snapshot.RunOwner).BeginRunkeeps its signature."run_owner"snapshot key, with no format-tag bump. Rollback is safe, because an older binary ignores the key and falls back to the session owner.adapters/grpcdriver) decodes and re-encodes snapshots, so a driver built against an engine withoutrun_ownerdrops it silently, even for runs started after the upgrade. That includes one built from the publishedadaptersmodule, which still requires enginev0.19.0. Upgrade the driver, and theadaptersmodule's engine requirement, together with the harness. A missing run owner must not be filled in from the session owner: the run's gateway calls are refused instead. Nothing reaches this today, since only mecak8s runs the identity broker and it has no remote session store.Shortcuts
newRunOwner, not inrootedRunContext.Testing
Focused tests:
internal/adapter/server/run_owner_test.go. Two services over onejsonlstoredirectory act as a restart. A probe tool reports the run that reaches a real tool call's context.TestRootedRunContextCarriesTheSessionRun: the run owner, not the session's, and no fallback.TestIdentityBrokerTeamRunOpensTheRootSession: new cases for no verified caller, and for a caller other than the root's owner.engine/adapter/sessnap/run_owner_test.go: byte-identical round trip, an older snapshot, unsafe identities refused, no owner recorded for an empty run ID or an unsafe identity, and beginning the current run again keeps its owner.TestATeamRunWithNoCallerClearsTheContextRun: a team run without a run of its own clears a run already on the context.Mutation checks. Each of these was reverted after the run.
rootedRunContexttosess.Ownerfails exactly the owner-changed and other-caller cases. Single-owner cases pass under both rules, which shows today's behaviour is unchanged.Locally, all passing:
go test ./internal/adapter/server/ ./cmd/mecak8s/go test ./cmd/mecak8s/ -run IdentityBroker(14 tests)sessnap,session, andmemstorepackages, with-racetask lint,task api:check,task docsFull suite.
task testpassed in every module except two tests that pass on their own (3 runs each). They timed out on subprocess launch under load:internal/adapter/microvmmanagerTestDefaultOperationsStartScrubsDaemonEnvironmentAndDetachesFromRequestandcmd/mecatui/agenthookTestDefaultRunnerDeliversPayloadAndHarness. Left to CI: the race matrix, platforms, and Kind deployment.Local end to end. I ran mecak8s's real startup in-process through the
cmd/mecak8sharness, with the identity broker on, the real AS-1 and AS-2, and the embedded vMCP, in--permission-mode default --headless=false. A throwaway harness test, not committed, read the broker's decision records.resolve-askrequest resumed it, and the call ran.Every broker decision was
success, withrun_owner= Alice's company identity = grant owner (owner_verified=true). The subagent's call ran under its own run and delegation and reported the same owner. The stored session'srun_ownermatched the requester for each run ID. A resume after a process restart is covered by the server tests, since the harness has no durable store to restart over.Review
/code-reviewfound 4 issues, all fixed:Panel review against #2947 found no blockers. It raised two important items, both fixed: this compatibility statement, and a test that scheduled runs are unchanged. I took most advisories: the
BeginRunForguards, "verified caller" wording,RunTeamthroughnewRunOwner, the domain-model clause, a sharedparkRun,waitExactPlanProceedwith Bob as approver, and a narrowed test comment.Declined advisories, with reasons:
GrantTypeSystemprincipals innewRunOwner. Unreachable with the broker. Run owners come from session owners, which need OIDC, which turns ownership enforcement on. The broker's owner check refuses such a run anyway.ApprovePlancontinuation, auto-approve, and MCP authorization continuations. Each reaches a seam that is already tested and mutation-checked. New runs take the context caller at the one mint site (covered with a detached context). Resumes read the stored owner inrootedRunContext.principalByteshelper inmemstore. It saves no lines.🤖 Generated with Claude Code