Repository navigation
fix(cache): a rolled-back transaction evicts the cache keys it wrote - #35722
Conversation
A read inside a transaction caches the uncommitted row it loads, and a failed transaction discarded its deferred evictions, so L1 and Redis kept serving the row the rollback undid until the repair or the TTL. A PUT that restores a soft-deleted ontology definition and then rejects its changed IRI left it cached as restored, so GET ?include=deleted answered 404 on the PostgreSQL + Elasticsearch + Redis lane (OntologyConceptResourceIT and OntologyPropertyResourceIT nativeDefinitionIriSurvivesUpdatesAndRestoration). A transaction that does not commit now evicts the keys its writes recorded, exactly like a commit, and a deadlock replay keeps the abandoned attempt's keys so the final commit or rollback evicts them too.
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically. Maintainers can bypass this check by adding the |
Every rolled-back transaction now evicts the keys it wrote, so the ContextMemory conflict decision no longer needs its own eviction, and ContextMemoryConflictReviewIT guards the platform rule instead. Also correct the comments that still described the cache collector as cleared per attempt and drained only after commit, and amend the memory-conflict decision record.
Inserts record no cache key, and the post-commit actions that evict the authorization caches still run only on commit, so the decision record no longer claims a rollback undoes everything a commit would evict.
Types Redis never caches and repositories that update through the DAO record no cache key, so the decision record lists them with inserts as cases whose code still evicts on its own failure path. Also reword the remaining comments that said the cache collector drains only after commit.
Code Review ✅ Approved🟡 Medium risk · Changing EntityRepository to evict recorded cache keys after rollback and retries could cause stale reads or excess cache reloads if key tracking is wrong. Fixes cache eviction for rolled-back transactions so keys written inside a failed unit of work are evicted instead of discarded, resolving the VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
🚦 Removed from the merge queue —
|
Describe your changes:
Fixes the
OntologyPropertyResourceITandOntologyConceptResourceITnativeDefinitionIriSurvivesUpdatesAndRestorationfailures on the PostgreSQL + Elasticsearch + Redis lane. That lane has been red onmainsince #35672 (push run), and it reproduced in #35666's queue run (39214030862).Root cause. The bug is in the cache platform, not the ontology code:
executeInTransaction. The restore evicts L1 at once and defers the Redis eviction to the commit.OntologyEntityRepository.useRestoredRevisionreads the definition back. L1 misses, so the loader reads the uncommitted restored row and caches it in L1 and Redis. The write epoch moved before that read started, so the race guard lets it through.DeferralScope.clear()discarded the deferred keys. Both caches kept the restored row until the 500 ms repair or the TTL, andGET ?include=deletedfiltered it out as not deleted and answered 404.The CI log shows the sequence:
Restoring the ontologyProperty …, thenCACHE: Writing entity to Redis … JSON length: 1731(the restored row), then the 404.ContextMemory conflict decisions hit the same failure in #35329 and fixed it only for themselves (ADR:2026-10-13-a-memory-conflict-opens-a-review-task-and-approving-it-supersedes-the-disputed-memory).
Fix in
EntityRepository.DeferralScope:Evicting is always safe, because the next read loads the committed row. The rule is recorded in
docs/decisions/2026-10-19-a-rolled-back-transaction-evicts-the-cache-keys-it-wrote.md. The ContextMemory decision's own eviction from #35329 is now redundant. The second commit removes it and amends that decision record, soContextMemoryConflictReviewITnow guards the platform rule. It also corrects comments that still described the cache collector as cleared per attempt and drained only after commit.Type of change:
High-level design:
Not applicable: a small fix of two Java files plus a decision record.
Tests:
Use cases covered
GET ?include=deletedreturns 200 with the same version.Unit tests
DeferredCacheInvalidationTestgets two new tests:aRolledBackTransactionEvictsTheRowAReaderCachedInsideItandaDeadlockReplayEvictsTheRowItsAbandonedAttemptCached.executeInTransactionboundary against an in-memory Redis.Redis must not keep … ==> expected: <0> but was: <1>. After it they pass.DeferredCacheInvalidationTest,DeadlockRetryTest,EntityCacheVirtualThreadTest,EntityLifecyclePostCommitTest,EntityRepositoryRestoreTest,RetryableBoundaryTest,TransactionRollbackTrackerTest,OntologyEntityDAOTest,OntologyHierarchyStorageTest,OntologyReleaseCaptureTest,ChangeRequestServiceTest,ChangeRequestLifecycleTest,RdfUpdaterTest.1070452cb10): 9 classes, 145 tests, 0 failures:DeferredCacheInvalidationTest,MemoryConflictResolutionTest,MemoryConflictReviewTasksTest,MemoryConflictDecisionTest,ContextMemoryLifecycleTest,RetryableBoundaryTest,DeadlockRetryTest,EntityRepositoryRestoreTest,TransactionRollbackTrackerTest.EntityRepository.DeferralScopehas 93% line coverage (55/59) fromDeferredCacheInvalidationTestalone. A whole-class figure forEntityRepositorysays nothing about this change.Backend integration tests
-Pcache-tests(PostgreSQL + Elasticsearch + Redis, parallel lane):0473a800496): bothnativeDefinitionIriSurvivesUpdatesAndRestorationcases fail withApiException (404)atBaseOntologyIT.java:164, as in CI.411cc9bf198): 452 tests, 0 failures, 60 skipped. Both target cases PASSED. The run also coveredOntologyConceptResourceIT,OntologyPropertyResourceIT,ContextMemoryConflictReviewIT,RestoreHierarchyIT,EntityCacheInvalidationIT,UnitOfWorkRollbackIT,EntityTransactionBoundaryITand everycache/*IT.1070452cb10):ContextMemoryConflictReviewIT,ContextMemoryLifecycleIT,OntologyConceptResourceITandOntologyPropertyResourceITran 465 tests with 0 failures and 59 skipped.aDecisionThatFailsPartWayLeavesBothMemoriesAsTheyWereand bothnativeDefinitionIriSurvivesUpdatesAndRestorationcases PASSED.make java_affectedselects the full unit and IT suites, becauseEntityRepositoryis over the planner's cap. The full matrix ran in CI on this branch for1070452cb10. The later commits (db9fbfb88b0,c0c8fb4e43c,e1fe2d60449) change only the decision records and comments. The first runs, for411cc9bf198, were cancelled when the self-review changes landed.Java test results: PASSED. These are CI runs on
1070452cb10, the last commit that changed code; the later commits change only comments and decision records.GitHub cut off the MySQL + Elasticsearch and Redis parallel-lane logs before Maven's totals. Both jobs concluded success, and their logs show no failing test. Unit tests ran in PR CI on
1070452cb10("Test Report"): 13,520 tests, 0 failed, 1 skipped.make java_affected_run --ci-runcan't record these runs, because it requires them to have tested HEAD.Ingestion integration tests
Not applicable: no ingestion changes.
Playwright (UI) tests
Not applicable: a backend-only cache fix.
Manual testing performed
None beyond the integration tests above, which drive the failing API sequence end to end against PostgreSQL, Elasticsearch and Redis.
UI screen recording:
Not applicable: a backend-only fix.
Checklist:
Fixes <issue-number>: <short explanation>. Not applicable: this is a test-failure fix, so it has a descriptive title and theskip-pr-checkslabel.Fixes #<issue-number>above. Not applicable, for the same reason.REVIEW.md(thepr-checklistskill runs it) and fixed every 🔴 finding, or answered it on the line below.411cc9bf198found no 🔴. Fixed in1070452cb10: the redundant ContextMemory eviction, whose Javadoc had become false, and the stale cache-collector comments.1070452cb10found one 🔴: the decision record overclaimed. It said code never needs its own failure-path eviction, but inserts record no cache key and the authorization-cache eviction runs only on commit.db9fbfb88b0scopes the record to the keys writes record (updates, restores, deletes) and names both exceptions. The code was unchanged.-Pcache-tests), so I ran the guards locally with it on both code commits (results above), and the Redis CI lane is dispatched below.db9fbfb88b0found one 🔴, again in the record's wording: the ten types Redis never caches (UNCACHED_ENTITY_TYPES) andTaskRepository/TaskFormSchemaRepository, which update through the DAO, record no key either.c0c8fb4e43clists them with inserts as cases whose code still evicts on its own failure path, and rewords six remaining comments that still said the cache collector drains only after commit. No code changed. Making the rule cover those types (record keys for every type, evict only L1 for uncached ones) is a possible follow-up; no caller hits it today.useRestoredRevisionmutates the sharedoriginal. It is not addressed here.c0c8fb4e43cfound no 🔴. Fixed its 🟡 on the record's insert wording ine1fe2d60449, a one-line documentation change: an insert does record a by-id key through its relationships; its by-name entries are what survive a rollback.docs/decisions/2026-10-19-a-rolled-back-transaction-evicts-the-cache-keys-it-wrote.md.🤖 Generated with Claude Code
Summary by Gitar
evictUncommittedrollback eviction fromMemoryConflictResolution.writeTogether, since rolled-back transactions now evict their own keysThis will update automatically on new commits.


Confidence Score: 5/5
The PR appears safe to merge; the latest documentation change matches the code.Summary
Rolled-back transactions now evict recorded cache keys instead of discarding them. Deadlock retries keep abandoned attempts’ keys for the final eviction.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Transaction records cache keys] --> B{Transaction result} B -->|Deadlock retry| C[Keep keys from abandoned attempt] C --> A B -->|Commit| D[Run deferred commit actions] D --> E[Evict recorded cache keys] B -->|Rollback| F[Discard deferred commit actions] F --> EReviews (5) · Last reviewed commit: "docs(cache): inserts leave their by-name..." · Reviewed by Greptile