fix!: 재리뷰가 찾은 결함과 색인에서 빠졌던 발견 5건을 고친다

문제: 성숙도 리뷰 수정을 다시 읽은 재리뷰(Critical 0, 회귀 0)가
Important 27건·Minor 41건을 찾았다. 수정이 새로 만든 결함이 많았다.
@SystemInvoked가 권한 규칙의 탈출구가 됐고, 데모 계정 거부가 정확히
prod일 때만 걸렸고, outbox 순서 번호가 업그레이드 때 뒤로 갔고,
GraphQL union 아래 복잡도가 0이었고, 서블릿 오류 응답이 success:true로
나갔고, 호출자 deadline이 breaker를 열었다. 원래 리뷰 색인이 06 영역
발견 5건(06-10~14)을 빠뜨려 그동안 처리되지 않았다.

방법: 영역별 7묶음이 test-driven-development 절차로 실패 테스트를
먼저 쓰고 고쳤다. 결정은 재리뷰 README 4절에 적었다: 순서 번호는 V21이
기록한 전역 floor부터, 데모 계정은 local·test·demo 허용 목록,
@SystemInvoked bean은 기동 실패, complete 단계 실패는
IDEMPOTENCY_COMPLETION_UNKNOWN(결과 불명), 캐시 조건부 쓰기는 별도
SCRIPT lane, strict lane 정책은 build cache 입력, 끝나지 않는 재시도
행은 원인 코드·지표·PARKED 절차. 레지스트리가 선언만 하고 아무 코드도
내보내지 않던 redis.capability.* 지표 6개는 빼고 runbook을 실제
지표(redis.lane.*) 기준으로 고쳤다.

위험·한계: V21을 V22 없이 직접 고쳤다(어느 배포에도 아직 없음). 이
브랜치의 V21을 적용한 개발 DB는 다시 만들어야 한다. 서블릿 오류
디스패치를 보안 체인이 허용한다. 발행·저장소 포트 시그니처가 바뀌어
파생 서비스 코드가 깨진다. prod에서 fixture-로 시작하는 설정값은
기동을 막는다. httpclient failure-injection lane의 main 단계 중복
실행은 이전 결정대로 남겼다. 실제 CI runner 실행은 확인하지 못했다.

검증: ci, mainCheck, :integrationCheck, -p optional-platforms ci
integrationCheck performanceCheck, :performanceCheck, :releaseCheck
(-PgitRevision), verify-compose-profile-contracts(18 lane) 통과.
첫 실행의 실패 2건(FindSecBugs 1, sample 동시 생성 테스트의 v4 event
id)은 고친 뒤 ci·integrationCheck·mainCheck를 다시 돌려 통과했다.

