Skip to content

fix(cl2k): heal each asset in the Drive folder that receives its type - #466

Merged
chodeus merged 2 commits into
developfrom
fix/self-heal-drive-twin-per-image-type
Aug 7, 2026
Merged

fix(cl2k): heal each asset in the Drive folder that receives its type#466
chodeus merged 2 commits into
developfrom
fix/self-heal-drive-twin-per-image-type

Conversation

@chodeus

@chodeus chodeus commented Aug 7, 2026

Copy link
Copy Markdown
Owner

Summary

poster_self_heal paired every locally-saved row with a single Drive id — the first gdrive_uploads entry claiming poster. That was fine when one entry took posters and another took all the art, but now that each art type routes to its own folder, a generated logo / background / squareart is renamed against the poster Drive, where the file does not exist.

rclone moveto exits non-zero, apply_proposal raises before reaching the local rename, and the row never heals — silently, on every scheduled run. This matters for anyone publishing an artwork drive: downstream users syncing it never receive the corrected filenames.

The twin is now resolved from the Drive claiming the row's own image_type.

Related issue

N/A

Type of change

  • Bug fix (non-breaking)
  • New feature (non-breaking)
  • Breaking change (config migration, schema, endpoint, or UI behavior)
  • Docs only
  • Refactor / internal cleanup

Fallback order is preserved exactly: a type no Drive claims still resolves to the poster Drive, and with no poster Drive at all it resolves to the first configured Drive — the pre-redesign behaviour of healing the linked folder even with uploads off. A single-Drive or uploads-off setup therefore behaves identically to before.

Only the local source was affected. Live-Drive rows already carried the folder they were listed from, so a Drive-only setup was never broken.

Testing

  • ruff check . — clean
  • python -m pytest — 1562 passed (5 new)
  • npm run lint / prettier — untouched, no frontend change

The mapping is extracted as drive_twins() so it can be tested directly rather than only through run(). The new tests were verified to fail against the previous behaviour — regressing twin_of to return the single fallback produces:

assert twin_of("background") == "BACKGROUNDS"
E  AssertionError: assert 'POSTERS' == 'BACKGROUNDS'

Covered: per-type routing, fallback for an unclaimed type, fallback when nothing claims posters, the no-Drives case, and that a blank folder_id contributes nothing while the first claimer of a duplicated type wins.

Screenshots

N/A — no UI change.

Checklist

  • Config schema updated if applicable (backend/util/config.py) — N/A, reads existing gdrive_uploads
  • Frontend builds cleanly — N/A, no frontend change
  • No new DAPS references introduced
  • Docs / wiki drafts updated if behavior or shape changed — drive_twins() carries the rationale in its docstring
  • CHANGELOG entry added for user-visible changes — N/A, develop-only extension; release-please runs on main only

Both changed files are develop-only additions, so the branch-isolation invariant holds.

Summary by CodeRabbit

  • Bug Fixes

    • Poster self-healing now uses the Drive folder configured for each image type.
    • Added fallback behavior for poster folders when no type-specific folder is available.
    • Improved handling of empty or incomplete folder configurations.
  • Tests

    • Added coverage for image-type routing, fallback behavior, blank folder IDs, and configuration precedence.

poster_self_heal paired every locally-saved row with a single Drive id — the
first upload claiming "poster". Now that art types route to their own folders,
a generated logo/background/squareart was renamed against the POSTER Drive,
where the file does not exist. rclone moveto exits non-zero, apply_proposal
raises before the local rename, and the row never heals — silently, on every
run.

Resolve the twin from the Drive claiming the row's own image_type. A type no
Drive claims still falls back to the poster Drive, then to the first Drive at
all, preserving the uploads-off behaviour.

Extracted as drive_twins() so the mapping is testable; the new tests fail
against the previous single-id behaviour.
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4f2f1313-e041-4e07-b94a-5c7f8b2a04fa

📥 Commits

Reviewing files that changed from the base of the PR and between 95b2506 and 995423b.

📒 Files selected for processing (1)
  • backend/modules/poster_self_heal.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • backend/modules/poster_self_heal.py

📝 Walkthrough

Walkthrough

The poster self-heal module now maps image types to configured Drive folders. Local posters use the matching folder, with poster-folder and first-configured-Drive fallbacks. Tests cover routing, blank IDs, empty configurations, and first-claimant precedence.

Changes

Poster Drive routing

Layer / File(s) Summary
Drive resolver and routing coverage
backend/modules/poster_self_heal.py, tests/test_poster_self_heal_resolver.py
drive_twins selects the first valid Drive that claims an image type. It falls back to the poster Drive or the first configured Drive. Tests cover routing and edge cases.
Self-heal routing integration
backend/modules/poster_self_heal.py
run() uses image-type routing for locally saved posters and preserves the discovered folder for Drive-discovered posters.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: healing each asset in the Drive folder configured for its image type.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/self-heal-drive-twin-per-image-type

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
backend/modules/poster_self_heal.py (1)

47-56: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Reduce the drive_twins docstring to its routing contract.

This docstring contains implementation history and failure details. Keep one or two lines that state the resolver order.

Proposed change
-    """``(drive_ids, twin_of)`` for the configured ``gdrive_uploads``.
-
-    ``twin_of(image_type)`` gives the Drive folder a locally-saved row of that
-    type should be renamed in. Art types route to their own folders, so a logo
-    must heal against the logo Drive — renaming it in the poster Drive raises
-    (the file isn't there) and the row then never heals at all. First claimer
-    wins, matching ``_drive_targets``' config-order preference; a type no Drive
-    claims falls back to the poster Drive, else the first Drive at all (the
-    pre-redesign behaviour of healing the linked folder even with uploads off).
-    """
+    """Return Drive IDs and an image-type Drive resolver.
+
+    The resolver uses the first claimant, then the poster Drive, then the first Drive.
+    """
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/modules/poster_self_heal.py` around lines 47 - 56, Shorten the
docstring describing drive_twins so it only states the routing contract: resolve
using the configured upload drives in configuration order, prefer the drive
matching the image type, and fall back to the poster drive or first configured
drive when needed. Remove implementation history, failure details, and healing
behavior explanations.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@backend/modules/poster_self_heal.py`:
- Around line 47-56: Shorten the docstring describing drive_twins so it only
states the routing contract: resolve using the configured upload drives in
configuration order, prefer the drive matching the image type, and fall back to
the poster drive or first configured drive when needed. Remove implementation
history, failure details, and healing behavior explanations.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 054bef5e-508c-4cd1-941d-17a3f96bbffc

📥 Commits

Reviewing files that changed from the base of the PR and between a1842a9 and 95b2506.

📒 Files selected for processing (2)
  • backend/modules/poster_self_heal.py
  • tests/test_poster_self_heal_resolver.py

The rationale and failure mode belong in the PR body, not the source.
@chodeus

chodeus commented Aug 7, 2026

Copy link
Copy Markdown
Owner Author

Trimmed in 995423b — the docstring now states just the resolver order (first claimant → poster Drive → first Drive). Agreed on the principle: the failure mode and the history belong in the PR body, which already carries them.

For the record, the repo style rule the path instructions are enforcing is the right call here — it was the one place this change duplicated prose that already exists above.

@chodeus
chodeus merged commit c2c3ee9 into develop Aug 7, 2026
12 checks passed
@chodeus
chodeus deleted the fix/self-heal-drive-twin-per-image-type branch August 7, 2026 06:11
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