fix(query): 같은 요청이 매번 받는 거절로 끝난 재전송은 결과 불명을 푼다

문제: 1106/03-01(2568587)은 결과 불명 요청을 같은 키로 다시 보낸 시도가
NOT_APPLIED·NOT_STARTED로 끝나면 이유와 상관없이 결과 불명과 키를 남긴다.
같은 요청이 매번 받는 거절(400 VALIDATION_FAILED, 400 IDEMPOTENCY_KEY_INVALID,
필드 목록이 있는 입력 검증)도 같다. 폼은 필드 오류를 버리고 "잠시 뒤 같은
요청으로 다시 보내 주세요"만 보인다. 저장은 꺼져 있고 다시 보내면 같은 400이
온다. 출구는 사실이 아닌 "변경됨으로 확인"이나 새로고침뿐이다. 815ea58
(1106/03-03)이 같은 길을 IDEMPOTENT 쓰기로 넓혔다(diff 리뷰 DR-01).

고른 방법(메인 세션 결정, D10 보충): 같은 키 재전송은 그 결과가 첫 요청에
무슨 일이 있었는지 보여 줄 때만 결과 불명을 푼다.
- 성공·APPLIED_CONFIRMED: 저장된 답의 재생이다. 지금처럼 푼다.
- 같은 요청이라 첫 요청도 받았을 거절: 푼다. src/contracts/errors.ts에
  isRefusedOnEveryAttempt를 두었다. effect NOT_APPLIED이고, kind
  VALIDATION_REJECTED(필드 목록이 있는 입력 검증)이거나 code·status가
  REFUSALS_OF_EVERY_ATTEMPT(400 VALIDATION_FAILED, 400 IDEMPOTENCY_KEY_INVALID)다.
- 그 밖(429, 401, 403, 503 RATE_LIMIT_*, 422 IDEMPOTENT_REQUEST_MISMATCH(키가
  이미 서버에 닿아야 나온다), 기능이 선언한 code(바뀌는 상태의 규칙일 수
  있다), IDEMPOTENT 쓰기의 404·412 같은 다른 code, NOT_STARTED): 지금처럼
  결과 불명과 키를 남긴다. 어느 쪽인지 모르는 code는 남긴다.
훅(resendLeavesUnknown)과 폼(resendLeftUnknown)이 같은 함수를 부른다. 폼은 푼
경우 처음 저장과 같이 보인다(필드 오류, 다시 받는 저장, 고친 값은 새 키).
남긴 경우 결과 불명 화면(확인·다시 보내기)이 그대로라 폼이 영영 막히지
않는다. 표는 backend-envelope.ts REFUSED_BEFORE_WRITE의 부분집합이어야 하고,
표의 나머지 행은 다른 쪽으로 분류된다. backend-envelope 단위 테스트가 둘을
대조해, 표에 새 행이 생기면 이 분류를 정할 때까지 실패한다. presentation은
adapters를 import할 수 없어(.dependency-cruiser.json) 판정을 contracts에 둔다.
버린 대안: 일시 거절(NOT_STARTED, retryable, RATE_LIMITED, RATE_LIMIT_*)만
남기기(diff 리뷰 안). 401·403과 422 IDEMPOTENT_REQUEST_MISMATCH, 기능 선언
code를 풀어 버린다. AppFailure에 새 칸을 더해 실행기가 표시하기(계약 타입과
실행기·바인딩을 함께 바꾼다).

위험·한계: 기능이 선언한 결정적 거절(생성 기능의 400 <FEATURE>_INVALID)은
어느 쪽인지 알 수 없어 결과 불명으로 남는다. 출구는 결과 불명 화면의
확인이다. 필드 목록이 있는 NOT_APPLIED는 기능 선언 code여도 입력 검증으로
본다. 리뷰 실험 03-R1 X1~X3·X5(503·429·NOT_STARTED)는 그대로 키가 모두
key-1이어야 한다. 런북 6.3-4를 고쳤다. CHANGELOG는 다음 커밋이 적는다.

검증: desktop batch에서 확인. node scripts/run-vitest.ts run
tests/component/application-mutation-admission.test.tsx
tests/component/form-foundation.test.tsx
tests/features/reference-feature/reference-page.test.tsx
tests/unit/backend-envelope.test.ts, 리뷰 실험 03-R1 패치를 이 커밋에 적용

Refs: 1106/03-01 (diff review DR-01)
This commit is contained in:
DongHyeonka
2026-11-06 08:00:56 +09:00
parent f173491348
commit 80e7f1d63a
8 changed files with 390 additions and 14 deletions
@@ -20,6 +20,7 @@ import {
import type { Result } from "../../../contracts/result.ts";
import {
createFailure,
isRefusedOnEveryAttempt,
normalizeUnknownFailure,
withFailureEffect,
type AppFailure,
@@ -268,8 +269,8 @@ type ApplicationMutationController<Input, Value> = Readonly<{
* new request, so it could apply twice. An IDEMPOTENT command
* (`resendSafe`) is sent without one (1106/03-03). 1106/03-01. A resend
* that ends `NOT_APPLIED` or `NOT_STARTED` resolves to that failure and
* leaves the request unknown with its key; only success or
* `APPLIED_CONFIRMED` settles it.
* leaves the request unknown with its key. Success, `APPLIED_CONFIRMED`
* and a refusal every attempt gets (`isRefusedOnEveryAttempt`) settle it.
*/
resendUnknownEffect(): Promise<ApplicationResult<Value> | null>;
/**
@@ -634,9 +635,15 @@ export function useApplicationMutation<Input, Value>(
// the write (429, the edge's 503 RATE_LIMIT_*) or never sent shows only
// that this attempt did not apply; the first may have. The request
// stays unknown with its intent, so the next save or resend carries
// the same key, never a new one (backend http-contract.md §2).
const resendLeavesUnknown = (): boolean =>
replayed !== undefined && (!scope || scope.isCurrent());
// the same key, never a new one (backend http-contract.md §2). A
// refusal every attempt of the request gets (input validation, a key
// the server's rule rejects) shows the first was refused too, so the
// request is settled and the form can take a corrected save
// (isRefusedOnEveryAttempt, D10 supplement).
const resendLeavesUnknown = (failure: AppFailure): boolean =>
replayed !== undefined &&
(!scope || scope.isCurrent()) &&
!isRefusedOnEveryAttempt(failure);
let runtimeExecution: RuntimeMutationExecution<Value> | undefined;
const pending = (async (): Promise<ApplicationResult<Value>> => {
@@ -700,7 +707,7 @@ export function useApplicationMutation<Input, Value>(
switch (failure.effect) {
case "NOT_STARTED":
case "NOT_APPLIED":
if (resendLeavesUnknown()) {
if (resendLeavesUnknown(failure)) {
optimisticLayer?.markUncertain();
holdUnknown(failure.retryAfterMs);
break;
@@ -755,7 +762,7 @@ export function useApplicationMutation<Input, Value>(
}),
"NOT_STARTED",
);
if (resendLeavesUnknown()) {
if (resendLeavesUnknown(failure)) {
admission.optimisticLayer?.markUncertain();
holdUnknown(undefined);
return { ok: false as const, error: failure };
+10 -3
View File
@@ -10,7 +10,10 @@ import {
} from "react";
import { flushSync } from "react-dom";
import type { ZodIssue, ZodType } from "../../contracts/zod.ts";
import type { AppFailure } from "../../contracts/errors.ts";
import {
isRefusedOnEveryAttempt,
type AppFailure,
} from "../../contracts/errors.ts";
import {
useLocale,
type ParameterlessMessageKey,
@@ -508,14 +511,18 @@ function refusalFor<Values extends FormValues>(
/**
* 1106/03-01. The resend did not reach the write: the request it repeats is
* still unknown, and the mutation coordinator keeps its key. Signing in again
* still comes first (D-2).
* still comes first (D-2). A refusal every attempt gets
* (`isRefusedOnEveryAttempt`, the coordinator's own test) settles the request
* instead, and the form shows it as for a first save (field errors, a save
* it takes again).
*/
function resendLeftUnknown(outcome: FormResult<unknown>): boolean {
return (
!outcome.ok &&
(outcome.error.effect === "NOT_APPLIED" ||
outcome.error.effect === "NOT_STARTED") &&
outcome.error.action !== "reauth"
outcome.error.action !== "reauth" &&
!isRefusedOnEveryAttempt(outcome.error)
);
}