Repository navigation
Renew a run's model gateway pass when it runs out, and send the call again once - #3004
Merged
Merged
Conversation
…again once
On staging an unattended job ran past its run's ten-minute pass to the model gateway; its next
model call got the gateway's 401 and the run ended. The server mints a fresh pass on every step it
carries a run through, but inside one engine run a long query, a harness's own tool loop or a step's
retries can outlast it.
The route may now carry a refresh credential ("refresh": "obgr_..."). On a 401 with
`x-openbot-pass: expired`, and only that, each engine's own hop asks the gateway for a fresh pass
(POST <gateway root>/pass with the refresh credential as its bearer), sends the call again once with
it, and keeps it for every later call of the run. Calls that run out together wait on one renewal.
A renewal that fails, a 401 without the header, and a second expired 401 hand back the gateway's 401
as it came. No refresh credential: as before. Neither credential is logged. This is OAuth's way with
an expired token (RFC 6750 §3.1), as google-auth and Claude Code do it.
- shared/run_model_key.py: the httpx hook every Python harness shares keeps the run's pass and
refresh credential in one holder in the context variable, and renews on sync and async clients.
- agent-claude-sdk: a thread's slot holds the run's pass, so the proxy renews Claude Code's calls
and the slot keeps the fresh pass.
- shared/model-pass.ts: a fetch for the TypeScript engines. agent-langgraph-ts gives it to
ChatOpenAI and ChatAnthropic on the gateway route (a renewed call is one call to retry.ts);
agent-mastra puts it innermost under its signing and tool-call-index fetches, one pass a run.
- Tests through each engine's real hop against a gateway stand-in on loopback: renewal, the next
call on the fresh pass, one renewal for concurrent calls, and the four ways it must not renew.
The Python harness contract checks renewal in every harness that runs on the gateway.
davidmckayv
requested review from
MikeRyanDev,
dustywusty,
guidovizoso,
mxmzb,
samjulien and
tylerslaton
as code owners
December 5, 2026 09:11
…t engine renews a run's pass
…does not renew A confidential client authenticates when it refreshes a token (RFC 6749 §6 and §10.4; RFC 9700 §4.14), so a refresh credential that leaked should be no use alone. Each engine already holds MANAGED_AGENT_TOKEN, the token it checks on the server's runs, and the gateway will now refuse `POST <gateway root>/pass` without it. So the renewal, and only the renewal, sends it trimmed as `x-openbot-agent-token`; with it unset or blank the engine does not ask, and the call gets the gateway's 401 as it came. It is never logged or shown on inspection. - shared/run_model_key.py: the run's pass holds the engine's secret, read when the run starts; every Python harness and the Claude engine's proxy go through it. - shared/model-pass.ts: RunPass takes the engine's secret; agent-langgraph-ts passes the engine's env, agent-mastra its process env. - The fake gateways require the header as the server will and record any model request that carried it. New tests: renewal with the right header, no renewal with the secret unset or blank, a renewal the gateway refuses for another engine's secret, and Mastra never showing the model the `OpenBot model route` entry, its pass or its refresh credential.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
For each run, the server gives an engine a short-lived pass to its model gateway (
openbotModelRoute.token, about ten minutes). The server now mints a fresh one on every step it carries a run through. But inside one engine run, the pass could still outlast its life, and the next model call got the gateway's 401, which ended the run:Now every engine's own hop renews the pass and sends the call again once. That is how an OAuth client treats an expired bearer token:
The contract:
"refresh": "obgr_…"besidetoken.x-openbot-pass: expired, never on any other 401. A provider's own key refusal carries no such header.POST <gateway root>/passwith the refresh credential as its bearer, gets{ "token": … }, sends the call again once, and keeps the fresh pass for every later call of the run.x-openbot-agent-token(MANAGED_AGENT_TOKEN), on that request and no other. An engine is a confidential client, and a confidential client authenticates when it renews (RFC 6749 §10.4; RFC 9700 §4.14, https://www.rfc-editor.org/rfc/rfc9700.html). With it unset, an engine doesn't renew. The server renews only for a run that is still going, and a refresh credential lasts two hours at most.Where:
shared/run_model_key.py: the httpx hook every Python harness shares (adk, ag2, agno, antigravity, crewai, langgraph-agui, langroid, llamaindex, microsoft, openai-agents, pydantic-ai, strands). One holder per run, sync and async.agent-claude-sdk/src/run_model_proxy.py: a thread's slot holds the run's pass, so Claude Code's calls renew and the slot keeps the fresh pass.shared/model-pass.ts, a renewingfetchused in two places:agent-langgraph-tsgives it to ChatOpenAI and ChatAnthropic on the gateway route. A renewed call is one call toretry.ts.agent-mastraputs it innermost, under its signing and tool-call-index fetches, with one pass per run.Where it runs
/passis stateless: a signed credential in, a signed pass out.Boundary and audit
API and database
api/, no app's requests, no database change and norelease-policy.json. The gateway is internal to a deployment.Changelog
Bots.
Proof
Each place has tests through its real hop against a gateway stand-in on loopback. They cover renewal, the next call on the fresh pass, one renewal for concurrent calls, and the four ways it must not renew: a 401 without the header,
/passrefusing or unreachable, no refresh credential, and a second expired 401.agent-claude-sdk/tests/test_run_model_pass.pydrives the real Anthropic SDK, sync and async. Red 10 failed, green 14 passed.shared/harness_contract.pygainscheck_pass_refresh, run in every harness's contract test (red on pydantic-ai: 2 failed).tests/test_run_model_key.pyrun the real Claude Code. Red 2 failed; the whole suite passes (198).test/model-route.test.tson both wires. Red: the renewal tests failed. Green: 133 passed, and typecheck is clean.agent-langgraph-agui/test_provider_boundaries.py, which need Docker and fail the same way on main./passwithout the engine's token, as the server does, and asserts no model call carries it. Renewal carries it trimmed; with it unset or blank, nothing is asked and the 401 comes back. Red then green: Python 12 failed → 203 passed; langgraph-ts 6/6 failed → 133 passed; Mastra 6 failed → 69 passed.OpenBot model routeentry, its pass and its refresh credential never reach what the model is told or the request bodies it receives.