feat(model-gateway): X-RLLM-* headers + inbound bearer auth#552
Open
jeffreysijuntan wants to merge 1 commit into
Open
feat(model-gateway): X-RLLM-* headers + inbound bearer auth#552jeffreysijuntan wants to merge 1 commit into
jeffreysijuntan wants to merge 1 commit into
Conversation
Header-stamped session metadata becomes the canonical identity carrier
for gateway requests. Body fields (`metadata.rllm.*`) and the legacy
`/sessions/{sid}/v1/...` URL form are kept as field-by-field
fallbacks; rLLM headers are stripped before forwarding upstream so
they never leak to providers.
Adds:
- `metadata.py` — `RllmMetadata` dataclass + `extract_metadata()` with
precedence header > body > path, merged field-by-field (so a request
can carry `session_id` in the URL and `run_id` in a header and both
contribute).
- Middleware attaches `RllmMetadata` to ASGI scope and gains an
optional inbound-auth gate: when a bearer token is configured, every
request must present `Authorization: Bearer <token>` (HMAC-compared)
or get 401. Used by remote-sandbox eval where the gateway is exposed
via a public tunnel.
- TraceRecord gains the rLLM identity fields (`run_id`, `harness`,
`step_id`, `parent_span_id`, `span_type`); `data_process.build_trace_record`
populates them from `RllmMetadata` when present.
- `models.py` carries the future-facing config fields (`UpstreamRoute`,
`routes`, `run_id`, `run_metadata`, `inbound_auth_token`) so the
upstream-proxy PR can wire them up without further model churn.
Tests: 22 new (15 metadata precedence/extract, 7 inbound-auth).
Full unit suite: 242 passed.
This was referenced May 5, 2026
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.
Summary
Stacked on #551. Header-stamped session metadata becomes the canonical identity carrier; body fields and the legacy
/sessions/{sid}/v1/...URL form are kept as field-by-field fallbacks. rLLM headers are stripped before forwarding upstream so they never leak to providers.metadata.py:RllmMetadatadataclass +extract_metadata()with precedence header > body > path, merged field-by-field (so a request can carrysession_idin the URL andrun_idin a header and both contribute).RllmMetadatato ASGI scope and gains an optional inbound-auth gate: when a bearer token is configured, every request must presentAuthorization: Bearer <token>(HMAC-compared) or get 401. Used by remote-sandbox eval where the gateway is exposed via a public tunnel.TraceRecordgains the rLLM identity fields (run_id,harness,step_id,parent_span_id,span_type);data_process.build_trace_recordpopulates them fromRllmMetadatawhen present.models.pycarries the future-facing config fields (UpstreamRoute,routes,run_id,run_metadata,inbound_auth_token) so the upstream-proxy PR can wire them up without further model churn.Stack
Test plan
python -m pytest tests/unit/— 242 passedtest_metadata.py(header/body/path precedence, field-level merge, scope-shape decoding)test_inbound_auth.py(token absent → open, presented → 200, missing/wrong → 401, HMAC compare)🤖 Generated with Claude Code