Repository navigation
fix(refine): keep refined SRT cues across a rate-limit pause - #313
Merged
Merged
Conversation
refine_srt_file had no RateLimitError handling: a 429 midway through an SRT refine pass propagated bare, every cue already refined was discarded, and a resume started the refinement over from the first cue. refine_subtitle_translations now attaches a partial result before re-raising: the complete position -> text map (refined for finished blocks, the draft for the failing block onward) plus the first position still to refine. refine_srt_file writes that map through the same helper as the success path, so cue numbers and timings stay verbatim, and records the last finished cue in the checkpoint before letting the error propagate to the pause / auto-resume logic. On resume, refine_file now forwards checkpoint_manager, translation_id and resume_from_index to the SRT refiner. It reads the finished cues back from the partial output (only when it still matches the input cue for cue, else it restarts from the first cue), sends only the remaining cues to the LLM, and reports progress against the whole file. Fixes #302 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #302
Problem
src/core/refine/srt_refiner.pyhad noRateLimitErrorhandling. A 429 during an SRT refine pass propagated bare, every cue already refined was lost, and a resume restarted refinement from the first cue.Fix
Follows the TXT refiner fix from #252 (#228), then goes one step further so the resume actually skips finished cues.
refine_subtitle_translationsattachesRateLimitError.partial_resultbefore re-raising: the complete position-to-text map (refined for finished blocks, the draft from the failing block onward) andnext_index, the first position still to refine.refine_srt_filecatches the error, writes the partial file through_write_refined_srt(shared with the success path, so cue numbers and timings stay verbatim), records the last finished cue viacheckpoint_manager.save_checkpoint, then re-raises so auto-pause / auto-resume still trigger.refine_filenow forwardscheckpoint_manager,translation_idandresume_from_indexto the SRT refiner. On resume, the finished cues are read back from the partial output, but only when it still lines up with the input cue for cue (same count and timings). Otherwise the pass logs a warning and restarts from the first cue. Only the remaining cues go to the LLM, and progress is reported against the whole file.Because the checkpoint index now advances, the auto-resume "stuck" detector in
handlers.pyalso sees real progress for SRT refine jobs.Note: the TXT refiner still saves its partial output but re-refines from chunk 0 on resume. That is unchanged here.
Tests
New
tests/unit/test_srt_refine_rate_limit.py(all 4 fail without the fix):Full suite: 2582 passed. Two known failures are unrelated. The
tests/characterization/test_progress_baseline.pygoldens are stale on main (deselected).test_litellm_provider.py::test_rate_limit_without_pool_keeps_plain_backofffails only in a full-suite run, and it fails the same way on the unmodified base.🤖 Generated with Claude Code