Skip to content

Commit 09d9e9a

Browse files
nodeeeeeeclaude
andcommitted
Don't lose drafts when verify/translate API calls fail
Previously a 429 (quota) or any provider error during the verify pass raised out of generate_section() before the draft was written to disk, so a perfectly good ~7KB codex-generated section was discarded. Same for the optional translate step. Both now log a warning and fall through with the unmodified draft, which matches how the image filter already handles vision errors (just keeps the image). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 9c7b29e commit 09d9e9a

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

note_generation.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,14 +1054,20 @@ def generate_section(
10541054
v_user = _P("verify").format(term_list=term_list, draft=draft[:2500])
10551055
# Always route the verify/revision pass through VERIFY_MODEL
10561056
# (gpt-4o) — cheap and fast, avoids burning codex quota on a
1057-
# short review call. Caller must have an OpenAI key configured.
1057+
# short review call. If OpenAI is unavailable (no key, quota
1058+
# exceeded, network issue), skip verification rather than losing
1059+
# the generated draft.
10581060
_vmodel = VERIFY_MODEL
1059-
v_result = _call(_vmodel, "", v_user, 1500)
1060-
if not v_result.strip().upper().startswith("APPROVED"):
1061-
if len(v_result) > len(draft) * 0.3:
1062-
draft = v_result
1063-
else:
1064-
tqdm.write(f" [warn] Verifier suspicious response, keeping draft")
1061+
try:
1062+
v_result = _call(_vmodel, "", v_user, 1500)
1063+
if not v_result.strip().upper().startswith("APPROVED"):
1064+
if len(v_result) > len(draft) * 0.3:
1065+
draft = v_result
1066+
else:
1067+
tqdm.write(f" [warn] Verifier suspicious response, keeping draft")
1068+
except Exception as _ve:
1069+
tqdm.write(f" [warn] Verify pass failed ({type(_ve).__name__}: "
1070+
f"{str(_ve)[:120]}) — keeping draft")
10651071

10661072
# Strip pipeline artifacts that may have leaked into the draft
10671073
draft = _clean_artifacts(draft)
@@ -1071,8 +1077,13 @@ def generate_section(
10711077
lang = _LANG_NAMES.get(NOTE_LANGUAGE, NOTE_LANGUAGE)
10721078
tqdm.write(f" translating to {lang}…")
10731079
_tt = _time.monotonic()
1074-
draft = _translate(draft, lang)
1075-
tqdm.write(f" ✓ translated ({_time.monotonic()-_tt:.0f}s)")
1080+
try:
1081+
draft = _translate(draft, lang)
1082+
tqdm.write(f" ✓ translated ({_time.monotonic()-_tt:.0f}s)")
1083+
except Exception as _te:
1084+
tqdm.write(f" [warn] Translation failed "
1085+
f"({type(_te).__name__}: {str(_te)[:120]}) — "
1086+
f"keeping draft in source language")
10761087

10771088
heading = f"### {lec_num}.{ci} {chunk_title}"
10781089
content = f"{heading}\n\n{draft}"

0 commit comments

Comments
 (0)