Skip to content

fix(codex): repair MultiRouter routing and history sync - #22

Draft
KeLearns wants to merge 1 commit into
BigStrongSun:bigstrongsun/ccsm-agent-meshfrom
KeLearns:agent/fix-codex-multirouter-target-materialization
Draft

fix(codex): repair MultiRouter routing and history sync#22
KeLearns wants to merge 1 commit into
BigStrongSun:bigstrongsun/ccsm-agent-meshfrom
KeLearns:agent/fix-codex-multirouter-target-materialization

Conversation

@KeLearns

@KeLearns KeLearns commented Aug 1, 2026

Copy link
Copy Markdown

Summary

  • Materialize pre-resolved Codex MultiRouter attempts from their referenced target provider before forwarding normal, raw, and realtime HTTP paths.
  • Sync unified Codex history into the stable MultiRouter provider bucket currently declared by the live config.toml, instead of a hard-coded legacy bucket.
  • Serialize official history migrations/restores and MultiRouter history syncs behind one provider-bucket operation lock.

Root cause

The retry chain expands MultiRouter routes ahead of forward() and marks each attempt with codexResolvedRouteId. The forwarder treated that marker as if the target provider had already been materialized. As a result, the attempt retained the parent router's local base_url and authentication context, recursively called the local proxy, and skipped target-specific protocol/history handling.

Unified history sync also assumed a fixed MultiRouter bucket. Current builds generate a stable bucket in the live Codex config, so JSONL session_meta.model_provider values and SQLite threads.model_provider rows could be migrated into a bucket that Codex was not displaying.

Changes

  • Feed already-resolved route attempts through the existing target-provider lookup and materialization path.
  • Cover standard Responses forwarding, raw passthrough, and raw/realtime provider resolution.
  • Detect the active MultiRouter bucket from model_provider plus the x-cc-switch-proxy-mode = "router" marker.
  • Rebucket all non-target JSONL and SQLite history into that live target, with offline-process checks, backups, transactions, idempotency, and shared locking.
  • Trigger the guarded sync at startup, settings changes, and Codex provider switches.
  • Add regression tests for route URL/auth materialization and dynamic history target migration.

User impact

MultiRouter requests now reach the selected external or official upstream instead of recursively returning to 127.0.0.1. Target-specific request conversion and chat-history enrichment can run against the effective provider. Unified Codex history remains visible after switching to MultiRouter.

Validation

  • Patched v3.19.0-3 binary tested with New Codex MultiRouter.
    • OpenCode Go Responses route used https://opencode.ai/zen/go/v1/responses and returned HTTP 200.
    • OpenAI Official route used https://chatgpt.com/backend-api/codex/responses and returned HTTP 200.
    • MultiRouter history sync completed with 737 JSONL files and 1,009 SQLite rows.
  • cargo test codex_history_migration::tests --lib — 52 passed.
  • cargo test proxy::forwarder::tests --lib — 116 passed.
  • Focused Codex Router, Codex Chat, provider refresh, and settings tests passed.
  • cargo check --lib passed (one pre-existing unused-function warning remains in proxy/usage/parser.rs).

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