feat(halacha): חילוץ מצטבר crash-safe + resume (A + resume) #31

Merged
chaim merged 1 commits from feat/halacha-incremental-resume into main 2026-05-31 21:28:20 +00:00
Owner

הבעיה

חילוץ הלכות החזיק את כל תוצאות ה-chunks בזיכרון ושמר פעם אחת בסוף. קריסה/הפסקה באמצע (כמו ה-freeze של 2026-05-31) = אובדן הכל + תשלום-מחדש על כל ה-LLM. (אישרת A + resume.)

הפתרון

כל chunk שמסתיים → ההלכות שלו נשמרות מיד וה-chunk מסומן (precedent_chunks.halacha_extracted_at):

  • V25: עמודת checkpoint per-chunk.
  • store_halachot_for_chunk: insert אטומי per-chunk (אינדקס ממשיך מ-MAX, serialization ב-store-lock) + סימון.
  • reset_halacha_extraction (force) / mark_all_chunks_extracted (legacy backfill).
  • _extract_impl נכתב מחדש: ברירת-מחדל resume (מדלג על chunks מסומנים; chunk שנכשל נשאר pending ומנוסה שוב; status נשאר processing עד שהכל done); force=True מוחק+מחדש הכל. reextract_halachot→force=True; ניקוי-התור (process_pending)→resume.
  • Legacy guard: פסק pre-V25 (יש הלכות, אין checkpoints) → backfill + נחשב done, לא מחולץ מחדש (היה משכפל).

אימות

  • 9002-24 (55 הלכות, legacy): resume → legacy-backfill, 0 שכפול (נשאר 55), כל ה-chunks מסומנים.
  • המשך-אינדקס: שמירה ב-55,56 אחרי max=54 — אין collision; ניקוי תקין.

עוקב #72. נכנס לתוקף ב-spawn הבא של ה-MCP (קוד טרי).

🤖 Generated with Claude Code

## הבעיה חילוץ הלכות החזיק את **כל** תוצאות ה-chunks בזיכרון ושמר פעם אחת **בסוף**. קריסה/הפסקה באמצע (כמו ה-freeze של 2026-05-31) = **אובדן הכל** + תשלום-מחדש על כל ה-LLM. (אישרת A + resume.) ## הפתרון כל chunk שמסתיים → ההלכות שלו נשמרות מיד **וה-chunk מסומן** (`precedent_chunks.halacha_extracted_at`): - **V25**: עמודת checkpoint per-chunk. - **`store_halachot_for_chunk`**: insert אטומי per-chunk (אינדקס ממשיך מ-MAX, serialization ב-store-lock) + סימון. - **`reset_halacha_extraction`** (force) / **`mark_all_chunks_extracted`** (legacy backfill). - **`_extract_impl` נכתב מחדש**: ברירת-מחדל **resume** (מדלג על chunks מסומנים; chunk שנכשל נשאר pending ומנוסה שוב; status נשאר `processing` עד שהכל done); `force=True` מוחק+מחדש הכל. `reextract_halachot`→force=True; ניקוי-התור (process_pending)→resume. - **Legacy guard**: פסק pre-V25 (יש הלכות, אין checkpoints) → backfill + נחשב done, **לא** מחולץ מחדש (היה משכפל). ## אימות - **9002-24** (55 הלכות, legacy): resume → legacy-backfill, **0 שכפול** (נשאר 55), כל ה-chunks מסומנים. - **המשך-אינדקס**: שמירה ב-55,56 אחרי max=54 — אין collision; ניקוי תקין. עוקב #72. נכנס לתוקף ב-spawn הבא של ה-MCP (קוד טרי). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
chaim added 1 commit 2026-05-31 21:28:12 +00:00
Halacha extraction held ALL chunk results in memory and stored once at the very
end — a crash/interrupt mid-run (e.g. the 2026-05-31 freeze) lost everything and
re-paid the full LLM cost on retry.

Now each chunk's halachot are stored AND the chunk is checkpointed
(precedent_chunks.halacha_extracted_at) the moment it finishes:

- V25 schema: precedent_chunks.halacha_extracted_at (per-chunk checkpoint).
- db.store_halachot_for_chunk: atomic per-chunk insert (halacha_index continues
  from MAX, caller serializes via an in-process store-lock) + checkpoint mark.
- db.reset_halacha_extraction (force) / mark_all_chunks_extracted (legacy backfill).
- _extract_impl rewritten: resume by default (skip checkpointed chunks; failed
  chunks stay pending and are retried; status stays 'processing' until all done);
  force=True wipes + redoes all. reextract_halachot passes force=True; the queue
  drain (process_pending) resumes by default.
- Legacy guard: a pre-V25 precedent (halachot exist, no checkpoints) is
  backfilled and treated as complete — never re-extracted (would duplicate).

Verified on 9002-24 (55 halachot, legacy): resume → legacy-backfill, NO
duplication (stays 55), all chunks checkpointed. Index continuation: store at
55,56 after max 54, no collision. Tracks #72.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
chaim merged commit acfd5bae3e into main 2026-05-31 21:28:20 +00:00
chaim deleted branch feat/halacha-incremental-resume 2026-05-31 21:28:20 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ezer-mishpati/legal-ai#31