Skip to content

Enforce .valid requirement for remote pulls and add progress tracking to image/PDF syncs#558

Draft
Copilot wants to merge 6 commits intomainfrom
copilot/improve-sync-process
Draft

Enforce .valid requirement for remote pulls and add progress tracking to image/PDF syncs#558
Copilot wants to merge 6 commits intomainfrom
copilot/improve-sync-process

Conversation

Copy link
Contributor

Copilot AI commented Jan 29, 2026

Problem

Remote document pulls had a "legacy migration" path importing documents without .valid markers, defeating the corruption-prevention mechanism. Progress notifications only worked for data sync, leaving image and PDF syncs silent.

Changes

Strict .valid enforcement for pulls

Removed legacy migration from importDocumentFromRemote(). Documents without .valid are now skipped:

override async importDocumentFromRemote(data: FileStat) {
    const hasValid = await this.hasValidMarker(data.basename);
    if (!hasValid) {
        return;  // Skip, don't import
    }
    // ... rest of import
}

Push operations (addDocumentToRemote(), syncDocumentOnRemote()) still create .valid markers, enabling subsequent pulls.

Progress tracking for image and PDF syncs

Added progress calculations and updateSyncProgress() calls to match data sync behavior:

  • Image sync: Per-page granularity (total pages across all documents)
  • PDF sync: Per-document granularity
// syncImageDocuments()
const totalPages = documentsToSync.reduce((sum, d) => sum + d.pages.length, 0);
// ... after each page:
this.updateSyncProgress('image', currentPageIndex, totalPages, doc.id, doc.name);

// syncPDFDocuments()
const totalDocuments = documentsToSync.length;
// ... after each document:
this.updateSyncProgress('pdf', currentDocIndex, totalDocuments, doc.id, doc.name);

Android foreground notifications now update for all sync types, preventing process termination.

Files Modified

  • app/services/sync/WebdavDataSyncService.ts (-18 lines)
  • app/workers/SyncWorker.ts (+16 lines)
Original prompt

I would like you to improve the sync process running through services/sync.ts and the corresponding worker in SyncWorker.ts

  • on android we need a notification to be seen while sync is in progress so that the system does not kill us if we go to backgroud during sync. It is hard to compute a progress for the sync service. If you can find a way implement it (we need to compute the the number of documents to sync and maybe even the size before hand for PDF, Images, Data, we could also first create a list of everyting to "sync" for all services/types, compute the progress and then start the actual sync with progress).
  • we are facing issues with stopped data sync during progress where in webdav you can end up with partially missing files which could make future sync fail with errors (like missing data.json). So i need the data sync process to be "safer". I am thinking:
  • use a .valid 0kb file pushed for each document folder
  • when starting sync for one folder:
  • if pulling from remote: if no .valid file on remote -> not valid -> remove remote document folder. Otherwise pull as it is ok to sync
  • if pushing to remote: if doc folder exists and .valid exists remove it first. Then push all. When done push a .valid file to say "valid" for future sync.

My only issue is how do we do now for existing synced document as they dont have .valid file? if we implement this and just run it first pull would remove the docs as it does not have a .valid file.
Try to find a solution before implementing


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 29, 2026 14:40
Co-authored-by: farfromrefug <655344+farfromrefug@users.noreply.github.com>
Co-authored-by: farfromrefug <655344+farfromrefug@users.noreply.github.com>
Copilot AI changed the title [WIP] Improve sync process in sync.ts and SyncWorker.ts Add .valid markers and Android foreground notifications for sync safety Jan 29, 2026
Copilot AI requested a review from farfromrefug January 29, 2026 14:51
…yncDocumentOnRemote

Co-authored-by: farfromrefug <655344+farfromrefug@users.noreply.github.com>
Copilot AI changed the title Add .valid markers and Android foreground notifications for sync safety Fix .valid marker migration for unchanged documents Jan 29, 2026
Copilot AI and others added 2 commits January 30, 2026 08:37
…om remote

Co-authored-by: farfromrefug <655344+farfromrefug@users.noreply.github.com>
Co-authored-by: farfromrefug <655344+farfromrefug@users.noreply.github.com>
Copilot AI changed the title Fix .valid marker migration for unchanged documents Enforce .valid requirement for remote pulls and add progress tracking to image/PDF syncs Jan 30, 2026
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.

2 participants