Skip to content

feat: rectifier, OpenAI format support, React admin panel & observability#23

Merged
broven merged 40 commits intomainfrom
dev
Feb 18, 2026
Merged

feat: rectifier, OpenAI format support, React admin panel & observability#23
broven merged 40 commits intomainfrom
dev

Conversation

@broven
Copy link
Owner

@broven broven commented Feb 18, 2026

Summary

A major update bringing several new features to the fallback proxy:

  • Request Auto-Rectification: Automatically detects and fixes incompatible request formats (thinking signatures, budget tokens, tool-use concurrency blocks) and retries, reducing unnecessary fallbacks
  • OpenAI Format Provider Support: Bidirectional request/response conversion enables using OpenAI-compatible APIs (OpenRouter, Azure, etc.) as fallback providers
  • React Admin Panel: Full SPA rewrite with login authentication, visual provider management, real-time circuit breaker status badges with manual reset
  • Sliding Window Circuit Breaker: Tiered cooldowns (0s/30s/60s/300s) with safety valve mechanism to prevent total service outage
  • Structured Observability: JSON-formatted logs with unique request IDs for end-to-end tracing, plus debug curl command generation
  • Provider Retry with Exponential Backoff: Configurable per-provider retry count
  • Prompt Cache Optimization: Strips volatile billing header parameters to improve cache hit rates
  • README updated with all new features documented

Test plan

  • Run npm test — all 367+ tests pass
  • Verify admin panel login flow works at /admin
  • Test rectifier by sending a request with invalid thinking signature
  • Test OpenAI format provider by configuring an OpenRouter fallback
  • Verify circuit breaker status badges update in real-time
  • Check npm run tail shows structured JSON logs with request IDs

🤖 Generated with Claude Code

broven and others added 30 commits February 8, 2026 17:56
* feat: add OpenAI format provider support

Add bidirectional format conversion for OpenAI Chat Completions API, enabling fallback providers like OpenRouter, Together AI, and any OpenAI-compatible endpoint.

Changes:
- Add format field to ProviderConfig (anthropic|openai)
- Implement request/response conversion with tool_use support
- Add streaming SSE conversion via TransformStream
- Update admin UI with format selector
- Add 37 comprehensive tests (259 total passing)
- Validate format field at API boundary

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>

* test: improve format-converter coverage to 99%+

Add tests for edge cases: non-string/non-array content, invalid JSON
in stream, interleaved text+tool_calls, flush with remaining buffer,
and usage in regular chunks.

* chore: add Codecov configuration with relaxed thresholds

Allow coverage to decrease by up to 5% and set patch target to 70%
to prevent CI failures on minor coverage fluctuations.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* feat: test multiple Claude models in testConnection with mapping suggestions

Refactor testProvider to test 4 models (Sonnet, Opus 4, Opus 4.6, Haiku) in
parallel instead of a single hardcoded model. Shows per-model results in the
admin UI and suggests adding model mappings when models fail without one
configured. Also adds claude-opus-4-6-20250415 to CLAUDE_MODELS.

* feat: add provider disable/enable toggle in admin panel

Show Anthropic primary API as fixed first entry with toggle switch.
Replace reorder arrow buttons with enable/disable toggles on all
providers. Disabled providers are skipped during request routing.

* test: add tests for provider disable/enable skipping behavior

Verify disabled Anthropic primary and fallback providers are skipped
during request routing, and that 502 is returned when all are disabled.

---------

Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
…error messages, and logging format. Adjust provider configurations and enhance circuit breaker functionality. Remove DEBUG variable from wrangler configuration.
* feat: new fallback algo

* docs: update documentation for circuit breaker implementation

- Update CLAUDE.md with circuit breaker architecture details
- Expand README.md with setup instructions
- Add comprehensive testing guide
- Update environment variables documentation
- Add contribution guidelines
- Expand runbook with troubleshooting steps

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
* feat: add structured logging and observability

Implements comprehensive observability with structured JSON logging:

- Add structured logger utility with JSON format output
- Generate unique Request ID for end-to-end tracing
- Return Request ID in response headers (X-Request-ID)
- Support client-provided Request ID via header
- Replace all console.log with structured events
- Track latency for all provider attempts
- Add 11 event types: request.*, provider.*, circuit_breaker.*, safety_valve.*, auth.*, config.*

All logs include:
- timestamp (ISO 8601)
- level (debug/info/warn/error)
- event type
- requestId
- structured data (provider, model, status, latency, error)

Benefits:
- Full request tracing via Request ID
- Easy querying in Cloudflare Dashboard
- Ready for Logpush to Grafana/Datadog/Sentry
- Automatic tracing integration (already enabled in wrangler.jsonc)

Documentation:
- Added docs/observability.md with usage guide
- Updated CLAUDE.md with observability section

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* fix: correct Headers type for x-request-id response header

Convert Record<string, string> from cleanHeaders to Headers object
before calling .set() method.

* chore: update

* feat: log reproducible curl command on request failure

When all providers fail, emit a `request.debug_curl` log entry containing
a copy-paste ready curl command that reproduces the original request to
the proxy. Accessible via `npm run tail` for local debugging.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Replace the health check endpoint at / with a 302 redirect to /admin,
preparing for login page support on the admin panel.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add loginPage export to admin.ts that renders a standalone login form.
The page validates the admin token against /admin/config, stores it in
localStorage for session persistence, and redirects to the admin panel
on success.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Switch admin panel fetch calls from passing token as query parameter
to using Authorization: Bearer header. This is more secure as tokens
in query params can leak via server logs and referrer headers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…nel (#16)

* feat: add GET /admin/provider-states endpoint

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: add CSS for circuit breaker status badges

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: show circuit breaker status badges on admin provider cards

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: add manual reset button for provider circuit breaker

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* docs: add implementation plan for admin circuit breaker status

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
* feat(rectifier): add type definitions for rectifier system

* feat(rectifier): implement Anthropic API rectifier system

Add automatic rectifier that detects and fixes Anthropic API request
compatibility issues with third-party providers. Includes thinking
signature rectification (removes thinking blocks, redacted_thinking
blocks, and signature fields) and thinking budget rectification
(adjusts budget_tokens and max_tokens to valid ranges). Each rectifier
retries once per request to prevent infinite loops. Configurable via
admin API endpoints with KV persistence.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* docs: add rectifier implementation plans

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
* feat: add GET /admin/provider-states endpoint

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: add CSS for circuit breaker status badges

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: show circuit breaker status badges on admin provider cards

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: add manual reset button for provider circuit breaker

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* docs: add implementation plan for admin circuit breaker status

* fix: syntax error in reset button onclick handler

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
- Add `retry` field to ProviderConfig in types
- Implement retry loop in `src/utils/provider.ts` for network and 5xx errors
- Add retry configuration UI to Admin Panel provider modal
- Exclude 4xx/429 errors from retry logic
- Add exponential backoff (500ms * 2^attempt)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When the safety valve is triggered (all providers in cooldown), the request
was bypassing the thinking signature rectification logic. This caused 400
Invalid Signature errors to persist even when using the safety valve.

This change adds the rectification logic to the safety valve execution path,
ensuring that invalid thinking blocks are removed before retrying the request.
Updates request handling to remove the 'accept-encoding' header before forwarding requests to upstream providers. This ensures that the runtime handles compression negotiation automatically, preventing issues where the worker receives compressed error responses (like 403s) and logs them as binary garbage.

Changes:
- Added `cleanRequestHeaders` in `src/utils/headers.ts` to filter unsafe headers including `accept-encoding`.
- Updated `src/index.ts` to use `cleanRequestHeaders` for primary and fallback requests.
- Updated `src/utils/provider.ts` to exclude `accept-encoding` and use `cleanHeaders` for error responses.
- Updated `src/admin.ts` to strip unsafe headers in provider testing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The x-anthropic-billing-header system message contains a 'cch' parameter
that changes with every request, preventing effective prompt caching.
This change strips that parameter while preserving the rest of the header.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Rectifier retry was using 30s timeout which was too short for large
request bodies after stripping thinking blocks. When timeout occurred,
the original 400 error was returned directly instead of trying fallback
providers. Now uses 120s timeout and sets status to 504 on timeout so
the request continues to fallback providers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 18, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
claude-code-fallback 4823762 Feb 18 2026, 03:50 PM

broven and others added 3 commits February 18, 2026 22:59
Auto-detect orphaned tool_use blocks missing corresponding tool_result
and inject dummy error tool_result to unblock the request. Integrated
into primary, safety valve, and fallback provider flows. Also unify
debug-skip header filtering (x-ccf-* prefix) and add error snippet to
failure logs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Feb 18, 2026

Codecov Report

❌ Patch coverage is 78.88283% with 155 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.64%. Comparing base (56a403b) to head (4823762).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/index.ts 63.36% 85 Missing ⚠️
src/utils/provider.ts 66.33% 34 Missing ⚠️
src/admin.ts 66.00% 17 Missing ⚠️
src/config.ts 87.87% 4 Missing ⚠️
src/utils/logger.ts 87.09% 4 Missing ⚠️
src/utils/rectifier/thinking-signature.ts 96.11% 4 Missing ⚠️
src/utils/rectifier/tool-use-concurrency.ts 92.59% 4 Missing ⚠️
src/utils/request-sanitizer.ts 90.90% 2 Missing ⚠️
src/utils/rectifier/thinking-budget.ts 97.77% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main      #23       +/-   ##
===========================================
- Coverage   96.76%   85.64%   -11.13%     
===========================================
  Files           7       15        +8     
  Lines         557     1198      +641     
  Branches      170      358      +188     
===========================================
+ Hits          539     1026      +487     
- Misses         17      171      +154     
  Partials        1        1               
Files with missing lines Coverage Δ
src/admin-html.ts 100.00% <ø> (ø)
src/utils/billing-header.ts 100.00% <100.00%> (ø)
src/utils/circuit-breaker.ts 100.00% <100.00%> (ø)
src/utils/curl.ts 100.00% <100.00%> (ø)
src/utils/headers.ts 100.00% <100.00%> (ø)
src/utils/rectifier/thinking-budget.ts 97.77% <97.77%> (ø)
src/utils/request-sanitizer.ts 90.90% <90.90%> (ø)
src/config.ts 96.22% <87.87%> (-1.08%) ⬇️
src/utils/logger.ts 87.09% <87.09%> (ø)
src/utils/rectifier/thinking-signature.ts 96.11% <96.11%> (ø)
... and 4 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@broven broven merged commit dab4dcf into main Feb 18, 2026
2 checks passed
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