ccproxy-api
ccproxy-api copied to clipboard
fix(responses): support OpenAI Responses tool loops
Summary
- Normalize OpenAI Responses
function_callitem IDs tofc_*while preservingcall_idascall_*. - Add true OpenAI-compatible Responses route coverage for
/responses,/v1/responses, and/codex/v1/responses. - Add local
previous_response_idcontinuation state for Codex Responses tool loops, scoped by client auth context with TTL/max-entry cleanup. - Accept Droid/Factory Responses streaming fields such as
stream_options.include_usage, plus Droid-sentprompt_cache_retentionandsafety_identifier, while stripping Codex-backend-unsupported fields before upstream dispatch. - Preserve valid Responses SSE for streaming tool calls, including
response.function_call_arguments.*.item_id == fc_*, completedfunction_call.id == fc_*, andfunction_call.call_id == call_*. - Normalize provider/FastAPI 4xx failures into OpenAI-style JSON error envelopes so clients see rejected parameters instead of empty bodies.
- Rebuild sparse Codex
response.completedpayloads from streamed output items when the final upstream completed event omits output.
This remains parallel to #64; it is the Responses/OpenAI-provider compatibility PR. The latest commit folds in the Droid/Factory streaming and continuation compatibility work on top of the original fc_* fix.
Validation
git diff --checkuv run ruff check ccproxy/plugins/codex/plugin.py ccproxy/plugins/codex/config.py ccproxy/plugins/codex/adapter.py ccproxy/plugins/codex/routes.py ccproxy/plugins/codex/responses_state.py ccproxy/llms/models/openai.py ccproxy/llms/streaming/accumulators.py ccproxy/llms/formatters/common/identifiers.py ccproxy/streaming/deferred.py ccproxy/streaming/buffer.py ccproxy/streaming/errors.py tests/plugins/codex/integration/test_codex_basic.py tests/plugins/codex/unit/test_adapter.py tests/plugins/codex/unit/test_responses_state.py tests/unit/llms/streaming/test_accumulators.py tests/unit/llms/test_openai_responses_request_models.py tests/unit/streaming/test_buffer_parse_responses.pyuv run ruff format --check ccproxy/plugins/codex/plugin.py ccproxy/plugins/codex/config.py ccproxy/plugins/codex/adapter.py ccproxy/plugins/codex/routes.py ccproxy/plugins/codex/responses_state.py ccproxy/llms/models/openai.py ccproxy/llms/streaming/accumulators.py ccproxy/llms/formatters/common/identifiers.py ccproxy/streaming/deferred.py ccproxy/streaming/buffer.py ccproxy/streaming/errors.py tests/plugins/codex/integration/test_codex_basic.py tests/plugins/codex/unit/test_adapter.py tests/plugins/codex/unit/test_responses_state.py tests/unit/llms/streaming/test_accumulators.py tests/unit/llms/test_openai_responses_request_models.py tests/unit/streaming/test_buffer_parse_responses.pyuv run pytest tests/plugins/codex/unit/test_adapter.py tests/plugins/codex/unit/test_responses_state.py tests/unit/llms/test_openai_responses_request_models.py tests/unit/streaming/test_buffer_parse_responses.py tests/unit/llms/streaming/test_accumulators.py tests/plugins/codex/integration/test_codex_basic.py -q- 58 passeduv run pytest tests/plugins/codex/unit/test_adapter.py tests/plugins/codex/unit/test_routes.py tests/plugins/codex/unit/test_responses_state.py tests/plugins/codex/integration/test_codex_basic.py tests/plugins/codex/integration/test_codex_websocket.py tests/unit/streaming/test_buffer_parse_responses.py tests/unit/llms/streaming/test_accumulators.py -q- 67 passeduv run pytest tests/plugins/codex tests/unit/streaming/test_buffer_parse_responses.py tests/unit/llms/streaming/test_accumulators.py tests/integration/test_streaming_converters.py -q- 91 passed, 1 existing Pydantic deprecation warninguv run mypy ccproxy/plugins/codex/adapter.py ccproxy/plugins/codex/routes.py ccproxy/plugins/codex/responses_state.py ccproxy/plugins/codex/plugin.py ccproxy/plugins/codex/config.py ccproxy/llms/models/openai.py ccproxy/llms/streaming/accumulators.py ccproxy/llms/formatters/common/identifiers.py ccproxy/streaming/deferred.py ccproxy/streaming/buffer.py ccproxy/streaming/errors.py tests/plugins/codex/integration/test_codex_basic.py tests/plugins/codex/unit/test_adapter.py tests/plugins/codex/unit/test_responses_state.py tests/unit/llms/streaming/test_accumulators.py tests/unit/llms/test_openai_responses_request_models.py tests/unit/streaming/test_buffer_parse_responses.py- success, 17 source files./Taskfile check- all checks passed; mypy success on 592 source files; 616 files already formatted
Live local smoke
- Local ccproxy
/healthreturnedpassafter restart. - Live curl verified streaming
/responses,/v1/responses, and/codex/v1/responseswithstream_options.include_usage. - Live curl verified streamed function tool call +
previous_response_idcontinuation, withfc_*item IDs andcall_*call IDs. - Live curl verified unknown
previous_response_idreturns OpenAI-style JSON error body. - Droid/Factory target passed:
droid exec \
--cwd /Users/smhanan/Projects/inline \
-m custom:ccproxy-chatgpt-5.5-0 \
--auto medium \
'Use the Execute tool to run exactly: pwd && git branch --show-current. Then reply beginning GPT_DROID_EXEC_OK.'
Output began with GPT_DROID_EXEC_OK and returned /Users/smhanan/Projects/inline plus branch codex/inline-typora-repair.
Coordination note for reviewers:
This PR is intentionally parallel to #64 and #66.
- #64 fixes Anthropic compacted tool-history sanitization and context truncation behavior.
- #65 fixes OpenAI Responses protocol compatibility for function-call item IDs (
fc_*item IDs while preservingcall_*call IDs). - #66 adds provider/model/effort aliases for Claude and Codex-compatible clients.
There is no intended dependency between these PRs. They can be reviewed and merged independently; if one lands first, I will rebase the others only if GitHub reports a conflict.