Skip to content

Phase 6a: OpenAI provider adapter (offline, mocked) - #51

Merged
samuelrojas-dev merged 5 commits into
mainfrom
claude/sleepy-noether-3oc5nl
Oct 2, 2026
Merged

samuelrojas-dev merged 5 commits into
mainfrom
claude/sleepy-noether-3oc5nl

Conversation

@samuelrojas-dev

Copy link
Copy Markdown
Owner

What

Phase 6a of the roadmap: a provider adapter so dowbench run can benchmark OpenAI chat models, the same way it already does Gemini and Anthropic. Everything here is offline and mocked — no real provider call is made. A real pilot smoke test is a separate, explicitly authorized step (Phase 6b).

Design decisions are recorded in ADR 0023:

  • Usage mapping. OpenAI usage is mapped to the neutral disjoint counters: input = prompt − cached, cache_read = cached_tokens, reasoning = completion reasoning_tokens, output = completion − reasoning, cache_write = 0. Anything unpriceable fails loudly instead of being mispriced (unknown keys, audio tokens, accepted/rejected prediction tokens, total ≠ prompt + completion) — per ADR 0007.
  • No replay codec. The assistant turn is a plain JSON dict (like Anthropic, unlike Gemini's types.Content), so the existing cassette JSON round-trip reproduces it with no new codec (ADR 0015).
  • Post-call token ceiling. OpenAI has no token-count endpoint. The Provider protocol gains a counts_tokens flag (default True; mock/gemini/claude unchanged) and the OpenAI adapter declares it False. The loop then skips the pre-call token gate and relies on the existing post-call total check; the estimate budgets the worst case at 2× the ceiling (one possible overshoot per episode, like the bring-your-own-agent path in ADR 0012). Capability is read offline via provider_counts_tokens without instantiating the SDK.

Key safety (ADR 0005): only OPENAI_API_KEY is read, the base URL is pinned to https://api.openai.com/v1, OPENAI_BASE_URL is refused, and max_retries=0. The openai SDK is an optional dependency (dowbench[openai]), imported lazily so the module loads without it.

Pricing for gpt-6-luna added to pricing.yaml (input $0.10/1M, cached input $0.01/1M, cache writes $0.125/1M, output $0.50/1M; verified 2026-10-02).

⚠️ Needs your confirmation: max_prompt_tokens: 128000 for gpt-6-luna is a conservative placeholder, not a verified number — I did not want to invent the short-context tier boundary. Please confirm the real value and I'll correct it.

Kind

  • fix
  • feature
  • docs
  • refactor / chore
  • test

Checklist

  • Small, focused change; Conventional Commits.
  • An ADR added under docs/adr/ for any non-obvious decision (ADR 0023).
  • No invented numbers — pricing is dated/sourced; max_prompt_tokens is explicitly flagged as a placeholder for you to confirm (see above).
  • No real provider call added to tests or scripts; tests use provider fakes and stay offline.
  • No secrets in code, logs, tests or commits.
  • If a test's expected behavior changed, the PR says which and why — the agent-loop test suite gains one case (a non-counting provider running via the post-call ceiling); existing behavior is unchanged.

Verification

$ ruff check .        && ruff format --check .
All checks passed!
76 files already formatted

$ mypy src tests scripts
Success: no issues found in 70 source files

$ python -m pytest
350 passed in 20.30s

$ python scripts/verify_cassettes.py
OK   focus-bloat-verify: replay reproduces 5ac674d8…4d7f7ac, and the README matches
OK   pilot-v2: replay reproduces 12abac6a…166dcad, and the README matches
all 2 published cassette(s) verified

Offline sanity checks (no network):

  • dowbench estimate configs/pilot-openai.yaml → worst case 320,000 tokens, $0.1600; "model calls: at most 70, checked after each call (no pre-call token count)" (the 2× factor applied).
  • env -u OPENAI_API_KEY dowbench run configs/pilot-openai.yaml --budget-usd 1.0 → cannot set up the run: OPENAI_API_KEY is not set; see .env.example.

🤖 Generated with Claude Code

https://claude.ai/code/session_014wCFhM2gxQCfJYcm4Zu6z4


Generated by Claude Code

claude added 5 commits October 2, 2026 18:50
Add an OpenAI Chat Completions provider on the official `openai` SDK:
strict usage mapping to disjoint neutral counters (cached input and
reasoning tokens handled separately; audio, predicted-output and
inconsistent totals refused), key safety (only OPENAI_API_KEY, pinned
base URL, OPENAI_BASE_URL refused, no retries), and a plain-JSON
assistant turn so no replay codec is needed.

OpenAI has no token-count endpoint, so the `Provider` protocol gains a
`counts_tokens` flag (default True; mock/gemini/claude unchanged) and the
OpenAI adapter declares it False. The loop then skips the pre-call token
gate and relies on the existing post-call total check, and the estimate
budgets the worst case at 2x the ceiling (one overshoot), read offline
via `provider_counts_tokens` without instantiating the SDK (ADR 0023).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014wCFhM2gxQCfJYcm4Zu6z4
…onfig

Add the `openai` optional dependency (`dowbench[openai]`) and register the
provider and sut_mapper entry points (ADR 0021). Add OPENAI_API_KEY to
.env.example (noting OPENAI_BASE_URL is refused), a pricing.yaml entry for
openai/gpt-6-luna (prices verified 2026-10-02), and configs/pilot-openai.yaml.

The gpt-6-luna max_prompt_tokens is a flagged conservative placeholder
pending confirmation of the short-context tier boundary.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014wCFhM2gxQCfJYcm4Zu6z4
Cover the OpenAI adapter with provider fakes (no real calls, no quota):
usage mapping and its strict rejections, request/response mapping, finish
reasons, replay round-trip, count_tokens returning None, setup errors,
map_sut_response, and the 2x worst-case estimate. Add an agent-loop test
for a non-counting provider running via the post-call ceiling, and update
the packaging, rate-limit and retry fakes for the new counts_tokens flag.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014wCFhM2gxQCfJYcm4Zu6z4
Record the three OpenAI design decisions in ADR 0023 (usage mapping, no
replay codec, post-call token ceiling), note the adapter under the
changelog Unreleased section, and mark roadmap Phase 6 as adapter done
(offline-tested; a real pilot is a separate authorized step).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014wCFhM2gxQCfJYcm4Zu6z4
The owner confirmed the short-context tier boundary: 272000 tokens (the
model's context window, verified on platform.openai.com/docs/models/gpt-6-luna
on 2026-10-02). The previous 128000 was a flagged placeholder and is in fact
the max_output_tokens, not the context window.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014wCFhM2gxQCfJYcm4Zu6z4
@samuelrojas-dev
samuelrojas-dev merged commit 83eda49 into main Oct 2, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants