From f6b74ed496bcc2f0ec990d877ee8e515d0ec5846 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Wed, 4 Nov 2026 20:56:03 +0900 Subject: [PATCH] =?UTF-8?q?fix(storage):=20put=20idle=20=EC=83=81=ED=95=9C?= =?UTF-8?q?=EC=9D=B4=20lock=20=EB=8C=80=EA=B8=B0=20=EC=83=81=ED=95=9C?= =?UTF-8?q?=EB=B3=B4=EB=8B=A4=20=EC=A7=A7=EC=A7=80=20=EC=95=8A=EC=9D=80=20?= =?UTF-8?q?OPFS=20=EC=A0=95=EC=B1=85=EC=9D=84=20=EA=B1=B0=EC=A0=88?= =?UTF-8?q?=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: putIdleTimeoutMs < mutationLockWaitTimeoutMs는 05-07이 기대는 관계다(멈춘 put이 idle 상한에서 origin lock을 놓아야 줄 선 writer가 대기 상한 전에 돈다). 이 관계가 opfs-policy.ts 주석에만 있고, 정책 검사는 각 값의 범위만 본다. 두 값을 뒤집은 정책은 조용히 통과하고, 멈춘 put 하나가 다른 탭의 모든 쓰기를 BLOCKED로 끝낸다. 고른 방법: assertOpfsRuntimePolicy가 putIdleTimeoutMs >= mutationLockWaitTimeoutMs를 TypeError로 거절한다. 다른 정책 오류와 같은 자리·같은 방식이다. 기본값(2분 < 10분)과 repo 안의 모든 정책은 이미 관계를 지킨다. 위험·한계: 이 관계를 어긴 정책을 쓰던 다운스트림은 조립 때 실패한다. 의도한 동작이다. 검증: - RED: opfs-worker-runtime.test.ts 새 2건(같음, 김)이 throw 없음으로 실패. - GREEN: OPFS 단위 3파일 + tests/recipes + tests/contract 174건 통과. check:types, 바꾼 파일 eslint 통과. Refs: docs/reviews/2026-11-03-maturity-review/05-adapters-storage-kernel.md 0929/05-09 --- src/adapters/storage/opfs/opfs-policy.ts | 7 +++++-- tests/unit/opfs-worker-runtime.test.ts | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/adapters/storage/opfs/opfs-policy.ts b/src/adapters/storage/opfs/opfs-policy.ts index f15e415d..c1dc0e56 100644 --- a/src/adapters/storage/opfs/opfs-policy.ts +++ b/src/adapters/storage/opfs/opfs-policy.ts @@ -25,8 +25,9 @@ export type OpfsRuntimePolicy = Readonly<{ /** * 05-07. How long a put may wait for its source's next bytes. The put holds * the origin mutation lock from BEGIN to FINISH, so a stalled source would - * otherwise stop every tab's writes until their lock wait ran out. Keep it - * below `mutationLockWaitTimeoutMs` so a queued writer outlasts it. + * otherwise stop every tab's writes until their lock wait ran out. It must + * be below `mutationLockWaitTimeoutMs` so a queued writer outlasts it; the + * policy check refuses one that is not ([0929] 05-09). */ putIdleTimeoutMs: number; reconciliationBudgetMs: number; @@ -107,6 +108,8 @@ export function assertOpfsRuntimePolicy(policy: OpfsRuntimePolicy): void { !Number.isSafeInteger(policy.putIdleTimeoutMs) || policy.putIdleTimeoutMs < 1_000 || policy.putIdleTimeoutMs > 60 * 60_000 || + // [0929] 05-09. A queued writer must outlast a stalled one. + policy.putIdleTimeoutMs >= policy.mutationLockWaitTimeoutMs || !Number.isSafeInteger(policy.reconciliationBudgetMs) || policy.reconciliationBudgetMs < 1 || policy.reconciliationBudgetMs > 60_000 || diff --git a/tests/unit/opfs-worker-runtime.test.ts b/tests/unit/opfs-worker-runtime.test.ts index 9b361ebc..e319754c 100644 --- a/tests/unit/opfs-worker-runtime.test.ts +++ b/tests/unit/opfs-worker-runtime.test.ts @@ -3034,6 +3034,29 @@ describe("05-07 a put whose source stops lets go of the origin lock", () => { expect(await putB).toMatchObject({ ok: true, value: { generation: 1 } }); stalled.release(); }); + + // [0929] 05-09. The test above holds only while a queued writer outlasts a + // stalled one. That ordering was a comment; a policy that breaks it is now + // refused when it is resolved. + it.each([ + ["equal to", 60_000], + ["longer than", 120_000], + ])("rejects an idle bound %s the lock wait", (_, putIdleTimeoutMs) => { + expect(() => + resolveOpfsRuntimePolicy({ + ...runtimePolicy, + mutationLockWaitTimeoutMs: 60_000, + putIdleTimeoutMs, + }), + ).toThrow(TypeError); + expect( + resolveOpfsRuntimePolicy({ + ...runtimePolicy, + mutationLockWaitTimeoutMs: putIdleTimeoutMs + 1, + putIdleTimeoutMs, + }).putIdleTimeoutMs, + ).toBe(putIdleTimeoutMs); + }); }); describe("05-10 the object id grammar is the prepared-object grammar", () => {