Skip to content

agents: delegate model connection use for start-run runs - #1186

Merged
railgrid-prow[bot] merged 2 commits into
mainfrom
agents-start-run-delegation
Nov 17, 2026
Merged

railgrid-prow[bot] merged 2 commits into
mainfrom
agents-start-run-delegation

Conversation

@cwilhit

@cwilhit cwilhit commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Why

The first live App Studio → Agents call on railgrid-dev failed. The prospecting Project's researcher integration called start-run/v1 on a model-backed agent. The action admitted the run, and the run failed 40 ms later:

modelproviderconnections.agents.railgrid.ai "railgrid" is forbidden: use permission is required

invokeRun starts the run with context.WithoutCancel(r.Context()), which keeps the shard-stamped caller. When the run resolves the agent's ModelProviderConnection, AuthorizeModelProviderConnectionUse treats the run as attended and asks the caller for use. The caller is the Project's workload identity, which holds exactly its granted actions, and the hub's identity policy has no clause for use on a connection. So, as #1181 shipped, no model-backed agent can serve an App Studio app.

What

Runs admitted through start-run/v1 spend the agent's configured models under the delegation that Schedule, Trigger and Webhook runs already use (docs/agents-model-provider-connections.md, "Access").

The delegation is a fact of the run, not of the request:

  • store.Run.ModelUseDelegated (new column model_use_delegated) is written at admission, only by start-run, and never cleared by a rewrite. Both the memory and Postgres stores are covered.
  • runTurn is the one path every start, resume, recovery and sub-agent turn takes. It runs a delegated run with no attending caller, using the new SDK helper dataplane.WithoutProxiedIdentity.
    • So an inbox approval no longer asks the approver for use, and crash recovery behaves the same way.
    • Configured delegates inherit the delegation. Configuring them is the same trusted delegation as configuring the parent's models.
  • Harness admission resolves the credential the same way, so an agent with a configured reasoning effort is not refused when start-run is called.
  • The run verb is unchanged and still requires use from its caller.

Trade-off, now stated plainly in the docs: anyone with RBAC on agents/start-run (plus get on the agent) can spend the agent's configured models without use. Anyone who can create a Schedule for the agent can already do that. Agents does not check consent itself; App Studio's grant flow does.

Docs updated: the model-connection design doc's Access section, docs/provider-actions.md, the Agents README, the skills/railgrid agents reference, and the AGENTS.md e2e table.

Testing

  • Unit test through serve.New, on the production admission path (provider view and vwSecrets):
    • start-run reaches the configured model and the run Succeeds.
    • The run verb from the same caller is refused at the use check, with no model call.
  • Resume test: a delegated run resumed under an approver without use reaches the model. The same run without delegation is refused.
  • Store round-trip of the flag, against memory and a real Postgres 16.
  • New real-kcp e2e case (TestNStartRunDelegatesModelConnectionUse in agentsprovider):
    • Setup: a tenant ServiceAccount with get on agents and create on agents/run and agents/start-run, no use; a real ModelProviderConnection; a fake model served from the test process.
    • Calls go through the hub's kcp front door and the results are read off the real Run objects.
  • Each new test fails without its part of the fix. With the delegation switched off, the e2e case fails with the exact railgrid-dev message.
  • Other gates:
    • make e2e-agents-provider: all 15 tests pass.
    • providers/agents go test ./...: all packages pass, with Postgres.
    • provider-sdk/dataplane tests pass.
    • golangci-lint: 0 issues on both modules and the e2e suite.
    • hack/verify-provider-contract.mjs: 0 violations.
    • make verify-boilerplate: passes.

Not yet verified: the live call on railgrid-dev after deploy.

🤖 Generated with Claude Code

A run admitted through the start-run/v1 action kept the caller's proxied
identity on its context, so resolving the agent's ModelProviderConnection
asked the caller for `use`. The caller of start-run is an App Studio
Project's workload identity, which the hub never grants `use`, so every
model-backed run started from an app failed at once with
"use permission is required". Found on railgrid-dev with the first live
App Studio -> Agents integration call.

start-run is an automation grant (consent-gated, risk medium), so its runs
now use the agent's configured models under the same delegation as
Schedule, Trigger and Webhook runs. The caller is still authorized for
agents/start-run and gated on `get` for the agent; only the connection use
check stops asking about it. The `run` verb is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cwilhit

cwilhit commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

/approve

@railgrid-prow

railgrid-prow Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cwilhit

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Review of the first fix found that a context flag on the start-run request
was the wrong altitude: an inbox approval resumed the run under the
approver's identity without the flag (so an approver without `use` failed
it), crash recovery behaved differently, and the exported helper that
switched off the check was ambient authority.

The delegation is now a fact of the run:
- store.Run.ModelUseDelegated (column model_use_delegated), written at
  admission by start-run/v1 only and never cleared by a rewrite (memory
  and Postgres).
- runTurn, the one path every start, resume, recovery and sub-agent turn
  takes, runs a delegated run with no attending caller, via the new
  dataplane.WithoutProxiedIdentity. Rebuilt runs (resume, background) and
  configured delegates carry the field.
- Harness admission resolves the credential the same way for a delegated
  run, so an agent with a configured reasoning effort is not refused at
  start-run time.
- agentsclient.WithDelegatedModelUse is removed.

Tests:
- The unit regression now goes through the production admission path
  (provider view, vwSecrets) and asserts the configured model was called
  and the run Succeeded; the run verb is still refused with no model call.
- A resume test: a delegated run resumed under an approver without `use`
  reaches the model; the same run undelegated is refused.
- Store round-trip for the flag, memory and Postgres.
- New real-kcp e2e case in agentsprovider: a tenant ServiceAccount with
  get + agents/run + agents/start-run and no `use`, a real
  ModelProviderConnection, a fake model in the test process. Verified to
  fail with the railgrid-dev message when the fix is switched off.

Docs no longer overclaim: anyone with RBAC on agents/start-run spends the
agent's configured models, Agents does not check consent itself, and the
delegation covers configured delegates and resumes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cwilhit
cwilhit requested a review from mjudeikis as a code owner November 17, 2026 14:17
@railgrid-prow
railgrid-prow Bot merged commit 7d9f3d1 into main Nov 17, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant