Skip to content

Fix checksum status reset bug preventing unnecessary recalculation on restart - #25

Merged
MarkProminic merged 1 commit into
mainfrom
devin/1758789733-fix-checksum-status-reset
Sep 25, 2025
Merged

MarkProminic merged 1 commit into
mainfrom
devin/1758789733-fix-checksum-status-reset

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Fix checksum status reset bug preventing unnecessary recalculation on restart

Summary

Fixed a critical performance bug where the file watcher was resetting checksum status from complete to pending for thousands of existing files on every application restart, causing massive unnecessary checksum recalculation.

Root Cause: The cacheItemInfoWithStats method (triggered by chokidar's add events for existing files during startup with ignoreInitial: false) was always setting checksum_status: 'pending', overwriting the correct complete status that was preserved during initial directory scan.

Solution: Modified cacheItemInfoWithStats to:

  • Check existing database records before updating
  • Preserve existing checksum_status instead of always setting to pending
  • Only queue checksums when actually needed (new files, changed files, failed checksums)
  • Match the intelligent behavior of cacheItemInfoWithLookup

Review & Testing Checklist for Human

⚠️ HIGH PRIORITY - 4 critical items to verify:

  • Restart behavior: Restart the application and verify existing files with valid checksums are NOT re-queued (SQL: SELECT COUNT(*) as total, checksum_status FROM files GROUP BY checksum_status - should show minimal pending files after restart)
  • New file detection: Upload/SFTP a new file and verify it gets detected and checksum calculated
  • Modified file detection: Modify an existing file and verify checksum gets recalculated
  • Performance impact: Monitor startup time and database query performance with the added findOne calls per file

Notes

This change affects a critical system component and adds database queries during startup. The fix prevents thousands of unnecessary checksum calculations (user reported 3,324 files being reset to pending on restart) but introduces per-file database lookups during chokidar initialization.

Link to Devin run: https://app.devin.ai/sessions/a84f1763f38f47c7a556fc6af605272c
Requested by: @MarkProminic

…necessary recalculation on restart

- Modified cacheItemInfoWithStats to check existing database records before updating
- Preserve existing checksum_status instead of always setting to 'pending'
- Only queue checksums when actually needed (new files, changed files, or failed checksums)
- Matches intelligent behavior of cacheItemInfoWithLookup method
- Fixes bug where 3,324+ files were reset from 'complete' to 'pending' on restart
- Root cause: chokidar ignoreInitial:false emits add events for existing files during startup

Co-Authored-By: mark.gilbert@prominic.net <mark.gilbert@prominic.net>
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@MarkProminic
MarkProminic merged commit 13c8669 into main Sep 25, 2025
1 of 4 checks passed
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.

1 participant