Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Session rows can collapse across different session IDs when creation timestamps collide

Đang mở
#562 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
52/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ệ
clickhouse, typescript
Lĩnh vực
analytics, databases

Hướng nghiên cứu

Read packages/db/src/code-migrations/8-order-keys.ts around the session sorting key and packages/core/src/buffers/session-buffer.ts around extendSession. Start by checking how the migration defines the session key and how update rows preserve the old key; the issue includes a ClickHouse SQL reproduction to guide regression coverage. Done means a reviewed migration and tests show separate sessions remain correct through updates, FINAL, and physical merges.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Summary

The current sessions sorting key omits the session ID:

ENGINE = VersionedCollapsingMergeTree(sign, version)
PARTITION BY toYYYYMM(created_at)
ORDER BY (project_id, toDate(created_at), created_at)

If two different sessions in the same project share the same millisecond creation timestamp, rows with the same version have the same collapse identity. Updating one session can cancel the other session's row. We reproduced a wrong final result after both sessions had been updated, and it remained wrong after OPTIMIZE ... FINAL.

Versions / code

  • OpenPanel main 7f6f7f9e2b978bd0472807f586d65928f793d08c (includes #560).
  • ClickHouse 25.10.2.65, standalone.
  • Session schema migration.
  • Session update implementation: extendSession copies the existing row with sign=-1, increments the version, and writes the new positive row. This happens while ingesting ordinary events; clients do not need to issue explicit SQL updates.

The tested sorting key matches the migrated schema. The reproduction below is an engine-level test using that sorting key, rather than a full SDK regression test. No claim is made that #560 introduced this schema issue.

Reproduction

Use an isolated ClickHouse instance/database. This script creates and finally drops its own diagnostic database. original uses the current sorting key; with_id adds id. Each table receives the same input directly (the control is not copied from already-collapsed data).

  1. Create A and B with identical project/time but distinct session IDs.
  2. Update both to version 2: both implementations return correct results under FINAL.
  3. Update A again to version 3; B legitimately remains at version 2.
  4. Query with FINAL and force a physical merge.
CREATE DATABASE session_both_updated_check;
CREATE TABLE session_both_updated_check.original (id String, project_id String, created_at DateTime64(3), sign Int8, version UInt64, event_count Int32, revenue Int64) ENGINE=VersionedCollapsingMergeTree(sign,version) PARTITION BY toYYYYMM(created_at) ORDER BY(project_id,toDate(created_at),created_at);
CREATE TABLE session_both_updated_check.with_id (id String, project_id String, created_at DateTime64(3), sign Int8, version UInt64, event_count Int32, revenue Int64) ENGINE=VersionedCollapsingMergeTree(sign,version) PARTITION BY toYYYYMM(created_at) ORDER BY(project_id,toDate(created_at),created_at,id);
INSERT INTO session_both_updated_check.original VALUES ('A','p','2026-10-20 00:00:00.001',1,1,1,10),('B','p','2026-10-20 00:00:00.001',1,1,1,100),('A','p','2026-10-20 00:00:00.001',-1,1,1,10),('A','p','2026-10-20 00:00:00.001',1,2,2,20),('B','p','2026-10-20 00:00:00.001',-1,1,1,100),('B','p','2026-10-20 00:00:00.001',1,2,2,200);
INSERT INTO session_both_updated_check.with_id VALUES ('A','p','2026-10-20 00:00:00.001',1,1,1,10),('B','p','2026-10-20 00:00:00.001',1,1,1,100),('A','p','2026-10-20 00:00:00.001',-1,1,1,10),('A','p','2026-10-20 00:00:00.001',1,2,2,20),('B','p','2026-10-20 00:00:00.001',-1,1,1,100),('B','p','2026-10-20 00:00:00.001',1,2,2,200);
SELECT 'both_v2' scenario,'original' variant,id,version,sign,event_count,revenue FROM session_both_updated_check.original FINAL ORDER BY id,version FORMAT JSONEachRow;
SELECT 'both_v2' scenario,'with_id' variant,id,version,sign,event_count,revenue FROM session_both_updated_check.with_id FINAL ORDER BY id,version FORMAT JSONEachRow;
INSERT INTO session_both_updated_check.original VALUES ('A','p','2026-10-20 00:00:00.001',-1,2,2,20),('A','p','2026-10-20 00:00:00.001',1,3,3,30);
INSERT INTO session_both_updated_check.with_id VALUES ('A','p','2026-10-20 00:00:00.001',-1,2,2,20),('A','p','2026-10-20 00:00:00.001',1,3,3,30);
SELECT 'a_v3_b_v2' scenario,'original' variant,id,version,sign,event_count,revenue FROM session_both_updated_check.original FINAL ORDER BY id,version FORMAT JSONEachRow;
SELECT 'a_v3_b_v2' scenario,'with_id' variant,id,version,sign,event_count,revenue FROM session_both_updated_check.with_id FINAL ORDER BY id,version FORMAT JSONEachRow;
OPTIMIZE TABLE session_both_updated_check.original FINAL;
OPTIMIZE TABLE session_both_updated_check.with_id FINAL;
SELECT 'after_physical_merge' scenario,'original' variant,id,version,sign,event_count,revenue FROM session_both_updated_check.original ORDER BY id,version FORMAT JSONEachRow;
SELECT 'after_physical_merge' scenario,'with_id' variant,id,version,sign,event_count,revenue FROM session_both_updated_check.with_id ORDER BY id,version FORMAT JSONEachRow;
DROP DATABASE session_both_updated_check;

Actual versus expected

Stage Original key Key with id
Both reach v2 A(v2), B(v2) — correct A(v2), B(v2) — correct
A reaches v3, B remains v2; SELECT ... FINAL A(v2), A(v3); B missing A(v3), B(v2)
After OPTIMIZE TABLE ... FINAL A(v2), A(v3); B still missing A(v3), B(v2)

The final expected revenue values are A=30 and B=200. The wrong original result retains A=20 and A=30 instead. Thus even the total row count and total event_count can look correct while session attribution and other metrics are wrong.

This is not an ID collision: IDs A and B are different. Nor is the demonstrated unequal-version result fixed simply by waiting for a merge.

Important qualification: an earlier synthetic run with all sessions ending at the same version produced incorrect per-ID signed aggregates without FINAL, but reconciled correctly with FINAL. We do not use that equal-version run as evidence of permanent loss. The unequal-final-version SQL above is the evidence for this issue.

Candidate correction / questions

Adding id to the sorting key fixes this reproduction:

ORDER BY (project_id, toDate(created_at), created_at, id)

Separate test tables using this key also passed event/session/profile reconciliation in 100k and 1m ingestion/replay tests. This is a candidate correction, not a completed production migration or proof covering every lifecycle edge case.

Migration and query performance need review. Affected historical rows already physically collapsed across IDs cannot be reconstructed merely by changing the sorting key; they may require rebuilding from retained source data.

Regarding late events: created_at can move earlier, but the implementation preserves the old timestamp in the cancellation row. A separate engine-level test using the candidate key successfully moved a session across a day and across a month/partition, under both FINAL and physical merge. We therefore do not claim that changing created_at is itself another bug, or that freezing business time is required. Correctly retaining the old sorting/partition key in the negative row is essential; application-level regression coverage for this path would still be useful.

Suggested regression cases: equal versus unequal final versions at identical timestamps, interleaved updates across batches, physical merge, and late-event moves across partition boundaries. This issue is independent of Kafka rebalance/redelivery duplicates.

Ngôn ngữ chính
TypeScript
Star
7.1k
Fork
516
Merge trung bình
1 ngày 2 giờ
Pull request đã merge (30 ngày)
18

Chuẩn bị môi trường

  • Có Dockerfile hoặc tệp Docker Compose
  • Không có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Openpanel-dev/openpanel

Tất cả issue của Openpanel-dev/openpanel

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.