Repository navigation
OwnedKeyMaterial tracks uses outside steps (spec 0004, entry 4) - #33
Merged
Merged
Conversation
A use counts itself in an atomic, copies the source into a concurrent map, then reads the state. Revoke commits as before and then wipes every mapped copy. The step that leaves forgotten material with no views, or the last use out after it, zeroes the source. An ordinary use of a held key view now commits no step. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A view borrowed and closed between releaseTerminal's read of inUse and the zeroing step could admit a use that the stale read missed; the source was then zeroed under it and its answer turned to Denied. The step now reads the count itself, so it commits only with no use in flight. Found in review of #33. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
matthewjones372
changed the base branch from
key-callers-atomic-count
to
main
December 1, 2026 11:40
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #32. Entry 4 of spec 0004,
key-material-uses-outside-steps.What changes
OwnedKeyMaterial.useno longer registers the use inShared. It uses two JDK structures, each commented with spec 0004:inUse(AtomicInteger): a use adds itself, copies the source, puts the copy incopies, then reads the state. Revoked, zeroed or a closed view means wipe the copy, take itself out, and answerDenied.copies(ConcurrentHashMap): revoke commits its state as before, then wipes every copy in the map.Each step (forget, close a view, revoke) commits, then reads
inUse. A use takes itself out, then reads the state. When forgotten material is left with no views, whichever side goes second, the step or the last use out, commitszeroedin one guarded step and wipes the source. That is the only time a use commits a step.One ordinary use of a held key view now commits 0 steps (it was 2 after #32).
KeyViewUseCostSuite's ceiling is 0; it failed at 2 before the change.Other changes:
refusedreads the clock before the state. A revoke made at that clock read is then still seen and answersDenied, which outranks expiry as before.Bench
./gradlew :surefold-tenancy-crypto-bench:run, paired runs alternating this branch and #32 on the same machine, load average 177 to 245 on 8 cores.Unlike #32, p99 is now steady across runs even at this load. Max is scheduler noise.
Stories
The two the spec names:
revocation during use admission wipes its copy and refuses before the callback: the revoke is made from the view's own clock, at the read after the copy. That is the point where the test holds control (spec question 2). It answersDenied, the callback never runs, and the source is wiped.revocation during an admitted callback refuses its normal answer(unchanged) still shows the copy in use is wiped. Stress:revocation racing uses either wipes and refuses or answers from an intact copy, 100 rounds of 4 uses against a revoke.the last use out of forgotten material wipes the source and notifies once: forget and close inside the callback. The source survives until the use leaves, the answer stands, then the source is wiped and notified once. Stress:forgetting during concurrent uses wipes the source only after the last use, before its notice, 100 rounds of 4×20 uses against forget and close.That stress story first asserted one notice, and it failed 4 times in 100 rounds with two. The close step and the last use out can both reach the notice. Notices are at least once by design (
a parallel acknowledgement survives another notice attempt failingrequires parallel attempts, and the ledger'sonTerminalis idempotent). The zeroing is a single guarded step. The story now asserts that every notice found the source already wiped, and that no use answered from a wiped copy.Removed:
a committed use with throwing instrumentation releases its unpublished use: a use commits no step, so there is no instrumentation to fault.Rewritten:
expiry during use admission refuses before the callback: it cut off on the use's commit. It now returns an expired time from the view's clock at the read after the copy.revocation during use admission refuses before the callback→ the first named story above.a committed terminal acknowledgement survives instrumentation failure: faults commit 2, not 1, because close, zeroing and acknowledgement are now three steps.Found in review
An independent review found a gap.
releaseTerminalreadinUsebefore the zeroing step, and the step did not read it again. In that gap, a view borrowed on forgotten material could admit a use and then be closed. The stale zeroing then committed under that use, and the use answeredDeniedafter a benign close. No bytes were exposed, because the use's copy is private. The zeroing step now reads the count inside its own transaction. It commits only if nothing committed since its snapshot, and that snapshot had no views, so any admitted use had already counted itself. No story pins this interleaving: it needs a borrow between a close's commit and its zeroing, and nothing there is a point where the test holds control.The review also confirmed
KeyCallersadmission (no call admitted after close returns, and the count never leaks), torn-copy refusal, and revoke reaching every copy in flight.Verified
./gradlew spotlessApply && ./gradlew :surefold-tenancy-crypto:buildis green, all 257 tests including the Postgres suites, with detekt and Kover.🤖 Generated with Claude Code