Skip to content

fix(ci): generate sqlc drift check out-of-tree (RIG-3591) - #1063

Open
rigel-mintaka wants to merge 2 commits into
mainfrom
compass-forge/rig-3591-sqlc-drift
Open

fix(ci): generate sqlc drift check out-of-tree (RIG-3591)#1063
rigel-mintaka wants to merge 2 commits into
mainfrom
compass-forge/rig-3591-sqlc-drift

Conversation

@rigel-mintaka

@rigel-mintaka rigel-mintaka commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Fixes RIG-3591.

Problem

compass-go:sqlc-drift is a dep of compass-go:ci and ran sqlc generate
in place, rewriting go/internal/store/db/*.go in the working tree. moon
schedules it in parallel with compass-go:build, :nilaway and :test,
which compile that same directory — no task declares a deps edge against it.
Readers caught a generated file mid-write:

internal/store/db/<file>.sql.go:1:1: expected 'package', found 'EOF'

A different random file each run, load-independent (seen at loadavg 13 through
96). A pre-push hook failure aborts the whole push atomically, so it presented
as the submitter's defect. Four consecutive submits of an unchanged tree failed
this way; the first submit after this fix passed.

Fix

Stage sqlc's inputs into a scratch dir and generate there. sqlc has no
output-redirect flag, so relocating the inputs is how the output relocates
(out: in go/sqlc.yaml resolves relative to the config's directory). The
task now performs zero writes into the working tree — it touches
internal/store/db only as the read side of git diff --no-index, so the
concurrent set becomes readers-only and the race is structurally eliminated
rather than narrowed.

Also closes a pre-existing fail-open

Surfaced by review, and not a symptom of the race. On main the gate
snapshotted the committed tree, regenerated in place, and diffed the two — so
when sqlc failed it wrote nothing, the snapshot matched the untouched
tree, and the gate went green. Verified A/B with a stub sqlc that exits 1:
old script rc=0, new script rc=1.

The second commit hardens this properly. sqlc generate's exit code was still
discarded, so the new form failed closed only as a side effect (missing output
dir → git diff errors), and reported a real sqlc error as
internal/store/db is stale, pointing the operator at a regen that fails the
same way. set -e aborts at the sqlc error instead; errexit is suspended inside
the if condition, so the drift comparison is unaffected and the EXIT trap
still fires.

Verification

  • Clean tree → passes, and internal/store/db is left unmodified (the point).
  • Mutation-proved: appending a DriftProbeXyz query makes the gate fail with a
    readable diff naming it; restored byte-identical.
  • Broken query (SELECT * FROM no_such_table_xyz) → aborts at the real sqlc
    error, and no longer prints the misleading is stale line.
  • Out-of-tree generate emits all 33 files, byte-identical to committed.
  • moon ci (MOON_BASE=origin/main): 29 actions, 0 failed.

Review: 0 high, 1 medium, 4 low. The medium (set -e) is fixed in the second
commit. Two lows declined as out of scope — pinning the gate on the sqlc
binary version (pre-existing, worth its own issue) and cosmetic diff prefixes.

sqlc-drift ran `sqlc generate` in place, rewriting go/internal/store/db while
moon ran build/nilaway/test against that same directory in parallel. A reader
could catch a generated file mid-write and fail with
`expected 'package', found 'EOF'` on a different random file each run, which
aborts the whole push atomically and reads as the submitter's defect.

Stage the sqlc inputs into a scratch dir and generate there, so the gate has no
shared mutable subject. The drift comparison is unchanged.

Co-authored-by: Matt Wilkinson <matt@rigel.build>
@linear-code

linear-code Bot commented Sep 10, 2026

Copy link
Copy Markdown

RIG-3591

@trunk-io

trunk-io Bot commented Sep 10, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@github-actions

github-actions Bot commented Sep 10, 2026

Copy link
Copy Markdown

Compass engineering docs preview: https://compass-forge-rig-3591-sqlc.compass-eng-docs.pages.dev

Deployed from compass-forge/rig-3591-sqlc-drift at bbc1464.

…RIG-3591)

Review finding: `sqlc generate`'s exit code was discarded, so the gate failed
closed only as a side effect — sqlc writing nothing made the comparison path
missing, which errored. A broken query therefore reported
`internal/store/db is stale` and pointed the operator at a regen that fails the
same way. It also left fail-closed depending on sqlc validating every block
before writing any, which is observed behaviour of the pinned version, not a
contract.

`set -e` aborts at the sqlc error instead. Errexit is suspended inside the
`if` condition, so the drift comparison is unaffected, and the EXIT trap still
fires. Also trims the task comment to the constraint a future editor needs.

Co-authored-by: Matt Wilkinson <matt@rigel.build>
@rigel-mintaka
rigel-mintaka marked this pull request as ready for review September 10, 2026 04:13
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