fix(query): IDEMPOTENT 쓰기는 결과 불명 뒤에도 다시 보낼 수 있게 한다
문제: 0929/03-03의 두 가드(재전송 버튼 canResend, 같은 입력 재제출 거절)가 intent의 키 유무로만 가른다. 뮤테이션 정책은 키 여부만 실어서 훅이 NEVER와 IDEMPOTENT를 가를 수 없다. 그래서 IDEMPOTENT 쓰기(손으로 쓴 PUT·DELETE)도 결과 불명 뒤 재전송 버튼이 없고 같은 입력 저장이 UNKNOWN_EFFECT_PENDING으로 거절된다. 출구는 사실을 모르는 "변경됨으로 확인"이나 새로고침뿐이다. 매뉴얼은 IDEMPOTENT를 "여러 번 적용해도 결과가 같다"로 적고, 실행기도 보낸 뒤에 다시 보낸다. 고른 방법(리뷰 03-03 대안 (a)): commandMutationIdentity가 resendSafe (KEYED 또는 IDEMPOTENT)를 함께 준다. BoundMutation에 선택 칸 resendSafe를 더했다(추가만). 훅은 admission마다 resendable(키가 있거나 정책이 resendSafe)을 적고, 두 가드가 키 대신 그 값을 본다. 칸이 없는 손으로 쓴 정책은 지금처럼 키 유무로 간다. NEVER의 재전송 금지와 같은 입력 거절은 그대로다. 매뉴얼 01·02와 런북 6.3-4에 IDEMPOTENT 행을 적었다. 버린 대안: 문서만 고치기(회복 경로가 그대로 불편하다), IDEMPOTENT에도 키를 붙이기(백엔드가 키를 읽지 않으면 의미가 없고 실행기가 UNEXPECTED_IDEMPOTENCY_KEY로 거절한다). 위험·한계: commandMutationIdentity의 반환 객체에 칸이 하나 늘었다. 그 값을 toEqual로 비교하던 테스트는 칸을 더해야 한다(이 repo는 1곳을 고쳤다). IDEMPOTENT로 잘못 선언한 쓰기(백엔드가 실제로는 중복을 막지 못함)는 이제 결과 불명 뒤 사용자가 다시 보낼 수 있다. 선언의 정확성은 기능 작성자 몫이다(02 결정표 3절). 템플릿 안에는 IDEMPOTENT 쓰기 소비자가 없다. CHANGELOG 행은 문서 담당이 적는다. 검증: desktop batch에서 확인. node scripts/run-vitest.ts run tests/component/application-mutation-admission.test.tsx tests/unit/command-mutation-identity.test.ts Refs: 1106/03-03
This commit is contained in:
@@ -249,6 +249,7 @@ type ApplicationMutationController<Input, Value> = Readonly<{
|
||||
* key. 0929/03-03. Without a key it is not sent: the result is a
|
||||
* `NOT_STARTED` `DUPLICATE_IN_FLIGHT` failure with code
|
||||
* `UNKNOWN_EFFECT_PENDING` until the unknown request is reconciled.
|
||||
* 1106/03-03. A `resendSafe` (IDEMPOTENT) policy sends it without a key.
|
||||
*/
|
||||
submit(input: Input): Promise<ApplicationResult<Value>>;
|
||||
resolveConflict(): Promise<void>;
|
||||
@@ -264,15 +265,17 @@ type ApplicationMutationController<Input, Value> = Readonly<{
|
||||
* intent, so a keyed command carries the same `Idempotency-Key`. Resolves
|
||||
* to `null` when nothing is waiting to be resent, and (0929/03-03) when
|
||||
* that request has no key: the server could not tell a second one from a
|
||||
* new request, so it could apply twice. 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.
|
||||
* 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.
|
||||
*/
|
||||
resendUnknownEffect(): Promise<ApplicationResult<Value> | null>;
|
||||
/**
|
||||
* 0929/03-03. `resendUnknownEffect` would send: the oldest request is
|
||||
* unknown, carries an idempotency key and is not being reconciled.
|
||||
* unknown, carries an idempotency key or comes from a `resendSafe`
|
||||
* policy (1106/03-03), and is not being reconciled.
|
||||
* `state.unknownEffectResendable` carries the same answer to `AsyncSurface`.
|
||||
*/
|
||||
canResendUnknownEffect: boolean;
|
||||
@@ -287,6 +290,11 @@ type MutationAdmission = {
|
||||
state: "ACTIVE" | "UNKNOWN" | "RECONCILING" | "SETTLED";
|
||||
readonly input: unknown;
|
||||
intent: MutationIntent | null;
|
||||
/**
|
||||
* 1106/03-03. Sending this request again cannot apply it twice: its intent
|
||||
* carries a key (KEYED) or the policy is `resendSafe` (IDEMPOTENT).
|
||||
*/
|
||||
resendable: boolean;
|
||||
/** Held while UNKNOWN so the same input keeps the same identity token. */
|
||||
identityLease: Readonly<{ release(): void }> | null;
|
||||
/** `performance.now()` before which a resend waits (see RESEND_WAIT_CEILING_MS). */
|
||||
@@ -371,6 +379,7 @@ export function useApplicationMutation<Input, Value>(
|
||||
"requiresIdempotencyKey" in options
|
||||
? options.requiresIdempotencyKey
|
||||
: false;
|
||||
const resendSafe = "resendSafe" in options && options.resendSafe === true;
|
||||
const unknownEffectChannelKey = scope
|
||||
? `bound:${scope.generation}:${scope.fingerprint}:${definitionId}:${definitionVersion}`
|
||||
: `legacy:${definitionId}:${
|
||||
@@ -573,8 +582,9 @@ export function useApplicationMutation<Input, Value>(
|
||||
// request from this one, so saving the same input again could apply it
|
||||
// twice. The unknown request is settled first (reconcileUnknownEffect),
|
||||
// never repeated; a page that calls submit outside the form meets this
|
||||
// too.
|
||||
if (replayed && replayed.intent?.idempotencyKey === undefined) {
|
||||
// too. 1106/03-03. An IDEMPOTENT command has no key but applying it
|
||||
// twice gives the same result, so it is sent (`resendable`).
|
||||
if (replayed && !replayed.resendable) {
|
||||
identityLease?.release();
|
||||
return Promise.resolve({
|
||||
ok: false,
|
||||
@@ -589,6 +599,7 @@ export function useApplicationMutation<Input, Value>(
|
||||
state: "ACTIVE",
|
||||
input,
|
||||
intent: null,
|
||||
resendable: false,
|
||||
identityLease: null,
|
||||
resendNotBefore: 0,
|
||||
scope: scope ?? null,
|
||||
@@ -639,6 +650,8 @@ export function useApplicationMutation<Input, Value>(
|
||||
requiresIdempotencyKey,
|
||||
});
|
||||
admission.intent = intent;
|
||||
admission.resendable =
|
||||
intent.idempotencyKey !== undefined || resendSafe;
|
||||
execution = Object.freeze({ kind: "BOUND", input, intent });
|
||||
} else {
|
||||
execution = Object.freeze({ kind: "LEGACY", input });
|
||||
@@ -777,6 +790,7 @@ export function useApplicationMutation<Input, Value>(
|
||||
mutationIntentFactory,
|
||||
mutationOperationId,
|
||||
requiresIdempotencyKey,
|
||||
resendSafe,
|
||||
scope,
|
||||
unknownEffectChannel,
|
||||
],
|
||||
@@ -876,7 +890,9 @@ export function useApplicationMutation<Input, Value>(
|
||||
/**
|
||||
* D-1 / 0929/03-03. A resend repeats the unknown request with its original
|
||||
* intent. Without an idempotency key (a `NEVER` command) nothing lets the
|
||||
* server recognise the repeat, so it is not offered.
|
||||
* server recognise the repeat, so it is not offered. 1106/03-03. An
|
||||
* IDEMPOTENT command (`resendSafe`) is: applying it twice gives the same
|
||||
* result.
|
||||
*/
|
||||
function canResend(
|
||||
channel: UnknownEffectChannel,
|
||||
@@ -884,7 +900,7 @@ function canResend(
|
||||
): boolean {
|
||||
return (
|
||||
head.state === "UNKNOWN" &&
|
||||
head.intent?.idempotencyKey !== undefined &&
|
||||
head.resendable &&
|
||||
!channel.reconciliationInFlight
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user