Experimental Native Protocol Rewrite - #162
Open
Mirrowel wants to merge 203 commits into
Open
Conversation
Captures the experimental branch workflow, protocol architecture goals, transform logging requirements, field-cache rules, provider priorities, routing, retry, usage, streaming, and config direction. Documents that every phase must be freshly planned in conversation, written as planning docs, reviewed by explore and explore-heavy agents, and reported to the user without committing reports by default.
Introduces protocol-neutral request, response, stream event, content, tool, reasoning, usage, cost, and context dataclasses with JSON-safe serialization for future transform tracing. Adds the override-friendly ProtocolAdapter base and auto-discovery registry with alias handling, duplicate detection, shared stateless instances, and tests for serialization, default preservation, registration, aliases, and protocol errors. Tests: python -m pytest tests/test_protocol_registry.py
Adds the explicit LiteLLM fallback protocol marker and a native OpenAI Chat Completions adapter for request parsing/building, response parsing/formatting, usage and provider-reported cost extraction, reasoning preservation, tool calls, multimodal content blocks, and SSE chunk parsing. The adapter remains isolated from runtime execution and preserves unknown extension fields for future adapter, field-cache, and transform logging phases. Tests: python -m pytest tests/test_protocol_registry.py tests/test_protocol_openai_chat.py
Adds a native Anthropic Messages protocol adapter for request parsing/building, response formatting, stream event parsing, tool_use/tool_result blocks, thinking and redacted-thinking signature preservation, and cache usage normalization. The existing compatibility routes remain untouched; this adapter is an isolated base for later native provider execution, field-cache rules, and transform logging. Tests: python -m pytest tests/test_protocol_registry.py tests/test_protocol_openai_chat.py tests/test_protocol_anthropic_messages.py
Adds a native Gemini generateContent adapter for request parsing/building, response formatting, stream event parsing, content parts, function calls/responses, thought signatures, generation config, safety settings, tools, and Gemini usage metadata. The adapter preserves raw Gemini-native fields and remains isolated from runtime execution so provider migration can happen in later checkpoints. Tests: python -m pytest tests/test_protocol_registry.py tests/test_protocol_openai_chat.py tests/test_protocol_anthropic_messages.py tests/test_protocol_gemini.py
Adds a native Responses protocol adapter for request parsing/building, response formatting, event-stream parsing, previous_response_id preservation, input and output item handling, reasoning items, function calls, usage details, provider-reported costs, and a WebSocket-ready transport capability flag. Routes, storage, and runtime wiring remain deferred to later checkpoints; this commit only adds the reusable protocol base and tests. Tests: python -m pytest tests/test_protocol_registry.py tests/test_protocol_openai_chat.py tests/test_protocol_anthropic_messages.py tests/test_protocol_gemini.py tests/test_protocol_responses.py
Addresses Phase 1 review findings by treating raw payloads as provenance instead of stale formatting authority in native adapters, tightening registry alias/name collision handling, adding JSON-safe serialization fallbacks, and avoiding default reasoning-token double counting. Adds nested raw preservation for tool, result, and reasoning structures, exposes WebSocket as a future Responses transport seam rather than current formatting support, expands Gemini tool declaration parsing, and switches protocol tests to the public package import path through a local test path fixture. Tests: python -m pytest tests/test_protocol_registry.py tests/test_protocol_openai_chat.py tests/test_protocol_anthropic_messages.py tests/test_protocol_gemini.py tests/test_protocol_responses.py Tests: python -m pytest tests/test_session_tracking.py tests/test_selection_engine.py
Preserves Anthropic system block shape and metadata during rebuilds, keeps unknown Responses output items while still applying unified-message mutations, and groups Gemini multi-declaration tools back into their original native tool container. Adds tests for Anthropic system cache metadata, Responses future output-item preservation, and Gemini multi-declaration rebuild fidelity. Tests: python -m pytest tests/test_protocol_registry.py tests/test_protocol_openai_chat.py tests/test_protocol_anthropic_messages.py tests/test_protocol_gemini.py tests/test_protocol_responses.py Tests: python -m pytest tests/test_session_tracking.py tests/test_selection_engine.py
Adds the Phase 2 plan for additive transform-pass transaction logging, including trace entry shape, writer behavior, request/response/stream pass names, sanitization, TransactionLogger and ProviderLogger integration, tests, risks, and review checkpoints. The Phase 1 report remains uncommitted for user-facing review only.
Introduces transform trace entries, a local-sequence JSONL/snapshot writer, recursive key-based redaction, filesystem-safe snapshot names, and JSON-safe payload serialization for future protocol and adapter pass logging. The trace writer is observability-only and isolated from runtime transaction logging in this checkpoint. Tests: python -m pytest tests/test_transform_trace.py
Wires the transform trace writer into TransactionLogger and ProviderLogger while preserving legacy request, transformed request, response, streaming chunk, metadata, and provider log files. Adds trace entries for raw client requests, prepared provider requests, raw and parsed stream chunks, assembled stream responses, final client responses, provider request payloads, provider raw stream chunks, provider final responses, and provider errors. Includes transaction logger tests for legacy compatibility, redaction, equality-skipped transformed requests, provider traces, streaming wrapper traces, and disabled logging. Tests: python -m pytest tests/test_transform_trace.py tests/test_transaction_logger_transform_trace.py Tests: python -m pytest tests/test_protocol_registry.py tests/test_protocol_openai_chat.py tests/test_protocol_anthropic_messages.py tests/test_protocol_gemini.py tests/test_protocol_responses.py Tests: python -m pytest tests/test_session_tracking.py tests/test_selection_engine.py
Hardens Phase 2 tracing after review by adding request, session, scope, classifier, exact model, and credential correlation to trace entries where available. Expands redaction for cookies and credential-bearing headers, extracts structured fields from SDK-like objects before repr fallback, scrubs header-like secrets from provider error text, and adds a standardized transform_log_error helper. Prevents provider snapshot collisions by namespacing provider writer snapshots while keeping stream chunks in JSONL only. Tests: python -m pytest tests/test_transform_trace.py tests/test_transaction_logger_transform_trace.py Tests: python -m pytest tests/test_protocol_registry.py tests/test_protocol_openai_chat.py tests/test_protocol_anthropic_messages.py tests/test_protocol_gemini.py tests/test_protocol_responses.py Tests: python -m pytest tests/test_session_tracking.py tests/test_selection_engine.py
Adds the Phase 3 plan for the adapter registry, built-in adapter bases, field-cache rule schema, path engine, store abstractions, scoped key behavior, transform trace integration, tests, risks, and review checkpoints. Reports remain uncommitted for user-facing review only.
Adds the Phase 3 adapter foundation with an override-friendly async base adapter, adapter context, ordered chain runner, auto-discovered registry, aliases, duplicate collision checks, and built-in base adapters for no-op, model override, developer-role suppression, and reasoning content normalization. Runtime request execution is not wired to the adapter chain yet; this checkpoint keeps behavior unchanged while establishing the extension point for native protocols and providers. Tests: python -m pytest tests/test_adapter_registry.py
Adds field-cache rule and injection dataclasses, cache context scope values, default provider/model/classifier/session scoping, and a small JSON-path-like engine for extraction and predictable injection. The path helper supports dict keys, list indexes, wildcard extraction, tail indexes, missing-path no-ops, and explicit errors for malformed paths or wildcard injection. Tests: python -m pytest tests/test_field_cache_paths.py
Adds async field-cache stores, a ProviderCache-backed wrapper, scoped cache key construction, and the extraction/injection engine for last, all, turn-compatible, stream-event, and per-tool-call-validated rules. The engine copies payloads by default, isolates values by provider/model/session/classifier/credential scope, skips missing required session scope, and emits transform trace metadata when a transaction logger is supplied. Tests: python -m pytest tests/test_field_cache_engine.py tests/test_field_cache_paths.py
Adds the missing before_field_cache_extraction and before_field_cache_injection trace passes so field-cache operations now emit both before and after states. Adds trace-focused tests for adapter chains, field-cache extraction/injection, rule metadata, cache hits, mutation flags, and transform_log_error emission on failed injection. Tests: python -m pytest tests/test_field_cache_trace.py tests/test_field_cache_engine.py tests/test_adapter_registry.py
Adds optional provider declarations for native protocol name, ordered adapter names, adapter config, and field-cache rules, all defaulting to empty/no-op behavior so existing providers remain on the current execution path until they opt in. These methods are the Phase 3 bridge that later provider work will use to attach native protocols, adapter chains, and provider-specific field-cache rules per model. Tests: python -m pytest tests/test_provider_protocol_declarations.py tests/test_adapter_registry.py tests/test_field_cache_engine.py tests/test_field_cache_paths.py tests/test_field_cache_trace.py
Adds the planned field_rename adapter, fixes field-cache trace direction for stream-sourced request injection, caps trace sample values, and documents the current limits of turn/tool-cache modes. Expands coverage for credential/provider scope isolation, stream-sourced injection trace direction, large sample truncation, field_rename behavior, and plain provider no-op protocol defaults. Tests: python -m pytest tests/test_adapter_registry.py tests/test_field_cache_paths.py tests/test_field_cache_engine.py tests/test_field_cache_trace.py tests/test_provider_protocol_declarations.py Tests: python -m pytest tests/test_protocol_registry.py tests/test_protocol_openai_chat.py tests/test_protocol_anthropic_messages.py tests/test_protocol_gemini.py tests/test_protocol_responses.py tests/test_transform_trace.py tests/test_transaction_logger_transform_trace.py tests/test_session_tracking.py tests/test_selection_engine.py
Adds the Phase 4 plan for Responses routes, response storage, previous_response_id continuation, bridge execution through the current client path, HTTP SSE conversion, WebSocket extension seams, tests, risks, and review checkpoints. Reports remain uncommitted for user-facing review only.
Adds the Phase 4 Responses storage foundation with StoredResponse, local response ID generation, an in-memory store, and a ProviderCache-backed wrapper that accepts an injected cache instead of constructing one globally. The store supports save, get, delete, and input item listing, preserves JSON-safe response metadata for previous_response_id continuation, and avoids SQLite or new persistence dependencies. Tests: python -m pytest tests/test_responses_store.py
Adds the temporary Responses-to-chat bridge for Phase 4, converting parsed Responses requests into current chat-completions kwargs and converting chat-completion responses back into Responses objects. The bridge preserves previous_response_id metadata, parent response messages, tool definitions, generation parameters, and unsupported extension fields for trace/debugging until native provider execution is wired in later phases. Tests: python -m pytest tests/test_responses_bridge.py tests/test_responses_store.py
Adds the non-streaming Responses service around the protocol adapter, bridge, and response store with validation, previous_response_id loading, get/delete/input-items helpers, and transform trace passes. The service keeps Phase 4 runtime conservative by bridging through the existing chat completion client path while preserving response storage and lineage metadata for later native provider work. Tests: python -m pytest tests/test_responses_service.py tests/test_responses_bridge.py tests/test_responses_store.py
Adds FastAPI routes for POST /v1/responses, GET /v1/responses/{id}, DELETE /v1/responses/{id}, and GET /v1/responses/{id}/input_items using the Phase 4 ResponsesService.
The create route currently handles non-streaming requests through the bridge and returns a documented 501 for streaming until the SSE checkpoint lands next.
Tests: python -m pytest tests/test_responses_routes.py tests/test_responses_service.py tests/test_responses_bridge.py tests/test_responses_store.py
Adds Responses HTTP SSE formatting, chat-stream conversion, streamed response accumulation/storage, response.failed events on stream errors, and a WebSocket formatter seam that is explicit but not exposed as a runtime route. Updates POST /v1/responses to return text/event-stream for stream=true while preserving the existing non-stream route behavior. Tests: python -m pytest tests/test_responses_streaming.py tests/test_responses_routes.py tests/test_responses_service.py tests/test_responses_bridge.py tests/test_responses_store.py
Wires Responses routes into the transform trace logger when request logging is enabled, adds coverage for unsupported Responses fields preserved in bridge metadata, and strengthens streaming tests to assert SSE event order. Tests: python -m pytest tests/test_responses_store.py tests/test_responses_bridge.py tests/test_responses_service.py tests/test_responses_routes.py tests/test_responses_streaming.py Tests: python -m pytest tests/test_protocol_registry.py tests/test_protocol_openai_chat.py tests/test_protocol_anthropic_messages.py tests/test_protocol_gemini.py tests/test_protocol_responses.py tests/test_transform_trace.py tests/test_transaction_logger_transform_trace.py tests/test_adapter_registry.py tests/test_field_cache_paths.py tests/test_field_cache_engine.py tests/test_field_cache_trace.py tests/test_provider_protocol_declarations.py tests/test_session_tracking.py tests/test_selection_engine.py
Adds the Phase 5 plan for native provider execution, provider declarations, HTTP and streaming seams, priority provider order, Antigravity restoration constraints, Gemini CLI parity review, fallback policy, transform tracing, field-cache rules, tests, and review checkpoints. Reports remain uncommitted for user-facing review only.
Adds the Phase 5 native provider foundation with execution context, HTTP transport wrapper, and non-streaming executor that runs protocol selection, adapter chains, field-cache injection/extraction, provider HTTP calls, and transform tracing. The foundation is not wired into live request execution yet, preserving current provider behavior while giving priority provider work a testable native path. Tests: python -m pytest tests/test_native_provider_executor.py tests/test_responses_store.py tests/test_responses_bridge.py tests/test_responses_service.py tests/test_responses_routes.py tests/test_responses_streaming.py
Adds opt-in native provider streaming support with streaming-capable transport seam, raw chunk tracing, protocol stream parsing, field-cache stream extraction, formatted client stream events, and transform error logging. The streaming foundation remains isolated from live provider routing so existing providers keep current behavior while Phase 5 provider implementations gain a mocked native stream path. Tests: python -m pytest tests/test_native_provider_executor.py tests/test_native_provider_streaming.py tests/test_responses_store.py tests/test_responses_bridge.py tests/test_responses_service.py tests/test_responses_routes.py tests/test_responses_streaming.py tests/test_protocol_responses.py tests/test_transform_trace.py tests/test_transaction_logger_transform_trace.py
Adds the first priority Phase 5 provider as an explicit native integration skeleton with Anthropic Messages protocol declaration, adapter config, thinking-signature field-cache rule, native header/endpoint helpers, and mock-friendly model discovery. This does not assume undocumented live behavior or wire the provider into the runtime native executor yet; it establishes a tested provider declaration path for later native routing. Tests: python -m pytest tests/test_claude_code_provider.py tests/test_provider_protocol_declarations.py tests/test_native_provider_executor.py tests/test_native_provider_streaming.py tests/test_protocol_anthropic_messages.py tests/test_adapter_registry.py tests/test_field_cache_engine.py
Mirrowel
added a commit
that referenced
this pull request
Aug 19, 2026
Content snapshot (not cherry-pick): post-checkout reactions run /tmp/react.sh (PR #162 Critical); pre-checkout starts guarded; GraphQL boundary notes. Trees identical to main for these files.
Mirrowel
added a commit
that referenced
this pull request
Aug 19, 2026
…-identity, AI-reviewer noise filtering Mirror of Mirrobot-agent d3d644b (live PR #162/#166 findings): taint warning = head -1 of taint file (no flatten spill); minimized content hidden from ALL blocks incl. agent own reviews; bare mirrobot dropped from BOT_NAMES_JSON (name != identity; @MirRobot routing unchanged); CONTEXT_IGNORE_AUTHORS + CONTEXT_FILTER_PATTERNS_JSON repo variables with baked AI-reviewer noise defaults (coderabbit rate-limit/skip, greptile status) keeping substantive reviews; ellipsis hardcode removed; other-reviews render bodies; AI reviewers = input-never- authority prompt stance. 57+339 battery green; e2e fixture 12/12.
2 tasks
1 task
Mirrowel
force-pushed
the
experimental
branch
from
September 5, 2026 16:46
b91c680 to
c83341d
Compare
Mirrowel
force-pushed
the
experimental
branch
from
September 5, 2026 16:47
c83341d to
f4ac60a
Compare
Repository owner
deleted a comment from
Mirrobot-Agent
Sep 5, 2026
Repository owner
deleted a comment from
Mirrobot-Agent
Sep 5, 2026
Repository owner
deleted a comment from
Mirrobot-Agent
Sep 5, 2026
Repository owner
deleted a comment from
Mirrobot-Agent
Sep 5, 2026
Repository owner
deleted a comment from
Mirrobot-Agent
Sep 5, 2026
Repository owner
deleted a comment from
Mirrobot-Agent
Sep 5, 2026
Repository owner
deleted a comment from
Mirrobot-Agent
Sep 5, 2026
Repository owner
deleted a comment from
Mirrobot-Agent
Sep 5, 2026
Repository owner
deleted a comment from
Mirrobot-Agent
Sep 5, 2026
Repository owner
deleted a comment from
Mirrobot-Agent
Sep 5, 2026
Repository owner
deleted a comment from
Mirrobot-Agent
Sep 5, 2026
Repository owner
deleted a comment from
Mirrobot-Agent
Sep 5, 2026
Repository owner
deleted a comment from
Mirrobot-Agent
Sep 5, 2026
Repository owner
deleted a comment from
Mirrobot-Agent
Sep 5, 2026
Repository owner
deleted a comment from
Mirrobot-Agent
Sep 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Experimental Native Protocol Roadmap
This branch is for a long-running experimental rewrite that makes native protocol support the first-class extension point of
rotator_library, while preserving the existing credential rotation, quota, fair-cycle, session tracking, and provider plugin strengths.Operating Rules
experimentalbranch.C:\Projects\test\LLM-API-Key-Proxyand child paths.docs/experimental/are committed.docs/experimental/phase-N-*.md.exploreandexplore-heavyagents to review the work against the phase plan, external reference areas, and current proxy behavior. Fix findings and re-review as needed.Strategic Goal
The target architecture is:
Providers should be able to declare an existing protocol and only override the parts that are genuinely provider-specific. A custom provider should usually be configurable through protocol choice, adapters, field-cache rules, auth strategy, and model options rather than requiring a large bespoke provider implementation.
Priority Order
.envand optional JSON. No SQLite dependency for now.Non-Goals For This Branch
UsageManager, fair-cycle, custom caps, or evidence-basedSessionTracker.Current Strengths To Preserve
Reference Gateway Ideas To Import Carefully
Phase Index
Each phase may be subdivided if implementation scope becomes too large.
Completeness Matrix
This matrix exists so the branch does not lose any requested scope while phases evolve. The phase plans are still refreshed before implementation, but every item below must remain accounted for.
litellm_fallbackprotocol path; later providers should prefer native protocols and use LiteLLM only for unsupported coverage.previous_response_id, storage, SSE, and WebSocket-ready transport shape.last,all,last_user_turn,last_assistant_turn, andper_tool_call.src/rotator_library/providers/_retired/.exploreandexplore-heavy.06-phase-workflow.mdsays planning docs are committed, but phase reports are not committed by default.Code Quality Expectations