Skip to content

refactor(semantic-cache): drop redundant B3 read-time threshold layer#151

Merged
jamby77 merged 1 commit into
feature/cache-proposal-data-modelfrom
feature/cache-proposal-data-model---libs-support-b3-cleanup
May 5, 2026
Merged

refactor(semantic-cache): drop redundant B3 read-time threshold layer#151
jamby77 merged 1 commit into
feature/cache-proposal-data-modelfrom
feature/cache-proposal-data-model---libs-support-b3-cleanup

Conversation

@jamby77
Copy link
Copy Markdown
Collaborator

@jamby77 jamby77 commented May 5, 2026

Summary

PR #134 landed an earlier B3 commit (5s-TTL read-time HGETALL on every check()) and #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.

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

  • 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: drops the read-time-overrides bullet, expands the periodic-refresh bullet to spell out hash field semantics and the synchronous-first-tick guarantee, and rewords the Behavior change note.

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 pass
  • pnpm --filter @betterdb/semantic-cache exec tsc --noEmit

Note

Medium Risk
Changes how check()/checkBatch() resolve thresholds by removing the 5s TTL per-call __config reads, 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}:__config threshold override layer (cached for 5s) and the associated helpers/state, so check() and checkBatch() now resolve thresholds only as options.thresholdcategoryThresholds[category]defaultThreshold.

Keeps the background config refresh mechanism as the single source of runtime threshold updates, cleans up the duplicate configKey wiring, and deletes the unit test suite that covered the removed per-call override behavior. Documentation in CHANGELOG.md is updated to describe the periodic refresh semantics (including synchronous first refresh on initialize()) and the __config hash field mapping.

Reviewed by Cursor Bugbot for commit 2979891. Bugbot is set up for automated code reviews on this repo. Configure here.

Base automatically changed from feature/cache-proposal-data-model---libs-support to feature/cache-proposal-data-model May 5, 2026 14:40
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.
@jamby77 jamby77 force-pushed the feature/cache-proposal-data-model---libs-support-b3-cleanup branch from 7fa7afb to 2979891 Compare May 5, 2026 14:47
@jamby77 jamby77 merged commit 39d5660 into feature/cache-proposal-data-model May 5, 2026
2 checks passed
@jamby77 jamby77 deleted the feature/cache-proposal-data-model---libs-support-b3-cleanup branch May 5, 2026 14:50
@github-actions github-actions Bot locked and limited conversation to collaborators May 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants