Skip to content

perf(cli): strategy-driven parallel provisioning for pg-delta next plan shadows - #6215

Open
avallete wants to merge 1 commit into
developfrom
claude/shadow-db-parallel-provision-fn9uue
Open

perf(cli): strategy-driven parallel provisioning for pg-delta next plan shadows#6215
avallete wants to merge 1 commit into
developfrom
claude/shadow-db-parallel-provision-fn9uue

Conversation

@avallete

@avallete avallete commented Aug 15, 2026

Copy link
Copy Markdown
Member

Summary

Rebased onto develop now that #6102, #6184, and #6203 are merged. The PR is only the plan-shadow overlap — not the lower-stack cache/stop work.

A declarative sync provisions two shadow databases (migrations + declarative). Those used to run strictly sequentially, so the declarative shadow's whole provision was added to the runtime instead of overlapping it.

Provisioning now peeks each shadow's baseline-cache state (legacyPeekShadowBaseline) and picks one of three strategies (legacy-pgdelta-next-shadow.plan.ts):

  • parallel — both snapshots already published: both warm-restore concurrently. A warm restore skips the platform baseline, so only the migrations fiber prints (Applying migration ...), live and in order.
  • baseline-handoff — first run, both cold under one cache key: the platform baseline is built once. The migrations shadow cold-provisions; its snapshot export at the baseline seam signals the declarative fiber, which warm-restores from the just-published tar concurrently with migration replay. A handle that will never snapshot signals immediately, and the runner Effect.ensurings the signal onto the whole provision as a liveness backstop.
  • sequential — different keys, mixed states, --no-cache, cache env off, PG≤14/OrioleDB: no baseline can be shared, so this keeps the pre-parallel flow and transcript.

Output ordering is a hard guarantee. In the concurrent strategies the declarative fiber's Output writes go through legacyBufferedShadowOutput and flush after the join. Post-flush writes pass through live so late teardown warnings are never lost.

Same-database identity still uses the acquired handles' snapshotKeys (not the peeks), so a delayed declarative re-resolve cannot lie about snapshot lineage.

Supporting cache changes:

  • legacyPeekShadowBaseline answers "what would the acquire do right now" without provisioning. The acquire always re-checks disk state.
  • Immediate acquires reuse peeked key inputs via precomputedKeyInputs so the JWKS discovery request is not resolved twice. Delayed declarative acquires re-resolve so a mid-run roles.sql edit cannot publish under a stale key.
  • Cold snapshot exports are serialized by an in-process mutex (legacyExportPgDataTar's temp name is pid-scoped). The absent-at-acquire dedupe skips a re-export only when the tar appeared after the cold acquisition began; a tar retained through a failed warm restore is still atomically replaced.

Dogfooded this PR against its merge base (develop@38f31b4) on supabase db schema declarative sync --no-apply --experimental (pg-delta next), full 2×2 matrix of {base, PR} × {SUPABASE_SHADOW_CACHE off/on}, 5 timed runs per cell plus extra cold-cache samples. All docker images pre-pulled and the local stack already running, so no run pays pull or stack-start cost. Times are full CLI wall-clock on a converged project ("No schema changes found" — both shadows still provisioned every run).

Scenario develop (base) this PR Delta
SUPABASE_SHADOW_CACHE=0 21.96s ± 0.42 (n=5) 22.32s ± 0.61 (n=5) none (within noise)
SUPABASE_SHADOW_CACHE=1, cold cache 16.02s ± 0.66 (n=4) 16.18s ± 0.38 (n=4) none (within noise)
SUPABASE_SHADOW_CACHE=1, warm cache 6.71s ± 0.49 (n=4) 5.25s ± 0.14 (n=4) −1.46s, 21.8% faster (1.28×)

Per-run warm values — base: 6.03, 6.80, 6.79, 7.21 · PR: 5.38, 5.14, 5.12, 5.35. The PR is also noticeably less noisy (σ 0.14 vs 0.49).

@avallete
avallete requested a review from a team as a code owner August 15, 2026 20:11

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 04da465f86

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/cli/src/legacy/shared/db-bootstrap/shadow-cache.ts Outdated
avallete pushed a commit that referenced this pull request Aug 16, 2026
… at acquire

The export dedupe skipped whenever a tar existed at the final path, but
the warm-fallback cold path deliberately RETAINS an unusable tar (an
extraction failure does not implicate its contents) precisely so the
fallback's own export atomically replaces it. Skipping there left a
genuinely corrupt tar in place forever, failing every later warm restore
into another cold provision. The skip now applies only on the cold path
whose tar was absent when the acquisition began, where a tar found at
export time can only be a same-key sibling's fresh publish.

The existing warm-fallback test asserted only the tar COUNT after the
republish, which is why the skip slipped through — it now corrupts the
tar's bytes up front and asserts the exported bytes replaced them.

Review: Codex on #6215.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NYVv1jjXdrTzqDTVrU4Had
@avallete avallete changed the title perf(cli): provision pg-delta next plan shadows in parallel perf(cli): strategy-driven parallel provisioning for pg-delta next plan shadows Aug 16, 2026

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d9a2f2ba1d

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

avallete pushed a commit that referenced this pull request Aug 16, 2026
…tive shadow

pg-delta's planSchemaFiles refuses to load declarative SQL when the
shadow and target report the same PostgreSQL identity unless
allowSameDatabaseIdentity is set. The baseline handoff restores the
declarative shadow from the tar the migrations shadow just exported —
an exact physical clone, same system identifier and database OIDs — but
the flag was computed as "both handles were warm restores", which the
cold migrations side fails, so the first cold plan would be rejected by
the guard it exists to bypass.

The flag now encodes actual snapshot lineage: true exactly when the
declarative shadow was RESTORED from the same snapshot key that also
produced the migrations cluster — same key means same tar, and the
migrations side is that tar's lineage whether it warm-restored from it
or cold-exported it this run. A freshly initdb'd declarative shadow has
its own identity and different keys mean different originating
clusters, so those stay false and keep the guard armed. Key equality is
taken from the peeks (deterministic over inputs), so disk-state races
cannot make it lie. A true alongside identities that happen to differ
is harmless: pg-delta's bypass only takes effect on an exact identity
match, never on a same-lineage sibling.

Review: Codex on #6215 (P1).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NYVv1jjXdrTzqDTVrU4Had

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b817476b5a

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

avallete pushed a commit that referenced this pull request Aug 16, 2026
The declarative shadow's acquire is delayed under the handoff (waits for
the baseline seam) and sequential (waits for the whole migrations
provision, including a possibly long replay) strategies, and the cache
key hashes mid-run-mutable inputs — supabase/roles.sql and the remote
JWKS — that a cold setup re-reads at its own time. Reusing the up-front
peek's resolved inputs there could publish a baseline under a key that
no longer describes it, letting a later run warm-restore the wrong
roles. Peeked inputs are now passed through only where the acquire
follows the peek immediately: the migrations acquire always, the
declarative one only under the parallel strategy. A delayed acquire
re-resolves at acquire time, which also self-corrects a handoff whose
key genuinely changed mid-run — the recomputed key misses the
just-exported tar and the declarative side cold-provisions with the
current inputs.

Review: Codex on #6215 (P2).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NYVv1jjXdrTzqDTVrU4Had

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c0511f1211

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

avallete pushed a commit that referenced this pull request Aug 16, 2026
The stale-peek refresh comment listed the remote JWKS among the inputs a
delayed acquire re-resolves, but that resolver is deliberately memoized
per shadow input (shadow-database.ts, review: Codex on #6184) so the
cache key and the baked baseline always carry the same value and cannot
diverge — a delayed acquire keeps the command-start JWKS, well inside
the staleness the snapshot cache accepts by design (a warm hit serves a
tar up to 14 days old under its matching key). Scope the comment to
roles.sql, the one input the refresh actually re-reads, and state the
JWKS exemption explicitly.

Review: Codex on #6215.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NYVv1jjXdrTzqDTVrU4Had

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5390632fcb

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 66911c3164

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/cli/src/legacy/commands/db/shared/legacy-pgdelta-next-shadow.layer.ts Outdated
@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Supabase CLI preview

npx --yes https://pkg.pr.new/supabase/cli/supabase@1477e0c1f9d20f643a72b365c97f0521943c08b1

Preview package for commit 1477e0c.

Base automatically changed from avallete/fast-stop-exec-wrappers to develop August 25, 2026 09:14
…an shadows

Overlap the two next-engine plan shadows when a baseline can be shared, and keep
progress lines ordered. Rebased onto develop after #6102/#6184/#6203 landed.
@avallete
avallete force-pushed the claude/shadow-db-parallel-provision-fn9uue branch from 66911c3 to 1477e0c Compare August 25, 2026 16:38
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.

2 participants