Refs: docs/reviews/2026-11-03-rereview/README.md 3·4·6·7절
BREAKING CHANGE: outbox 발행 포트와 저장소 포트 시그니처, 순서 번호
첫 값(V21 floor 다음), 샘플 데모 계정 프로필 허용 목록, 새 오류 코드
IDEMPOTENCY_COMPLETION_UNKNOWN, prod의 fixture- 값 거부, 기동 rule은
static·의존 없음이어야 한다.
This commit is contained in:
DongHyeonka
2026-11-03 23:29:35 +09:00
parent 7ef8d0b4cb
commit bbe944bd3c
406 changed files with 13493 additions and 1656 deletions
@@ -16,6 +16,9 @@ dependencies {
// so a provider adapter in any leaf extends the same contract (capability criterion 5).
testFixturesImplementation 'org.junit.jupiter:junit-jupiter-api'
testFixturesImplementation 'org.assertj:assertj-core'
// OverlappingWrites (two transactions of one key, overlapped on purpose) lives beside
// application-core's transaction fake: the outbox counter contract needs it too.
testFixturesImplementation testFixtures(project(':application-core'))
// Use-case tests run over application-core's shared transaction fake (DirectTransactionPort),
// the one held to the transaction port contract, not a hand-written port per test class.
@@ -35,7 +35,9 @@ public interface ReconciliationJobStorePort {
* <p>The claim is ownership that outlives the statement that took it: until {@code now + lease}
* no other caller is handed the same job, whether or not a transaction is open. That is what lets
* the caller ask a provider about each job with no database transaction held across the call. A
* job whose lease has passed is claimable again, so the lease must cover the whole pass.
* job whose lease has passed is claimable again, so the lease must cover the whole pass. Taking
* over such a job counts the abandoned claim as one attempt, so a job its worker dies on every
* time still reaches the attempt limit.
*
* @param limit how many to take
* @param now the current instant
@@ -12,7 +12,7 @@ import dev.caskeleton.application.notification.platform.api.DeliveryAttemptId;
import dev.caskeleton.application.notification.platform.api.NotificationId;
import dev.caskeleton.application.notification.platform.api.RecipientDeliveryId;
import dev.caskeleton.application.notification.platform.api.TenantId;
import dev.caskeleton.application.notification.platform.policy.testkit.OverlappingWrites;
import dev.caskeleton.application.transaction.testkit.OverlappingWrites;
import java.util.List;
import java.util.Optional;
import java.util.Set;
@@ -81,6 +81,10 @@ public final class InMemoryReconciliationJobStore implements ReconciliationJobSt
.toList();
List<ReconciliationJob> claimed = new ArrayList<>();
for (Row row : due) {
if (row.claimedUntil != null) {
// The previous claim's lease ran out with no reschedule or completion: it was an attempt.
row.attempts++;
}
row.claimedUntil = now.plus(lease);
row.claimFence++;
claimed.add(row.copy());
@@ -12,7 +12,7 @@ import dev.caskeleton.application.notification.platform.dispatch.NotificationReq
import dev.caskeleton.application.notification.platform.dispatch.NotificationRequestRecord;
import dev.caskeleton.application.notification.platform.dispatch.NotificationRequestStorePort;
import dev.caskeleton.application.notification.platform.dispatch.RecipientDeliveryRecord;
import dev.caskeleton.application.notification.platform.policy.testkit.OverlappingWrites;
import dev.caskeleton.application.transaction.testkit.OverlappingWrites;
import java.time.Instant;
import java.util.List;
import java.util.Optional;
@@ -118,6 +118,25 @@ public abstract class ReconciliationJobStoreContract {
.containsExactly(id);
}
/**
* A worker that dies on the same job every time never reschedules it, so the lease expiry is the
* only trace its attempt leaves. Counting it is what lets the attempt limit end the loop, as the
* file server's reclaim does (review RR-03-08).
*/
@Test
@DisplayName("lease가 지나 다시 가져간 job은 끝내지 못한 이전 claim을 시도 한 번으로 센다")
void reclaimingAJobWhoseLeasePassedCountsTheAbandonedClaimAsAnAttempt() {
// given
scheduleDueJob();
store().claimDue(10, NOW, LEASE);
// when
List<ReconciliationJob> reclaimed = store().claimDue(10, NOW.plus(LEASE), LEASE);
// then
assertThat(reclaimed).extracting(ReconciliationJob::attempts).containsExactly(1);
}
@Test
@DisplayName("lease가 1마이크로초라도 남은 job은 다른 인스턴스가 가져가지 못한다")
void aJobWhoseLeaseHasNotPassedIsNotClaimed() {
@@ -161,11 +180,12 @@ public abstract class ReconciliationJobStoreContract {
// when
store().reschedule(stale, "STILL_UNKNOWN", NOW.plus(Duration.ofHours(1)));
// then
// then: two abandoned leases count, the stale reschedule does not (it would also have moved
// the job an hour out of this claim)
assertThat(store().claimDue(10, NOW.plus(LEASE.multipliedBy(2)), LEASE))
.as("two holders counting one question would reach the attempt limit early")
.extracting(ReconciliationJob::attempts)
.containsExactly(0);
.containsExactly(2);
}
@Test
@@ -7,6 +7,7 @@ import dev.caskeleton.application.notification.platform.api.TenantId;
import dev.caskeleton.application.notification.platform.policy.DeduplicationResult;
import dev.caskeleton.application.notification.platform.policy.DeduplicationStorePort;
import dev.caskeleton.application.notification.platform.policy.RecipientIdentity;
import dev.caskeleton.application.transaction.testkit.OverlappingWrites;
import java.util.List;
import java.util.UUID;
import java.util.function.Supplier;
@@ -1,96 +0,0 @@
package dev.caskeleton.application.notification.platform.policy.testkit;
import java.time.Duration;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Function;
import java.util.function.Supplier;
/**
* Two writes of the same key whose transactions overlap, in an order that does not depend on luck.
*
* <p>The first write runs and then holds its transaction open. The second starts while the first is
* still uncommitted — the moment a find-then-insert reads "absent" twice — and the first commits
* only once the second has either finished or had time to block on the first's row. A store that
* has no transactions simply runs the two one after the other, which is the answer it must give
* anyway.
*
* <p>Public because every store contract with an insert-or-find has the same race to show: the
* suppression and preference contracts here, and the admin operation claim.
*/
public final class OverlappingWrites {
private static final Duration SECOND_WRITE_HEAD_START = Duration.ofMillis(500);
private static final Duration LIMIT = Duration.ofSeconds(30);
private OverlappingWrites() {}
/**
* Runs both writes and returns their results, first then second.
*
* @param inTransaction runs one unit of work in one committed transaction of the store
* @param first the write whose transaction is held open
* @param second the write that starts while the first is uncommitted
* @return both results; a write that failed fails this call with its cause
*/
public static <T> List<T> run(
Function<Supplier<T>, T> inTransaction, Supplier<T> first, Supplier<T> second) {
CountDownLatch firstWrote = new CountDownLatch(1);
CountDownLatch releaseFirst = new CountDownLatch(1);
ExecutorService threads = Executors.newFixedThreadPool(2);
try {
Future<T> firstResult =
threads.submit(
() ->
inTransaction.apply(
() -> {
T written = first.get();
firstWrote.countDown();
await(releaseFirst);
return written;
}));
if (!firstWrote.await(LIMIT.toMillis(), TimeUnit.MILLISECONDS)) {
throw new IllegalStateException("the first write never finished its statement");
}
Future<T> secondResult = threads.submit(() -> inTransaction.apply(second));
try {
secondResult.get(SECOND_WRITE_HEAD_START.toMillis(), TimeUnit.MILLISECONDS);
} catch (TimeoutException blockedOnTheFirst) {
// Expected on a database: the second write waits for the first's uncommitted row.
} catch (ExecutionException failed) {
// Reported below, after the first transaction has been allowed to finish.
}
releaseFirst.countDown();
return List.of(
firstResult.get(LIMIT.toMillis(), TimeUnit.MILLISECONDS),
secondResult.get(LIMIT.toMillis(), TimeUnit.MILLISECONDS));
} catch (ExecutionException failed) {
throw new AssertionError("an overlapping write failed", failed.getCause());
} catch (InterruptedException interrupted) {
Thread.currentThread().interrupt();
throw new AssertionError("interrupted while racing two writes", interrupted);
} catch (TimeoutException stuck) {
throw new AssertionError("an overlapping write did not finish", stuck);
} finally {
releaseFirst.countDown();
threads.shutdownNow();
}
}
private static void await(CountDownLatch latch) {
try {
if (!latch.await(LIMIT.toMillis(), TimeUnit.MILLISECONDS)) {
throw new IllegalStateException("the first write was never released");
}
} catch (InterruptedException interrupted) {
Thread.currentThread().interrupt();
throw new IllegalStateException(interrupted);
}
}
}
@@ -6,6 +6,7 @@ import dev.caskeleton.application.notification.platform.api.TenantId;
import dev.caskeleton.application.notification.platform.api.routing.Channel;
import dev.caskeleton.application.notification.platform.policy.PreferenceRecord;
import dev.caskeleton.application.notification.platform.policy.PreferenceStorePort;
import dev.caskeleton.application.transaction.testkit.OverlappingWrites;
import java.time.Instant;
import java.util.List;
import java.util.Optional;
@@ -9,6 +9,7 @@ import dev.caskeleton.application.notification.platform.policy.SuppressionReason
import dev.caskeleton.application.notification.platform.policy.SuppressionScope;
import dev.caskeleton.application.notification.platform.policy.SuppressionSource;
import dev.caskeleton.application.notification.platform.policy.SuppressionStorePort;
import dev.caskeleton.application.transaction.testkit.OverlappingWrites;
import java.time.Duration;
import java.time.Instant;
import java.util.List;