folded-runs: bound crypto-provider cache with idle TTL eviction - #529
Merged
Merged
Conversation
Route createCryptoProviderCache through @corbits/collections' createExpiringMap instead of an unbounded Map. Each access refreshes the entry's ttl, so a key in active use is never evicted -- only one untouched for a full week is treated as abandoned and re-minted on next use. Re-minting is safe: nothing in this codebase persists or re-checks a signing key's public half against an earlier value (the one place CryptoProvider.getPublicKey() feeds a verification check, @intx/mailbox's fetch.ts, is never wired to this cache), so an idle key rotating after a week of disuse is not a correctness risk.
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.
CL-7223
createCryptoProviderCacheminted oneCryptoProviderper cache key(a workbench or instance id) in a plain
Mapwith no eviction, so along-lived hub process accumulated one entry per distinct key it ever
saw, forever -- including for workbenches/instances deleted long ago.
Fix
Routes the cache through
@corbits/collections'createExpiringMap(added by CL-7233) instead of hand-rolling eviction: a 7-day idle ttl,
refreshed on every access, so a key in steady use is never evicted --
only one nobody has touched in a full week is treated as abandoned and
re-minted on next use.
Eviction-safety reasoning
The original doc comment argued against eviction because "a key going
momentarily unreachable (idle sleep, a sweep) does not mean it is gone
for good" -- rotating a signing key on every idle-sleep wake would be
wrong. An idle-refreshed ttl addresses this directly: the default
idle-sleep reap window (
DEFAULT_CHAT_IDLE_REAP_MS, 30 minutes) isfar shorter than the 7-day ttl, so a normal sleep/wake cycle, or even
someone coming back to a workbench the next day, never sees a
rotation.
For the rare key that goes untouched for a full week, re-minting is
cheap (one Ed25519 keypair generation, no external registration) and
not side-effect-bearing: nothing in this codebase persists a
CryptoProvider's public key or re-checks it against an earlier value
for continuity. The one place
CryptoProvider.getPublicKey()feeds averification decision,
@intx/mailbox'sfetch.ts(
verifyMessageSignature), takes its expected-signer lookup as acaller-supplied callback and is never wired up against this cache
anywhere in this repo --
sendFoldedMail/listFoldedMailsignoutbound mail and read it back via
parseMailToEmail, which neverre-verifies a signature. So a rotated key for a truly abandoned
workbench/instance has no observable effect: nothing today checks that
two messages from the same key came from the same key.
Testing
bun run typecheckHUB_DATA_DIR=$(mktemp -d) bun test packages/folded-runs(pre-existingunrelated failures in
launch.test.ts/credential-delivery-error.test.tsfrom a stale
@intx/dbexport also fail identically onmain)bun run check:structural(all checks pass exceptcheck:report-error,which fails identically on
mainand is not wired into CI)