This repository was archived by the owner on Oct 16, 2026. It is now read-only.
Repository navigation
Commit 0146e93
committed
Fix opencode-go limit judgment: tunable thresholds + zen credit detection
opencode-go (opencode zen) exposes no usage/limit API — the local DB
holds no quota state (see anomalyco/opencode#10448), and `cost` is a
display-only token-price estimate, machine-local. The previous
heuristic (sum local cost over sliding 5h/weekly/monthly windows vs
hardcoded $12/$30/$60) has no correspondence to zen's real model
(credit balance + monthly cap), so it under-reports "limited" and the
provider gets selected while actually rate-limited.
* Make the three USD thresholds configurable via env
(`SEHER_OPENCODE_5H_LIMIT_USD` / `_WEEKLY_` / `_MONTHLY_`), default
to the previous values. A value of `0` disables that window — lets
the user drop the invented 5h/weekly windows and keep only a monthly
cap matching their zen plan.
* `OpencodeGoUsageWindow`: `limit_usd <= 0` now means *disabled*
(never limited, 0% utilization), instead of always-limited / 100%.
* Broaden `is_pi_limit` to catch zen's credit-exhaustion wording
("usage exceeded" / "add credits" / "insufficient credits" / "out of
credits" / "credit balance"), so when zen is driven through pi's
OpenAI-compatible endpoint the run-time error triggers retry-on-limit
— the only reliable signal absent a usage API.
Tests: +5 (disabled window, env default fallback, threshold limited,
zen credit phrases). 146 total.1 parent 9204765 commit 0146e93
3 files changed
Lines changed: 128 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
16 | 32 | | |
17 | 33 | | |
18 | | - | |
| 34 | + | |
| 35 | + | |
19 | 36 | | |
20 | | - | |
| 37 | + | |
21 | 38 | | |
22 | 39 | | |
23 | | - | |
| 40 | + | |
| 41 | + | |
24 | 42 | | |
25 | | - | |
| 43 | + | |
26 | 44 | | |
27 | 45 | | |
28 | | - | |
| 46 | + | |
| 47 | + | |
29 | 48 | | |
30 | 49 | | |
31 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
32 | 73 | | |
33 | 74 | | |
34 | 75 | | |
| |||
207 | 248 | | |
208 | 249 | | |
209 | 250 | | |
210 | | - | |
211 | | - | |
212 | | - | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
213 | 254 | | |
214 | 255 | | |
215 | 256 | | |
| |||
236 | 277 | | |
237 | 278 | | |
238 | 279 | | |
239 | | - | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
240 | 283 | | |
241 | 284 | | |
242 | 285 | | |
| |||
354 | 397 | | |
355 | 398 | | |
356 | 399 | | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
357 | 445 | | |
358 | 446 | | |
359 | 447 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | | - | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
27 | | - | |
| 29 | + | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
30 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
31 | 45 | | |
32 | 46 | | |
33 | 47 | | |
| |||
256 | 270 | | |
257 | 271 | | |
258 | 272 | | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
259 | 282 | | |
0 commit comments