Skip to content

fix(ci): refuse schema dumps newer than the checkout - #131364

Merged
trunk-io[bot] merged 2 commits into
masterfrom
posthog/refuse-newer-schema-dumps
Nov 7, 2026
Merged

trunk-io[bot] merged 2 commits into
masterfrom
posthog/refuse-newer-schema-dumps

Conversation

@posthog

@posthog posthog Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Backend contributors can see missing-table teardown failures when CI restores a schema newer than their checkout (report).

Why: Avoid schema failures and repeated CI runs.

Changes

  • Restore refuses unknown managed migrations before database changes. Callers fall back to full migrations.
  • Squash replacements and separately routed apps remain valid.
  • Named migration references fix Semgrep mechanically.

How did you test this code?

  • Existing schema tests, Ruff, pinned Semgrep, and preflight.
  • Stacked Backend CI and post-merge savings remain unverified.

Test rationale: Existing cases cover rejection, matching schemas, squashes, and routed apps.

Release status

  • No feature flag controls this change

Docs update

  • None.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Agent: Claude Code, claude-opus-5-5; Codex CI repair, gpt-6.1-sol

Skills: /authoring-ci-workflows, /writing-tests, /writing-code-comments, /writing-pr-descriptions, /writing-dataclasses, /verifying-changes, /running-ci-preflight, /pr-shepherd, /qa-swarm, /review-triage, /ci-shepherd

More context for AI agents
  • Decisions: #130664 was closed because a branch-name gate could let stack-built dumps poison master-based PRs through the shared prefix.
  • Decisions: content checks cover both master-on-stack and stack-on-master dumps, including the model swap from #127809.
  • Decisions: the stdlib frozen dataclass avoids importing Django through posthog.__init__ in standalone hogli.
  • Decisions: the original artifact check accepted matching code, rejected missing migrations, and accepted deleted squash-replaced files.
  • Follow-ups: inspect five eligible restores after merge for the missing-table signature, unchanged tests and cleanup, total job time, and reruns. Savings remain unmeasured.
  • Follow-ups: stacked PRs still run full migrations per shard because prime-schema-cache counts prefix matches as hits.
  • Follow-ups: ci-rust-flags-integration.yml uses raw psql, so it does not get this guard.
  • Follow-ups: preflight's toolbar-launch ownership warning is outside this diff; the CI report's backend-lane warning is informational.
  • Read closely: _check_dump_is_not_newer_than_checkout in tools/hogli-commands/hogli_commands/db_schema.py. All hogli restore callers use this check.

Created with PostHog Desktop

The schema restore now reads the dump's django_migrations rows and refuses
a dump that records migrations of our own apps the checkout does not have.
Such a dump comes from newer code, such as the newest master dump restored
for a stacked branch, and migrate cannot remove what that code added.
Callers already treat a failed restore as a miss and run the full migrate.

Squash-replaced names count as known, and product-routed apps are skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Generated-By: PostHog Desktop
Task-Id: 7ae05f85-8f9b-432c-96f2-c0eb41c76f92
@posthog posthog Bot added the self-driving label Nov 7, 2026
@trunk-io

trunk-io Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

😎 Merged successfully - details.

@posthog
posthog Bot requested review from a team and webjunkie November 7, 2026 12:12
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

🤖 CI report

⚠️ Trunk lane — backend Python lane

This PR is assigned to the backend Python lane. It runs backend Python tests and may merge in parallel with PRs in other lanes.

✅ Duplication (Python) — clean

New Python code duplication introduced by this branch. Fails at 70+ tokens in app code, or 150+ tokens when both copies live in test files. Advisory while the gate proves itself: extract a shared helper instead of copying.

✅ Duplication (TypeScript) — clean

New TypeScript code duplication introduced by this branch. Fails at 70+ tokens in app code, or 150+ tokens when both copies live in test files. Advisory while the gate proves itself: extract a shared helper instead of copying.

@posthog
posthog Bot marked this pull request as ready for review November 7, 2026 12:26
@parameterai

parameterai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Risk: No findings

The only change since the last review is a mechanical refactor of the migration-reference sets from tuples to a frozen ordered dataclass in the hogli schema-restore check; it is behavior-equivalent at every use site and introduces no new security surface.

Sentinel reviewed 4149133 · Review settings

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

PostHog Review · Standard · reviewed f3ece21: no findings.

Generated-By: PostHog Desktop
Task-Id: 2cddad30-90ed-45de-bc3f-46315bd5b38c
@posthog

posthog Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

Robot:

Note

🤖 Automated comment by QA Swarm

Verdict: ✅ APPROVE (round 2 @ 4149133)

The named migration reference fixes the Semgrep failure. Unit tests and the pinned rule pass. The router and simplification pass found no further defects. Schema rejection still occurs before database changes. Post-merge savings need measurement.

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

PostHog Review · Standard · reviewed 4149133: no findings.

@trunk-io
trunk-io Bot merged commit 554a079 into master Nov 7, 2026
234 of 235 checks passed
@trunk-io
trunk-io Bot deleted the posthog/refuse-newer-schema-dumps branch November 7, 2026 20:23
@deployment-status-posthog

deployment-status-posthog Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-11-07 20:43 UTC Run
prod-us ✅ Deployed 2026-11-07 20:59 UTC Run
prod-eu ✅ Deployed 2026-11-07 20:58 UTC Run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant