@magpie-community/opencode-qoder-auth 0.2.70 → 0.2.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +8 -2
  2. package/index.mjs +33 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -193,7 +193,7 @@ itself.
193
193
  | A refused sign-in (no code, or code 105) | 401 |
194
194
  | A quota (codes 110, 112–119, 122) | 429 |
195
195
  | A model the account's listing has off while its usage says no credits are left (since 0.2.64, #880) | 429 usage limit reached, with the credits used and the model; a model off with credits left, or whose usage can't be read, stays 400 `unknown or disabled model`, and an id Qoder never served is that 400 at once |
196
- | Busy or queued for the model (code 10605) | Since 0.2.28 the request waits in Qoder's queue as Qoder's client does (below), then is sent again; since 0.2.62 a streamed request is answered 200 at once and kept alive with SSE comments for up to an hour, its outcome in the stream; past the wait, 503 with `Retry-After` from Qoder's `retryAfterSeconds` (30s when it gives none). Since 0.2.40, when magpie has another candidate after this request (`x-magpie-fallback: 1`), the 503 comes at once, saying the queue and how many are ahead, and magpie asks the next. The sign-in is untouched |
196
+ | Busy or queued for the model (code 10605) | Since 0.2.28 the request waits in Qoder's queue as Qoder's client does (below), then is sent again; since 0.2.62 a streamed request is answered 200 at once and kept alive with SSE comments for up to an hour (since 0.2.71, 5 minutes when the queue hasn't moved with nothing ahead), its outcome in the stream; past the wait, 503 with `Retry-After` from Qoder's `retryAfterSeconds` (30s when it gives none). Since 0.2.40, when magpie has another candidate after this request (`x-magpie-fallback: 1`), the 503 comes at once, saying the queue and how many are ahead, and magpie asks the next. The sign-in is untouched |
197
197
  | A refusal of the request itself (codes 406, 416, 430, 80411, 80412, 100400–100403) | 400, with Qoder's words |
198
198
  | "Error in upstream response", the model's own vendor behind Qoder failing, which Qoder sends as a 400 (since 0.2.24) | 502, so magpie asks again or another account; the sign-in is untouched |
199
199
  | "Range of max_tokens should be [1, N]" behind "Error in upstream response" (since 0.2.63) | Asked again once with max_tokens N, which later requests for that model are sent from the start; refused again, 400 with Qoder's words, the sign-in untouched. QoDuck (`lmodel`) is never sent more than 131072, and a model whose listing entry names `max_output_tokens` never more than that; a smaller max_tokens goes as asked |
@@ -596,7 +596,13 @@ SSE comment saying the queue (": Qoder queued the request for smodel
596
596
  on: a Codex client is told `response.in_progress`, the event its 300s idle
597
597
  timeout counts, and a Chat client gets the comment. What comes of the wait
598
598
  goes on in the same stream: the answer, or a refusal (the queue's own after
599
- the hour) as the stream's error. Nothing needs setting. A request that isn't
599
+ the hour) as the stream's error. Since **0.2.71** a wait with nothing ahead of
600
+ the request (`queueCount` 1 or none) whose queue state comes back the same
601
+ at every ask for 5 minutes ends there, with the queue's 503 and "the queue
602
+ hasn't moved in 5 minutes with nothing ahead" (plugins#1220: Qoder CN held
603
+ such a RESOURCE_LIMIT queue unchanged, and the agent heard only
604
+ keepalives); magpie can then rest the account or ask the next. A queue with
605
+ others ahead is still waited out. Nothing needs setting. A request that isn't
600
606
  streamed has nothing to keep its client alive with, so it still waits 4
601
607
  minutes at most before the 503. Claude Code takes a ping as life only 30
602
608
  times in a row, about 35 minutes, so a longer wait still ends there. Qoder's client also reports the end
package/index.mjs CHANGED
@@ -1735,6 +1735,15 @@ const QUEUE = {
1735
1735
  // fail over from. A queued call answers its 10605 at once, and a
1736
1736
  // thinking model streams its reasoning, so a real answer starts sooner.
1737
1737
  silent: 120_000,
1738
+ // the longest a wait goes on with nothing ahead of the request
1739
+ // (queueCount 1 or none) and the queue's state the same at every ask.
1740
+ // Qoder CN once held such a RESOURCE_LIMIT queue unchanged, 1 in p4,
1741
+ // for every request from one hour on (plugins#1220): the hour's hold
1742
+ // then left the agent with keepalives only. After this it is the
1743
+ // queue's 503 with Retry-After, which magpie can rest the account on
1744
+ // or fail over from. A queue with others ahead is waited out as
1745
+ // Qoder's client waits it (#807).
1746
+ stuck: 5 * 60 * 1000,
1738
1747
  now: () => Date.now(),
1739
1748
  // every calls fn each ms until the returned stop is called
1740
1749
  every: (fn, ms) => {
@@ -1788,7 +1797,7 @@ function queueState(text) {
1788
1797
  if (isQueued !== undefined || serviceAvailable !== undefined) {
1789
1798
  const num = (v) => (v == null || v === "" || !Number.isFinite(Number(v)) ? undefined : Number(v))
1790
1799
  const str = (v) => (typeof v === "string" && v ? v : undefined)
1791
- return { isQueued, serviceAvailable, modelKey: str(o.modelKey), queueType: str(o.queueType), retryAfterSeconds: num(o.retryAfterSeconds) }
1800
+ return { isQueued, serviceAvailable, modelKey: str(o.modelKey), queueType: str(o.queueType), retryAfterSeconds: num(o.retryAfterSeconds), queueCount: num(o.queueCount), subCode: str(o.subCode) }
1792
1801
  }
1793
1802
  for (const k of ["data", "result", "message", "body"]) {
1794
1803
  const v = o[k]
@@ -1820,13 +1829,25 @@ async function queueStatus(api, cred, { requestSetId, modelKey, queueType, reque
1820
1829
  return st
1821
1830
  }
1822
1831
 
1832
+ // stuckKey is what a queue's state says of the request's place in it, or
1833
+ // "" when others are ahead of it (a queue that moves while they are
1834
+ // served is waited out, QUEUE.stuck never ends it).
1835
+ function stuckKey(st) {
1836
+ const n = Number(st?.queueCount)
1837
+ if (Number.isFinite(n) && n > 1) return ""
1838
+ return JSON.stringify([st?.isQueued, st?.serviceAvailable, Number.isFinite(n) ? n : null, st?.queueType ?? null, st?.subCode ?? null, st?.retryAfterSeconds ?? null])
1839
+ }
1840
+
1823
1841
  // queueWait waits in Qoder's queue for the request, from the state its
1824
1842
  // refusal gave, until the queue lets it through (true) or the wait ends
1825
- // (false). A cancelled request throws.
1843
+ // (false). A wait ended by QUEUE.stuck sets ask.stuck. A cancelled request
1844
+ // throws.
1826
1845
  async function queueWait(api, cred, ask, first, signal, deadline, site) {
1827
1846
  let q = first ?? {}
1828
1847
  let asked = false
1829
1848
  let failed = 0
1849
+ let same = stuckKey(q)
1850
+ let since = QUEUE.now()
1830
1851
  for (;;) {
1831
1852
  if (signal?.aborted) throw signal.reason ?? new DOMException("aborted", "AbortError")
1832
1853
  if (QUEUE.now() >= deadline) return false
@@ -1845,6 +1866,14 @@ async function queueWait(api, cred, ask, first, signal, deadline, site) {
1845
1866
  }
1846
1867
  failed = 0
1847
1868
  q = { ...st, modelKey: st.modelKey ?? q.modelKey, queueType: st.queueType ?? q.queueType }
1869
+ const key = stuckKey(q)
1870
+ if (!key || key !== same) {
1871
+ same = key
1872
+ since = QUEUE.now()
1873
+ } else if (QUEUE.now() - since >= QUEUE.stuck && st.isQueued !== false) {
1874
+ ask.stuck = true
1875
+ return false
1876
+ }
1848
1877
  if (st.isQueued === false) {
1849
1878
  if (st.retryAfterSeconds > 0) await QUEUE.pause(Math.min(queuePause(st.retryAfterSeconds), Math.max(0, deadline - QUEUE.now())), signal)
1850
1879
  return QUEUE.now() < deadline
@@ -3858,7 +3887,8 @@ const makePlugin = (site) => async ({ client }) => {
3858
3887
  onHeld(held.response)
3859
3888
  }
3860
3889
  try {
3861
- if (!(await queueWait(api, cred, ask, f.queue, signal, deadline, siteOf(site, cred)))) return errorResponse(f)
3890
+ if (!(await queueWait(api, cred, ask, f.queue, signal, deadline, siteOf(site, cred))))
3891
+ return errorResponse(ask.stuck ? { ...f, message: `${f.message} (the queue hasn't moved in ${Math.round(QUEUE.stuck / 60_000)} minutes with nothing ahead)` } : f)
3862
3892
  } catch (e) {
3863
3893
  return errorResponse({ status: 502, message: e?.message ?? String(e) })
3864
3894
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-qoder-auth",
3
- "version": "0.2.70",
3
+ "version": "0.2.71",
4
4
  "description": "Qoder and QwenWork (千问办公) subscriptions in OpenCode and magpie: qoder.com, qoder.cn, gateway.qwenwork.cn and the enterprise flagship, VPC and dedicated domains",
5
5
  "type": "module",
6
6
  "main": "./opencode.mjs",