fix(gateway): enforce OpenAI-compatible response contracts - #116354
fix(gateway): enforce OpenAI-compatible response contracts#116354steipete wants to merge 1 commit into
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed August 1, 2026, 3:31 PM ET / 19:31 UTC. ClawSweeper reviewWhat this changesThis PR makes OpenAI-compatible Gateway endpoints keep stream timestamps stable, reject invalid embedding options before provider creation, preserve structured body-limit errors, and expand Responses usage output. Merge readiness⛔ Blocked until real behavior proof from a real setup is added - 6 items remain Keep this protected, maintainer-owned Gateway PR open. Current Priority: P2 Review scores
Verification
How this fits togetherOpenClaw’s Gateway accepts OpenAI-compatible HTTP requests, validates them, starts agent/provider work, and serializes JSON or SSE responses back to SDK clients. The changed code sits at that client contract boundary, including request-body lifecycle handling and token-usage projection. flowchart LR
Client[OpenAI-compatible client] --> Endpoint[Gateway HTTP endpoint]
Endpoint --> Validate[Request and body validation]
Validate --> Agent[Agent and provider execution]
Agent --> Usage[Canonical usage projection]
Usage --> Stream[JSON or SSE serializer]
Stream --> Client
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +123, Tests +251. Total +374 across 13 files. View PR surface stats
Review metricsNone. Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Rebase onto current Do we have a high-confidence way to reproduce the issue? Yes, from source: a streamed chat response crossing a second can emit different Is this the best way to solve the issue? No, not as the branch stands: its Responses usage code duplicates a current-main canonical repair from #117533. A rebase that preserves that repair while retaining the three independent contract fixes is the narrower maintainable solution. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 3b70c3535ff5. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (6 earlier review cycles)
|
|
ClawSweeper status: review started. I am starting a fresh review of this pull request: fix(gateway): enforce OpenAI-compatible response contracts This is item 2/3 in the current shard. Shard 9/82. This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking. Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted. |
What Problem This Solves
Fixes several OpenAI-compatible Gateway contract failures: streamed objects changed their creation time mid-response, Responses usage could omit real runtime usage or produce inconsistent totals, malformed embedding requests were silently coerced, and oversized/stalled JSON uploads reset the socket before the promised
413/408error could reach the client.Why This Change Was Made
Each logical response now owns one timestamp and one canonical usage projection, embeddings validate the upstream request contract before provider creation, and the bounded-body reader has an explicit response-owner mode that flushes the existing JSON error before closing the request. Existing direct body-reader and plugin callers retain their prior teardown behavior. This is an AI-assisted maintainer QA fix.
User Impact
OpenAI SDK clients receive stable stream identities, complete and internally consistent usage data, deterministic
400errors for invalid embeddings input, and actual structured upload-limit/timeout responses instead ofECONNRESET.Evidence
openai-node@6.49.0source/types were checked directly for Chat chunk timestamps, Responses lifecycle/usage details, and embeddings validation.tbx_01kys7heeb752cfqwtapy2z6d9: 180/180 focused Gateway + real-socket infra tests passed.check:changed: passed core/coreTests formatting, tsgo, lint, dead-export, import-cycle, storage, webhook, pairing, and boundary guards.0.90.