Skip to content

refactor: align codex provider and local runtime - #415

Merged
delete-cloud merged 1 commit into
mainfrom
refactor/codex-responses-local-runtime
Jun 1, 2026
Merged

delete-cloud merged 1 commit into
mainfrom
refactor/codex-responses-local-runtime

Conversation

@delete-cloud

@delete-cloud delete-cloud commented Jun 1, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • replace the codex provider's Chat Completions path with ChatGPT-backed Responses SSE
  • add local CLI runtime boundary and task packets for session/workspace refactor
  • document the provider and product-boundary decisions in ADRs

Root cause

The old codex provider treated the ChatGPT Codex backend as an OpenAI-compatible Chat Completions endpoint. Official Codex CLI uses the Responses wire protocol against /backend-api/codex/responses.

Validation

  • uv run pytest tests/coding_agent/plugins/test_llm_provider.py tests/providers/test_codex_responses.py -v
  • uv run pytest tests/cli/test_repl.py tests/cli/test_commands.py -v
  • uv run ruff check src/coding_agent/providers/codex_responses.py src/coding_agent/plugins/llm_provider.py src/coding_agent/providers/init.py tests/providers/test_codex_responses.py tests/coding_agent/plugins/test_llm_provider.py
  • uv run python -m coding_agent --provider codex --model gpt-5.5 run --goal 'Reply with exactly: codex smoke ok' --repo . --max-steps 1 --approval yolo

Summary by CodeRabbit

Release Notes

  • New Features

    • Codex provider now uses the official Responses HTTP SSE transport for improved ChatGPT integration.
  • Documentation

    • Added architectural decision records defining clearer boundaries between local CLI runtime, control-plane session management, and workspace execution layers.
  • Bug Fixes & Improvements

    • Enhanced local session management for improved REPL reliability.

Replace the codex provider's Chat Completions path with the ChatGPT-backed Responses SSE wire protocol. Add ADR/task packets for the local CLI boundary and workspace/session refactor direction.
@coderabbitai

coderabbitai Bot commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR introduces two independent architectural boundaries: a local CLI session manager protocol to decouple the REPL from server HTTP session management, and a Codex-specific Responses wire protocol provider with OAuth token refresh and SSE streaming.

Changes

Local CLI Runtime Boundary

Layer / File(s) Summary
Protocol and factory definition
src/coding_agent/cli/local_runtime.py, .opencode/prompts/tasks/local-cli-runtime-boundary-task-packet.md
LocalCliSessionManager protocol defines the session methods required by the CLI/REPL; create_local_cli_session_manager() factory constructs a SessionManager with filesystem-backed HTTP sessions and JSONL runtime storage.
REPL integration and import boundary
src/coding_agent/cli/repl.py, tests/cli/test_repl.py
REPL imports and uses the new LocalCliSessionManager boundary instead of directly importing the server SessionManager; new test verifies the import boundary by inspecting source to ensure SessionManager is not imported while create_local_cli_session_manager is present.

Codex Responses Provider Implementation

Layer / File(s) Summary
CodexResponsesProvider core implementation
src/coding_agent/providers/codex_responses.py
Implements request building from messages/tools into Responses API payload format, OAuth token snapshot retrieval with single 401→refresh retry, SSE event parsing that converts event kinds into TextEvent, ThinkingEvent, ToolCallEvent, UsageEvent, and DoneEvent, including helpers for message conversion, tool translation, and error extraction.
Provider wiring and exports
src/coding_agent/plugins/llm_provider.py, src/coding_agent/providers/__init__.py
LLMProviderPlugin.provide_llm instantiates CodexResponsesProvider with OAuth token source and computed Codex base URL for provider="codex" instead of the previous OpenAI-compat provider; exports CodexResponsesProvider from providers package.
Provider tests and validation
tests/coding_agent/plugins/test_llm_provider.py, tests/providers/test_codex_responses.py, docs/adr/0057-codex-provider-responses-wire-protocol.md, .opencode/prompts/tasks/codex-provider-responses-task-packet.md
Updates Codex provider test to validate CodexResponsesProvider instantiation; adds three async pytest test cases covering request headers/payload shape validation, SSE event conversion, tool-call argument parsing, and 401 token refresh retry behavior with token snapshot refresh.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 A boundary now guards the CLI realm,
Where protocols keep SessionManager's helm,
While Codex streams through SSE skies,
OAuth tokens refresh before our eyes,
Two walls of separation, both standing tall—
Clean architecture serving us all!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.12% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'refactor: align codex provider and local runtime' accurately summarizes the main changes: replacing the codex provider implementation with Responses SSE protocol and adding local runtime boundary abstractions.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/codex-responses-local-runtime

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@delete-cloud
delete-cloud merged commit 2dabb6b into main Jun 1, 2026
1 check was pending
@delete-cloud
delete-cloud deleted the refactor/codex-responses-local-runtime branch June 1, 2026 16:33
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.

1 participant