Release 2.0.0 and unblock compatible jobs during visual discovery #11
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/visual-dedup-worker-concurrency"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Changes
Evidence
Remaining acceptance
Operator activation and confirmation that the real production queue advances. No production jobs or media were changed by the disposable tests. Version promotion alone does not publish a Git tag.
Automated code review
Reviewed commit:
8515d062831e90a29c63237734a87e4f8ae20804Verdict: Requires further work
Resolve the blocking or important findings and investigate failed deterministic checks before merging.
Overall assessment
This pull request promotes Redview to version 2.0.0 and implements a concurrency fix for visual discovery jobs. The primary code change modifies the job claiming logic in
src/worker.tsto allow non-destructive visual hashing (hash_only,scan) to run concurrently with rip, tagging, and purge jobs, while maintaining exclusivity for destructive operations (moves, exact dedup, apply modes). Additionally,src/similar.tsintroduces existence checks and immediate writer transactions to prevent foreign key constraint violations when media is purged during the hashing or comparison phases. Documentation and requirements traces are updated to reflect these changes.Blocking findings
None.
Important findings
ensureCurrentBands(src/similar.ts:78; medium confidence)The code checks for the existence of
media_idinmedia_hashesbefore removing bands:if (!ctx.db.prepare('SELECT 1 FROM media_hashes WHERE media_id=?').get(row.media_id)) continue;. However, it does not check if the parentmediarow still exists. If a purge job deletes themediarow and its associatedmedia_hashes(due to foreign key cascades) between the batch selection and this check, the subsequentremove.run(row.media_id)might fail or leave orphaned bands if the cascade hasn't completed or if the transaction isolation is insufficient.Impact: Could lead to database integrity errors or orphaned data in
media_hash_bandsif a purge occurs during the rebanding phase.Suggested fix: Add an existence check for the
mediarow (SELECT 1 FROM media WHERE id=?) before attempting to remove bands, similar to the check added in thesavetransaction. Alternatively, ensure theremoveoperation is wrapped in a transaction that handles potential missing rows gracefully.Suggestions
Hardcoded SQL String in Worker Claim Logic (src/worker.ts:135; medium confidence)
The
independentfunction constructs a SQL string using template literals:const independent = (alias: string) => .... This string is then interpolated into the main query. While functional, this approach can be harder to maintain and review than parameterized queries or separate helper functions.Impact: Maintainability and readability of the concurrency logic.
Suggested fix: Consider refactoring the claim predicate into a more structured format or using a query builder if available, to improve clarity and reduce the risk of SQL injection (though currently safe due to controlled inputs) or syntax errors.
Test Environment Variable Pollution (tests/visual-job-concurrency.test.mjs:45; medium confidence)
The test modifies
process.env.REDVIEW_PYTHONandprocess.env.REDVIEW_PHASH_WORKERdirectly. While it attempts to restore them in thefinallyblock, if a test fails or throws before restoration, subsequent tests might be affected.Impact: Test flakiness or interference between tests.
Suggested fix: Use a more robust environment variable management strategy, such as storing the original values in a map and restoring them only after all tests have run, or using a test framework feature for environment isolation.
Tests and validation
Questions
ensureCurrentBandsfunction need to check for the existence of themediarow itself, not justmedia_hashes, to prevent issues if the media is purged during rebanding?Review limitations
better-sqlite3was not performed.Diff coverage
CHANGELOG.md: reviewed — included in a context-limited batchREQUIREMENTS-TRACE.md: reviewed — included in a context-limited batchREQUIREMENTS.md: reviewed — included in a context-limited batchVERSION: reviewed — included in a context-limited batchpackage.json: reviewed — included in a context-limited batchsrc/similar.ts: reviewed — included in a context-limited batchsrc/worker.ts: reviewed — included in a context-limited batchtests/visual-job-concurrency.test.mjs: reviewed — included in a context-limited batchReview metadata
I reviewed the rebanding finding against the actual transaction and schema.
ensureCurrentBandscallssave.immediate(batch): SQLite acquires the writer lock before the existence check, so a concurrent purge cannot interleave between that check and band insertion.media_hashes.media_idreferences media andmedia_hash_bands.media_idreferences media_hashes, both with ON DELETE CASCADE; worker connections enable foreign_keys. The check therefore tests the band's direct parent. A completed purge makes that check false; an in-progress purge completes before this transaction can begin. DELETE of an absent band is harmless. There is no window with a partially completed foreign-key cascade. The new hash-save and comparison guards address the real asynchronous/batch-selection windows.The SQL aliases are fixed internal literals, not request input. The test environment overrides are enclosed in try/finally with restoration or deletion of previously absent variables; the test cases run sequentially. A query builder or additional parent check would not add protection for these cases.
The final installed release package also passed all nine focused scheduling/purge-race checks on the target host using disposable databases/files. This does not claim real production queue acceptance before the operator activates the update.