Repository navigation
refactor(cache): scope stale-lock orphan query to known candidate IDs - #1229
Conversation
PR #1217 swapped the working []struct{Sum sql.NullInt64 \`sql:"sum"\`} pattern for &sql.NullInt64, but Ent's Select.Scan calls sql.ScanSlice which rejects non-slice destinations ("expected slice as an argument"), so the gauge callback was effectively broken. Confirmed against a live SQLite database: - []sql.NullInt64 fails: scanStruct can't map SUM(...) to NullInt64 fields (the Int64/Valid fields don't carry the tag). - []*int64 (the suggestion in PR #1229's review) fails on NULL — when SUM returns NULL on an empty table the driver errors with "converting NULL to int64 is unsupported". - []struct{ Sum sql.NullInt64 \`sql:"sum"\` } works: scanStruct splits the column name at "(" and lowercases the leading token, so "SUM(file_size)" → "sum" matches the field tag, and NullInt64 captures the NULL/empty-table case via sql.Scanner. This is the same pattern already in use at pkg/cache/cache.go:711. Addresses gemini-code-assist comments on PR #1229 (PRRT_kwDONV6tZs6D5Lec, PRRT_kwDONV6tZs6D5Lem) — the underlying bug is fixed even though the specific []*int64 suggestion would not have worked. Co-Authored-By: Claude Opus 4.7 <[email protected]>
e385a99 to
5bc3549
Compare
4873832 to
2dd750b
Compare
For a very large NAR file split into small CDC chunks, the staleLockChunks slice can hold many thousands of partial-chunk IDs, and a single Chunk.Query().Where(IDIn(ids...)) would exceed older SQLite's ≤ 999 placeholder ceiling. Batch the IDIn call using the existing cdcCleanupHashBatchSize (500), matching the HashIn pattern already used by runCDCDeletedCleanup. Addresses gemini-code-assist comment on PR #1229 (PRRT_kwDONV6tZs6D5LeW). Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
|
Automated stack merge failed during the rebase step. The |
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
Restrict the orphan-check query inside cleanupStaleLockChunks to the chunk IDs we already know about from staleLockChunks, instead of pulling every orphan in the database and filtering them in memory. The post-filter `if _, ok := staleByID[oc.ID]; !ok` is no longer needed since the query already returns only candidates. Addresses gemini-code-assist comment on PR #1209 (PRRT_kwDONV6tZs6D3VF-). Co-Authored-By: Claude Opus 4.7 <[email protected]>
queryCDCNarFilesWithSizeMismatch's `seen` map was redundant: Ent's All(ctx) returns one row per NarFile, and the inner loop already breaks after recording the first mismatch, so each NarFile can only be appended to mismatched once. Addresses gemini-code-assist comment on PR #1212 (PRRT_kwDONV6tZs6D3P8r). Co-Authored-By: Claude Opus 4.7 <[email protected]>
Replace context.Background() with t.Context() so the schema-create call is bound to the test lifetime. Drops the now-unused context import. Addresses gemini-code-assist comment from PR #1214 (PRRT_kwDONV6tZs6D3PyX); the original test_schema_parity file was folded into client_test.go but the same pattern lives in freshSchemaSQLite. Co-Authored-By: Claude Opus 4.7 <[email protected]>
…e-check After acquiring the migration lock, distinguish ent.IsNotFound (the expected "not yet migrated" case, fall through to migrate) from other DB errors (log at warn level instead of silently swallowing). The migration still attempts on any error so a transient lookup glitch doesn't block progress; if the DB is genuinely broken the upsert below will surface the failure. Addresses gemini-code-assist comment on PR #1216 (PRRT_kwDONV6tZs6D3YoD). Co-Authored-By: Claude Opus 4.7 <[email protected]>
Ent's Aggregate(ent.Sum(...)) emits a raw SUM(...) expression without an
alias; scanning into []struct{ Sum sql.NullInt64 \`sql:"sum"\` } relied
on tag-name resolution that may not match the column header. Scan
positionally into a single sql.NullInt64 instead, which is more robust
and also correctly handles the NULL result that SUM returns on an empty
table.
Addresses gemini-code-assist comments on PR #1217
(PRRT_kwDONV6tZs6D3Um1, PRRT_kwDONV6tZs6D3Um6).
Co-Authored-By: Claude Opus 4.7 <[email protected]>
The previous wording referenced a "well-known Ent sentinel below" that doesn't exist in this file — IsNotFoundError simply delegates to isEntNotFound (declared in ent_errors.go) which keeps the ent import isolated to a single file. Addresses gemini-code-assist comment on PR #1218 (PRRT_kwDONV6tZs6D3WsX). Co-Authored-By: Claude Opus 4.7 <[email protected]>
ent/generate.go is hand-written (carries the //go:generate directive) but the broad ent/*.go exclusion swept it into the codegen-only group. Add an explicit !ent/generate.go negation so it stays formattable without re-introducing diff loops against the codegen drift check. Addresses gemini-code-assist comment on PR #1221 (PRRT_kwDONV6tZs6D3zlq). Co-Authored-By: Claude Opus 4.7 <[email protected]>
The package doc claimed the binary exits non-zero on the first mismatch. The implementation actually iterates every dialect and only exits at the end, reporting all offending directories at once. Update the doc to match. Addresses gemini-code-assist comment on PR #1222 (PRRT_kwDONV6tZs6D31Je). Co-Authored-By: Claude Opus 4.7 <[email protected]>
Quote the path expansions when sourcing the pre/post-check helper scripts in schema-equivalence-check. Nix store paths don't contain spaces in practice, but quoting is shell best practice and silences shellcheck-style nitpicks on the inherited shell content. Addresses gemini-code-assist comment on PR #1223 (PRRT_kwDONV6tZs6D32tm). Co-Authored-By: Claude Opus 4.7 <[email protected]>
…e down - Bring the Common Commands DSN examples in line with the Database section by using the full host:port/database placeholder for postgresql/mysql. - Replace "there is no migrate down command" with the accurate phrasing: the command is implemented (pkg/ncps/migrate.go:107) but returns an error pointing at the expand-contract policy. Addresses gemini-code-assist comments on PR #1224 (PRRT_kwDONV6tZs6D37b-, PRRT_kwDONV6tZs6D37cD). The third sqlfluff suggestion is intentionally skipped — migrations/ is sealed by atlas.sum so sqlfluff isn't run against it, and the only SQL outside migrations/ is already covered by nix fmt. Co-Authored-By: Claude Opus 4.7 <[email protected]>
Both .agent/skills/ent-schema/SKILL.md and CLAUDE.md described A2 as the snake_case enum-type convention, which contradicted cmd/ent-lint/main.go (line 286+) and openspec/specs/ent-schema-lint/spec.md — both of which treat A2 as the "OnDelete on edge.From is forbidden" check. Reword A2 in both docs to match the actual linter invariant, and move the snake_case enum-type rule into its own section labelled as a convention enforced by code review until the schema tree gains its first field.Enum(...) declaration. Addresses gemini-code-assist comment on PR #1225 (PRRT_kwDONV6tZs6D34eU). Co-Authored-By: Claude Opus 4.7 <[email protected]>
- Lead with the Taskfile entrypoint (task migrations:gen NAME=...) for generating new migrations, since it regenerates the Ent client first via task ent:generate. Mention the underlying go run invocation in parentheses for users who want the raw command. - The schema_migrations adoption verifies row-count consistency, not parity — the new table intentionally adds a sentinel row, so the expected post-count is preCount + 1. Reword to make that explicit. Addresses gemini-code-assist comments on PR #1226 (PRRT_kwDONV6tZs6D3756, PRRT_kwDONV6tZs6D376E). Co-Authored-By: Claude Opus 4.7 <[email protected]>
Four wording corrections so the OpenSpec specs match what the code does: - Fresh-install seeding text claimed the Go side passes a time.Now() to schema_migrations.tstamp. Goose's database.InsertRequest exposes only Version, so the tstamp column relies on the database's default timestamp function. Reword the Requirement and Scenario lines to match. - The "Forbidden DDL" scenario claimed cmd/ent-lint SHALL fail on a forbidden DDL statement. The linter has not yet been wired up for that check (see cmd/ent-lint/main.go:21 deferral comment and the scope note already documented in ent-schema-lint/spec.md). Update the THEN clause to describe the current manual-review enforcement, retaining the future-cmd/ent-lint intent. - The example output in ent-schema-lint/spec.md no longer matches cmd/ent-lint/main.go:511-515 — the real output includes the source line number and a fuller "Ent will fabricate a phantom FK column" trailer. Update the example accordingly. Addresses gemini-code-assist comments on PR #1228 (PRRT_kwDONV6tZs6D4drm, PRRT_kwDONV6tZs6D4dr2, PRRT_kwDONV6tZs6D4dsA, PRRT_kwDONV6tZs6D4dsG). Co-Authored-By: Claude Opus 4.7 <[email protected]>
For a very large NAR file split into small CDC chunks, the staleLockChunks slice can hold many thousands of partial-chunk IDs, and a single Chunk.Query().Where(IDIn(ids...)) would exceed older SQLite's ≤ 999 placeholder ceiling. Batch the IDIn call using the existing cdcCleanupHashBatchSize (500), matching the HashIn pattern already used by runCDCDeletedCleanup. Addresses gemini-code-assist comment on PR #1229 (PRRT_kwDONV6tZs6D5LeW). Co-Authored-By: Claude Opus 4.7 <[email protected]>
PR #1217 swapped the working []struct{Sum sql.NullInt64 \`sql:"sum"\`} pattern for &sql.NullInt64, but Ent's Select.Scan calls sql.ScanSlice which rejects non-slice destinations ("expected slice as an argument"), so the gauge callback was effectively broken. Confirmed against a live SQLite database: - []sql.NullInt64 fails: scanStruct can't map SUM(...) to NullInt64 fields (the Int64/Valid fields don't carry the tag). - []*int64 (the suggestion in PR #1229's review) fails on NULL — when SUM returns NULL on an empty table the driver errors with "converting NULL to int64 is unsupported". - []struct{ Sum sql.NullInt64 \`sql:"sum"\` } works: scanStruct splits the column name at "(" and lowercases the leading token, so "SUM(file_size)" → "sum" matches the field tag, and NullInt64 captures the NULL/empty-table case via sql.Scanner. This is the same pattern already in use at pkg/cache/cache.go:711. Addresses gemini-code-assist comments on PR #1229 (PRRT_kwDONV6tZs6D5Lec, PRRT_kwDONV6tZs6D5Lem) — the underlying bug is fixed even though the specific []*int64 suggestion would not have worked. Co-Authored-By: Claude Opus 4.7 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1229 +/- ##
=====================================
Coverage 5.50% 5.50%
=====================================
Files 6 6
Lines 400 400
=====================================
Hits 22 22
Misses 374 374
Partials 4 4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
refactor(cache): scope stale-lock orphan query to known candidate IDs
Restrict the orphan-check query inside cleanupStaleLockChunks to the chunk
IDs we already know about from staleLockChunks, instead of pulling every
orphan in the database and filtering them in memory. The post-filter
if _, ok := staleByID[oc.ID]; !okis no longer needed since the queryalready returns only candidates.
Addresses gemini-code-assist comment on PR #1209 (PRRT_kwDONV6tZs6D3VF-).
Co-Authored-By: Claude Opus 4.7 [email protected]
refactor(fsck): drop redundant seen map in CDC size-mismatch check
queryCDCNarFilesWithSizeMismatch's
seenmap was redundant: Ent'sAll(ctx) returns one row per NarFile, and the inner loop already breaks
after recording the first mismatch, so each NarFile can only be appended
to mismatched once.
Addresses gemini-code-assist comment on PR #1212 (PRRT_kwDONV6tZs6D3P8r).
Co-Authored-By: Claude Opus 4.7 [email protected]
test(database): use t.Context() in freshSchemaSQLite helper
Replace context.Background() with t.Context() so the schema-create call
is bound to the test lifetime. Drops the now-unused context import.
Addresses gemini-code-assist comment from PR #1214
(PRRT_kwDONV6tZs6D3PyX); the original test_schema_parity file was folded
into client_test.go but the same pattern lives in freshSchemaSQLite.
Co-Authored-By: Claude Opus 4.7 [email protected]
refactor(cache): explicit not-found vs error split in migration double-check
After acquiring the migration lock, distinguish ent.IsNotFound (the
expected "not yet migrated" case, fall through to migrate) from other DB
errors (log at warn level instead of silently swallowing). The migration
still attempts on any error so a transient lookup glitch doesn't block
progress; if the DB is genuinely broken the upsert below will surface
the failure.
Addresses gemini-code-assist comment on PR #1216 (PRRT_kwDONV6tZs6D3YoD).
Co-Authored-By: Claude Opus 4.7 [email protected]
refactor(analytics): scan SUM(file_size) into a single sql.NullInt64
Ent's Aggregate(ent.Sum(...)) emits a raw SUM(...) expression without an
alias; scanning into []struct{ Sum sql.NullInt64 `sql:"sum"` } relied
on tag-name resolution that may not match the column header. Scan
positionally into a single sql.NullInt64 instead, which is more robust
and also correctly handles the NULL result that SUM returns on an empty
table.
Addresses gemini-code-assist comments on PR #1217
(PRRT_kwDONV6tZs6D3Um1, PRRT_kwDONV6tZs6D3Um6).
Co-Authored-By: Claude Opus 4.7 [email protected]
docs(database): correct IsNotFoundError comment about delegation
The previous wording referenced a "well-known Ent sentinel below" that
doesn't exist in this file — IsNotFoundError simply delegates to
isEntNotFound (declared in ent_errors.go) which keeps the ent import
isolated to a single file.
Addresses gemini-code-assist comment on PR #1218 (PRRT_kwDONV6tZs6D3WsX).
Co-Authored-By: Claude Opus 4.7 [email protected]
build(formatter): re-include ent/generate.go in the formatter glob
ent/generate.go is hand-written (carries the //go:generate directive)
but the broad ent/*.go exclusion swept it into the codegen-only group.
Add an explicit !ent/generate.go negation so it stays formattable
without re-introducing diff loops against the codegen drift check.
Addresses gemini-code-assist comment on PR #1221 (PRRT_kwDONV6tZs6D3zlq).
Co-Authored-By: Claude Opus 4.7 [email protected]
docs(atlas-sum-check): correct doc comment about exit behavior
The package doc claimed the binary exits non-zero on the first mismatch.
The implementation actually iterates every dialect and only exits at the
end, reporting all offending directories at once. Update the doc to
match.
Addresses gemini-code-assist comment on PR #1222 (PRRT_kwDONV6tZs6D31Je).
Co-Authored-By: Claude Opus 4.7 [email protected]
build(checks): quote $src paths in schema-equivalence preCheck
Quote the path expansions when sourcing the pre/post-check helper
scripts in schema-equivalence-check. Nix store paths don't contain
spaces in practice, but quoting is shell best practice and silences
shellcheck-style nitpicks on the inherited shell content.
Addresses gemini-code-assist comment on PR #1223 (PRRT_kwDONV6tZs6D32tm).
Co-Authored-By: Claude Opus 4.7 [email protected]
docs(claude): use host:port/database in URL examples + clarify migrate down
by using the full host:port/database placeholder for postgresql/mysql.
the command is implemented (pkg/ncps/migrate.go:107) but returns an
error pointing at the expand-contract policy.
Addresses gemini-code-assist comments on PR #1224 (PRRT_kwDONV6tZs6D37b-,
PRRT_kwDONV6tZs6D37cD). The third sqlfluff suggestion is intentionally
skipped — migrations/ is sealed by atlas.sum so sqlfluff isn't run
against it, and the only SQL outside migrations/ is already covered by
nix fmt.
Co-Authored-By: Claude Opus 4.7 [email protected]
docs(ent-schema): A2 is the OnDelete invariant, not enum naming
Both .agent/skills/ent-schema/SKILL.md and CLAUDE.md described A2 as the
snake_case enum-type convention, which contradicted cmd/ent-lint/main.go
(line 286+) and openspec/specs/ent-schema-lint/spec.md — both of which
treat A2 as the "OnDelete on edge.From is forbidden" check.
Reword A2 in both docs to match the actual linter invariant, and move
the snake_case enum-type rule into its own section labelled as a
convention enforced by code review until the schema tree gains its
first field.Enum(...) declaration.
Addresses gemini-code-assist comment on PR #1225 (PRRT_kwDONV6tZs6D34eU).
Co-Authored-By: Claude Opus 4.7 [email protected]
docs(changelog): mention task migrations:gen and clarify row-count check
generating new migrations, since it regenerates the Ent client first
via task ent:generate. Mention the underlying go run invocation in
parentheses for users who want the raw command.
parity — the new table intentionally adds a sentinel row, so the
expected post-count is preCount + 1. Reword to make that explicit.
Addresses gemini-code-assist comments on PR #1226
(PRRT_kwDONV6tZs6D3756, PRRT_kwDONV6tZs6D376E).
Co-Authored-By: Claude Opus 4.7 [email protected]
docs(openspec): align migration + lint specs with actual implementation
Four wording corrections so the OpenSpec specs match what the code does:
to schema_migrations.tstamp. Goose's database.InsertRequest exposes
only Version, so the tstamp column relies on the database's default
timestamp function. Reword the Requirement and Scenario lines to
match.
forbidden DDL statement. The linter has not yet been wired up for
that check (see cmd/ent-lint/main.go:21 deferral comment and the
scope note already documented in ent-schema-lint/spec.md). Update
the THEN clause to describe the current manual-review enforcement,
retaining the future-cmd/ent-lint intent.
cmd/ent-lint/main.go:511-515 — the real output includes the source
line number and a fuller "Ent will fabricate a phantom FK column"
trailer. Update the example accordingly.
Addresses gemini-code-assist comments on PR #1228
(PRRT_kwDONV6tZs6D4drm, PRRT_kwDONV6tZs6D4dr2, PRRT_kwDONV6tZs6D4dsA,
PRRT_kwDONV6tZs6D4dsG).
Co-Authored-By: Claude Opus 4.7 [email protected]