fix(storage): put idle 상한이 lock 대기 상한보다 짧지 않은 OPFS 정책을 거절한다

문제: 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
This commit is contained in:
DongHyeonka
2026-11-04 20:56:03 +09:00
parent f485e51e21
commit f6b74ed496
2 changed files with 28 additions and 2 deletions
+5 -2
View File
@@ -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 ||
+23
View File
@@ -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", () => {