Repository navigation
fix(provider): fail fast on content-filter blocks, cap shared-pool 429 retries, local PAN pre-check - #1511
fix(provider): fail fast on content-filter blocks, cap shared-pool 429 retries, local PAN pre-check#1511ianalitis wants to merge 8 commits into
Conversation
|
Comments Outside DiffThese findings could not be posted inline.
|
|
@greptileai review |
|
@greptileai review |
|
Non-TUI error blocks still blame the key: wire This branch already handles a content-filter block correctly on one path: Measured with headless
That text is newer than this branch: This branch's non-2xx path takes I have that as a small patch against master: |
…29 retries An OpenRouter guardrail block is decided by text in the conversation, and every turn resends the full history, so the TUI auto-retry continuation resent the same blocked request every few seconds (measured 2026-09-25). Treat 'blocked by content filter' like the #387 model/endpoint mismatch: clear the retry, stop auto-poke, and name the entity with what to do. The fail-fast branch moves to remote/terminal_errors.rs so server_events.rs shrinks under its size budget. 429s that OpenRouter attributes to upstream_provider_shared_pool now retry at most twice instead of the full configured ladder. (cherry picked from commit 5feca93)
…ble routes Gateway guardrails match card shapes without a checksum, so four-digit issue lists read as cards. Before a request leaves the machine, scan every string in messages for 15/16 contiguous digits or 4-4-4-4 / 4-6-5 groups with an issuer prefix and a valid Luhn checksum. On a match, fail closed naming the message index and role, never the value. The error keeps the 'blocked by content filter: [PAN]' wording so the TUI fail-fast path stops auto-retry. Loopback bases are exempt and JCODE_DISABLE_PAN_CHECK=1 is the escape hatch. Scan of 1,500 recent local session files: no hits other than published processor test numbers. (cherry picked from commit e7f83a9)
- Exempt loopback only when the parsed host is exactly localhost or a loopback IP, so hosts like localhost.example.com stay checked. - JCODE_DISABLE_PAN_CHECK opts out only when set to 1. - Report the message role from a closed set, never request text. - Stop auto-poke on a content-filter block, including the local one. - Cap shared-pool retries only for HTTP 429.
A loopback endpoint can redirect or proxy the request body to a remote host, so the loopback exemption let a card number leave the machine. Drop it; JCODE_DISABLE_PAN_CHECK=1 remains the explicit escape hatch.
6feb861 to
a621564
Compare
Problem
OpenRouter workspace guardrails can block a request with
403 request blocked by content filter: [credit_card]. Their built-in card matcher does not check a Luhn checksum, so ordinary text trips it. In our case it was a shell loop over four consecutive four-digit issue numbers. Two things then made a single false positive expensive:limit_source: upstream_provider_shared_pool, the retry ladder ran in full, even though OpenRouter had already tried every provider it could route to. On 2026-09-24 we logged 394 such 429s againstopenrouter/auto, and each one held the whole retry budget.Change
Commit 1:
fix(provider): fail fast on content-filter 403s and cap shared-pool 429 retriesfailover::content_filter_block_label()recognises a gateway content-filter block. The TUI's newterminal_errors::fail_fast_on_deterministic_errorstops the remote auto-retry and auto-poke on it, names the filter label, and restores the input. It also absorbs the existing Volcengine Ark model fails during reconnect / recovery continuation because it does not support the coding plan feature #387 model/endpoint fail-fast. A provider-level test pins that the block is never retried.upstream_provider_shared_poolretries at most twice. Ordinary 429s keep the configured ladder.Commit 2:
feat(provider): local pre-send PAN check with Luhn for OpenAI-compatible routesjcode-provider-core::failover::pan_checkscans every string inmessagesbefore send. It looks for 15- or 16-digit contiguous runs, or 4-4-4-4 and 4-6-5 groups joined by one repeated space or dash. A match needs a valid issuer prefix, the matching brand length and a valid Luhn checksum. A digit run glued to an ASCII letter or digit does not count.blocked by content filter: [PAN]wording so commit 1's fail-fast path applies.JCODE_DISABLE_PAN_CHECK=1is the explicit escape hatch for a false positive. Separately, parsed loopback bases always use a no-proxy transport on initial sends and retries. Redirects are followed only to other parsed loopback destinations, with a ten-hop limit. Remote redirects stop before dispatch. Client construction errors fail closed, never fall back to a proxy-aware client.loopback_clean_request_bypasses_proxy_and_follows_local_redirectscovers clean POSTs through both 307 and 308 local redirects, without any proxy connection. It fails with the no-redirect client and passes with bounded loopback-only redirects. Card-bearing requests intentionally remain blocked by default, even for local endpoints, because arbitrary local services may forward them remotely. For deliberate synthetic-card work on a trusted local model, launch that process withJCODE_DISABLE_PAN_CHECK=1; this explicit opt-out is covered byexplicit_opt_out_allows_local_card_test_data. It is not an automatic exemption and applies to the whole process, including any remote requests.loopback_pan_is_blocked_before_a_forwarder_can_receive_itfails on6ee407fd5because a connection reaches the local endpoint, then passes with the exemption removed. No external endpoint or literal card fixture is used. Runtime suite after the transport/redirect follow-ups: 147 passed, 1 ignored. Target-crate clippy (--no-deps -- -D warnings) passes; dependency-inclusive clippy remains blocked by the existingjcode-core::stdin_detectrange-loop lint.Validation
cargo test -p jcode-provider-core -p jcode-provider-openrouter-runtime: 145 + 142 passed.content_filter_block_is_never_retriedshared_pool_429_retries_at_most_twicepan_pre_send_blocks_a_card_number_without_echoing_itpan_checkunit tests (issue lists, mixed separators, glued digits, bad Luhn, each brand)Test fixtures build card-shaped values at runtime, so no card-number literal appears in the diff.