refactor(semantic-cache): drop redundant B3 read-time threshold layer#151
Merged
jamby77 merged 1 commit intoMay 5, 2026
Conversation
Base automatically changed from
feature/cache-proposal-data-model---libs-support
to
feature/cache-proposal-data-model
May 5, 2026 14:40
KIvanow
approved these changes
May 5, 2026
PR #134's earlier B3 commit added a 5s-TTL read-time override (HGETALL on each check()) and PR #148's commit added a 30s background refresh that mutates defaultThreshold/categoryThresholds in-place. Both read the same {prefix}:__config hash; running both is duplicated work and the file even ended up with a duplicate `private readonly configKey: string` field declaration. Keep the 30s background-refresh approach (cleaner lifecycle, opt-out flag, prometheus counter, no per-call overhead) and delete the B3 machinery: - Removes private fields thresholdOverrides, thresholdOverridesCachedAt, thresholdOverridesRefresh and the THRESHOLD_OVERRIDES_TTL_MS constant. - Removes private helpers resolveThreshold, getThresholdOverrides, refreshThresholdOverrides. - Restores check()/checkBatch() threshold resolution to the simple options.threshold > categoryThresholds[category] > defaultThreshold chain; refreshConfig() updates those mutable fields. - Deletes runtime-threshold-overrides.test.ts (covered the deleted helpers). - Removes the duplicate configKey field declaration and constructor assignment. - CHANGELOG: drop the read-time-overrides bullet, expand the periodic-refresh bullet to spell out hash field semantics and the synchronous-first-tick guarantee, and reword the Behavior change note. Tests: 128/128 pass. Trade-off: propagation goes from ~5s to ~30s worst-case, which is acceptable given the human-approval flow upstream.
7fa7afb to
2979891
Compare
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
PR #134 landed an earlier B3 commit (5s-TTL read-time
HGETALLon everycheck()) and #148's commit added a 30s background refresh that mutatesdefaultThreshold/categoryThresholdsin place. Both read the same{prefix}:__confighash; running both is duplicated work and the file even ended up with a duplicateprivate readonly configKey: stringfield declaration.This PR keeps the 30s background-refresh approach (cleaner lifecycle, opt-out flag, Prometheus counter, no per-call overhead) and removes the B3 machinery.
Changes
thresholdOverrides,thresholdOverridesCachedAt,thresholdOverridesRefreshand theTHRESHOLD_OVERRIDES_TTL_MSconstant.resolveThreshold,getThresholdOverrides,refreshThresholdOverrides.check()/checkBatch()threshold resolution to the simpleoptions.threshold > categoryThresholds[category] > defaultThresholdchain;refreshConfig()updates those mutable fields.runtime-threshold-overrides.test.ts(covered the deleted helpers).configKeyfield declaration and constructor assignment.Net diff: −315 / +21 LoC.
Trade-off
Propagation latency for an approved threshold proposal goes from ~5s (B3 read-time) to ~30s worst-case (configurable). Acceptable given the human-approval flow upstream.
Test plan
pnpm --filter @betterdb/semantic-cache exec vitest run— 128/128 passpnpm --filter @betterdb/semantic-cache exec tsc --noEmitNote
Medium Risk
Changes how
check()/checkBatch()resolve thresholds by removing the 5s TTL per-call__configreads, so runtime threshold updates now depend solely on the periodic refresh cadence and could affect hit/miss behavior if refresh is delayed or disabled.Overview
Removes the redundant read-time
{prefix}:__configthreshold override layer (cached for 5s) and the associated helpers/state, socheck()andcheckBatch()now resolve thresholds only asoptions.threshold→categoryThresholds[category]→defaultThreshold.Keeps the background config refresh mechanism as the single source of runtime threshold updates, cleans up the duplicate
configKeywiring, and deletes the unit test suite that covered the removed per-call override behavior. Documentation inCHANGELOG.mdis updated to describe the periodic refresh semantics (including synchronous first refresh oninitialize()) and the__confighash field mapping.Reviewed by Cursor Bugbot for commit 2979891. Bugbot is set up for automated code reviews on this repo. Configure here.