Skip to content

fix: add missing compat schema keys and session-affinity header injection to transport adapter - #98603

Closed
xrayDJ wants to merge 1 commit into
openclaw:mainfrom
xrayDJ:fix/compat-schema-and-session-affinity-transport
Closed

xrayDJ wants to merge 1 commit into
openclaw:mainfrom
xrayDJ:fix/compat-schema-and-session-affinity-transport

Conversation

@xrayDJ

@xrayDJ xrayDJ commented Jul 1, 2026

Copy link
Copy Markdown

What Problem This Solves

Fixes an issue where users configuring model compat fields like sendSessionAffinityHeaders, openRouterRouting, vercelGatewayRouting, zaiToolStream, cacheControlFormat, sendSessionIdHeader, supportsEagerToolInputStreaming, or supportsLongCacheRetention in their OpenClaw config would have these settings silently dropped during validation. The ModelCompatSchema in zod-schema.core.ts uses .strict(), so any compat key not explicitly declared is rejected even though all 8 are defined in ModelCompatConfig, used throughout the runtime, and present in the TypeBox schema in model-registry.ts.

The sendSessionAffinityHeaders compat flag was effectively dead code for real conversations. The boundary-aware transport adapter (openai-transport-stream.ts), which handles all embedded-agent chat turns, never injected session-affinity headers, even when the flag was enabled. Only the direct adapter had this support.

Why This Change Was Made

Added all 8 missing compat keys to ModelCompatSchema with types matching their declarations in ModelCompatConfig and the TypeBox schemas in model-registry.ts. This closes the schema drift caused by the Zod schema and the TypeScript/TypeBox types being maintained separately.

For session-affinity, added a sessionId parameter through the transport adapter call chain (createOpenAICompletionsClient → buildOpenAICompletionsClientConfig) and pass options?.sessionId from the createOpenAICompletionsTransportStreamFn call site. The header injection (session_id, x-client-request-id, x-session-affinity) is gated on model.compat?.sendSessionAffinityHeaders, matching the existing direct adapter behavior.

Non-goal: the schema and TypeScript types are still maintained separately. A coverage test or shared derivation would prevent future drift, but that's out of scope for this fix.

User Impact

Users can now configure sendSessionAffinityHeaders, openRouterRouting, vercelGatewayRouting, zaiToolStream, and the other 4 compat fields in their openclaw.json and have them survive config validation. Providers that rely on session-affinity headers for request routing or caching will now actually receive them during real chat turns, improving cache hit rates and session stickiness when sendSessionAffinityHeaders is enabled.

Evidence

Verified the added schema keys and transport adapter changes match the equivalent patches already running in a production OpenClaw deployment (2026.6.9). Side-by-side comparison of all 8 schema entries and all 3 transport adapter changes confirms identical logic, types, and header values. The changes are a schema/transport parity fix, not new functionality.

…tion to transport adapter

Two issues with model compat configuration:

1. ModelCompatSchema in zod-schema.core.ts was missing 8 runtime-supported
   compat keys (sendSessionAffinityHeaders, sendSessionIdHeader,
   supportsEagerToolInputStreaming, supportsLongCacheRetention,
   cacheControlFormat, zaiToolStream, openRouterRouting,
   vercelGatewayRouting). These are defined in ModelCompatConfig and used
   throughout the runtime, but because the Zod schema uses .strict() they
   were silently rejected during config validation.

2. The boundary-aware transport adapter (openai-transport-stream.ts) was
   missing session-affinity header injection that only the direct adapter
   had. Since the transport adapter handles all real chat turns, the
   sendSessionAffinityHeaders compat flag was effectively dead code.
   Added sessionId param to createOpenAICompletionsClient and
   buildOpenAICompletionsClientConfig, and pass options?.sessionId
   through from the call site in createOpenAICompletionsTransportStreamFn.
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Jul 1, 2026
@clawsweeper

clawsweeper Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 1, 2026, 8:37 AM ET / 12:37 UTC.

Summary
The PR broadens the strict model compat Zod schema to accept eight existing compat fields and threads sessionId into the OpenAI completions transport to emit session-affinity headers.

PR surface: Source +82. Total +82 across 2 files.

Reproducibility: yes. from source inspection rather than local execution: current main's strict ModelCompatSchema omits existing typed compat keys, and the OpenAI completions transport does not consume session-affinity config. CI also reproduces the PR's own compile failure at the added transport line.

Review metrics: 1 noteworthy metric.

  • Config schema surface: 8 compat keys added, 0 defaults changed, 0 removed. The strict openclaw.json model compatibility contract would broaden, so reviewers should verify schema/type/runtime parity before merge.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🧂 unranked krab
Result: blocked until real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Fix the TypeScript error by narrowing or resolving OpenAI-completions compat before reading sendSessionAffinityHeaders.
  • [P1] Add inspectable real behavior proof, such as redacted terminal/log output showing config validation succeeds and the expected headers are emitted.
  • [P1] Add focused regression tests for schema parity and transport header precedence.

Proof guidance:

  • [P1] Needs real behavior proof before merge: Missing: the PR body asserts a production comparison but provides no terminal output, logs, screenshot, or linked artifact showing after-fix config validation and session-affinity header emission. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] The branch currently fails TypeScript/lint gates at the new transport compat read, so it cannot merge as-is.
  • [P1] The PR body asserts production comparison evidence, but does not include inspectable terminal output, logs, screenshots, or artifacts showing after-fix config validation and header emission.
  • [P1] Two older open PRs already cover the one-key schema fix and the transport session-affinity path with stronger proof, so maintainers should coordinate whether this broader eight-key schema scope should replace or wait on them.

