Skip to content

QVAC-17783 fix: scope kv-cache invalidation to deleted key on RPC delete-cache#1740

Merged
maxim-smotrov merged 3 commits into
tetherto:mainfrom
maxim-smotrov:fix/cache-delete-single-key
Apr 24, 2026
Merged

QVAC-17783 fix: scope kv-cache invalidation to deleted key on RPC delete-cache#1740
maxim-smotrov merged 3 commits into
tetherto:mainfrom
maxim-smotrov:fix/cache-delete-single-key

Conversation

@maxim-smotrov

@maxim-smotrov maxim-smotrov commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

🎯 What problem does this PR solve?

  • Deleting a single cache via the delete-cache RPC (removeCache({ kvCacheKey, modelId })) wiped the entire in-memory cachedMessageCounts map, not just entries for the deleted target. Unrelated caches lost their cached message counts and were forced to reprocess history on the next completion.

📝 How does it solve it?

  • handleDeleteCache now scopes both invalidations to the actually-removed target:
    • clearCachedMessageCounts(removedPath) — only entries under the deleted directory
    • clearCacheRegistry({ cacheKey, modelId }) — only matching modelId:configHash:cacheKey entries
    • { all: true } branch now also resets the registry (it wasn't being cleared before).
  • deleteCache now returns the removed path so the handler can pass it to the message-count cleaner, and uses rm({ recursive: true, force: true }) so a missing dir is not an error. Errors propagate to the handler's existing structured-error wrapper instead of being silently logged.
  • clearCacheRegistry rewritten to parse the composite key (modelId:configHash:cacheKey) and exact-match on cacheKey and/or modelId instead of substring matching.
  • clearCachedMessageCounts matches by exact key or prefix + path.sep so a deleted directory invalidates only its own entries, not unrelated keys sharing a string prefix.

🧪 How was it tested?

  • Manually exercised the delete-cache RPC with { kvCacheKey, modelId } and verified that:
    • message counts for unrelated caches are preserved
    • initializedCaches no longer retains entries for the deleted target
    • subsequent completions on the deleted cache reinitialize cleanly
  • Verified { all: true } still wipes everything end-to-end.

@maxim-smotrov maxim-smotrov requested review from a team as code owners April 24, 2026 10:19
@maxim-smotrov maxim-smotrov changed the title QVAC-17783 fix: scope kv-cache invalidation to deleted key QVAC-17783 fix: scope kv-cache invalidation to deleted key on RPC delete-cache Apr 24, 2026
@maxim-smotrov

Copy link
Copy Markdown
Contributor Author

/review

@github-actions

Copy link
Copy Markdown
Contributor

Tier-based Approval Status

**PR Tier:** TIER1

**Current Status:** ✅ APPROVED

**Requirements:**
- 1 Team Member approval ✅ (1/1)
- 1 Team Lead OR Management approval ✅ (1/1)



---
*This comment is automatically updated when reviews change.*

@maxim-smotrov maxim-smotrov merged commit 8d35f3b into tetherto:main Apr 24, 2026
19 of 22 checks passed

@simon-iribarren simon-iribarren left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving as team member — lead (NamelsKing) and opaninakuffo already signed off.

The bug and fix are both well-characterized:

  • handleDeleteCache was wiping the entire cachedMessageCounts map on single-key deletes; now scoped to the removed path.
  • clearCacheRegistry was substring-matching on the composite key (modelId:configHash:cacheKey) and could false-positive across entries; now parses and exact-matches.
  • clearCachedMessageCounts matches on exact key or prefix + path.sep, avoiding the unrelated-prefix-collision class of bugs.
  • { all: true } branch now also resets the registry, closing a gap the old code had.
  • deleteCache returning the removed path + switching to rm({ recursive: true, force: true }) is the right shape — idempotent on missing dirs and errors surface through the handler's existing structured-error wrapper.

Small diff (+54/-49, 3 files), tightly scoped to the invalidation path. Ship it.

Proletter pushed a commit that referenced this pull request May 24, 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.

4 participants