Skip to content

fix(gateway): honor session history Accept negotiation - #116535

Merged
steipete merged 3 commits into
mainfrom
codex/autoqa-session-history-accept-20260730
Jul 30, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/autoqa-session-history-accept-20260730

Conversation

@steipete

@steipete steipete commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where session-history HTTP clients could be switched from a finite JSON response to a persistent SSE stream when the Accept header merely contained a lookalike media type, a quoted decoy, malformed parameter syntax, or an explicit text/event-stream;q=0 rejection.

Why This Change Was Made

Session-history negotiation now uses one quote-aware RFC 9110 media-range parser instead of substring matching. It opts into SSE only for an explicit exact text/event-stream range with positive effective quality, applies media parameters and specificity regardless of q ordering, and intentionally leaves wildcards on the finite JSON representation.

The change is confined to representation selection for the existing endpoint. It adds no route, configuration, authentication behavior, or protocol shape.

Standards note

RFC 9110 section 12.5.1 removed the older accept-params / accept-ext grammar. It says senders should put q last, but recipients should process any parameter named q as weight regardless of parameter ordering. Accordingly, this parser treats every non-q parameter—before or after q—as a media-range parameter. Reintroducing the RFC 7231-era post-q extension rule would make valid current-standard ranges select the wrong representation.

User Impact

REST and automation clients reliably receive JSON unless they explicitly request an acceptable event stream. Standards-compliant EventSource-style requests continue to receive SSE, while malformed or rejected stream ranges no longer create surprising long-lived responses.

Release-note context: Gateway session history now honors strict HTTP Accept negotiation instead of opening SSE streams for rejected or lookalike media types.

Evidence

  • Before: direct route regressions reproduced text/event-streaming, quoted decoys, and text/event-stream;q=0 opening SSE through substring matching.
  • After: 72 focused helper and real Gateway HTTP tests passed on rebased exact head b3355e1e6b202e269d4abcf112262ac97d686545, including valid SSE, finite JSON fallbacks, qvalue precedence/order, parameter specificity, quoted delimiters, empty slots, and malformed whitespace.
  • Blacksmith Testbox tbx_01kyt9z4fwadr8hb5a6ar7k1d9; changed gate and focused suite succeeded in run 30577465815.
  • Final Codex autoreview on the complete exact-head branch: clean, confidence 0.98.
  • git diff --check: clean.
  • Contract source: RFC 9110 section 12.5.1, including removal of post-weight accept extensions and order-independent q recognition.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M maintainer Maintainer-authored PR labels Jul 30, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jul 30, 2026
@clawsweeper

clawsweeper Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 30, 2026, 4:17 PM ET / 20:17 UTC.

ClawSweeper review

What this changes

The PR makes the Gateway session-history endpoint select its persistent SSE response only for an explicit, acceptable text/event-stream media range, returning finite JSON for lookalikes, quoted decoys, malformed ranges, rejections, and wildcards.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

The patch appears correct and resolves the substring-based SSE selection bug without changing routes, authentication, or protocol shape. It should remain open because the protected maintainer label and the intentional compatibility change need explicit maintainer acceptance before merge; the prior post-q concern is resolved by RFC 9110 and the author’s documented contract decision.

Priority: P2
Reviewed head: b3355e1e6b202e269d4abcf112262ac97d686545
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Strong focused regression proof and a narrow standards-backed patch, with protected maintainer compatibility acceptance remaining outside the quality rating.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body reports direct before-and-after Gateway HTTP route regressions, 72 focused exact-head tests, a Testbox run, and a linked successful changed-gate run; this is sufficient real behavior evidence for a non-visual HTTP response-selection change.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body reports direct before-and-after Gateway HTTP route regressions, 72 focused exact-head tests, a Testbox run, and a linked successful changed-gate run; this is sufficient real behavior evidence for a non-visual HTTP response-selection change.
Evidence reviewed 5 items Changed Gateway decision point: shouldStreamSse now delegates to hasExplicitAcceptableMediaRange using the actual SSE content type, replacing accept.includes("text/event-stream"); this directly addresses lookalike and rejected media-range false positives.
Focused boundary coverage: The PR adds direct Gateway HTTP and helper coverage for exact matches, case handling, parameters, quoted delimiters, malformed syntax, q=0, q-value precedence, specificity, and finite-JSON fallbacks. The supplied PR evidence reports 72 focused checks on the exact head.
HTTP contract: RFC 9110 §12.5.1 defines media-range parameters and requires recipients to process any parameter named q as weight regardless of ordering; it removed the former accept-extension grammar. That supports the revised handling of parameters after q.
Findings None None.
Security None None.

How this fits together

Gateway session history serves either a finite JSON history response or a persistent Server-Sent Events stream to authenticated HTTP clients. The request Accept header drives that representation choice before the endpoint writes the response headers and body.

flowchart LR
  Client[HTTP client] --> Accept[Accept header]
  Accept --> Parser[Media-range parser]
  Parser --> Decision{Explicit acceptable SSE?}
  Decision -->|Yes| Stream[SSE session-history stream]
  Decision -->|No| Json[Finite JSON history]
  Stream --> Consumer[Client consumer]
  Json --> Consumer
Loading

Decision needed

Question Recommendation
Should this PR intentionally change existing session-history clients that used wildcard, lookalike, or substring Accept values from a persistent SSE response to finite JSON? Accept strict negotiation: Merge after refresh if maintainers accept that only an explicit positive exact SSE range opts into the persistent response.

Why: The implementation is narrowly supported by the HTTP contract, but accepting an upgrade-visible representation change is a product and compatibility decision reserved for protected maintainer review.

Before merge

  • Resolve merge risk (P1) - Existing clients that depended on the previous substring or wildcard behavior can receive finite JSON instead of a persistent SSE response after upgrade. The change is deliberate and standards-aligned, but the protected maintainer review should explicitly accept that compatibility boundary before merge.
  • Resolve merge risk (P1) - The PR head is behind current main; refresh the merge result and allow the remaining required checks to finish before landing.
  • Complete next step (P2) - No mechanical repair is indicated; a Gateway owner must accept the intentional compatibility change and review the refreshed merge result.
Agent review details

Security

None.

PR surface

Source +199, Tests +198. Total +397 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 3 206 7 +199
Tests 1 198 0 +198
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 404 7 +397

Review metrics

None.

Stored data model

Persistent data-model change detected: serialized state: src/gateway/sessions-history-http.test.ts, unknown-data-model-change: src/gateway/sessions-history-http.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Accept strict HTTP negotiation (recommended)
    Approve the intentional move from legacy substring/wildcard SSE selection to explicit positive exact media-range negotiation after the refreshed head is green.
  2. Add a supported compatibility path
    If known clients require permissive selection, define and test an explicit upgrade-safe compatibility mode rather than restoring raw substring matching.
  3. Pause pending client contract confirmation
    Do not merge until Gateway ownership confirms no supported client contract depends on wildcard or lookalike SSE selection.

Technical review

Best possible solution:

Keep strict RFC 9110 parsing, retain the finite JSON fallback for wildcard and non-exact requests, and merge only after a Gateway owner explicitly accepts the intentional response-selection compatibility change on the refreshed head.

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

Yes from source and the supplied exact-head test evidence: the former includes("text/event-stream") decision makes lookalike and q=0 values select SSE, while the new parser tests cover those cases. A live local reproduction was not run in this read-only review.

Is this the best way to solve the issue?

Yes, subject to maintainer acceptance of the compatibility boundary: centralizing quote-aware RFC 9110 media-range parsing is safer and more maintainable than adding more substring exclusions. Restoring obsolete post-q accept extensions would contradict the current HTTP contract.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 78fd4f99fe96.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: The bug affects a user-visible Gateway response representation and can create an unexpected persistent stream, but the blast radius is limited to session-history HTTP clients.
  • merge-risk: 🚨 compatibility: Merging deliberately changes legacy loose or wildcard Accept values from SSE to finite JSON for existing clients.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body reports direct before-and-after Gateway HTTP route regressions, 72 focused exact-head tests, a Testbox run, and a linked successful changed-gate run; this is sufficient real behavior evidence for a non-visual HTTP response-selection change.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body reports direct before-and-after Gateway HTTP route regressions, 72 focused exact-head tests, a Testbox run, and a linked successful changed-gate run; this is sufficient real behavior evidence for a non-visual HTTP response-selection change.

Evidence

What I checked:

  • Changed Gateway decision point: shouldStreamSse now delegates to hasExplicitAcceptableMediaRange using the actual SSE content type, replacing accept.includes("text/event-stream"); this directly addresses lookalike and rejected media-range false positives. (src/gateway/sessions-history-http.ts:61, b3355e1e6b20)
  • Focused boundary coverage: The PR adds direct Gateway HTTP and helper coverage for exact matches, case handling, parameters, quoted delimiters, malformed syntax, q=0, q-value precedence, specificity, and finite-JSON fallbacks. The supplied PR evidence reports 72 focused checks on the exact head. (src/gateway/sessions-history-http.test.ts:452, b3355e1e6b20)
  • HTTP contract: RFC 9110 §12.5.1 defines media-range parameters and requires recipients to process any parameter named q as weight regardless of ordering; it removed the former accept-extension grammar. That supports the revised handling of parameters after q. (src/gateway/http-media-range.ts:1, b3355e1e6b20)
  • Maintainer review context: The visible follow-up comment rejects restoring RFC 7231-style post-q accept extensions and states that the exact-head tests cover matching and mismatching parameters after q; the PR’s current head was force-pushed afterward to b3355e1e6b202e269d4abcf112262ac97d686545. (b3355e1e6b20)
  • Current review state: The supplied checks show the focused quality, security, dependency, type, and real-behavior-proof jobs passing; broader build and smoke jobs were still in progress, so this review does not treat CI completion as a merge authorization. (b3355e1e6b20)

Likely related people:

  • steipete: Authored all three commits in this PR and the visible follow-up comment records the RFC 9110 interpretation governing the disputed Accept-parameter behavior. (role: recent Gateway contributor and contract-decision author; confidence: medium; commits: 58765ab88e9b, c09525590819, b3355e1e6b20; files: src/gateway/http-media-range.ts, src/gateway/sessions-history-http.ts, src/gateway/sessions-history-http.test.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

History

Review history (3 earlier review cycles)
  • reviewed 2026-07-30T19:19:45.434Z sha e6618fc :: found issues before merge. :: [P2] Treat parameters after q as accept extensions
  • reviewed 2026-07-30T19:28:18.740Z sha e6618fc :: found issues before merge. :: [P2] Ignore accept extensions after q
  • reviewed 2026-07-30T20:08:18.780Z sha e6618fc :: needs maintainer review before merge. :: none

@steipete

Copy link
Copy Markdown
Contributor Author

Maintainer contract decision for the remaining ClawSweeper move: skip the requested post-q accept-extension behavior because it is the obsolete RFC 7231 model, not the current HTTP specification.

RFC 9110 section 12.5.1 says:

Previous specifications allowed additional extension parameters to appear after the weight parameter. The accept extension grammar (accept-params, accept-ext) has been removed...

Senders using weights SHOULD send "q" last (after all media-range parameters). Recipients SHOULD process any parameter named "q" as weight, regardless of parameter ordering.

Therefore text/event-stream;q=1;foo=bar is a range with media parameter foo, not a current-standard accept extension, and it must not match an emitted representation that lacks foo. The exact-head tests already cover both matching and mismatching parameters after q. Changing the implementation as requested would deliberately restore a grammar RFC 9110 removed, so this move is rejected with authoritative contract evidence.

The hosted check-lint failure is separate current-main drift: src/gateway/server.node-pairing-authz.test.ts exceeds the max-lines policy on both this PR and current main. That test-only baseline repair is being handled separately before this PR is refreshed and prepared.

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 30, 2026
@steipete
steipete force-pushed the codex/autoqa-session-history-accept-20260730 branch from e6618fc to b3355e1 Compare July 30, 2026 20:13
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jul 30, 2026
@steipete
steipete merged commit a079d79 into main Jul 30, 2026
131 of 134 checks passed
@steipete
steipete deleted the codex/autoqa-session-history-accept-20260730 branch July 30, 2026 20:31
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 31, 2026
* fix(gateway): parse session history Accept ranges

* fix(gateway): enforce HTTP media parameter grammar

* fix(gateway): honor Accept parameter ordering
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant