Skip to content

feat(server): record an interactive run's owner from the request that starts it - #2968

Merged
rdimitrov merged 8 commits into
mainfrom
claude/interactive-run-owner-fbfee6
Nov 24, 2026
Merged

rdimitrov merged 8 commits into
mainfrom
claude/interactive-run-owner-fbfee6

Conversation

@rdimitrov

@rdimitrov rdimitrov commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

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

  • Engine. session.Session gains BeginRunFor(runID, owner) and RunOwner(). 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. BeginRunFor records none for an empty run ID or an identity that is not well framed, so a saved snapshot always restores. sessnap persists it under an optional "run_owner" key and checks its framing on restore, like "owner". API snapshot and engine/CHANGELOG.md updated (Added, minor).
  • Server. The one run-mint site (startRunContentLocked) records the owner through newRunOwner: the verified caller (session.PrincipalFromContext, the company identity from sub_id in mecak8s). rootedRunContext, which every engine entry and resume passes through, reads sess.RunOwner() instead of sess.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 the RunTeam caller, through the same newRunOwner. A team with no run of its own clears any run on the caller's context, as rootedRunContext does.
  • Helpers. Unchanged: a helper's delegation already takes its owner from the delegating run on the context, so it now inherits the request's owner.
  • Docs. implementation.md gains a "Run owner checks" bullet for the mecak8s side. domain-model.md notes that a continuation keeps the run's recorded owner.

Decisions

  • A resume keeps the owner the run started with. It does not take the resuming caller. run-owner.md defines 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.
  • New runs started on someone's behalf. A steer promotion, or a run an approved plan starts, mints a new run owned by the caller of the request that started it: the steerer, or the approver. Today ownership enforcement makes all of these the session's owner.
  • RunTeam supersedes 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.md makes 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.
  • Scheduled runs keep their session's owner (Phase 2, Slice 3: Scheduled runs — A scheduled run calls gateway tools on its own grant, with no one present #2569). The shortcut comment now names only Phase 2, Slice 3: Scheduled runs — A scheduled run calls gateway tools on its own grant, with no one present #2569 and sits in newRunOwner.
  • A run with no recorded owner fails closed. The user chose this over falling back to the session owner. It matches agent-definitions.md: "An unfinished run whose owner cannot be restored denies calls."

API compatibility

  • Assessment: no wire change. No protobuf, HTTP, or event field changes, and no client-visible semantics change while ownership is enforced. The run owner goes only to the in-process identity broker (experimental, mecak8s only, single replica). With ownership enforced (OIDC on, which the broker's session owners need), the caller equals the session owner on every run entry, so the reported owner is the same value as before.
  • Major/feature changes: none. No major bump, no feature identifier, no approval needed.
  • Go source: additive engine API (BeginRunFor, RunOwner, sessnap.Snapshot.RunOwner). BeginRun keeps its signature.
  • Stored data: a new optional "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.
  • Upgrade implications:
    • A run parked on an approval, or a failed run awaiting retry, that was saved before the upgrade has a run ID but no recorded owner. After the upgrade, its resume carries no run, so its gateway calls are refused. A new prompt starts a run with an owner.
    • The same happens if an older replica re-saves a session during a rolling deploy. The identity broker supports one replica only.
    • A remote session store driver (adapters/grpcdriver) decodes and re-encodes snapshots, so a driver built against an engine without run_owner drops it silently, even for runs started after the upgrade. That includes one built from the published adapters module, which still requires engine v0.19.0. Upgrade the driver, and the adapters module'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.
    • Deployments without the identity broker are unaffected.

Shortcuts

Testing

Focused tests:

  • internal/adapter/server/run_owner_test.go. Two services over one jsonlstore directory act as a restart. A probe tool reports the run that reaches a real tool call's context.
    • Approve and run-ask resumes keep Alice's owner when resumed by Alice, and when the session's owner value has changed to Bob, who resumes.
    • A new run is owned by its caller, and a run with no verified caller has no owner. Every case resumes as Bob, so a run with no owner does not take the resuming caller.
    • A retry keeps the owner after the session's owner changes.
    • A plan proceed run is owned by its approver.
    • A scheduled run keeps its session's owner whatever the context's caller.
  • 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.

  • Reverting rootedRunContext to sess.Owner fails exactly the owner-changed and other-caller cases. Single-owner cases pass under both rules, which shows today's behaviour is unchanged.
  • Making detached control contexts drop the caller fails the plan test.
  • Removing the scheduler branch fails the scheduled test.

Locally, all passing:

  • go test ./internal/adapter/server/ ./cmd/mecak8s/
  • go test ./cmd/mecak8s/ -run IdentityBroker (14 tests)
  • engine sessnap, session, and memstore packages, with -race
  • task lint, task api:check, task docs

Full suite. task test passed in every module except two tests that pass on their own (3 runs each). They timed out on subprocess launch under load: internal/adapter/microvmmanager TestDefaultOperationsStartScrubsDaemonEnvironmentAndDetachesFromRequest and cmd/mecatui/agenthook TestDefaultRunnerDeliversPayloadAndHarness. 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/mecak8s harness, 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.

  • Alice signed in, created a session, and prompted.
  • The main agent's gateway call asked. A separate resolve-ask request resumed it, and the call ran.
  • The main agent then delegated a subagent, which made its own gateway call.
  • Alice signed in again and prompted a second run.

Every broker decision was success, with run_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's run_owner matched 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-review found 4 issues, all fixed:

  • the upgrade effect, now documented above;
  • untested retry and plan-proceed owners, now tested;
  • a stale comment at the mint site;
  • a probe tool that could deadlock.

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 BeginRunFor guards, "verified caller" wording, RunTeam through newRunOwner, the domain-model clause, a shared parkRun, waitExactPlanProceed with Bob as approver, and a narrowed test comment.

Declined advisories, with reasons:

  • Drop GrantTypeSystem principals in newRunOwner. 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.
  • End-to-end tests for steer promotion, the legacy ApprovePlan continuation, 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 in rootedRunContext.
  • A shared principalBytes helper in memstore. It saves no lines.

🤖 Generated with Claude Code

rdimitrov and others added 7 commits November 24, 2026 12:03
… 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]>
…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]>
- 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]>

@jhrozek jhrozek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread engine/session/session.go Resolved
Comment thread docs/architecture/domain-model.md Resolved
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]>
@rdimitrov
rdimitrov requested a review from jhrozek November 24, 2026 11:57
@rdimitrov
rdimitrov merged commit e41144f into main Nov 24, 2026
50 checks passed
@rdimitrov
rdimitrov deleted the claude/interactive-run-owner-fbfee6 branch November 24, 2026 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Record an interactive run's owner from the request that starts it

2 participants