Skip to content

ci: run the DB-backed query-budget pins against Postgres - #1374

Merged
Quick104 merged 2 commits into
mainfrom
ci/db-statement-count-pins
Sep 24, 2026
Merged

Quick104 merged 2 commits into
mainfrom
ci/db-statement-count-pins

Conversation

@Quick104

Copy link
Copy Markdown
Contributor

Problem

Related issue: #599 (Phase 3, narrowed to the query-budget pins)
Validation tasks: none (CI and a test runner only; no server, API or client behavior changes)

make test-go runs without SILO_TEST_DATABASE_URL, so every DB-backed test skips, and go test reports a skip as a pass. That includes the tests that pin query budgets: statement counts for item detail, listing totals, card play targets, season and episode writes, refresh debt, home-section overlays, settings resolution and book scans, plus two index-plan checks for keyset pages. None of them runs in CI. A PR that turns the 9-statement season write into a per-episode N+1 merges green today; the budget holds only if someone runs it locally against a migrated database.

A lane that sets the URL and trusts go test's exit code would still leave two gaps. If the URL went missing, two of these tests would still pass at the top level, because only their subtests skip. Against an unmigrated schema, three skip on their own schema check, so a dropped or misdirected migrate step would switch those three off while CI stayed green.

Approach

A new Go DB pins job starts a pgvector/pgvector:pg18 service (the image docker-compose.yml runs; the schema needs vector), migrates it with go run ./cmd/silo/ --migrate-only, and runs make test-db-pins.

  • scripts/ci/db-pins.txt is the checked-in list: one ./<package dir> <TestName> per line, 19 tests in 6 packages. Later perf PRs append their pins in the same change that sets the budget.
  • scripts/ci/dbpins runs go test -count=1 -json -run '^(name|name|...)$' <dirs> and reads the event stream. It fails when a listed test is missing, skipped, failing or unfinished, and when any subtest, or any other test the pattern matched, skips or fails. It prints the output of every test that did not pass.
  • make test-db-pins runs the same thing locally against SILO_TEST_DATABASE_URL. It is not part of the mandatory pre-PR gate: CI runs it for every PR, and CONTRIBUTING.md asks contributors to run it when they change database or query code or add a pin, with the commands to create and migrate a scratch database on the Compose Postgres.
  • A unit test in make test-go parses the committed list, so a malformed edit fails the normal suite too.

Alternatives considered:

Not included: the tier-1 scenario executor under SILO_SCENARIO_DATABASE_URL still runs only locally, and whole DB-backed packages can join once #633 lands. Both are follow-ups.

Before and after

Metric Before After How measured
Listed pins that run their DB assertions in CI 0 of 19 19 of 19 Before: go test -count=1 -json with the same anchored -run list on current main, no SILO_TEST_DATABASE_URL (what make test-go does). After: make test-db-pins against a freshly migrated pgvector Postgres 18 database
Result of those 19 tests with no database go test exit 0: 17 skip, 2 pass with all 13 of their subtests skipped make test-db-pins fails: 30 problems (17 skipped pins, 13 skipped subtests) Same list, URL unset
Against an empty, unmigrated database n/a Fails: 12 fail, 3 skip on their schema check, 4 pass (they use temp tables) Created an empty database and ran make test-db-pins against it
A listed test that no longer exists n/a Fails with MISSING Temporary copy of the list with a renamed entry
A broken budget n/a Fails with bounded statement count = 9, want 8 Temporarily set the canonical season-write budget from 9 to 8, then reverted
Repeat runs on one database n/a 5 of 5 passed Consecutive make test-db-pins runs with -p=4
Local wall time n/a make test-db-pins 7.0–10.5 s; --migrate-only 4.6–6.0 s Single runs on a shared 48-core machine with a warm build cache. CI will be slower: the job installs libvips and builds cmd/silo for the migration. I have not measured the job on GitHub; a few minutes is an estimate

Validation

Commands assume the repository root is the cwd. Every check below ran on the branch rebased onto current main.

  • make test-db-pins against a freshly migrated pgvector/pgvector:pg18 container configured like the CI service: all 19 pins passed in 5 of 5 consecutive runs with GOFLAGS=-p=4. They also pass against a reused local database that had been migrated before.
  • The database setup commands in CONTRIBUTING.md, run against a throwaway pgvector/pgvector:pg18 container with the Compose default credentials (through docker exec and a different host port): the database was created and migrated, and all 19 pins passed.
  • The failure cases in the table, re-run: no database URL (30 problems), a renamed list entry (MISSING), an empty unmigrated database (12 fail, 3 skip, 4 pass) and the season-write budget lowered from 9 to 8 (bounded statement count = 9, want 8). The before case, re-run on current main with the same anchored list and no URL, exits 0 with 17 skips and 2 passes whose 13 subtests all skip.
  • go test -count=1 ./scripts/ci/dbpins/: passes (list parsing, anchored arguments, event parsing, and skip, missing, subtest, unfinished and same-name-in-another-package cases).
  • actionlint v1.7.7 with shellcheck on .github/workflows/ci.yml: no findings. The file also parses as YAML.
  • make embed-stub, go build ./..., gofmt -l . (empty), go vet ./... and make lint-changed (0 issues): pass.
  • GOFLAGS=-p=6 make test-go: all 160 packages pass, including scripts/ci/dbpins.
  • make verify-settings-bindings-all verify-playback-fixtures verify-route-inventory verify-migration-ledger verify-scenario-catalogs verify-offline-routes verify-apiv2-openapi verify-apiv2-contract verify-apiv2-fixtures verify-local-paths and go test -count=1 -run '^TestCommittedArtifactMatchesRouter$' ./internal/apiv2/: pass.
  • Not run: the web checks and make migrate-validate, because the branch changes no files under web/ or migrations/.

No check failed, so there were no pre-existing failures to compare against main.

Risks

  • The new job is not a required check until a maintainer adds Go DB pins to branch protection.
  • A flaky pin would turn the job red. The fixtures use temp tables or unique prefixes, CI starts from an empty database on every run, and five consecutive local runs passed. A pin that turns flaky should come off the list rather than gain a retry.
  • TestLibraryCollectionContinuationDB leaves five media_items rows per run in a reused local database. CI's database is new each run, so this does not affect the gate.
  • The job adds one runner per CI run, including a libvips install and a cmd/silo build.
  • The job saves its own per-commit Go build and module cache (cache-name: db-pins), about 1 GB zstd-compressed when I built its work into empty caches locally, similar to the go-test entry. The repository's Actions caches already hold about 15 GB, so each commit adds eviction pressure on the go-test, go-lint and go-verify caches. Restoring an existing cache without saving would avoid that, but the shared setup action does not support it yet; that is a possible follow-up.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.

AI Disclosure

  • Harness: Claude Code, running in T3 Code
  • Tool(s): Claude Code built-in tools (shell, file read/edit, Workflow subagents), GitHub CLI (gh)
  • Model(s): claude-opus-5-5[1m] for the main session and all subagents
  • Involvement: Fully AI-generated; maintainer review pending
  • Adversarial review: A separate reviewer subagent (claude-opus-5-5) reviewed the full diff, re-ran the measurements and checked for regressions. Method: it started its own pgvector/pgvector:pg18 container with the CI service settings, migrated it with the CI command, and re-ran the after, no-database, bogus-name, broken-budget and unmigrated-schema cases on the branch and the before case on current main. It also ran the pins against current main after applying main's newer migrations, confirmed the branch merges cleanly, and ran actionlint, the runner tests, go vet, gofmt, make lint-changed and make verify-local-paths. Every number reproduced and it found no blockers or majors. Findings and resolutions: (1) listing make test-db-pins in the mandatory pre-PR gate would require a migrated pgvector database for every change, including web-only ones: moved out of the gate, with scoped guidance and database setup commands in CONTRIBUTING.md; (2) the Involvement and Adversarial review fields held placeholders: filled in here; (3) the new job adds a per-commit Actions cache: measured at about 1 GB and added to Risks, with restore-only caching left as a follow-up because the shared setup action does not support it; (4) the list missed TestPlayableTargetResolverProfileStateAvailabilityAndAccess, which pins that leaf cards and a validated anchor hint issue no watch-progress query: added, and it passes on a fresh database; (5) the Problem section said a broken migrate step would switch pins off while CI stayed green, but a failing migration fails the job: reworded to a dropped or misdirected migrate step; (6) the Validation section carried session detail about an unrelated handlers timing flake: shortened; (7) if reading the event stream failed, nothing drained go test's stdout and Wait could block: the runner now drains the pipe before waiting.

🤖 Generated with Claude Code

Quick104 and others added 2 commits September 24, 2026 02:56
make test-go runs without SILO_TEST_DATABASE_URL, so every DB-backed
test skips and go test reports the skip as a pass. The statement-count
and query-plan pins that guard item detail, listings, metadata refresh,
home sections, settings resolution and book scans have never run in CI,
so a change that turns a pinned budget into an N+1 merges green.

Add a Go DB pins job that migrates a fresh pgvector/pgvector:pg18
database with cmd/silo --migrate-only and runs the tests listed in
scripts/ci/db-pins.txt through make test-db-pins. The runner in
scripts/ci/dbpins reads go test -json and fails when a listed test is
missing, skipped or failing, and on any skipped subtest: without a
database, two of the pinned tests pass at the top level because only
their subtests skip.

The job is separate from go-test so it adds nothing to that job's time,
and because the full schema needs pgvector, which go-test's image lacks.
CONTRIBUTING.md lists the new target in the pre-PR gate.

Refs #599.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
CONTRIBUTING.md listed make test-db-pins in the mandatory pre-PR gate,
which would ask every contributor, even on a web-only change, for a
migrated pgvector database. Move it out of the gate: CI runs it for
every pull request, and contributors run it when they change database or
query code or add a pin. Say how to create and migrate the database with
the Compose defaults.

Add TestPlayableTargetResolverProfileStateAvailabilityAndAccess to the
list: leaf cards and a validated anchor hint must resolve without a
watch-progress query. It passes on a freshly migrated database.

The runner now drains go test's output if reading the event stream
fails, so a go test still writing cannot block on a full pipe before
Wait returns.

Refs #599.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Quick104 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@coderabbitai

coderabbitai Bot commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 1 minute.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: c00983fb-ba5b-46e0-8073-bd2d651d2bd9

📥 Commits

Reviewing files that changed from the base of the PR and between d4e35ba and ab8777c.

📒 Files selected for processing (6)
  • .github/workflows/ci.yml
  • CONTRIBUTING.md
  • Makefile
  • scripts/ci/db-pins.txt
  • scripts/ci/dbpins/main.go
  • scripts/ci/dbpins/main_test.go

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-24T03:59:00.421431Z ab8777c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Quick104
Quick104 merged commit 0f4c28a into main Sep 24, 2026
11 checks passed
@Quick104
Quick104 deleted the ci/db-statement-count-pins branch September 24, 2026 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant