Skip to content

Commit 618c4ff

Browse files
authored
Merge pull request #141 from cporcellijr/fix/remove-storyteller-fallback
* [Fix] Remove Storyteller fallback collection logic * [Fix] Optimize SyncManager self-healing logic
2 parents c501aed + 8486574 commit 618c4ff

File tree

3 files changed

+11
-29
lines changed

3 files changed

+11
-29
lines changed

src/sync_manager.py

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,10 +1077,7 @@ def _sync_cycle_internal(self, target_abs_id=None):
10771077

10781078
try:
10791079
# -----------------------------------------------------------------
1080-
# SPARSE MAP DETECTOR (Self-Healing)
1081-
# If a book was aligned under the old N=12 logic, it might have
1082-
# sparse anchors. This forces them back to the background queue
1083-
# to get a dense Pass 3/4 map without blocking the UI cycle.
1080+
# MIGRATION UPGRADE
10841081
# -----------------------------------------------------------------
10851082
if self.alignment_service:
10861083
alignment = self.alignment_service._get_alignment(abs_id)
@@ -1091,24 +1088,6 @@ def _sync_cycle_internal(self, target_abs_id=None):
10911088
book.transcript_file = 'DB_MANAGED'
10921089
self.database_service.save_book(book)
10931090

1094-
if len(alignment) > 2:
1095-
last_ts = float(alignment[-1].get('ts', 0))
1096-
anchor_count = len(alignment)
1097-
avg_gap = last_ts / anchor_count if anchor_count > 0 else 0
1098-
1099-
if avg_gap > 45.0:
1100-
logger.info(f" 🩹 Self-Healing: Sparse alignment map detected (avg gap {avg_gap:.1f}s). Queuing for dense re-processing.")
1101-
book.status = 'pending'
1102-
self.database_service.save_book(book)
1103-
continue
1104-
else:
1105-
# Alignment map is completely missing
1106-
if getattr(book, 'sync_mode', 'audiobook') != 'ebook_only':
1107-
logger.info(f" 🩹 Self-Healing: Missing alignment map detected for '{title_snip}'. Queuing for deep anchoring.")
1108-
book.status = 'pending'
1109-
self.database_service.save_book(book)
1110-
continue
1111-
11121091
# Get previous state for this book from database
11131092
previous_states = self.database_service.get_states_for_book(abs_id)
11141093

@@ -1262,6 +1241,15 @@ def _sync_cycle_internal(self, target_abs_id=None):
12621241
# At this point we have a significant change to act on
12631242
logger.info(f"🔄 '{abs_id}' '{title_snip}' Change detected")
12641243

1244+
# [NEW] Missing Map Check (Deep Anchoring)
1245+
# Only heal if progress is actively happening to avoid unnecessary processing
1246+
if getattr(book, 'sync_mode', 'audiobook') != 'ebook_only':
1247+
if self.alignment_service and not self.alignment_service._get_alignment(abs_id):
1248+
logger.info(f" 🩹 Self-Healing: Missing deep anchoring map detected after progress on '{title_snip}'. Queuing for processing.")
1249+
book.status = 'pending'
1250+
self.database_service.save_book(book)
1251+
continue
1252+
12651253
# Status block - show only changed lines
12661254
status_lines = []
12671255
for key, cfg in config.items():

src/web_server.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,9 +1333,6 @@ def match():
13331333
if container.storyteller_client().is_configured():
13341334
if book.storyteller_uuid:
13351335
container.storyteller_client().add_to_collection_by_uuid(book.storyteller_uuid)
1336-
else:
1337-
fallback_name = original_ebook_filename or ebook_filename
1338-
container.storyteller_client().add_to_collection(fallback_name)
13391336

13401337
# Auto-dismiss any pending suggestion for this book
13411338
# Need to dismiss by BOTH abs_id (audiobook-triggered) and kosync_doc_id (ebook-triggered)
@@ -1498,9 +1495,6 @@ def batch_match():
14981495
if container.storyteller_client().is_configured():
14991496
if book.storyteller_uuid:
15001497
container.storyteller_client().add_to_collection_by_uuid(book.storyteller_uuid)
1501-
else:
1502-
fallback_name = original_ebook_filename or ebook_filename
1503-
container.storyteller_client().add_to_collection(fallback_name)
15041498

15051499
# Auto-dismiss any pending suggestion
15061500
database_service.dismiss_suggestion(item['abs_id'])

tests/test_webserver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def test_match_endpoint_with_clean_di(self):
439439

440440
self.mock_abs_client.add_to_collection.assert_called_once_with('test-audiobook-123', 'Synced with KOReader')
441441
self.mock_booklore_client.add_to_shelf.assert_called_once_with('test-book.epub', 'Kobo')
442-
self.mock_storyteller_client.add_to_collection.assert_called_once_with('test-book.epub')
442+
self.mock_storyteller_client.add_to_collection.assert_not_called()
443443

444444
print("[OK] Match endpoint test passed with clean DI")
445445

0 commit comments

Comments
 (0)