Skip to content

fix(db): limit signal snapshot dedupe to cache signals - #3971

Merged
JSONbored merged 1 commit into
mainfrom
codex/propose-fix-for-signal-snapshot-dedupe-issue
Jul 7, 2026
Merged

fix(db): limit signal snapshot dedupe to cache signals#3971
JSONbored merged 1 commit into
mainfrom
codex/propose-fix-for-signal-snapshot-dedupe-issue

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Motivation

  • A recent global dedupe removed all but the latest signal_snapshots row per (signal_type, target_key), which deleted bounded historical series that callers rely on (e.g. contributor-decision-pack and queue-health).
  • The retention job must remove superseded cache snapshots while preserving historical series used for dashboards and trend computations.

Description

  • Add a LATEST_ONLY_SIGNAL_SNAPSHOT_TYPES allowlist containing latest-only cache signal types (repo-culture-profile, repo-doc-refresh-attempt) and document the rationale in the function comment.
  • Restrict dedupeSignalSnapshots to only consider signal types present in the allowlist by selecting DISTINCT signal_type WHERE signal_type IN (...) and processing those types only.
  • Preserve existing batching/cap logic and dry-run behavior while changing the query shape to bind allowlist placeholders for safe SQL parameters.
  • Update test/unit/retention.test.ts to use the canonical latest-only signal names, add a regression test that verifies historical-series signal types (e.g. contributor-decision-pack, queue-health) are preserved, and adjust test mocks accordingly.

Testing

  • Ran npx vitest run test/unit/retention.test.ts and all tests in that file passed.
  • Ran npm run typecheck which completed successfully.
  • Attempted a coverage run with npm run test:coverage scoped to the retention tests; the tests executed successfully but V8 coverage remapping failed with TypeError: jsTokens is not a function before producing a coverage report (test assertions themselves passed).

Codex Task

@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.68%. Comparing base (b8a1186) to head (a5d6c22).
⚠️ Report is 18 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3971   +/-   ##
=======================================
  Coverage   93.68%   93.68%           
=======================================
  Files         373      373           
  Lines       34895    34897    +2     
  Branches    12768    12768           
=======================================
+ Hits        32692    32694    +2     
  Misses       1584     1584           
  Partials      619      619           
Files with missing lines Coverage Δ
src/db/retention.ts 96.49% <100.00%> (+0.12%) ⬆️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 7, 2026
@loopover-orb

loopover-orb Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Warning

🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨

⏸️ Gittensory review result - manual review recommended

Review updated: 2026-07-07 08:21:51 UTC

2 files · 1 AI reviewer · 2 blockers · readiness 93/100 · CI green · clean

⏸️ Suggested Action - Manual Review

  • No linked issue detected — If this PR is intended to solve an issue, link it explicitly in the PR body.
  • Maintainer requires a linked issue — Link the relevant issue (for example Closes #123) before opening the PR.

Review summary
This narrows dedupeSignalSnapshots to only touch a hardcoded allowlist (repo-culture-profile, repo-doc-refresh-attempt) instead of every distinct signal_type, correctly fixing the prior regression that deleted bounded historical series like queue-health and contributor-decision-pack. The IN-clause/placeholder binding is correctly wired (?1..?N matched to LATEST_ONLY_SIGNAL_SNAPSHOT_TYPES spread in bind), and the per-type stale-row deletion logic inside the loop is unchanged and still correct. Tests were updated to use the canonical signal names and a new regression test explicitly asserts historical types are left untouched, closing the gap that let the original incident happen.

Nits — 4 non-blocking
  • The latest-only-vs-historical distinction is now encoded as a standalone string array in retention.ts; if there's a central signal-type registry elsewhere in the codebase, consider deriving this list from it instead of a second hardcoded source of truth that can drift.
  • The PR description doesn't cite a tracking issue number for this regression fix beyond referencing obs(selfhost): monitor Cloudflare D1 database size and add bounded dedup retention for signal_snapshots #3810 in a comment — worth confirming this closes/links an actual open issue per repo convention.
  • Consider adding a comment near RETENTION_POLICY or the signal-snapshot writer noting that any new latest-only cache signal type must be added to LATEST_ONLY_SIGNAL_SNAPSHOT_TYPES, so future signal types default to 'preserved' rather than silently needing an opt-in.
  • The dry-run/no-meta defensive tests in retention.test.ts were adjusted to branch on `sql.includes('SELECT DISTINCT')`; this is a bit brittle (string-matching SQL) but acceptable as an existing test pattern.

Concerns raised — review before merging

  • No linked issue detected — If this PR is intended to solve an issue, link it explicitly in the PR body.
  • Maintainer requires a linked issue — Link the relevant issue (for example Closes #123) before opening the PR.
Signal Result Evidence
Code review ❌ 2 blockers 1 reviewer
Linked issue ⚠️ Missing No linked issue or no-issue rationale found.
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (no linked issue context).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 51 registered-repo PR(s), 43 merged, 343 issue(s).
Contributor context ✅ Confirmed Gittensor contributor JSONbored; Gittensor profile; 51 PR(s), 343 issue(s).
Gate result ❌ Blocking Repo-configured hard blocker found.
Review context
  • Author: JSONbored
  • Role context: owner (maintainer lane)
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: Python, TypeScript, JavaScript, Ruby, Go, Kotlin, MDX, Shell
  • Official Gittensor activity: 51 PR(s), 343 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Treat this as maintainer-lane context rather than normal contributor-lane activity.
  • Explain no-issue PR.
  • Link the issue being solved, or explicitly explain why this is a no-issue PR.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.

  • Re-run Gittensory review

@loopover-orb loopover-orb Bot added the manual-review Gittensor contributor context label Jul 7, 2026
@JSONbored
JSONbored merged commit 33cc16b into main Jul 7, 2026
10 checks passed
@JSONbored
JSONbored deleted the codex/propose-fix-for-signal-snapshot-dedupe-issue branch July 7, 2026 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. manual-review Gittensor contributor context

Development

Successfully merging this pull request may close these issues.

1 participant