Skip to content

Free-tier IP abuse 403 is retried on the same exit and in the keyed tiers #131

Closed

Description

@cheerc

Problem

When OpenCode's free gateway blocks the egress IP, the gateway treats the 403 as
an ordinary upstream rejection and keeps working through the retry plan:

  1. doAnonymousUpstream tries the next anonymous upstream on the same exit even
    though the block belongs to the IP, not to the lane;
  2. doUpstreamTiers then falls through to the keyed tiers, which leave from the
    same network and get the same 403;
  3. the block is not remembered, so every following client request (and every
    background availability probe) repeats the whole walk.

Upstream's message is explicit that retrying lengthens the penalty and that the
official client sees the same answer from the same IP, so the current behaviour
is the worst possible reaction. Clients also receive the upstream text ("turn it
off" if you are on a VPN), which misdescribes a gateway whose egress is a
configured proxy.

Evidence

Observed on a local instance (single direct exit) through a shim that logs
every upstream request:

18:16:50 client request  deepseek-v4.1-flash-free  (329 KB, Anthropic session X)
18:16:50 → 403 abusive traffic      (v1 /zen lane)
18:16:54 → 403 abusive traffic      (v2 /inference lane, same exit)
18:16:57 → 403 abusive traffic      (keyed Zen tier, same exit)
18:17:01 → 403 abusive traffic      (keyed Zen tier, same exit)
18:19:22 same pattern for a different session, 4 more requests

So one client request produced four upstream 403s from the same IP. The
availability probe has the same problem with a different symptom: issue #54
showed probes misreading upstream rejections, and this 403 is currently recorded
as http_403, indistinguishable from a request-shape rejection.

A control run minutes later proved the block is per-IP and transient rather
than per-session: the exact failed request body replayed with the same session
id returned 200. The defect is therefore not "which requests are blocked" but
"how the gateway reacts to being blocked".

Source: internal/gateway/upstream.go (doAnonymousUpstream,
doUpstreamTiers), internal/gateway/pool.go (anonymousCursor.Next),
internal/gateway/probe.go (probeAttempt).

Scope

Expected Outcome

  • One client request against a flagged exit sends at most one upstream request.
  • The flagged exit is skipped for a bounded TTL and comes back by itself.
  • Other configured exits still serve traffic.
  • Clients receive 503 free_tier_ip_blocked with the gateway's own message; the
    upstream text is never forwarded.
  • Availability probes record network_abuse_blocked instead of http_403.

Related

Activity

  1. tubimasky commented on Oct 20, 2026

    @tubimasky

    补充一个本地已实现并验证的互补方案,供参考:

    车道级熔断(而非只冷却出口)

    • 连续失败达到阈值(默认 6)或收到 403/429(明确封禁信号)立即熔断整条匿名车道;
    • 暂停时长 base_hours << (strike-1),封顶 max_hours(默认 1h → 2h → 4h → … → 24h 指数退避),任意一次成功即复位;
    • 暂停期间不取游标、零探测流量(不产生任何 403 往返),路由直接落到已认证层级;
    • 配置:models.anonymous_backoff = {threshold, base_hours, max_hours},默认关闭(threshold: 0),保持现有行为不变;可在诊断/日志中暴露 paused_until 与 strikes。

    与 #131 的一个关键差异:不建议"全部出口被封就给 503"

    • "keyed tiers 从同一 IP 也 403" 只对 Zen key(同一免费网关、同一 IP 封禁)成立;
    • Go Key(/zen/go,认证请求)不受免费层 IP 封禁影响,实测同一 IP 下返回 200;
    • 因此建议:匿名车道熔断后,zen-only 模型报明确错误(如 503 free_tier_ip_blocked),而配置了 Go Key 的模型回落到 Go 层,不要一刀切 503,否则会挡掉本来可用的付费层;
    • 可用性探针也应遵守熔断状态,避免后台探测持续延长封禁。

    本地验证

    • 环境:Debian 12 / aarch64,OpenCode 2.0.32 客户端,静态代理 + direct;
    • 熔断前:裸模型名(自动路由)每个请求约 10–50s,均消耗在 403 探测上;
    • 熔断后:首个 403 即暂停,后续裸名请求约 1.5s 直达 Go 层;封禁解除后首次探测成功即自动恢复免费层。

    如方向认可,我可以提 PR(config + pool + upstream 约 190 行,默认关闭、向后兼容)。

  2. cheerc commented on Oct 20, 2026

    @cheerc
    ContributorAuthor

    Thanks a lot for digging into this issue. Could you open a new PR to fix it? Looking forward to your fix. Thanks again.

  3. tubimasky commented on Oct 20, 2026

    @tubimasky

    按上一条讨论实现了对应 PR:#140 —— 默认关闭,配置 models.anonymous_backoff 后启用:

    • threshold 次连续失败,或单次 403/429 立即暂停整条匿名车道;每次再触发暂停窗口翻倍(1h → 2h → … → 24h),成功即复位;
    • 暂停期间不取游标、不发任何上游请求,路由直接落到已认证层级;可用性探针同样遵守熔断,避免后台探测延长封禁;
    • 与 Free-tier IP abuse 403 is retried on the same exit and in the keyed tiers #131 的差异:配置了 Go Key 时,认证请求 /zen/go 不受免费层 IP 封禁影响,因此回落到已认证层级仍可服务,而不是统一 503(Zen key 共享免费网关,仍会 403)。若维护者倾向 503 语义,可在此 PR 上叠加。
  4. jasonxu114514 commented on Oct 20, 2026

    @jasonxu114514
    Owner

    Fixed in 0bb23c7. performance.max_anonymous_exits now caps distinct static exits per anonymous request (default 8); rotating #pool transports still follow retry.max_attempts. An IP-abuse 403 marks only that exit (performance.free_tier_block_seconds, default 900s); the lane breaker opens only when every exit is blocked, and a single shape 403/429 no longer pauses the lane. After a block, the Zen keyed tier is skipped because it shares the free gateway, while the authenticated Go tier is still tried.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions