Files
document-haness/docs/clean-architecture-backend-template/tech-log-studio/state-machines-and-ownership/concept/concept-adapter-outbound-persistence-jpa-c36.md
T
DongHyeonkaandClaude Opus 5 b2963105a8 docs(keycloak-session-store): import the session-storage lab as a new project
The keycloak project ended with four open questions that design could not
settle. A two-VM lab was built to answer them by measurement, and this is
that material: 26 experiments, 125 raw command outputs, 22 browser captures.

Follows the import procedure in README.md.

  source/     the originating repository verbatim — 78 documents, 28 SVGs,
              8 manifests, plus .source-revision recording the commit
  final/      the SSOT
    document.md   729 lines written from the 29 experiment documents, not
                  concatenated: what was predicted, what was measured, and
                  where the measurement itself was wrong
    evidence/raw    125 outputs, flattened to <experiment>__<file> because
                    the originals collided (01-baseline.txt appeared three
                    times) and the audit only globs the top level
    evidence/meta   one per raw file; command and exitCode are null and the
                    README says why rather than inventing them
    evidence/browser  22 captures
    assets/       three diagrams through techviz
    .techviz/     their VizSpecs

A separate project rather than an addition to keycloak: the B-layer answers
that project's four questions, but the A, C and D layers are about cluster
failure, SSO and operations, and one document.md should hold one subject.
The four question records there can point here through 관계.

Recorded rather than papered over: only three of the 28 diagrams were
remade. The repository forbids hand-drawn SVG and forbids titles inside the
canvas; all 28 originals carry both, so converting them is redrawing, not
reformatting. They stay in source/ and the gap is written into the document.

verify-pipeline.py passes. audit-records.py reports no issues.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 22:51:59 +09:00

60 lines
3.5 KiB
Markdown

---
kind: CONCEPT
slug: adapter-outbound-persistence-jpa-c36
title: 만료된 COMPLETED row를 inspect와 claim이 다르게 읽는다
topic: state-machines-and-ownership
project: clean-architecture-backend-template
status: 게시 전
sourceRevision: 21234e38cdb9a926cbc92bb97a2aee2e4a7d2916
rootTreeNode: concept:adapter-outbound-persistence-jpa-c36
evidenceCapturedOn: 2026-09-01
assets:
- key: adapter-outbound-persistence-jpa-c36
file: ../../../final/evidence/rendered/adapter-outbound-persistence-jpa-c36.svg
- key: adapter-outbound-persistence-jpa-c36-diagram
file: ../../../final/assets/diagrams/adapter-outbound-persistence-jpa-c36.svg
evidence:
- ../../../final/evidence/raw/adapter-outbound-persistence-jpa-c36.txt
source:
- 원본 분석 절은 analysis/05-adapter-outbound-persistence-jpa.md#L2669 이다.
module: adapter-outbound-persistence-jpa
---
# 만료된 COMPLETED row를 inspect와 claim이 다르게 읽는다
`PostgreSqlOwnerSafeIdempotencyStore`의 owner/CAS 구조 자체는 강하지만, `inspect()``replayUntil` 만료를 보지 않는다.
## 본문
<!-- body:start -->
`PostgreSqlOwnerSafeIdempotencyStore`는 row lock, owner token, attempt, state revision, operation id와 transition digest를 결합해 claim/renew/fail/complete를 보호한다. `renew``markFailed`는 동일 operation id replay에서도 semantic argument를 digest에 넣어 `SAME_ARGUMENTS``DIFFERENT_ARGUMENTS`를 분리한다. 이 구조 자체는 강하다. 현재 revision에서는 `PostgreSqlIdempotencyProviderConfig`가 이 store를 production provider로 실제 생성하므로 아래는 dormant helper 문제가 아니다.
## 같은 row를 읽는 두 경로
:::evidence key="adapter-outbound-persistence-jpa-c36-diagram" alt="만료된 COMPLETED row 에서 inspect 와 claim 두 상자로 화살표가 나가고 화살표에 서로 다른 결과가 붙은 구조" caption="같은 row 를 읽는 두 경로" zoom="false"
:::
`inspect()`는 row가 `COMPLETED`이고 response payload가 있으면 `replayUntil`이 이미 지난 값인지 확인하지 않고 무조건 `COMPLETED_REPLAY`를 반환한다. 반면 claim path는 DB time과 expiry를 보고 만료된 row를 takeover 가능 상태로 처리한다. 실제 PostgreSQL 16에서 replay TTL 25ms로 완료한 뒤 50ms를 기다린 probe 결과는 이렇다.
```text
expiredInspect.outcome=COMPLETED_REPLAY
expiredInspect.replayUntil=<already expired>
expiredInspect.claimAfterExpiry=TakenOverClaimed
```
## PostgreSqlOwnerSafeIdempotencyStore 참조 위치
:::evidence key="adapter-outbound-persistence-jpa-c36" alt="코드베이스에서 PostgreSqlOwnerSafeIdempotencyStore 를 검색한 출력 14줄. 이 기록이 세는 참조가 그 출력에 그대로 보인다." caption="PostgreSqlOwnerSafeIdempotencyStore 코드베이스 검색 — 14줄 · exit 0" zoom="true"
:::
## introspection 문제가 아니라 lifecycle 문제인 이유
`IdempotencyExecutorV2`는 reconciliation에서 `COMPLETED_REPLAY`를 실제 저장 응답 반환 신호로 사용한다. 따라서 이 불일치는 **만료 후 새 실행이 허용된 시점에도 이전 응답을 reconciliation 결과로 반환할 수 있는 lifecycle correctness 문제**다.
## 같은 계약의 다른 구현은 만료로 수명을 끝낸다
JPA 설계 문서가 동일 Idempotency V2 contract를 구현한다고 참조하는 Redis state machine도 `COMPLETED -> [*] : replay TTL expires`로 수명을 끝낸다. JPA `inspect()`만 이 만료를 무시한다.
<!-- body:end -->