Skip to content

operability(document-records): make durable metadata persistence idempotent under uncertain retry #309

Description

@seonghobae

Verified buyer/operability gap

The current document_records persistence stack (#98 → #107) correctly hardens evidence identity, immutable metadata, tenant RLS, exact canonical bytes, and duplicate-key ambiguity. The current #107 0021_document_record_persistence.sql write boundary, however, still has no explicit idempotency authority for an uncertain-outcome retry.

The table has tenant-scoped unique constraints for document/artifact/audit/outbox references. Those constraints prevent duplicate durable facts, but they do not by themselves give a caller deterministic replay semantics. If PostgreSQL commits an insert and the caller loses the response, retrying the same logical command can surface a uniqueness error rather than return the first committed authoritative result. A uniqueness violation is not proof to the caller that the existing row was produced by the exact same semantic command rather than by a conflicting command that reused one reference.

This is a document_records owner concern. Do not solve it in talent_acquisition, people_core, #307, or a consumer by retry heuristics, cross-service SQL, timeout assumptions, or by copying mutable #98/#107 source.

Required domain contract

Define a tenant-scoped, versioned persistence command/result boundary with an explicit idempotency identity and a deterministic semantic command digest over the already-governed persistence inputs. The authoritative persistence transaction must distinguish:

  • first execution: write one immutable document_record plus its required audit/outbox evidence and return one authoritative receipt/result;
  • same idempotency identity + same semantic digest: converge to the original committed document identity and receipt without creating another business/audit/outbox fact;
  • same idempotency identity + different semantic digest: fail closed as a conflicting replay;
  • concurrent first attempts for the same idempotency identity: serialize so exactly one semantic command wins and every same-semantic participant converges to that result;
  • timeout/connection loss after commit: a later retry can recover the authoritative first result without treating absence, elapsed time, or a generic uniqueness error as success evidence.

The idempotency key/receipt must be purpose-bound and PII-minimized. It must not store document bytes, credentials, free-form HR content, or duplicate Person/Employment truth. Preserve #107's exact canonical-evidence byte/digest invariants and document_records ownership.

Executable acceptance

  • Add RED PostgreSQL/application contracts for uncertain post-commit retry, same-key/same-semantic concurrency, same-key/different-semantic conflict, duplicate delivery/reordering where applicable, and connection cleanup.
  • Exercise real PostgreSQL concurrency; a single-threaded unit fixture is insufficient transaction evidence.
  • Prove one durable document fact and exactly-once logical audit/outbox evidence for same-semantic replay.
  • Bind the returned replay result to the original committed document identity and immutable receipt; do not generate a fresh identity on replay unless the contract explicitly proves why that identity is non-authoritative.
  • Keep aggregate/transaction scope minimal and tenant-scoped; use UPSERT/locking only where the semantic digest and result-recovery contract make the replay decision unambiguous.
  • Preserve FORCE RLS/NOBYPASSRLS acceptance and no cross-service application-table SQL.
  • Record failure/recovery semantics in ADR/OPERABILITY/TEST_STRATEGY/TRACEABILITY through the canonical writer paths.
  • Any new PostgreSQL acceptance contract must be admitted through the package-/contract-neutral Foundation owner (ci: preserve declared Python compatibility in canonical Foundation ownership #258/ci: enforce declared Python package compatibility #259 or verified successor), not a resurrected feature-local workflow.
  • Final integration requires fresh exact-head hosted evidence after feat(document-records): add governed HR document evidence #98/feat(document-records): persist immutable HR document metadata #107 and Foundation prerequisites are reconciled with protected develop.

This issue is not a reason to close or weaken #107. It is the next operability increment after immutable persistence authority is established.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions