- Skip both cache_control walks with a byte-level precheck when the body
has at most 4 cache_control keys, no thinking block and no 1h TTL; skip
the block-limit walk when only 1h is present. Bodies containing \u
escapes always take the original path.
- Replace gjson Array() materialization with Get("0")/ForEach in the
beta, toolset, tool-rewrite, web-search and system-preview helpers.
- Build the Claude Code mimic debug line lazily; it is only read on
credential-scope errors.
- Compute the billing-header fingerprint once instead of per block.
Differential tests copy the previous implementations verbatim and
compare byte for byte across edge cases and 3000 randomized bodies.
Batching TTL rewrites with sjson ReplaceInPlace was rejected because it
resolves duplicate keys differently.
Common ~32KB Claude Code request: enforceCacheControlLimit 100us/21
allocs -> 21.6us/0 allocs; helper set 47.6us/103KB -> 37.9us/69KB;
debug line 9.1us/53 allocs -> ~0.
An ephemeral Codex fork, such as app-server thread/sample, keeps its parent's
session-id header and prompt_cache_key but names itself in
client_metadata.session_id. Account identity scoping compared the key only
with client_metadata.session_id, so a fork's key fell into the prompt-cache
namespace and reached upstream as a different value from its parent's, and
the fork lost the parent's prompt cache.
Treat a key that equals either client_metadata.session_id or the client's
session-id header as a session key.
SyncGroupRateMultipliers and SyncGroupRPMOverrides ran three destructive
statements in autocommit mode: clear rows missing from the payload,
delete all-NULL rows, then upsert the payload. If the upsert failed
(deleted user FK, duplicate user_id, transient DB error), the clear and
delete had already committed, silently wiping the group's overrides.
Wrap each sync in one transaction and dedupe entries by user_id before
writing so ON CONFLICT cannot hit the same row twice. Any failure now
rolls the whole sync back.
Add sqlmock tests covering commit, rollback and dedupe.
Anthropic SSE processing decoded every data line into map[string]any even
though most events (content_block_delta, ping, ...) are forwarded
verbatim. A 120-byte text delta cost ~915ns, 1185B and 20 allocations;
a 1500-chunk response burned ~1.4ms CPU and ~30k allocations for no
semantic gain.
Parse only events that can change usage, model, cache_control or
keepalive state. Replace the per-line SSE regex with a prefix check, and
add a string variant of tool-name restoration so the streaming writer no
longer copies each chunk through []byte/string.
Benchmark (content_block_delta): 915ns/20 allocs/1185B -> 164ns/0
allocs/0B. Output remains byte-for-byte identical; existing streaming
tests pass.
The auth cache snapshot records the (user, group) RPM override for the
API key's group. checkRPM used it for any group whenever it was non-nil,
so a fallback request (for example the Antigravity prompt-too-long path)
applied group A's override to group B: override=0 disabled B's
rpm_limit entirely, while a positive override throttled B to the wrong
rate.
Only trust the snapshot override when UserGroupRPMOverrideGroupID
matches the current group; otherwise fall back to the DB lookup as the
snapshot versioning intended.
Alipay refunds used a UnixNano timestamp as out_request_no, so an admin
retry after an ambiguous gateway error minted a new request and refunded
the user twice. Use the same deterministic order+amount id as the other
providers (wxpayRefundID, Stripe idempotency key).
Same order and amount now map to the same Alipay refund request; the
existing QueryRefund prefix contract is unchanged.
Persist BALANCE_RECHARGE_MULTIPLIER with up to 6 decimal places so operators
can track a live FX rate (e.g. 1 USD = 7.100000 CNY -> 0.140845). Values with
more than 6 decimals are rejected instead of being silently truncated.
Credited balance still rounds to settlement-currency precision, so order and
ledger semantics are unchanged.
Adds backend unit tests and a frontend formatter test; updates the admin input
step/preview and the checkout rate display.
RefreshTokenPair read the token and deleted it in two Redis calls. Two
concurrent requests with the same refresh token both passed the read and
validation, so both could mint a new token pair, keeping a stolen token
alive across rotations.
Add an atomic ConsumeRefreshToken (Lua GET+DEL) and require rotation to
win that consume. Losers get ErrRefreshTokenInvalid; Redis errors now
fail closed instead of issuing a new pair without invalidating the old
token.