Skip to content

test(ingestor): seed tx_last_seen backfill fixtures in one transaction - #1021

Merged
dborup merged 1 commit into
masterfrom
fix/tx-last-seen-backfill-test-seed-tx
Nov 28, 2026
Merged

dborup merged 1 commit into
masterfrom
fix/tx-last-seen-backfill-test-seed-tx

Conversation

@dborup

@dborup dborup commented Nov 28, 2026

Copy link
Copy Markdown
Owner

Relates to #1012

Summary

TestBackfillTxLastSeen_ResolvesFromMaxObservationTimestamp failed on all three "Go Build & Test" runs for #1012 (run 46132323901) with last_seen = 100, want 300.

Root cause

  1. The CI runs tested stale code. The job checked out merge commit 5072050d (feat(info): /guider page with click-to-play video guides #1012 head cb99a342 merged into 4af4177c, the tip of codex/meshview-info-pages from before feat(info): /guider page with click-to-play video guides #1012 was retargeted to master). That base forked from master before 14789759 and 3bbd5507, which added WaitForAsyncMigrations() before seeding and made newTestStore drain backfillWg. Re-runs reuse the same merge SHA, so every attempt tested the code without the wait.
  2. The race itself: OpenStore schedules tx_last_seen_backfill_v1 in a goroutine. seedTxWithObs inserted the transmission and each observation as separate autocommit statements. If the goroutine ran between them, it stamped last_seen from the first observation only (100), and the test's own backfillTxLastSeen call then skipped the row because it only selects last_seen = 0. The CI log shows exactly this: the async run reports 1 rows updated and "tx_last_seen_backfill_v1" done after the test's direct backfill started.

Is the wait on master sufficient?

Yes. RunAsyncMigration calls backfillWg.Add(1) synchronously before OpenStore returns, and backfillTxLastSeen does all its chunks inside that one goroutine, so no chunk is rescheduled outside the WaitGroup. No trigger writes transmissions.last_seen. The only other writer is InsertTransmission, which these seeds don't use.

This change (test only)

seedTxWithObs now inserts the transmission and all of its observations in one transaction. A backfill running at any point (with SetMaxOpenConns(1) it blocks on the pool until commit) sees the row with none or all of its observations, so the result is MAX = 300 either way. seedTxNoObs reuses the same helper. A comment on seedTxWithObs explains the race. No production code changes.

Action for #1012

Its current failures go away once CI runs on a fresh merge ref against master: push a commit, or merge master into the branch. Re-running the old run won't help.

Tests

  • Reproduced on the old code (4af4177c, the same cmd/ingestor code as the failing merge commit) with go test -race -count=200 -cpu 1,2 -run TestBackfillTxLastSeen and 12 busy-loop CPU hogs. The run gave 15 failures in the same class: an async backfill stamped rows the test did not expect (IgnoresRowsInsertedAfterSnapshot ×11, OrphanNeverLoopsForever ×3, ChunksAcrossMultipleBatches ×1), then hit the 10 m default timeout.
  • Same stress on this branch (-timeout 0, 2000 test runs under the same load): ok (4177 s).
  • cd cmd/ingestor && go test ./...: ok.

No frontend or browser-visible change, so no browser validation is needed. No config or customizer implications.

🤖 Generated with Claude Code

seedTxWithObs inserted the transmission and each observation as separate
autocommit statements. If the tx_last_seen_backfill_v1 goroutine that
OpenStore schedules ran between them, it stamped last_seen from a partial
set of observations (100 instead of 300), and the test's own backfill
call then skipped the row because it only selects last_seen = 0.

newTestStore and WaitForAsyncMigrations already drain that goroutine
before seeding, so current master is not exposed. The failures on
#1012 came from a merge commit (5072050, base 4af4177)
whose test code predates those waits. Seeding in one transaction closes
the window regardless: a backfill running at any point sees the row with
none or all of its observations. seedTxNoObs now reuses the same helper.

Relates to #1012

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

dborup commented Nov 28, 2026

Copy link
Copy Markdown
Owner Author

Review — CS-Minimax PR#1021 — head cceb357

Dom: APPROVE med nits

(Review written in English; verdict wording above kept to the agreed vocabulary: approve, with nits.)

Findings

# Sev Finding Evidence
1 nit The PR text says the failures were caused by a stale merge ref. On current master the race is already closed by WaitForAsyncMigrations() before seeding. The one-transaction seed is therefore defence in depth, not a fix for a failure reproducible on master. The text says this itself, but the title and the commit body read as if the test is still flaky on master. [K] diff + PR body
2 nit Issue #1012 is the /guider feature, not a flaky-test issue. It has no acceptance criterion for this change. The PR correctly uses "Relates to" and no closing keyword. [K] gh issue view 1012
3 nit seedTxNoObs now calls seedTxWithObs with zero timestamps. That is correct and keeps its behaviour. A caller passing a duplicate hash would still hit the same unique-constraint failure as before. [K] diff

No blocking findings.

Answers to the review points

  • Root cause matches the code. [K] OpenStore schedules tx_last_seen_backfill_v1 through RunAsyncMigration, which calls backfillWg.Add(1) synchronously (async_migration.go:97). The backfill (db.go:264-300) selects only last_seen = 0 rows that have an observation, so a row stamped from a partial set is skipped by the test's later direct call. The old seed used separate autocommit statements, so that window existed. With SetMaxOpenConns(1) (db.go:166) a transaction holds the single connection until commit, so the backfill sees none or all observations. This is a real removal of the race, not a longer timeout.
  • Same behaviour tested. [K] The diff touches only the seed helpers. Assertions, the 300 expectation, and the batch/yield overrides are unchanged. [T] Mutants below still fail the suite.
  • Only test code changed. [K] One file, cmd/ingestor/tx_last_seen_backfill_test.go. No production, cmd/server, or frontend change. No new map[string]interface{}. scripts/check-xss-sinks.sh --diff origin/master reports nothing to scan.
  • Author and attribution. [K] Commit author is dborup <kontakt@meshview.dk>. No closing keyword.

Tests

Run on the merged tree (git merge-tree --write-tree origin/master <head> against a49526df), exported with git archive into scratch.

Mutants (own, on production backfill in db.go)

Mutant Result
MAX(timestamp) → MIN(timestamp) killed: ResolvesFromMaxObservationTimestamp fails [T]
Drop the EXISTS (…observations…) filter killed: OrphanNeverLoopsForever fails after 5 s [T]
Drop last_seen = 0 from the batch filter killed by hang only: the run did not finish within the 400 s limit and I stopped it. Not a clean assertion failure. [T]

Not verified

  • [A] The "red before" state: I did not reproduce the original race on the stale base 4af4177c. I rely on the author's stress-run numbers. On master the race cannot occur because of the existing wait, so a red-before/green-after pair does not exist for master.
  • [A] The author's 2000-run stress under CPU load (4177 s). Not repeated.
  • E2E/browser: not applicable, no UI or server change.
  • sh test-all.sh, node test-frontend-helpers.js, and the Go server suites were not re-run by me. The change is one ingestor test file, and CI passed these.

@dborup
dborup merged commit a15ddce into master Nov 28, 2026
18 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.

1 participant