fix(precedents): מראה-מקום never blank — seed at upload + inline Gemini enrichment #318

Merged
chaim merged 1 commits from worktree-citation-autofill-root into main 2026-06-20 15:30:40 +00:00
Owner

שורש הבעיה

שדה "מראה המקום" בטופס-ההעלאה נשמר רק כ-case_number; citation_formatted נשאר ריק וממולא רק ע"י חילוץ-המטא האסינכרוני שרץ ב-drainer המקומי (לא בקונטיינר) — כי הוא לוכד יחד עם חילוץ-ההלכות. לכן היו"ר ראה מראה-מקום ריק בחלון-הזמן ומילא ידנית.

הפתרון (היברידי — שלב: הקלדה מיידית + העשרת-LLM)

  • Seed: _create_external_record/create_external_case_law שומרים את הציטוט שהיו"ר הקליד כ-citation_formatted כבר ב-INSERT → השדה לעולם לא ריק. קידום cited_only→external משמר ערך קיים (עריכה קודמת).
  • Enrich: ingest_precedent מריץ חילוץ-מטא inline בקונטיינר (gemini_session = REST ישיר, ללא CLI מקומי) עם force_citation=True — משדרג את ה-seed לציטוט הקנוני (צדדים + נבו + תאריך) לפני שהיו"ר פותח את הדף. Best-effort: בלי מפתח / כשל-API ה-seed נשאר וה-drainer המקומי הוא fallback. חילוץ-הלכות לא נוגעים בו (נשאר מקומי — claude_session).
  • apply_to_record/extract_and_apply מקבלים force_citation: מרכיבים-מחדש גם כשהשדה לא-ריק, אך כותבים רק כשההרכבה מצליחה (ה-seed נשמר באבסטנציה). ה-drainer נשאר בברירת-מחדל (False) כך שעריכה ידנית של היו"ר ב-/precedents/[id] לא נדרסת.

אופס

GOOGLE_GEMINI_API_KEY נוסף ל-Coolify של legal-ai (runtime) — הערך מ-Infisical nautilus:/external-apis/gemini, אומת מול ה-API (מחזיר את רשימת המודלים).

אימות

  • ast.parse נקי לשלושת המודולים. ספירת placeholders/params ב-INSERT תואמת (18/18).
  • בדיקה ידנית לאחר deploy: העלאת תקדים → מראה-מקום מלא מיידית.

Invariants

  • G2 — מסלול-פתרון-ציטוט אחד + מסלול-חילוץ-מטא אחד, בשימוש-חוזר (אין לוגיקה מקבילה).
  • INV-ID2 / X1§3citation_formatted נשאר שדה-נגזר; ה-seed provisional ומשודרג.
  • INV-G10 — עריכות-יו"ר נשמרות (force_citation רק בקליטה, לא ב-drainer).
  • ללא שינוי-סכמה.

🤖 Generated with Claude Code

## שורש הבעיה שדה "מראה המקום" בטופס-ההעלאה נשמר רק כ-`case_number`; `citation_formatted` נשאר ריק וממולא **רק** ע"י חילוץ-המטא האסינכרוני שרץ ב-drainer המקומי (לא בקונטיינר) — כי הוא לוכד יחד עם חילוץ-ההלכות. לכן היו"ר ראה מראה-מקום ריק בחלון-הזמן ומילא ידנית. ## הפתרון (היברידי — שלב: הקלדה מיידית + העשרת-LLM) - **Seed:** `_create_external_record`/`create_external_case_law` שומרים את הציטוט שהיו"ר הקליד כ-`citation_formatted` כבר ב-INSERT → השדה לעולם לא ריק. קידום `cited_only→external` משמר ערך קיים (עריכה קודמת). - **Enrich:** `ingest_precedent` מריץ חילוץ-מטא **inline בקונטיינר** (`gemini_session` = REST ישיר, ללא CLI מקומי) עם `force_citation=True` — משדרג את ה-seed לציטוט הקנוני (צדדים + נבו + תאריך) לפני שהיו"ר פותח את הדף. Best-effort: בלי מפתח / כשל-API ה-seed נשאר וה-drainer המקומי הוא fallback. **חילוץ-הלכות לא נוגעים בו** (נשאר מקומי — `claude_session`). - `apply_to_record`/`extract_and_apply` מקבלים `force_citation`: מרכיבים-מחדש גם כשהשדה לא-ריק, אך כותבים רק כשההרכבה **מצליחה** (ה-seed נשמר באבסטנציה). ה-drainer נשאר בברירת-מחדל (False) כך שעריכה ידנית של היו"ר ב-`/precedents/[id]` לא נדרסת. ## אופס `GOOGLE_GEMINI_API_KEY` נוסף ל-Coolify של legal-ai (runtime) — הערך מ-Infisical `nautilus:/external-apis/gemini`, אומת מול ה-API (מחזיר את רשימת המודלים). ## אימות - `ast.parse` נקי לשלושת המודולים. ספירת placeholders/params ב-INSERT תואמת (18/18). - בדיקה ידנית לאחר deploy: העלאת תקדים → מראה-מקום מלא מיידית. ## Invariants - **G2** — מסלול-פתרון-ציטוט אחד + מסלול-חילוץ-מטא אחד, בשימוש-חוזר (אין לוגיקה מקבילה). - **INV-ID2 / X1§3** — `citation_formatted` נשאר שדה-נגזר; ה-seed provisional ומשודרג. - **INV-G10** — עריכות-יו"ר נשמרות (`force_citation` רק בקליטה, לא ב-drainer). - ללא שינוי-סכמה. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
chaim added 1 commit 2026-06-20 15:30:33 +00:00
fix(precedents): מראה-מקום never blank — seed at upload + inline Gemini enrichment (root cause)
All checks were successful
G12 Leak-Guard / leak-guard (pull_request) Successful in 4s
Lint — undefined names / undefined-names (pull_request) Successful in 11s
b0bcdbeeef
Root cause: the upload form "מראה המקום" field is stored only as case_number;
citation_formatted was left empty and filled ONLY by the async metadata
extraction, which runs in the local drainer (not the container) because it was
lumped with halacha extraction. Result: the chair saw an empty מראה-מקום during
the window and re-typed it by hand.

Fix (hybrid — Option C):
- Seed: _create_external_record / create_external_case_law store the chair's typed
  citation as citation_formatted at INSERT, so the field is never blank. A
  cited_only→external promotion preserves an existing non-empty value (prior edit).
- Enrich: ingest_precedent runs metadata extraction INLINE in-container
  (gemini_session is direct REST, no local CLI) with force_citation=True, upgrading
  the seed to the canonical derived citation (parties + reporter + date) before the
  chair opens the page. Best-effort: on no key / API failure the seed remains and
  the queued metadata drain stays as the fallback. Halacha extraction is untouched
  (stays local — claude_session).
- apply_to_record / extract_and_apply gain force_citation: re-assemble even when
  citation_formatted is non-empty, writing only when assembly SUCCEEDS (seed
  preserved on abstention). The drainer keeps the default (False) so a chair's
  manual edit in /precedents/[id] is never clobbered.

Ops: GOOGLE_GEMINI_API_KEY added to the legal-ai Coolify app (runtime) — the SoT
value from Infisical nautilus:/external-apis/gemini, validated against the API.

Invariants: G2 (one citation-resolution + one metadata-extraction path, reused —
no parallel logic), INV-ID2/X1§3 (citation_formatted stays a derived field; the
seed is provisional and upgraded), INV-G10 (chair edits preserved). No schema change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
chaim merged commit b8c49a1269 into main 2026-06-20 15:30:40 +00:00
chaim deleted branch worktree-citation-autofill-root 2026-06-20 15:30:40 +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#318