fix(sync): include needUpload/needSyncMtime in initial pull-ack decision - #22
fix(sync): include needUpload/needSyncMtime in initial pull-ack decision#22lyston11 wants to merge 1 commit into
Conversation
The server (fast-note-sync-service >= 3.5.0) delivers download detail frames (NoteSyncNeedPush / NoteSyncModify / NoteSyncMtime / NoteSyncDelete and their file/setting counterparts) through a paged download channel. It only sends a page after the client sends the initial pull ack (XxxSyncPageAck with pageIndex=-1). All four sync modules computed `total_expected = needModify + needDelete` to decide whether to send that initial ack. This silently dropped uploads and mtime-only syncs: when the server reported needUploadCount > 0 but needModify/needDelete == 0 (the common case of local-new-notes-only), total_expected was 0, the initial ack was never sent, the download pump never started, and NoteSyncNeedPush never reached the client — so the new note was never uploaded. The CLI logged "Sync complete" and committed lastTime anyway. Fix: add _expected_upload / _expected_mtime counters in note_sync, file_sync, and setting_sync (folder_sync has no upload/mtime in its End message), include them in total_expected for both the initial-ack decision and the completion check, and credit the corresponding detail handlers (NoteSyncNeedPush / NoteSyncMtime / NoteSyncRename; FileUpload / FileSyncMtime; SettingSyncNeedUpload / SettingSyncMtime) with the received count so _check_all_received/_check_complete can finish. Verified end-to-end against fast-note-sync-service 3.6.1: a vault with only a local-new note now triggers the initial ack, receives NoteSyncNeedPush, uploads via NoteModify, and the note lands on the server. Also ignore local test artifacts (.venv/, config-test.yaml, vault/).
Reviewer's GuideFixes paged sync deadlocks by incorporating upload and mtime counts into initial pull-ack and completion logic across note, file, and setting synchronization, and credits their corresponding detail handlers so upload-only or mtime-only syncs complete correctly. Sequence diagram for upload-only paged syncsequenceDiagram
participant Client
participant SyncModule
participant Server
Server->>SyncModule: SyncEnd(needUploadCount > 0)
SyncModule->>SyncModule: _on_sync_end()
SyncModule->>Server: XxxSyncPageAck(pageIndex=-1)
Server-->>SyncModule: NoteSyncNeedPush / FileUpload / SettingSyncNeedUpload
SyncModule->>Server: NoteModify via push_modify()
SyncModule->>SyncModule: _check_all_received()
Flow diagram for upload and mtime completion accountingflowchart TD
A[SyncEnd counts] --> B{total_expected > 0?}
B -->|No| C[Commit last time]
B -->|Yes| D[Send initial page ack]
D --> E[Paged detail handlers]
E --> F[Credit received count]
F --> G{total_received >= total_expected?}
G -->|No| E
G -->|Yes| H[Complete sync]
A --> A1[needModify + needDelete + needUpload + needSyncMtime]
E --> E1[Upload, modify, delete, rename, or mtime detail]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've reviewed your changes and they look great!
Sourcery assessment
Needs a human reviewer. This changes synchronization behavior so the client begins requesting and applying upload, modification, deletion, and mtime pages that were previously skipped. If the counts or received-item accounting are wrong, the client could apply incomplete or incorrect file updates, and upload stale content to the server; reverting would not undo those already-applied or uploaded changes, though they are generally bounded and repairable by resynchronizing or restoring files.
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
The server (fast-note-sync-service >= 3.5.0) delivers download detail frames (NoteSyncNeedPush / NoteSyncModify / NoteSyncMtime / NoteSyncDelete and their file/setting counterparts) through a paged download channel. It only sends a page after the client sends the initial pull ack (XxxSyncPageAck with pageIndex=-1).
All four sync modules computed
total_expected = needModify + needDeleteto decide whether to send that initial ack. This silently dropped uploads and mtime-only syncs: when the server reported needUploadCount > 0 but needModify/needDelete == 0 (the common case of local-new-notes-only), total_expected was 0, the initial ack was never sent, the download pump never started, and NoteSyncNeedPush never reached the client — so the new note was never uploaded. The CLI logged "Sync complete" and committed lastTime anyway.Fix: add _expected_upload / _expected_mtime counters in note_sync, file_sync, and setting_sync (folder_sync has no upload/mtime in its End message), include them in total_expected for both the initial-ack decision and the completion check, and credit the corresponding detail handlers (NoteSyncNeedPush / NoteSyncMtime / NoteSyncRename; FileUpload / FileSyncMtime; SettingSyncNeedUpload / SettingSyncMtime) with the received count so _check_all_received/_check_complete can finish.
Verified end-to-end against fast-note-sync-service 3.6.1: a vault with only a local-new note now triggers the initial ack, receives NoteSyncNeedPush, uploads via NoteModify, and the note lands on the server.
Also ignore local test artifacts (.venv/, config-test.yaml, vault/).
Summary by Sourcery
Prevent sync operations from silently completing without applying upload and mtime-only changes.
Bug Fixes:
Enhancements:
Chores: