Skip to content

fix(review): include mutable prompt inputs in ai slop cache fingerprint - #4073

Merged
JSONbored merged 1 commit into
mainfrom
codex/fix-ai-slop-cache-fingerprinting-logic-rkarxw
Jul 7, 2026
Merged

fix(review): include mutable prompt inputs in ai slop cache fingerprint#4073
JSONbored merged 1 commit into
mainfrom
codex/fix-ai-slop-cache-fingerprinting-logic-rkarxw

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Motivation

  • The ai slop advisory cache previously keyed only on repo/PR/head SHA and provider identity, which allowed stale advisory results to be replayed when mutable prompt inputs (PR title/body, the built diff, or deterministic band) changed for the same head SHA.

Description

  • Bumped the ai slop cache input version to ai-slop-input:v2 and extended AiSlopCacheInput to include title, body, diff, and deterministicBand in src/review/ai-slop-cache-input.ts.
  • Replaced the prior compact payload with a JSON payload hashed via sha256Hex(JSON.stringify(payload)) to fingerprint mutable prompt inputs.
  • In runAiSlopForAdvisory (src/queue/processors.ts) build the review diff once with buildAiReviewDiff(args.files), include title, body, diff, and deterministicBand in the cache fingerprint, and reuse the same aiSlopDiff for the fresh advisory call on cache misses.
  • Updated the migration comment in migrations/0119_ai_slop_cache.sql to reflect that the fingerprint covers mutable prompt inputs as well as provider identity.
  • Added/updated unit tests in test/unit/ai-slop-cache.test.ts and test/unit/ai-slop.test.ts to assert that changes to title/body/diff/deterministicBand produce distinct fingerprints and to seed cache rows using the new prompt-aware fingerprint.

Testing

  • Ran targeted unit tests: npx vitest run test/unit/ai-slop-cache.test.ts test/unit/ai-slop.test.ts, and the modified test suites passed locally.
  • Ran typecheck with npm run typecheck, which succeeded.
  • Verified migrations with npm run db:migrations:check, which succeeded.
  • Attempted full coverage with npm run test:coverage, but coverage remapping failed in this container (Node v24.15.0) with TypeError: jsTokens is not a function; the repository expects Node 22 for a successful coverage run.
  • npm audit --audit-level=moderate could not complete in this environment due to the npm audit endpoint returning 403 Forbidden.

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.
⚠️ Please upload report for BASE (main@cd8adb4). Learn more about missing BASE report.
⚠️ Report is 33 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4073   +/-   ##
=======================================
  Coverage        ?   93.56%           
=======================================
  Files           ?      381           
  Lines           ?    35480           
  Branches        ?    13014           
=======================================
  Hits            ?    33198           
  Misses          ?     1621           
  Partials        ?      661           
Files with missing lines Coverage Δ
src/queue/processors.ts 94.71% <100.00%> (ø)
src/review/ai-slop-cache-input.ts 100.00% <100.00%> (ø)
🚀 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 23:33:32 UTC

5 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 closes a real cache-staleness gap: the ai_slop_cache fingerprint previously covered only byok/provider/model, so a PR whose title/body were edited or whose diff changed relative to base (retarget, base update) at an unchanged head SHA could replay a stale advisory instead of missing the cache. The fix bumps the fingerprint version, folds title/body/diff/deterministicBand into a JSON-hashed payload, and reuses a single buildAiReviewDiff(args.files) call for both the fingerprint and the fresh advisory call on a miss, avoiding double diff-building. Tests assert each new field independently flips the fingerprint, and the migration file only got a doc-comment update (no functional SQL change), so no new migration is required.

Nits — 5 non-blocking
  • migrations/0119_ai_slop_cache.sql:14-17 edits the comment on an already-applied migration; since no SQL/executable content changed this is low-risk, but per the numbering/immutability rule it's cleaner to leave shipped migration files untouched and put doc updates elsewhere.
  • src/queue/processors.ts: buildAiReviewDiff(args.files) is now always computed before the cache lookup, even on a cache hit, reintroducing the diff-build cost the cache was partly meant to avoid — likely cheap (no network/DB), but worth confirming it isn't doing anything heavier (e.g., large-file truncation work) on every scheduled sweep tick.
  • test/unit/ai-slop-cache.test.ts: the new fingerprint tests only cover the 'defined value differs from another defined value' arm of each `?? ""`/`?? null`, not the null/undefined-vs-defined arm (e.g. body: null vs body: "cleanup") — worth a quick assertion that omitting a field also changes the fingerprint vs. an empty-string/null default colliding with a real value.
  • Consider adding one test where `body` is `undefined` vs an explicit empty string to confirm they don't collide in the JSON payload (`input.body ?? null` maps both `undefined` and `null` to `null`, which is fine, but an explicit test would document the intent).
  • If buildAiReviewDiff is nontrivial in cost, consider short-circuiting: check byok/provider/model-only fields first isn't viable since diff is part of the fingerprint by design, but a comment noting the intentional always-compute tradeoff would help future readers understand why the old fast-path was removed.

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, 503 issue(s).
Contributor context ✅ Confirmed Gittensor contributor JSONbored; Gittensor profile; 51 PR(s), 503 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), 503 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 cd1d0a1 into main Jul 7, 2026
11 checks passed
@JSONbored
JSONbored deleted the codex/fix-ai-slop-cache-fingerprinting-logic-rkarxw branch July 7, 2026 23:37
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