upsertPricePoints can synthesize an event id from the wall clock, breaking dedupe
Maintainer thường phản hồi trong vòng 3 ngày
@sparkysolutions10-pixel đang làm issue này rồi.
Từ ngày 25/10/2026.
- #621 của @sparkysolutions10-pixel — đã merge
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 55/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- postgresql, typescript
Hướng nghiên cứu
Start with src/db.ts and trace upsertPricePoints into synthesizeEventId; compare the timestamp fallback with the identity invariant in prisma/schema.prisma. Add a regression case in src/__tests__/backfill.test.ts for identical points without timestamp or observedAt, then run the full npm test suite. Done when the no-anchor behavior is explicit and repeated ingests preserve idempotency.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Background
prisma/schema.prisma states the invariant the price-point identity index depends on:
sources with none — AMM/Soroswap pool snapshots, Aquarius, anything added later — get a key synthesized deterministically from the row's content, never from a clock.
synthesizeEventId honours that by hashing the row's content, including the timestamp:
const content = [ network, p.source, p.pairKey, p.poolId ?? '', String(p.ledger),
p.timestamp.toISOString(), String(p.price), ... ]
#394 introduced a fallback in upsertPricePoints (src/db.ts):
const observedAt = p.observedAt ?? p.timestamp ?? new Date()
const timestamp = p.timestamp ?? observedAt
...
eventId: p.eventId || synthesizeEventId(network, { ...p, timestamp })
When a point arrives with neither timestamp nor observedAt, timestamp becomes new Date() — so the synthesized event id now incorporates the wall clock. Two ingests of byte-identical data produce different event ids, the (network, source, eventId) identity index does not match, and skipDuplicates does not skip. The row is inserted twice.
That is the exact failure the identity work in #237 was built to make impossible, and it inflates volume and skews VWAP — silently, because nothing errors.
How it was found
Lens #385 (historical backfill) has a test that is the clearest statement of the contract:
proves idempotency on re-run: second run inserts 0 points and changes nothing
AssertionError: expected 1 to be +0
It passed on that branch against main as of this morning and fails after merging current main. The branch is not at fault — its test is the thing that noticed.
Why it is subtle
Before #394, a point with no timestamp would have thrown on p.timestamp.toISOString(). #394 turned a loud crash into silent non-determinism, which is the worse of the two.
What to build
- Decide what a point with no
timestampmeans. If every real ingester always sets one, the fallback should be an error rather than a clock read — a crash is recoverable, a duplicated money row is not. - If a clock fallback must stay, it must not reach
synthesizeEventId. The id has to be derived only from fields that are stable across runs, and a row with no stable temporal anchor cannot be given a deterministic identity at all — it should be rejected rather than assigned a random one. - Either way,
observedAtitself may keep thenew Date()default; it is "when Lens saw it" and is not part of the identity.
Acceptance criteria
- A point ingested twice with identical content produces the identical
eventId, with notimestampand noobservedAtsupplied - A test that fails against current
mainand passes after - The behaviour for a point with no temporal anchor is explicit — documented, and either rejected or given a non-clock identity
-
src/__tests__/backfill.test.ts's idempotency case passes in a fullnpm testrun, not only in isolation
Notes
Found while reviewing #385, which is blocked on it. That PR should not be asked to fix this — it is a regression in main.
scripts/migrations/2026-10-17-price-point-identity.sql and the @@unique in prisma/schema.prisma are the surrounding context.
- Ngôn ngữ chính
- TypeScript
- Star
- 4
- Fork
- 71
- Merge trung bình
- 3 ngày 10 giờ
- Pull request đã merge (30 ngày)
- 154
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Divinity-Labs/Lens
-
Webhook retries have no jitter, so failures synchroniseCó thể đã có người làm @Richard-tobi đã nhận 10 ngày trước. Đang mởarea:reliability difficulty:easy help wanted points:100 Stellar Wave
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
Divinity-Labs/Lens#341 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 3 ngày
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
Divinity-Labs/Lens#626 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
Divinity-Labs/Lens#625 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Live Service Spec Drift ReportĐang mởarea:tests automated live-spec-report
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 28/100
Divinity-Labs/Lens#606 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
The key is accepted only as a bearer token, and nothing says soCó thể đã có người làm @krsnak đã nhận 8 ngày trước. Đang mởarea:docs difficulty:easy help wanted points:100 Stellar Wave
Divinity-Labs/Lens#512 · 4 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của Divinity-Labs/Lens
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
juice-shop/juice-shop#3706 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
sbx up from a subfolder silently pushes the whole work treeCó thể đã có người làm @pdettori đã nhận hôm nay. Đang mởenhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
outline/outline#14348 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày