Skip to content

worker: keep metadata history monotonic - #299

Draft
spencerc99 wants to merge 3 commits into
mainfrom
cx/metadata-history-monotonic
Draft

worker: keep metadata history monotonic#299
spencerc99 wants to merge 3 commits into
mainfrom
cx/metadata-history-monotonic

Conversation

@spencerc99

Copy link
Copy Markdown
Owner

Summary

  • Keep page metadata history monotonic by observation timestamp.
  • Ignore delayed or duplicate navigation snapshots that are not newer than the current row.
  • Cover older retries, exact duplicate event IDs, and chronological handling of an out-of-order batch.

Root cause

The history write ran after the event upsert but queried only the current metadata hash. A delayed retry with different metadata could close a newer row at an older timestamp and replace it as current.

Validation

  • bun run test in extension/worker (45 tests)
  • Conservative local review: no findings.

@pkg-pr-new

pkg-pr-new Bot commented Jul 12, 2026

Copy link
Copy Markdown

Open in StackBlitz

bun add https://pkg.pr.new/@playhtml/common@299
bun add https://pkg.pr.new/playhtml@299
bun add https://pkg.pr.new/@playhtml/react@299

commit: 2457652

@spencerc99

Copy link
Copy Markdown
Owner Author

Code review

  • P1 extension/db/migrations/page_metadata_history_atomic.sql:46 still lets a stale, different snapshot replace metadata observed later. The function compares an incoming timestamp with valid_from_ts, but a newer observation with the same hash returns at lines 50-51 without advancing any watermark. Starting with current A@100, processing A@300 leaves the comparison timestamp at 100; a delayed B@200 then passes the timestamp check, closes A at 200, and becomes current even though A was observed at 300. Store a separate latest-observation timestamp and advance it for same-hash observations, then reject every incoming snapshot at or below that watermark.

  • P2 extension/worker/src/__tests__/ingest.test.ts:189 tests serialization implemented by the mock instead of the SQL function. The mock itself applies the monotonic timestamp rule, so the assertion cannot validate the advisory lock, transaction, or database behavior and conflicts with the project rule against tests of mocked behavior. Exercise concurrent calls against real PostgreSQL/Supabase, or narrow this unit test to request/RPC plumbing without claiming it verifies serialization.

  • P3 extension/db/migrations/page_metadata_history_atomic.sql:1 violates the repository's mandatory two-line ABOUTME: header rule for code files. Add the required two-line file description.

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