Skip to content

refactor(cache): standardize not-found checks - #1287

Merged
kalbasit merged 1 commit into
mainfrom
refactor/standardize-notfound-checks
May 29, 2026
Merged

kalbasit merged 1 commit into
mainfrom
refactor/standardize-notfound-checks

Conversation

@kalbasit

Copy link
Copy Markdown
Owner

Summary

The cache layer detected missing rows inconsistently: pkg/cache called ent.IsNotFound directly at ~20 sites while the purpose-built database.IsNotFoundError helper was used only once. That helper is the intended single predicate — it matches both Ent's *NotFoundError and the database.ErrNotFound sentinel returned by the cache test fakes. Calling ent.IsNotFound directly meant those sites silently failed to recognize the sentinel.

  • Replace every direct ent.IsNotFound(x) in cache.go and build_trace.go with database.IsNotFoundError(x), preserving each argument and negation; add the pkg/database import to build_trace.go.
  • Behavior-preserving for real Ent errors (the helper is a superset matcher) and strictly more correct for the sentinel, which the cache paths now honor.
  • Package-specific sentinels (storage/upstream/chunk/config ErrNotFound) are left matched by their own errors.Is checks.
  • Records a database-orm spec requirement for the single-predicate contract.

Test plan

  • task fmt / task lint (0 issues) / task test (full suite green)
  • Existing cache suite (incl. fakes returning database.ErrNotFound) covers the not-found paths

@kalbasit

kalbasit commented May 29, 2026 •

Copy link
Copy Markdown
Owner Author

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. go Pull requests that update go code labels May 29, 2026
@coderabbitai

coderabbitai Bot commented May 29, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 80321513-29a5-4553-88e5-4738799cb1d6

📥 Commits

Reviewing files that changed from the base of the PR and between 014e8e3 and 0230e29.

📒 Files selected for processing (8)
  • openspec/changes/archive/2026-05-29-standardize-notfound-checks/.openspec.yaml
  • openspec/changes/archive/2026-05-29-standardize-notfound-checks/design.md
  • openspec/changes/archive/2026-05-29-standardize-notfound-checks/proposal.md
  • openspec/changes/archive/2026-05-29-standardize-notfound-checks/specs/database-orm/spec.md
  • openspec/changes/archive/2026-05-29-standardize-notfound-checks/tasks.md
  • openspec/specs/database-orm/spec.md
  • pkg/cache/build_trace.go
  • pkg/cache/cache.go
✅ Files skipped from review due to trivial changes (3)
  • openspec/changes/archive/2026-05-29-standardize-notfound-checks/.openspec.yaml
  • openspec/changes/archive/2026-05-29-standardize-notfound-checks/tasks.md
  • openspec/changes/archive/2026-05-29-standardize-notfound-checks/design.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • pkg/cache/build_trace.go
  • pkg/cache/cache.go

📝 Walkthrough

Summary by CodeRabbit

  • Refactor

    • Standardized detection of “row not found” across the cache layer for more consistent and correct handling of missing data.
  • Documentation

    • Added design, proposal, specification, task checklist and archive notes describing the unified missing-row classification and rollout guidance.
  • Tests

    • Confirmed existing test suite passes with no behavioral regressions.

Walkthrough

Standardizes "not found" error classification in the cache package by replacing all ent.IsNotFound(err) checks with the centralized database.IsNotFoundError(err) predicate across docs and 19 cache call sites, and adds a pkg/database import where required.

Changes

Cache not-found standardization

Layer / File(s) Summary
Specification and design documentation
openspec/changes/archive/2026-05-29-standardize-notfound-checks/design.md, openspec/changes/archive/2026-05-29-standardize-notfound-checks/proposal.md, openspec/changes/archive/2026-05-29-standardize-notfound-checks/specs/database-orm/spec.md, openspec/changes/archive/2026-05-29-standardize-notfound-checks/tasks.md, openspec/specs/database-orm/spec.md, openspec/changes/archive/2026-05-29-standardize-notfound-checks/.openspec.yaml
Adds design, proposal, spec, tasks, and openspec metadata that require and document using database.IsNotFoundError in pkg/cache instead of direct ent.IsNotFound checks.
Cache implementation: predicate standardization
pkg/cache/build_trace.go, pkg/cache/cache.go
Replaces ent.IsNotFound(err) with database.IsNotFoundError(err) across cache lookup and mutation flows (progressive streaming, narinfo retrieval/migration/deletion, nar-file queries, chunk serving, pinning/BFS), preserving negations and branches; adds pkg/database import in build_trace.go.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • kalbasit/ncps#1193: Overlaps with Ent-to-database not-found changes in pkg/cache for deleteNarInfoFromStore/PinClosure.
  • kalbasit/ncps#1207: Overlaps on chunk/streaming not-found classification in pkg/cache.
  • kalbasit/ncps#1216: Overlaps in MigrateNarInfo post-lock recheck and narinfo migration paths.

Poem

🐰 I hopped through code both near and far,
Swapped checks to one bright guiding star.
Cache now asks the database first,
No more dual answers to disperse.
🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'refactor(cache): standardize not-found checks' clearly and concisely summarizes the main change: standardizing not-found detection in the cache layer.
Description check ✅ Passed The description thoroughly explains the problem, solution, and testing approach, directly addressing the changeset's purpose of standardizing not-found checks in pkg/cache.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request standardizes "not found" error detection in the cache layer (pkg/cache) by replacing direct calls to ent.IsNotFound(err) with the single predicate database.IsNotFoundError(err). This ensures that both Ent's *NotFoundError and the package-level database.ErrNotFound sentinel are correctly recognized as not-found errors across all cache operations. The change includes adding the pkg/database import to pkg/cache/build_trace.go and updating the design documentation and specifications to reflect this requirement. There are no review comments, so I have no feedback to provide.

@kalbasit
kalbasit force-pushed the refactor/standardize-notfound-checks branch from 895160e to 106d5e9 Compare May 29, 2026 17:42
@kalbasit
kalbasit force-pushed the refactor/extract-cache-query-helpers branch from 8a4b3eb to d887e91 Compare May 29, 2026 17:54
@kalbasit
kalbasit force-pushed the refactor/standardize-notfound-checks branch from 106d5e9 to 014e8e3 Compare May 29, 2026 17:54
Base automatically changed from refactor/extract-cache-query-helpers to main May 29, 2026 18:42
The cache layer detected missing rows inconsistently: pkg/cache
called ent.IsNotFound directly at ~20 sites while the purpose-built
database.IsNotFoundError helper was used only once. The helper is the
intended single predicate — it matches both Ent's *NotFoundError and
the database.ErrNotFound sentinel returned by the cache test fakes.
Calling ent.IsNotFound directly meant those sites silently failed to
recognize the sentinel, and the not-found policy was scattered.

Replace every direct ent.IsNotFound(x) in cache.go and build_trace.go
with database.IsNotFoundError(x), preserving each argument and
negation, and add the pkg/database import to build_trace.go. This is
behavior-preserving for real Ent errors (the helper is a superset
matcher) and strictly more correct for the sentinel, which the cache
paths now honor — making the dual-mode predicate load-bearing rather
than vestigial. Package-specific sentinels (storage/upstream/chunk/
config ErrNotFound) are left matched by their own errors.Is checks.

Records a database-orm spec requirement for the single-predicate
contract.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@kalbasit
kalbasit force-pushed the refactor/standardize-notfound-checks branch from 014e8e3 to 0230e29 Compare May 29, 2026 18:42
@kalbasit
kalbasit enabled auto-merge (squash) May 29, 2026 18:42
@kalbasit
kalbasit merged commit 86bf552 into main May 29, 2026
37 of 43 checks passed
@kalbasit
kalbasit deleted the refactor/standardize-notfound-checks branch May 29, 2026 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go Pull requests that update go code merge-stack size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant