Skip to content

refactor(openai): avoid redundant image auth lookup - #135259

Merged
steipete merged 1 commit into
mainfrom
codex/refactor-openai-image-auth
Sep 1, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/refactor-openai-image-auth

Conversation

@steipete

@steipete steipete commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

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:

Probe auth inputs Before store lookups After store lookups
OAuth/token profile, agent directory, no supplied store 3 2
Explicit configured key with agent directory 2 2
Supplied store 0 0

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.

@clawsweeper

clawsweeper Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete

steipete commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

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

@clawsweeper

clawsweeper Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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. labels Sep 1, 2026
@clawsweeper

clawsweeper Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 1, 2026, 10:50 AM ET / 14:50 UTC.

ClawSweeper review

What this changes

The 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 readiness

⚠️ Ready for maintainer review - 1 item remains

No 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
Reviewed head: 3ac5536f4885e5ed0c8e1d0fb7a054402b918a23

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A clean, net-negative owner-boundary refactor with retained route coverage and no actionable defect found.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored behavior-neutral refactor is exempt from the external-contributor proof gate; the supplied real Images API result is consistent with the unchanged standard image path, while source establishes the eliminated resolver lookup.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored behavior-neutral refactor is exempt from the external-contributor proof gate; the supplied real Images API result is consistent with the unchanged standard image path, while source establishes the eliminated resolver lookup.
Evidence reviewed 6 items Introduced runtime change: The PR deletes a selector whose every branch returned "openai" and replaces its wrapper call with the same optional resolver and the same cfg, agentDir, and supplied-store arguments.
Current main still needs the cleanup: Current main retains both the constant selector and forwarding wrapper, so it has not already adopted this PR’s central simplification.
Resolver ownership: The plugin-SDK resolver forwards its complete parameter object to the runtime auth owner, whose provider-scoped lookup lazily obtains the auth store when one was not supplied.
Findings None None.
Security None None.

How this fits together

The 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
Loading

Before merge

  • Complete next step (P2) - No discrete repair is needed; this is ready for ordinary maintainer merge handling.
Agent review details

Security

None.

PR surface

Source -24, Tests -380. Total -404 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 6 30 -24
Tests 1 153 533 -380
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 159 563 -404

Review metrics

Metric Value Why it matters
Production vs test delta production -24, tests -380 The net-negative change deletes redundant production routing and repeated fixture scaffolding without adding a configuration or API surface.

Technical review

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

Labels

Label changes:

  • add P3: This is a focused internal performance and maintainability cleanup with no intended product behavior change.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored behavior-neutral refactor is exempt from the external-contributor proof gate; the supplied real Images API result is consistent with the unchanged standard image path, while source establishes the eliminated resolver lookup.

Label justifications:

  • P3: This is a focused internal performance and maintainability cleanup with no intended product behavior change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored behavior-neutral refactor is exempt from the external-contributor proof gate; the supplied real Images API result is consistent with the unchanged standard image path, while source establishes the eliminated resolver lookup.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

@steipete
steipete merged commit ae24725 into main Sep 1, 2026
108 checks passed
@steipete
steipete deleted the codex/refactor-openai-image-auth branch September 1, 2026 14:54
@steipete

steipete commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: openai maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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