Skip to content

fix(did): add TTL to DidResolver pre-resolution cache - #248

Closed
forumevi wants to merge 1 commit into
agentcommercekit:mainfrom
forumevi:fix/didresolver-cache-staleness
Closed

forumevi wants to merge 1 commit into
agentcommercekit:mainfrom
forumevi:fix/didresolver-cache-staleness

Conversation

@forumevi

@forumevi forumevi commented Oct 7, 2026

Copy link
Copy Markdown

Problem

The DidResolver pre-resolution cache (addToCache / addResolutionResultToCache) has no expiry. An entry added at startup stays in the cache for the lifetime of the process:

#cache = new Map<string, DIDResolutionResult>()  // no timestamp, no TTL

In a long-running service this means a DID document whose keys have since been rotated or revoked continues to pass every downstream signature and issuer check until the process restarts or removeFromCache() is called manually. The W3C DID Core spec defines nextUpdate and nextValidUntil metadata fields precisely to signal when a cached document should be refreshed — the current implementation ignores them entirely.

Fix

Add a configurable TTL (default 5 minutes). Cache entries older than the TTL are evicted on the next resolve() call and a fresh network resolution is performed.

// Default — 5-minute TTL
const resolver = getDidResolver()

// Longer-lived cache (e.g. for a read-heavy verification service)
const resolver = new DidResolver(registry, { cacheTtlMs: 30 * 60 * 1000 })

// Restore old unlimited-cache behaviour explicitly
const resolver = new DidResolver(registry, { cacheTtlMs: Infinity })

// Disable cache entirely (equivalent to cache: false)
const resolver = new DidResolver(registry, { cacheTtlMs: 0 })

Breaking change

Callers that relied on the implicit addToCache entry living forever (e.g. tests or demos that populate the cache once at startup and never refresh it) will now see a network re-resolution after 5 minutes. Pass cacheTtlMs: Infinity to restore the previous behaviour.

The pre-resolution cache had no expiry: a DID document added with
addToCache() or addResolutionResultToCache() stayed cached for the
lifetime of the process. In a long-running service this means a rotated
or revoked key continues to pass every signature and issuer check until
the process restarts or removeFromCache() is called manually.

Add a configurable TTL (default 5 minutes). Cache entries older than
the TTL are evicted on the next resolve() call and a fresh resolution is
performed. Callers that need the old behaviour can pass cacheTtlMs:
Infinity to the constructor.
@coderabbitai

coderabbitai Bot commented Oct 7, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 57 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e827a7d1-331c-4113-9c34-f3713330e414
📥 Commits

Reviewing files that changed from the base of the PR and between 3db94d6 and da92103.

📒 Files selected for processing (1)
  • packages/did/src/did-resolvers/did-resolver.ts
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@forumevi

forumevi commented Oct 7, 2026

Copy link
Copy Markdown
Author

Closing: speculative, not a bug.

@forumevi forumevi closed this Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant