Repository navigation
feat: add ownership checkpointing database foundation - #81
Merged
Merged
Conversation
Migration 013 implements the database substrate of the merged ownership checkpoint architecture: versioned scope membership, ephemeral build state, and the lifecycle/restart/promotion/abandon/GC primitives the multi-invocation history walk requires. - ownership_scope_versions (RETAINED/CORE) splits immutable base-scope identity from per-version membership; exclusion state is versioned. - ownership_history_work + ownership_contributor_build_work (EPHEMERAL, backup-excluded) hold crash-safe counters and represented-key staging only — pseudonymous work keys, no plaintext identity in counters. - ownership_snapshots->scope FK re-created ON DELETE NO ACTION; new composite snapshot->membership FK (scope, repo, user, version) NO ACTION makes snapshots impossible without same-tenant/same-repo/same-version membership while repository/account teardown still cascades in one statement through the direct tenant FKs. - own_checkpoint_page (single-transaction page CAS + cursor advance), own_restart_scope (committed-V-provenance staging cleanup), own_promote_build (exact-set validation before atomic flip), own_abandon_build (the one canonical cleanup), own_build_preflight/own_build_init (retired-version GC gate, split per §5.6c), own_sweep_stale_work — all SECURITY INVOKER, service_role-only. - dash_ownership_scopes now enumerates scopes through version membership at active_version; building-version scopes/exclusion never leak. - 012-era rows are backfilled into membership inside 013 before the composite FK validates; migration 012 itself is untouched. - Recovery drill extended: real-Postgres A-AA integrity matrix, restored-building abandon proof, and a 012->013 upgrade leg (MIGRATE_UP_TO bounds the applied chain). Database layer only — no worker, no GitHub traversal, no wiring. Real-Postgres 17 proofs run in scripts/recovery-drill.mjs (npm run db:drill) and CI's postgres:17 service. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
own_checkpoint_page staged identity for any key with pass-1 counters, but overflow-only contributors also carry counters — a caller bug could persist github_node_id/display_login for a key that never reaches the finalized scope output. The database now computes the represented set itself (per-period touch_commits DESC, work_key ASC ranks 1..25, unioned, unlinked excluded — bit-equivalent to the canonical reducer) and ignores non-represented submissions before any pass-2 check or write. Adds a reducer-vs-DB exact-set differential proof with 27+ linked keys covering rank 25/26, tie-break, multi-month union, overflow-every- month, and pass-2-only cases. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
4 tasks done
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 1C-B1 — the database substrate of the merged ownership checkpoint
architecture (PR #79), gated on the B0.5 pinned-revision spike (PR #80,
verdict PASS).
Migration
013_ownership_checkpointing.sqlcreated — database layeronly. It adds the relations and primitives the crash-safe
multi-invocation history walk requires:
ownership_scope_versions(RETAINED / CORE) — separates immutablebase-scope identity from per-version membership at grain
(scope_id, calculation_version);excluded/exclusion_reasonareversioned,
cardinality_cap-only. Tenant pair and scope/repo pair areDB-enforced; the scope FK is exactly
ON DELETE NO ACTION.ownership_history_work(EPHEMERAL) — perscope×version×month×work_key accumulation counters.
work_keyisunlinkedor a 64-hex pseudonymous key; no plaintext contributoridentity, no paths, no provider payloads.
ownership_contributor_build_work(EPHEMERAL) — build-levelidentity staging for represented keys only (
(repository, version, work_key)); synthetic buckets structurally refused; no scopeprovenance column per §5.3.
ownership_snapshots → ownership_scopesFK re-createdON DELETE NO ACTION(same deployed constraint name/keys) plus a new compositeownership_snapshots_scope_versionFK(scope_id, repository_id, user_id, calculation_version) → ownership_scope_versionsNO ACTION: a snapshot cannot exist withoutmatching same-repo/same-tenant/same-version membership, while
repository/account teardown still destroys the complete ownership
graph in one statement through the direct tenant cascades (proven).
own_checkpoint_page(page delta + durable cursor inone CAS transaction; replay returns
stale, never double-counts),own_restart_scope(staging cleanup by committed-V provenance),own_promote_build(exact-set staged≡represented validation before theatomic flip + metadata apply),
own_abandon_build(the one canonicalcleanup),
own_build_preflight/own_build_init(§5.6c retired-versionGC gate, split so no third version coexists),
own_sweep_stale_work(abandon-routed sweep). All
SECURITY INVOKER,service_role-only,closed
OWNERSHIP_INTERNAL_ERRORtaxonomy.dash_ownership_scopesnow enumerates scopes throughownership_scope_versionsatactive_version; building-versionscopes and exclusion state cannot leak into active output. Same
signature, grants, invoker model.
membership inside 013 before the composite FK validates. Migration 012
is untouched.
ownership_scope_versions→ CORE (backedup); both work tables → EPHEMERAL (never in the dump — a restored
building version is abandoned, not resumed piecemeal).
Scope
Not in this tranche (still unimplemented, by design): production GitHub
history walking, live
object(oid:)traversal, runtime pagination,ACCUMULATE/RESOLVE worker loops, cron/webhook ownership orchestration,
serverless slicing, live promotion trigger, UI, dashboard launch, feature
flags, backfill, or any production ownership writes.
Production untouched. Migration 013 was applied only to throwaway
local Postgres 17 databases. The production ownership worker is not
wired and no ownership rows were written anywhere but synthetic
scratch databases.
.env.localwas never used.Security / privacy impact
Security/privacy behavior changed and is explained below
New tables: RLS enabled, zero browser/user policies,
service_roleDML only — same model as 012. New functions:
SECURITY INVOKER,search_pathpinned,EXECUTErevoked frompublic/anon/authenticated, granted toservice_roleonly.Privacy: counter rows carry pseudonymous
work_keyonly; identityfields (
github_node_id,display_login) exist solely inrepresented-key staging + retained contributor rows; synthetic
unlinked/othercan never enter staging. No emails, names,databaseIds, paths, commit text, or provider error text anywhere.
Backup: work tables are backup-excluded (fail-closed classification in
backup-scope.mjs); restore of a mid-build version routes through thecanonical abandon primitive — proven in the drill.
Database / deployment impact
013_ownership_checkpointing.sql)db:migratepath; 012-era rows are backfilled by the migration itself
Verification
npm run buildnpm run typechecknpm test— 631 pass / 0 fail (3 pre-existing env-gated skips)npm audit --audit-level=moderate— 0 vulnerabilitiesnpm run db:drill— real Postgres 17, full PASSExact real-Postgres integrity tests performed (all inside
npm run db:drill,scripts/ownership-checkpoint-proofs.mjs):cross-repo, cross-tenant all rejected by name-checked constraints;
membership delete blocked by snapshot; legal order succeeds.
snapshots→membership→scope prune succeeds.
DELETE FROM repositories/DELETE FROM usersremoves all seven ownership relations including both work tables.
active-N
dash_ownership_scopes.byte-identical, prunes N+1-only contributors/scopes.
contributors), preserves committed-V-provenanced staging, resets to
fresh ACCUMULATE.
exact set and applies metadata atomically with the flip.
mid-GC failure rolls back atomically and retries cleanly; clean-state
preflight is a no-op.
cursor/version rejection with zero writes, additive counters, least/
greatest timestamp merge, pass transitions, frozen is_bot staging,
attribution drift fails closed.
ownership_scope_versionspresent; restored building version cleanly abandoned; V1 preserved.
preserved, membership backfilled,
confdeltype='a'on all three FKs.Test plan
mainContributor agreement
Generated with Devin