Skip to content

fix(e2e): stabilize mv_replay empty-target backfill on ObsessionDB - #225

Merged
KeKs0r merged 1 commit into
mainfrom
cursor/fix-mv-replay-empty-target-e2e-8c06
Sep 28, 2026
Merged

KeKs0r merged 1 commit into
mainfrom
cursor/fix-mv-replay-empty-target-e2e-8c06

Conversation

@KeKs0r

@KeKs0r KeKs0r commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Summary

The obsessiondb job on 7564cac (run 36437314070) failed @chkit/plugin-backfill#test in packages/plugin-backfill/src/mv-replay-plan.e2e.test.ts. verify was green. One chunk's INSERT…SELECT finished with writtenRows: 0 (f26814ae900eeac9), so bucket "2" never landed in the empty aggregate. The other three chunks wrote one row each, and a consistent read of the source still had all four buckets (0–3).

#221 appended select_sequential_consistency = 1 to the chunk SQL and polled the target. That poll cannot repair a chunk that already committed an empty replay. The setting does not fetch parts from a normal, non-quorum insert; it only hides or rejects blocks the quorum has not confirmed. Chunk queries are submitted on a stateless client, so each one can run on a different replica than the session that inserted the source. ObsessionDB also enables parallel replicas by default, and a stale follower can satisfy one partition with an empty scan while the query still reports finished. The chunk's dedup token then makes another attempt with the same plan id commit nothing again.

The harness change is limited to that e2e:

  • On Replicated/Shared engines, each active replica is sampled on a fresh session. That session runs SYSTEM SYNC REPLICA … LIGHTWEIGHT and then counts. The backfill does not start until every sample sees all 4000 source rows. Plain MergeTree (the single-node verify service) only counts.
  • The generated chunk SQL also sets enable_parallel_replicas = 0, matching planning.
  • A chunk that still finishes with 0 written rows is run again under a new plan id, so it gets a new query id and dedup token, after another sync. Up to three times. The assertion message lists written rows per attempt.

Test plan

  • biome lint on the test file, and the non-e2e @chkit/plugin-backfill unit tests
  • The same e2e against a local single-node ClickHouse 26.10 (MergeTree, no sync): passed in about 3s
  • PR verify covers the single-node ClickHouse 26.3 path used in CI
  • The obsessiondb job runs only on pushes to main, so this PR's CI will not prove the live fix. After merge, watch the obsessiondb job on main. Do not treat a green PR verify as coverage of this race.
Open in Web Open in Cursor 

select_sequential_consistency does not fetch parts from a non-quorum
insert, so a chunk INSERT…SELECT on a stale replica finishes with 0
written rows and the dedup token makes that replay stick. Sync each
active replica before reading, disable parallel replicas on the chunk
query, and reissue any still-empty chunk under a new token.

Co-authored-by: Marc Höffl <marc.hoeffl@gmail.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-28T15:02:33.580985Z 64939e6 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: 64939e67a2

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

const [row] = await session.query<{ cnt: string }>(
`SELECT toString(count()) AS cnt FROM ${sourceFqn} SETTINGS select_sequential_consistency = 1`,
)
if (Number(row?.cnt ?? 0) === SOURCE_ROWS) readySamples += 1

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Require distinct replicas before declaring the source ready

When the load balancer routes multiple fresh sessions to the same healthy replica, each successful count increments readySamples, so this can reach active_replicas without ever checking a lagging replica. A subsequent stateless chunk can still land on that unchecked replica and reproduce the 0-row replay this change is intended to prevent. Record a replica identity with each sample and require the expected number of distinct ready replicas, or target every replica explicitly.

Useful? React with 👍 / 👎.

@KeKs0r
KeKs0r merged commit 62a3685 into main Sep 28, 2026
12 checks passed
@KeKs0r
KeKs0r deleted the cursor/fix-mv-replay-empty-target-e2e-8c06 branch September 28, 2026 15:03
KeKs0r added a commit that referenced this pull request Sep 28, 2026
ObsessionDB's managed role cannot SELECT system.replicas, so the replica
count added in #225 failed the empty-target e2e with ACCESS_DENIED.
Fall back to one visibility sample, skip SYSTEM SYNC REPLICA only when
that command is denied too, and keep parallel-replica disable plus
empty-chunk replay.

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
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