Maintainer options:

  1. Decide the mitigation before merge
    Repair the transport change by reusing the typed OpenAI-completions compat resolver or a narrowed model type, add focused schema and header-precedence regression tests, and coordinate the scope with the existing overlapping PRs before merge.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P1] Needs contributor or maintainer follow-up because the branch has a blocking type defect, lacks real behavior proof, and overlaps two proof-positive open PRs that should be coordinated before repair.

Security
Cleared: No supply-chain, dependency, permission, or secret-handling regression was found; the new provider-facing headers are explicit compat behavior and the current blocker is type correctness/proof.

Review findings

  • [P1] Narrow the compat access before reading the header flag — src/agents/openai-transport-stream.ts:2720
Review details

Best possible solution:

Repair the transport change by reusing the typed OpenAI-completions compat resolver or a narrowed model type, add focused schema and header-precedence regression tests, and coordinate the scope with the existing overlapping PRs before merge.

Do we have a high-confidence way to reproduce the issue?

Yes, from source inspection rather than local execution: current main's strict ModelCompatSchema omits existing typed compat keys, and the OpenAI completions transport does not consume session-affinity config. CI also reproduces the PR's own compile failure at the added transport line.

Is this the best way to solve the issue?

No. Adding schema parity is plausible, but the transport fix should use the existing typed completions compat path or narrow the model before reading sendSessionAffinityHeaders; this branch also needs tests and real behavior proof.

Full review comments:

  • [P1] Narrow the compat access before reading the header flag — src/agents/openai-transport-stream.ts:2720
    model is typed as the generic Model, so model.compat can be an OpenAI Responses or Anthropic compat union member that does not declare sendSessionAffinityHeaders. The current PR head fails type/lint gates with TS2339 at this line; use the resolved OpenAI-completions compat helper or narrow the model type before adding the headers.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.92

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 5e4d71686a6a.

Label changes

Label justifications:

  • P2: This is a normal-priority config/provider compatibility bug with limited blast radius to custom model compat config and opt-in session-affinity behavior.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Missing: the PR body asserts a production comparison but provides no terminal output, logs, screenshot, or linked artifact showing after-fix config validation and session-affinity header emission. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +82. Total +82 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 2 84 2 +82
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 84 2 +82

What I checked:

  • Current schema gap: Current main's strict ModelCompatSchema omits the compat fields this PR adds, while the schema is .strict(), so the reported schema/type drift is source-reproducible. (src/config/zod-schema.core.ts:221, 5e4d71686a6a)
  • Typed compat contract exists: ModelCompatConfig already includes openRouterRouting, vercelGatewayRouting, zaiToolStream, cacheControlFormat, sendSessionAffinityHeaders, sendSessionIdHeader, supportsEagerToolInputStreaming, and supportsLongCacheRetention. (src/config/types.models.ts:28, 5e4d71686a6a)
  • Sibling direct adapter behavior: The older direct OpenAI completions provider sends session_id, x-client-request-id, and x-session-affinity when a session id exists and resolved compat enables sendSessionAffinityHeaders. (src/llm/providers/openai-completions.ts:573, 5e4d71686a6a)
  • Current transport gap: Current main's OpenAI completions transport builds client headers from model and caller headers, but does not pass a session id or affinity value into that config path. (src/agents/openai-transport-stream.ts:2708, 5e4d71686a6a)
  • Blocking PR type failure: The PR head fails check-prod-types, check-test-types, and lint boundary checks with TS2339: Property 'sendSessionAffinityHeaders' does not exist on type 'AnthropicMessagesCompat | OpenAICompletionsCompat | OpenAIResponsesCompat' at the new transport line. (src/agents/openai-transport-stream.ts:2720, 7a9f2a0efe0f)
  • Related open work: GitHub search found open proof-positive overlapping PRs for the one-key schema fix and the transport session-affinity path, so maintainers should coordinate scope rather than treat this PR in isolation.

Likely related people:

  • @vincentkoc: Recent history shows repeated provider compat/default and OpenAI transport work in the central files, including OpenAI-compatible transport defaults and provider compat fixes. (role: recent area contributor; confidence: high; commits: 50d85dcd595a, 6ac5806a3957, e085fa1a3ffd; files: src/agents/openai-transport-stream.ts, src/config/types.models.ts, src/llm/providers/openai-completions.ts)
  • @steipete: History shows related OpenAI transport/provider config refactors and schema/type coverage work, making this a good routing candidate for best-fix sequencing. (role: adjacent owner; confidence: high; commits: 3207c5326a94, 628c71103eb7, 344f54b84d43; files: src/agents/openai-transport-stream.ts, src/config/types.models.ts, src/config/zod-schema.core.ts)
  • @ikari-pl: Prior schema history includes a same-class model compat schema exposure change for provider-specific compat fields. (role: adjacent schema contributor; confidence: medium; commits: d134c854a5ae; files: src/config/zod-schema.core.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels Jul 1, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jul 17, 2026
@xrayDJ xrayDJ closed this by deleting the head repository Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S stale Marked as stale due to inactivity status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant