Skip to content

fix: repair daemon Codex sessions - #536

Merged
delete-cloud merged 1 commit into
mainfrom
fix/daemon-codex-sessions
Jun 4, 2026
Merged

delete-cloud merged 1 commit into
mainfrom
fix/daemon-codex-sessions

Conversation

@delete-cloud

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

Copy link
Copy Markdown
Owner

Summary

  • pass explicit daemon client provider/model/base_url into local daemon session creation
  • report non-JSON remote responses as ClickException instead of JSONDecodeError tracebacks
  • encode assistant history as output_text for Codex Responses multi-turn sessions

Verification

  • uv run pytest tests/cli/test_remote_client.py tests/providers/test_codex_responses.py tests/coding_agent/plugins/test_llm_provider.py -k "codex or local_daemon_session or daemon_run_sends_env_provider_model" -q
  • uv run ruff check src/coding_agent/cli/serve_command.py src/coding_agent/remote/client.py src/coding_agent/providers/codex_responses.py tests/cli/test_remote_client.py tests/providers/test_codex_responses.py
  • uv run ruff format --check src/coding_agent/cli/serve_command.py src/coding_agent/remote/client.py src/coding_agent/providers/codex_responses.py tests/cli/test_remote_client.py tests/providers/test_codex_responses.py

Runtime smoke

  • local daemon two-turn Codex session: "你是谁" then "你能看到上个请求吗" returned the previous user request correctly
  • wrong 8080 target now reports a non-JSON Coding Agent server URL error instead of a traceback

Summary by CodeRabbit

  • New Features

    • Runtime configuration (provider, model, and base URL) can now be overridden via environment variables or CLI arguments.
    • Daemon session creation now accepts runtime override parameters.
  • Bug Fixes

    • Improved message content handling in response processing.
    • Enhanced error reporting for non-JSON responses.
  • Tests

    • Added coverage for runtime configuration overrides and error handling scenarios.

@delete-cloud
delete-cloud merged commit 66eff81 into main Jun 4, 2026
@delete-cloud
delete-cloud deleted the fix/daemon-codex-sessions branch June 4, 2026 15:19
@coderabbitai

coderabbitai Bot commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 47c86081-2fb7-43e2-8918-03c04848cb03

📥 Commits

Reviewing files that changed from the base of the PR and between f16d88c and 900e3e2.

📒 Files selected for processing (5)
  • coding-agent/src/coding_agent/cli/serve_command.py
  • coding-agent/src/coding_agent/providers/codex_responses.py
  • coding-agent/src/coding_agent/remote/client.py
  • coding-agent/tests/cli/test_remote_client.py
  • coding-agent/tests/providers/test_codex_responses.py

📝 Walkthrough

Walkthrough

This PR enables daemon CLI commands to accept and forward runtime configuration overrides (provider, model, base_url) from Click context or environment variables through the daemon session creation flow. It introduces centralized JSON error handling with diagnostic details and updates message content type logic in the Codex provider to vary by message role.

Changes

Runtime Override Flow from CLI through Daemon Session

Layer / File(s) Summary
CLI Runtime Override Utilities
coding-agent/src/coding_agent/cli/serve_command.py
Introduces _shared_cli_arg() to extract values from Click context and _daemon_runtime_overrides() to build override dict from context or environment variables (AGENT_PROVIDER, AGENT_MODEL, AGENT_BASE_URL).
Daemon Commands with Context and Overrides
coding-agent/src/coding_agent/cli/serve_command.py
Updates daemon run, daemon repl, and daemon tui to accept ctx via @click.pass_context and pass computed runtime_overrides into _create_daemon_local_session().
Remote Session Extended for Overrides and JSON Error Handling
coding-agent/src/coding_agent/remote/client.py
Extends create_local_daemon_session() with optional provider_name, model_name, base_url parameters and conditionally includes them in /sessions POST payload. Introduces shared _response_json() utility for consistent JSON parsing error handling with content-type and response preview diagnostics.
Codex Provider Message Content Type Logic
coding-agent/src/coding_agent/providers/codex_responses.py
Updates _message_item() to select content type by role: assistant → output_text, others → input_text. Includes formatting updates to error messages and conditional expressions.
Test Coverage for Override Forwarding and Error Handling
coding-agent/tests/cli/test_remote_client.py, coding-agent/tests/providers/test_codex_responses.py
Adds tests verifying runtime overrides appear in /sessions payload, environment variables flow through daemon commands, JSON parsing errors include diagnostics, and assistant message history converts to output_text content.

Sequence Diagram

sequenceDiagram
  participant CLI as CLI (daemon run/repl/tui)
  participant Override as _daemon_runtime_overrides
  participant DaemonHelper as _create_daemon_local_session
  participant SessionClient as create_local_daemon_session
  participant HTTP as Remote Daemon API
  CLI->>Override: ctx
  Override->>Override: read from shared_cli_args or env vars
  Override-->>CLI: {provider, model, base_url}
  CLI->>DaemonHelper: runtime_overrides dict
  DaemonHelper->>SessionClient: forward as kwargs
  SessionClient->>SessionClient: build payload with provider/model/base_url
  SessionClient->>HTTP: POST /sessions with overrides
  HTTP-->>SessionClient: session_id
  SessionClient-->>CLI: session_id
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • delete-cloud/Coding-Agent-Loop#116: Both PRs modify remote session client code—the main PR refactors JSON error handling and extends daemon session payloads, which builds on the remote session/streaming functionality from the remote attach CLI PR.
  • delete-cloud/Coding-Agent-Loop#482: Both PRs update daemon TUI and local-daemon session wiring—main PR extends _create_daemon_local_session and CLI override forwarding so daemon tui passes runtime overrides into the daemon session request.
  • delete-cloud/Coding-Agent-Loop#134: Both PRs wire runtime provider/model through client request schemas—main PR forwards these into /sessions payload while the retrieved PR updates HTTP session request validation.

Poem

🐰 Through context and env the overrides flow,
From CLI commands to daemon below,
Assistant messages speak in output text,
JSON errors tell what went wrong next,
Tests confirm the path is true!

✨ 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 fix/daemon-codex-sessions

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.

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