Skip to content

Fix nested subquery move replay across restarts - #1

Merged
joshdchang merged 6 commits into
sapien/shape-startupfrom
josh/nested-subquery-replay
Jul 13, 2026
Merged

Fix nested subquery move replay across restarts#1
joshdchang merged 6 commits into
sapien/shape-startupfrom
josh/nested-subquery-replay

Conversation

@joshdchang

@joshdchang joshdchang commented Jul 13, 2026

Copy link
Copy Markdown

Summary

Integrates Electric's restart-replay work from electric-sql#4681 into the Sapien fork and fixes nested dependency replay when generated control records and spliced move-in rows do not encode their persisted log offsets.

Linear: SAP-7363

Root cause

The dependency materializer reconstructed replay positions from JSON headers. Ordinary replication records contain an LSN and operation position, but generated move controls, snapshot-end controls, and spliced move-in rows do not. Nested materializers therefore tagged replay with the wrong cursor and outer shapes could miss dependency move-ins or move-outs after restart.

Changes

  • Add an optional storage capability that streams main-log records with their authoritative persisted offsets.
  • Preserve exact sparse offsets through in-memory, disk, hibernated, and mixed disk/ETS reads.
  • Reconstruct the dependency seed at the outer consumer's persisted cursor, then lazily replay only the strictly bounded missing tail.
  • Persist and commit per-dependency move positions only after the corresponding outer-shape writes are durable (from upstream Restore subquery shapes correctly after a server restart (materializer move replay) electric-sql/electric#4681).
  • Add repeated three-level restart, generated-control, move-in-splice, sparse-boundary, early-halt, and storage compatibility regressions.
  • Preserve the Sapien fork's infinite materializer subscription timeout.

No on-disk format, database schema, HTTP Shape API, or model behavior changes.

Verification

  • mix format --check-formatted
  • mix compile --force --warnings-as-errors
  • 206 focused storage/materializer/consumer tests
  • full sync-service test suite
  • restart oracle: ordinary dependency, 200-transaction catch-up, and repeated three-level nested move-out/move-in
  • property oracle: 100 shapes, 500 mutations
  • hostile follow-up code review: no remaining findings

The inherited PR matrix will additionally run PostgreSQL 14/15/17/18, oracle, performance, formatting, and Lux checks.

Rollout

This PR does not publish an image while it is open. After review and green CI, merging to sapien/shape-startup publishes the multi-architecture Sapien image. Sapien Core will pin the resulting immutable digest only after its disposable exact-citation restart harness passes. Rollback is the prior digest; storage format remains compatible.


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.

robacourt and others added 6 commits July 12, 2026 21:10
…l timeout

The per-dependency moves-position is now staged when the move pipeline drains
and only committed+persisted once the writer confirms the flush has passed the
move's splice (and, at terminate, after the writer has been flushed). This
keeps the persisted position from running ahead of durable storage across a
restart, which could otherwise leave a subquery shape permanently missing rows.

Also raise the oracle-restore test's long_poll_timeout: a very short one trips
a separate post-restart long-poll readiness race (bug 3), unrelated to the
subquery-restore behaviour under test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
It is called from terminate/2 after terminate_writer/1 has popped :writer off
the state, so the value is no longer typed as %State{} and the %State{} clauses
were flagged as never matching. Match a bare map and read the fields via
Map.get instead.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@joshdchang joshdchang self-assigned this Jul 13, 2026
@joshdchang

Copy link
Copy Markdown
Author

CI triage: the red checks are fork infrastructure failures, not test failures.

  • PostgreSQL 14/15/17/18, oracle, and performance jobs stopped while pulling the fork-private ghcr.io/ai-sapien/electric/postgres:* images with a workflow token that has only contents: read (denied before checkout/tests).
  • TypeScript test commands completed; their jobs failed afterward because this fork has no Codecov token.
  • TS formatting fails on the pre-existing fork-only .github/workflows/sapien-sync-service.yml, outside this PR's diff.
  • Elixir formatting/compilation and Lux both passed.

Equivalent sync-service coverage passed locally: warnings-as-errors compilation, 206 focused tests, the full suite, repeated nested restart oracles, 200-transaction catch-up, and the 100-shape/500-mutation property oracle. The stacked upstream-only PR is electric-sql#4699 and will receive the upstream repository's normal matrix once a maintainer approves fork workflows.

@joshdchang
joshdchang marked this pull request as ready for review July 13, 2026 03:04
@joshdchang
joshdchang merged commit b58a610 into sapien/shape-startup Jul 13, 2026
25 of 46 checks passed
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