Repository navigation
Conversation
Port the cache-stability and message-format fixes from the reference 2api gateways and cc-switch: - Recognise conversation ids from headers and body metadata aliases (Sliverkiss/workbuddy2api caigee-cmd#35, qoder2api-hub session affinity), so turns stay on one account instead of rotating and losing the upstream prompt cache. - Add opt-in CLI2API_MSGSTAT_SHARDS (workbuddy2api-hub WB_MSGSTAT_SHARDS): one (key, model, system prefix, tools) tuple maps to a small stable account set instead of being scattered by the first user message. - Add opt-in CLI2API_AFFINITY_DEBUG diagnostics separating route-level session affinity from real upstream cache-token hits. - Rectify historical Anthropic thinking / redacted_thinking blocks and stale signatures on /v1/messages (cc-switch Rectifier). Disable with CLI2API_THINKING_RECTIFIER=off. - Skip WAF fingerprint regexes for bodies with no known trigger, avoiding needless CPU work on large histories and keeping cached prefixes stable. No SQL migration changes; diagnostics are structured logs. New env switches are documented in deploy/README.md. Add a bilingual changelog fragment.
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.
Summary
Port cache-stability and message-format fixes from the reference 2api gateways and cc-switch.
Conversation id aliases: recognise
X-Conversation-Id,X-Session-Id,X-Thread-Id,X-CLI2API-Sessionand bodyconversation_id/conversationId/session_id/metadata.*aliases (Sliverkiss/workbuddy2api feat: add named client API keys with provider allowlists #35, qoder2api-hub session affinity). Turns stay on one account instead of rotating and losing the upstream prompt cache.CLI2API_MSGSTAT_SHARDS(opt-in, default 0): maps one (API key, model, system prefix, tools) tuple to a small stable account set, mirroring workbuddy2api-hubWB_MSGSTAT_SHARDS. Avoids scattering one-shot/v1/messagescalls across the whole pool.CLI2API_AFFINITY_DEBUG(opt-in): structured logs separating route-level session affinity (header/conversation/shard/content-seed) from real upstream cache-token hits, with prompt/cache tokens and hit rate. No SQL migration changes.Thinking rectifier (cc-switch-style, on by default):
/v1/messagesinbound cleanup of historicalthinking/redacted_thinkingblocks and stalesignaturefields. OpenAI-compatible upstreams do not validate Anthropic signatures; replaying them causes 400s and<thinking>scaffolding. Disable withCLI2API_THINKING_RECTIFIER=off.WAF prefilter: skip fingerprint regexes when the request body contains no known trigger. Reduces per-request CPU on large histories and avoids rewriting cached prefixes.
Validation
go build ./...andgo veton touched packages: passgo test -count=1for gateway / translate / workbuddy / console / control / codex / command: passExecutor session/shard/prepare targeted tests: pass (two unrelated pre-existing time-precision failures in
pool_test.goand Windows file-lock failures ininternal/storereproduce on cleanorigin/main)Frontend
npx tsc -b --force(TS 6.0.3), globaltsc -p tsconfig.app.json --noEmit(TS 5.9.3),npx oxlint: passEnd-to-end against a freshly built binary:
/v1/messageswith a stale signed thinking block returnsX-Cli2api-Rectified: thinking=1; a bodyconversationIdproducessession affinity ... source="conversation"and cache diagnostics underCLI2API_AFFINITY_DEBUG=1.Switches are documented in
deploy/README.md; bilingual changelog fragment included.