Repository navigation
refactor(openai): avoid redundant image auth lookup - #135259
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
@clawsweeper review Please review the image auth-owner simplification and adjacent fixture cleanup. The PR retains 108 image cases plus 16 plugin cases, passes complete changed checks and a full build, and has a clean independent Codex review. The extracted owner probe shows the redundant profile lookup falling from three to two with auth decisions preserved; the separate real API-key request successfully generated a PNG. Production decreases by 24 lines and tests by 380. The body documents exact scope, live-proof limits, and direct upstream Codex auth inspection. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Codex review: needs maintainer review before merge. Reviewed September 1, 2026, 10:50 AM ET / 14:50 UTC. ClawSweeper reviewWhat this changesThe PR removes a redundant OpenAI image-auth selector and forwarding wrapper, then consolidates repeated OpenAI image-provider test setup without changing the covered routes. Merge readinessNo blocking correctness or security finding: the direct call preserves the fixed OpenAI provider identity and resolver arguments while removing a constant-valued selector and its extra store lookup. This maintainer-authored PR remains necessary because current main still contains the wrapper. Priority: P3 Review scores
Verification
How this fits togetherThe bundled OpenAI plugin registers an image-generation provider. Image requests using a ChatGPT/Codex subscription are routed through the Codex Responses transport after OpenClaw resolves OpenAI credentials; other requests use the standard Images HTTP endpoint. flowchart LR
A[Image request] --> B[OpenAI image provider]
B --> C{Subscription response route}
C -->|Yes| D[OpenAI credential resolver]
D --> E[Codex Responses transport]
C -->|No| F[Images API transport]
E --> G[Generated image result]
F --> G
Before merge
Agent review detailsSecurityNone. PR surfaceSource -24, Tests -380. Total -404 across 2 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Land the smaller canonical resolver call and retain the consolidated route-level tests, leaving credential precedence and profile selection exclusively with the shared auth resolver. Do we have a high-confidence way to reproduce the issue? Yes, by source: with an agent directory and no supplied auth store, the route check loads the store, the removed selector loaded it again, and the shared resolver then performs its own provider-scoped lookup. The direct call removes only the middle lookup. Is this the best way to solve the issue? Yes. Calling the existing resolver directly with the constant provider identity is the smallest owner-preserving solution; forwarding a preloaded store would create a new caching and store-identity decision. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 29cc0bd10fbd. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
What Problem This Solves
OpenAI image requests could load the auth-profile store only to run a provider selector whose every branch returned
openai. That repeated work added nothing to the canonical resolver's auth decision and obscured the image route's ownership.Why This Change Was Made
The image provider now calls the existing optional auth resolver directly with
provider: "openai". It removes the constant-valued selector and its forwarding async wrapper. Profile selection, credential precedence, supplied-store identity, transport routing, and errors remain with the same existing owners.The adjacent tests now share the stateless provider, default request scaffolding, and generated-PNG response setup. Equivalent Azure hostname/path cases use small tables; distinct API-key, OAuth, edit, timeout, SSRF, and response-stream behavior remains explicit. Two unreachable duplicate mock branches and one consecutive duplicate assertion are removed. No production test seam is added.
User Impact
Profile-backed image requests with an agent directory and no supplied auth store perform one fewer store lookup. Existing API-key, OAuth/token, Azure, custom endpoint, generation, and edit behavior remains covered. There is no configuration, model, dependency, or public API change.
Evidence
All 124 focused tests pass: 108 image-provider cases and 16 plugin-registration cases. The image suite retains all 108 expanded cases after consolidating repeated setup. Full changed-file checks, including production and test types, pass; full build and fresh isolated Codex autoreview pass.
A before/after probe executes the extracted route-detection and auth-resolution functions, including the current canonical auth owner, with synthetic injected auth boundaries. These counts cover that owner path, not every operation in a complete image request:
Across eight cases, selected auth mode, profile, source, transport eligibility, and exact supplied-store identity agree. Missing credentials still return null from the optional resolver and fatal errors still propagate. Removing the forwarding async wrapper shortens promise settlement by one observer microtask; exact microtask timing is not a preserved contract. These are owner-call observations, not disk-I/O, heap, RSS, or Gateway latency measurements.
The final production source also completed a real OpenAI Images API request with an explicit API key and an isolated empty supplied store:
{ "passed": true, "node": "v26.8.1", "model": "gpt-image-2", "images": 1, "mimeType": "image/png", "bytes": 768939, "width": 1024, "height": 1024, "elapsedMs": 12940.917417, "temporaryStateRemoved": true }Production source SHA-256:
94a05ee6392529c88e63ad82923ca91e713b4ec305230e24e3e3616062b2c42f. The live API-key request proves the real image flow; the separate synthetic auth-owner probe proves the profile-lookup change. No live subscription-auth or memory-saving claim is inferred from the API-key request.Direct upstream Codex inspection preserved the API-key versus ChatGPT auth distinction: auth manager and provider auth resolution. The changed code continues to use the canonical OpenClaw resolver and its returned mode rather than adding an alternate auth policy.
Production: +6/-30, net -24 lines. Tests: +153/-533, net -380 lines. This cleanup preserves the existing behavior coverage and makes no test-runtime or memory claim from fixture consolidation. Duplicate search found other image-response work in #117226 and #105323; those concern usage and base64 response handling, not this auth-owner invariant.