Release 2.0.0 and unblock compatible jobs during visual discovery #11

Merged
nimmo merged 1 commit from fix/visual-dedup-worker-concurrency into main 2026-10-02 15:25:56 +01:00
Owner

Changes

  • Promote the user-authorized first stable version to 2.0.0, keeping VERSION/package/generated OpenAPI/Nix metadata aligned.
  • Allow visual hash and candidate discovery to coexist with rip, tagging and purge. Folder scans, moves, exact dedup and visual apply modes remain exclusive.
  • Protect hash, band and candidate updates from media removed concurrently by purge, using immediate writer transactions and existence checks.
  • Clarify OPS-08 and record the regressions and version evidence in the requirement trace.

Evidence

  • Four target workers are healthy; production feedback confirmed queued work behind visual discovery.
  • Focused scheduling tests failed before the change; purge-during-hash failed with a foreign-key constraint before the guard.
  • Nine focused checks pass, including both directions of compatibility, older blocked jobs, unknown/apply-mode exclusion and hash/comparison purge races.
  • NVIDIA package build/install gate: 144 Node and 30 Python tests pass. Existing migration-fixture ResourceWarnings are unchanged.

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.

## Changes - Promote the user-authorized first stable version to 2.0.0, keeping VERSION/package/generated OpenAPI/Nix metadata aligned. - Allow visual hash and candidate discovery to coexist with rip, tagging and purge. Folder scans, moves, exact dedup and visual apply modes remain exclusive. - Protect hash, band and candidate updates from media removed concurrently by purge, using immediate writer transactions and existence checks. - Clarify OPS-08 and record the regressions and version evidence in the requirement trace. ## Evidence - Four target workers are healthy; production feedback confirmed queued work behind visual discovery. - Focused scheduling tests failed before the change; purge-during-hash failed with a foreign-key constraint before the guard. - Nine focused checks pass, including both directions of compatibility, older blocked jobs, unknown/apply-mode exclusion and hash/comparison purge races. - NVIDIA package build/install gate: 144 Node and 30 Python tests pass. Existing migration-fixture ResourceWarnings are unchanged. ## 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.
Release 2.0.0 with concurrent visual discovery jobs
All checks were successful
Build and Push Attic Cache / build (pull_request) Successful in 40s
AI pull-request review / review (pull_request) Successful in 1m54s
Build and Push Attic Cache / build (push) Successful in 58s
8515d06283
Author
Owner

Automated code review

Reviewed commit: 8515d062831e90a29c63237734a87e4f8ae20804

Verdict: 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.ts to 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.ts introduces 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

  • Potential Foreign Key Constraint Violation in ensureCurrentBands (src/similar.ts:78; medium confidence)
    The code checks for the existence of media_id in media_hashes before 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 parent media row still exists. If a purge job deletes the media row and its associated media_hashes (due to foreign key cascades) between the batch selection and this check, the subsequent remove.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_bands if a purge occurs during the rebanding phase.
    Suggested fix: Add an existence check for the media row (SELECT 1 FROM media WHERE id=?) before attempting to remove bands, similar to the check added in the save transaction. Alternatively, ensure the remove operation 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 independent function 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_PYTHON and process.env.REDVIEW_PHASH_WORKER directly. While it attempts to restore them in the finally block, 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

  • package-checks: success

Questions

  • Does the ensureCurrentBands function need to check for the existence of the media row itself, not just media_hashes, to prevent issues if the media is purged during rebanding?
  • Are there any other places in the worker code where similar concurrency issues between purge and hash/candidate operations might exist?

Review limitations

  • The review is based on the provided diff and documentation. Live testing or deeper analysis of the SQLite transaction isolation levels used by better-sqlite3 was not performed.
  • The impact of the concurrency changes on production-scale workloads with high purge rates cannot be fully assessed without load testing.

Diff coverage

  • CHANGELOG.md: reviewed — included in a context-limited batch
  • REQUIREMENTS-TRACE.md: reviewed — included in a context-limited batch
  • REQUIREMENTS.md: reviewed — included in a context-limited batch
  • VERSION: reviewed — included in a context-limited batch
  • package.json: reviewed — included in a context-limited batch
  • src/similar.ts: reviewed — included in a context-limited batch
  • src/worker.ts: reviewed — included in a context-limited batch
  • tests/visual-job-concurrency.test.mjs: reviewed — included in a context-limited batch
Review metadata
  • Reviewer: forgejo-ai-review v1
  • Model: qwen3.6:35b-a3b-q8_0
  • Guidance loaded: .forgejo/ai-review.md, .forgejo/ai-review.yml, AGENTS.md, README.md
  • Commits considered: 1
  • Previous automated review: none found
  • Findings: 3
<!-- forgejo-ai-review:v1 --> ## Automated code review Reviewed commit: `8515d062831e90a29c63237734a87e4f8ae20804` ## Verdict: 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.ts` to 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.ts` introduces 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 - **Potential Foreign Key Constraint Violation in `ensureCurrentBands`** (src/similar.ts:78; medium confidence) The code checks for the existence of `media_id` in `media_hashes` before 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 parent `media` row still exists. If a purge job deletes the `media` row and its associated `media_hashes` (due to foreign key cascades) between the batch selection and this check, the subsequent `remove.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_bands` if a purge occurs during the rebanding phase. Suggested fix: Add an existence check for the `media` row (`SELECT 1 FROM media WHERE id=?`) before attempting to remove bands, similar to the check added in the `save` transaction. Alternatively, ensure the `remove` operation 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 `independent` function 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_PYTHON` and `process.env.REDVIEW_PHASH_WORKER` directly. While it attempts to restore them in the `finally` block, 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 - package-checks: **success** ### Questions - Does the `ensureCurrentBands` function need to check for the existence of the `media` row itself, not just `media_hashes`, to prevent issues if the media is purged during rebanding? - Are there any other places in the worker code where similar concurrency issues between purge and hash/candidate operations might exist? ### Review limitations - The review is based on the provided diff and documentation. Live testing or deeper analysis of the SQLite transaction isolation levels used by `better-sqlite3` was not performed. - The impact of the concurrency changes on production-scale workloads with high purge rates cannot be fully assessed without load testing. ### Diff coverage - `CHANGELOG.md`: **reviewed** — included in a context-limited batch - `REQUIREMENTS-TRACE.md`: **reviewed** — included in a context-limited batch - `REQUIREMENTS.md`: **reviewed** — included in a context-limited batch - `VERSION`: **reviewed** — included in a context-limited batch - `package.json`: **reviewed** — included in a context-limited batch - `src/similar.ts`: **reviewed** — included in a context-limited batch - `src/worker.ts`: **reviewed** — included in a context-limited batch - `tests/visual-job-concurrency.test.mjs`: **reviewed** — included in a context-limited batch <details><summary>Review metadata</summary> - Reviewer: forgejo-ai-review v1 - Model: qwen3.6:35b-a3b-q8_0 - Guidance loaded: .forgejo/ai-review.md, .forgejo/ai-review.yml, AGENTS.md, README.md - Commits considered: 1 - Previous automated review: none found - Findings: 3 </details>
Author
Owner

I reviewed the rebanding finding against the actual transaction and schema. ensureCurrentBands calls save.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_id references media and media_hash_bands.media_id references 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.

I reviewed the rebanding finding against the actual transaction and schema. `ensureCurrentBands` calls `save.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_id` references media and `media_hash_bands.media_id` references 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.
nimmo merged commit 8515d06283 into main 2026-10-02 15:25:55 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
nimmo/redview!11
No description provided.