aw-sync: events at a page boundary are synced with duration 0 (clipped re-fetch), permanently

Đang mở
#874 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

@TimeToBuildBob đang làm issue này rồi.

Từ ngày 25/11/2026.

  • #905 của @TimeToBuildBob — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
Nửa ngày
Mức phù hợp với người mới
70/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ệ
rust
Lĩnh vực
backend, data

Hướng nghiên cứu

Start in aw-sync/src/sync.rs at sync_one (around lines 1215–1245), where the page boundary run is dropped and re-fetched with fetch_end = Some(boundary_ts), then compare with the cut - 1ns workaround in dedupe.rs. Run the repro test in boundary_dedup_multipage_tests first; it fails with left 100, right 120. Done means that test passes, every boundary event keeps its duration, and the existing multipage tests still pass. Either re-fetch the boundary run with get_events_unclipped or page with end = boundary_ts - 1ns.

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

Mô tả

When sync_one (aw-sync/src/sync.rs ~1215–1245) gets a full page, it drops the run of events at the page's oldest timestamp (boundary_ts) and re-fetches it on the next page with fetch_end = Some(boundary_ts). But get_events clips results to the query end (parse_event_row). Every event that starts at boundary_ts therefore comes back as (boundary_ts, duration 0) and is inserted into the destination that way.

dedupe.rs already documents this clipping and works around it with cut - 1ns. sync_one does not.

Effect: on any pass that copies more than one page (5000 events) of a bucket, one event per page boundary lands with duration 0. That includes every first sync of a real bucket and catch-up after time offline. Later passes don't repair it, because the (timestamp, duration) identity no longer matches. The loss is silent and permanent, and on AFK buckets a single event can be hours long. It affects pull (peer → local) and push (local → staging → every peer).

Repro: add this test to boundary_dedup_multipage_tests in aw-sync/src/sync.rs, where BATCH_SIZE is small. It fails on master ea6f09c with left: 100, right: 120, and the boundary events come back at 0 s.

#[test]
fn page_boundary_event_keeps_its_duration() {
    let ds_src = Datastore::new_in_memory(false);
    let ds_dest = Datastore::new_in_memory(false);
    let bucket: Bucket = serde_json::from_value(serde_json::json!({
        "id": "bucket-0", "type": "test", "hostname": "device-0", "client": "test"
    })).unwrap();
    ds_src.create_bucket(&bucket).unwrap();
    let base_ts: DateTime<Utc> = Utc::now() - Duration::hours(1);
    let events: Vec<Event> = (0..12).map(|i| serde_json::from_value(serde_json::json!({
        "timestamp": (base_ts + Duration::seconds(i * 10)).to_rfc3339(),
        "duration": 10.0,
        "data": {"title": format!("w{i}")}
    })).unwrap()).collect();
    ds_src.insert_events("bucket-0", &events).unwrap();
    ds_src.force_commit().unwrap();

    sync_datastores(&ds_src, &ds_dest, false, None, &SyncSpec::default()).unwrap();
    let got = ds_dest.get_events("bucket-0-synced-from-device-0", None, None, None).unwrap();
    let total: i64 = got.iter().map(|e| e.duration.num_seconds()).sum();
    assert_eq!(got.len(), 12);
    assert_eq!(total, 120, "every event must keep its duration across page boundaries");
}

The existing multipage tests check counts and duplicates, not durations, which is why they pass.

Suggested fix: re-fetch the boundary run unclipped (get_events_unclipped already exists on the datastore), or page with end = boundary_ts - 1ns and keep the boundary run whole, as dedupe.rs does. #789 keeps this timestamp path for push and its fallback, so it does not fix this.

Ngôn ngữ chính
Rust
Star
322
Fork
107
Merge trung bình
2 ngày 16 giờ
Pull request đã merge (30 ngày)
25

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

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

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 ActivityWatch/aw-server-rust

Tất cả issue của ActivityWatch/aw-server-rust

Issue tương tự

Thêm issue về Rust

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.