feat(semantic-cache): runtime-configurable defaultTtl via __config hash#161
Open
amitkojha05 wants to merge 1 commit into
Open
feat(semantic-cache): runtime-configurable defaultTtl via __config hash#161amitkojha05 wants to merge 1 commit into
amitkojha05 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d093106. Configure here.
d093106 to
b547545
Compare
Contributor
Author
8 tasks
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.

Closes #147.
What this does
Adds runtime TTL configuration to
@betterdb/semantic-cache(TS + Python) via the existing{name}:__confighash — same mechanism asthreshold_adjust. A running process picks up TTL changes on the nextrefreshConfig()tick without a restart.Changes
SemanticCache (TS)
defaultTtlis now mutable;_initialDefaultTtlcaptures the constructor value as the permanent fallbackrefreshConfig()reads thettlfield at the end of every tick — after threshold processing, no field collision_initialDefaultTtlrestored. No throws anywhere in the path.Discovery (TS)
buildSemanticMetadata()indiscovery.tsnow advertises'ttl_adjust'alongside'threshold_adjust'MCP
cache_propose_ttl_adjusttool registered aftercache_propose_threshold_adjustcache_namenew_ttl_seconds(1–604800)reasoning(≥20 chars)Example
packages/semantic-cache/examples/monitor-proposals/index.tsextended with a TTL proposal demo loop:Python mirrors
_initial_default_ttlcaptured in__init__refresh_config()with identical validation logic:math.isfinitebuild_semantic_metadata()indiscovery.pyadvertises'ttl_adjust'Tests
8 cases each in TS + Python — field read, fallback, restore on removal, invalid values (0, negative, float, string), timer propagation, discovery capability
What's not in this PR
The library side is fully wired —
refreshConfig()reads thettlfield, validation matches the threshold pattern, and the MCP tool is registered.The remaining pieces to close the propose→approve→apply→pickup loop live in
proprietary/:CacheApplyDispatcher— routeproposal_type: 'ttl_adjust'to a newapplySemanticTtlAdjusthandler:semantic-ttl-adjustPOST route that thecache_propose_ttl_adjusttool calls.Both are one-line additions mirroring the existing
threshold_adjustcounterparts. Happy to implement if you'd prefer, or these can land internally.Note
Medium Risk
Medium risk because it changes cache expiration behavior at runtime in both TS and Python, which can affect memory usage and cache hit patterns; validation is defensive and covered by new tests.
Overview
Adds a runtime-configurable semantic-cache default TTL via the existing
{name}:__confighash in both@betterdb/semantic-cache(TS) andbetterdb-semantic-cache(Python), withrefreshConfig()/refresh_config()applying a validated positive-integerttlvalue and restoring the constructor TTL when the field is removed.Updates discovery metadata to advertise the new
ttl_adjustcapability, adds an MCP toolcache_propose_ttl_adjustto create TTL-change proposals, and extends the monitor-proposals example plus TS/Python test suites to cover TTL read/fallback/restore/invalid-value and refresh-tick propagation cases.Reviewed by Cursor Bugbot for commit b547545. Bugbot is set up for automated code reviews on this repo. Configure here.