test(fetchers): a released model-cache flight leaves its 15s deadline armed, so shuffled runs fail on order

未關閉
#2,513 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 3 天內回覆

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
72/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
node.js, typescript

研究方向

Start with src/api/providers/fetchers/modelCache.ts, especially dedupedFetch around lines 413–478, and inspect how the timeout and waiter view are handled when the last waiter detaches. Reproduce with the Vitest command in the issue using seed 102, then check the model cache spec under shuffled order. Done when the released flight's timer and waiter view cannot affect later tests, and the shuffled run passes.

由索引模型根據 Issue 內容生成。

描述

Symptom

Any shuffled Vitest mix that includes src/api/providers/fetchers/__tests__/modelCache.spec.ts fails with unhandled rejections and wrong call counts (fetchModels called 2 times). The failure count depends on the seed: 2, 4, 11 or 15 failures. Runs in declaration order pass, so CI is green today.

Measured on main content

  • Fails at requesty head 3f59a3fa93cc with seed 100 (4 failures) and seed 102 (11 failures).
  • Fails identically with the requesty spec files reverted to base 75a93a9d9acc: seed 100 gives 4, seed 102 gives 15. So the defect is not introduced by the abort-signal units.
  • Repro: cd src && npx vitest run api/providers/fetchers/__tests__/modelCache.spec.ts api/providers/__tests__/requesty.modelCache.spec.ts --sequence.shuffle --seed 102
  • A single-flight isolation spec that does not use the shared cache (requesty.modelCache.spec.ts) is green under shuffle at seeds 42 and 7 on its own.

Mechanism

dedupedFetch arms a real 15 second deadline: const controller = new AbortController(), const timeoutSignal = AbortSignal.timeout(MODEL_CATALOG_FETCH_TIMEOUT_MS), const onTimeout = () => controller.abort(timeoutSignal.reason), timeoutSignal.addEventListener("abort", onTimeout, { once: true }) (src/api/providers/fetchers/modelCache.ts:413-417). removeTimeoutListener() runs only on the settle paths (:435, :441). A flight whose last waiter detaches is aborted and released synchronously (:477-478), but the armed AbortSignal.timeout is a live Node timer for the rest of the run. When it fires during a later test it aborts a stale waiter's view signal, and the rejection lands in whichever test is currently executing. The flight's own promise has a terminal observer (void promise.catch(() => {}) at :452), so the unhandled rejection comes from the per-waiter view side, not from the flight.

Expected

Either release the deadline with the flight - disarm the timeout when the last waiter detaches - or have the affected specs dispose their flights and pending fetches in afterEach, so test order cannot change results. The point is that the timer and the waiter view must not outlive the test that created them.

Why it matters now

The abort-signal series adds more specs that park a model lookup and release it late. Every one of them inherits this order dependency, and any move to randomised ordering in CI would turn it into a permanent flake.

主要語言
TypeScript
星號
2k
分支
301
平均合併
3 天 14 小時
30 天內合併 PR
103

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

Zoo-Code-Org/Zoo-Code 的其他 Issue

查看 Zoo-Code-Org/Zoo-Code 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。