Repository navigation
ENG-15749: fix(agent): preserve per-turn provider session headers - #141
Conversation
|
I'll analyze this and get back to you. |
There was a problem hiding this comment.
All reported issues were addressed across 17 files
Heads up: you’re close to your included review allowance. Set a flex budget so reviews don’t pause.
Re-trigger cubic
There was a problem hiding this comment.
1 issue found across 12 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/agents/sessions/sdk.ts">
<violation number="1" location="src/agents/sessions/sdk.ts:216">
P1: When a model carries any non-session model or per-turn header, this merge drops it from the outbound request; the smoke injector, for example, loses `X-Boon-Provisioning-Smoke-Run-ID`. Merge `modelHeaders` into the base headers, keeping runtime headers ahead of ordinary model headers, then reassert the signed smoke session.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
…9-smoke-refund-openclaw
…9-smoke-refund-openclaw
The header-preservation fix for provisioning smoke turns also moved model.headers to the end of the merge order in three places (anthropic.ts's 5 createClient branches, model-registry.ts, sdk.ts), letting a static model header win over dynamicHeaders/optionsHeaders/ resolved auth for every session, not just smoke ones. Restore the pre-existing merge order everywhere; the narrow preserveProvisioningSmokeSessionHeader reassertion still does the actual job of protecting a smoke session's headers. Also broadens that reassertion itself: it only ever restored X-Boon-Session-ID, but the Gateway needs X-Boon-Provisioning-Smoke-Run-ID and X-Boon-Provisioning-Smoke-Capability to travel with it too. A stale/incomplete upstream header set could silently drop those two while the session id alone survived, breaking refund attribution while looking intact. Co-Authored-By: Claude Sonnet 5 <[email protected]>
There was a problem hiding this comment.
e2e review across ENG-15749 (this PR + boon#14260, boon-llm-gateway#85, anychat-boon-web#81).
The narrow fix does exactly what it says.
preserveProvisioningSmokeSessionHeaderrestoresX-Boon-Session-ID— AND, correctly broadened this pass,X-Boon-Provisioning-Smoke-Run-ID+X-Boon-Provisioning-Smoke-Capability— frommodelHeaders(Gateway/AnyChat-injected) when downstream attribution would otherwise overwrite them.- Reason this matters: the Gateway middleware requires all three headers together (session validated via signed capability), and boon-core's session-id refs a
provisioning-smoke-…value. Ordinary attribution overwriting even one of the three breaks refund attribution silently while looking intact. The reassertion covers the whole triple.
The critical correctness point in the last commit. ENG-15749: restore per-session header precedence, keep smoke reassertion reverts a subtle regression that the earlier commits introduced: an intermediate revision moved model.headers to the END of the merge order in anthropic-transport-stream.ts (5 branches), model-registry.ts, and sdk.ts — which would have made a static model header win over dynamicHeaders/optionsHeaders/resolved auth for every session, not just smoke. Restoring the pre-existing merge order everywhere and letting the narrow reassertion do the actual smoke job is the right shape — ordinary sessions retain their runtime-attribution-wins precedence, only smoke sessions get their signed triple protected.
Model-registry change.
mergeTransportHeaders(model.headers, providerHeaders, modelHeaders)thenpreserveProvisioningSmokeSessionHeader— clean.- Bearer
Authorizationis now correctly merged last (mergeTransportHeaders(headers, { Authorization:Bearer ${apiKey}})) so a dynamic bearer beats a static modelAuthorization— regression test in place. - The subtle spec commentary in
model-registry.test.tsabout why the model.headers-not-registered variant tests the source-order regression is worth its weight; that's the exact class of bug this PR was created to prevent.
Per-turn plumbing. applyModelRequestHeaders threads params.modelRequestHeaders from RunEmbeddedAgentParams → runEmbeddedAttemptWithBackend → params.model clone at the top of runEmbeddedAttempt. No mutation of the passed-in model object ({ ...model, headers: mergeTransportHeaders(model.headers, headers) }), and the identity short-circuit (if (!headers) return model) avoids unnecessary allocations.
Boon usage headers guard. withBoonUsageHeaders now skips any header whose lowercase name already exists — no accidental overwrite of an explicitly-set X-Boon-Session-ID from the smoke path.
Regression surface.
- Only case-insensitive merge behaviour changes, and the smoke-triple reassertion is opt-in (empty modelHeaders → identity). Every existing precedence test is preserved.
- Anthropic transport: 4 branches now use
mergeAnthropicRequestHeaders, all with the same shape. sdk.tsandanthropic-transport-stream.tstests explicitly cover: "preserves an explicit smoke session over runtime attribution" + "keeps ordinary runtime attribution ahead of an ordinary model session" — the exact two regressions this could have introduced.
Tests. 118 checks green, 24 skipped, 2 neutral — no failures. test: cover model request header propagation adds the end-to-end propagation test.
Secrets clean. Only test fixtures.
Ship it. 🧙
…9-smoke-refund-openclaw
…191) Carries #190 (ENG-19115) — forward run.oboToken into the embedded runner params so x-boon-gateway-obo-token is actually emitted and the tier-1 signed-OBO meter-skip fires — and #141 (ENG-15749) preserve per-turn provider session headers. Fork gateway + @openclaw/slack + @openclaw/msteams + @openclaw/diagnostics-prometheus bumped in lockstep via release:prep; CHANGELOG.md gains the 2026.6.11-boon.35 section the prepack requires.

What Problem This Solves
Fixes an issue where a provisioned smoke turn could have its signed per-turn session identity overwritten by ordinary request attribution. The Gateway then rejected the otherwise valid smoke capability before the model request could run.
Why This Change Was Made
Canonicalize request header names case-insensitively across model resolution and Anthropic transport. Provider-authenticated per-turn headers take precedence over ordinary attribution only when both target the same header, preserving normal behavior for all other requests.
User Impact
Provisioning validation now reaches the tenant model route with the intended signed session context. Customer chat requests retain their normal attribution behavior.
Evidence
Related: ENG-15749
Summary by cubic
Preserves signed provisioning smoke session headers so smoke turns reach the Gateway with the intended session and refund attribution intact. Previously, ordinary attribution could overwrite a smoke turn's signed
X-Boon-Session-ID(e.g. viax-boon-session-id), causing Gateway rejection.X-Boon-Session-ID,X-Boon-Provisioning-Smoke-Run-ID, andX-Boon-Provisioning-Smoke-Capabilitytogether so refund attribution isn't lost.Authorizationahead of any static modelAuthorizationin the registry.GetReplyOptions.modelRequestHeadersthrough the embedded runner and applies them after cached model headers.X-Boon-Session-IDto aprovisioning-smoke-...value viamodelRequestHeadersto reach the Gateway under the intended session, supporting ENG-15749.Written for commit b53a072. Summary will update on new commits.