Repository navigation
feat(jobs): add single-worker jobs manager with cancellation and atomic writes - #13
Merged
Merged
Conversation
…ic writes Implements ARCHITECTURE.md section 7.8: one generation at a time on a single-worker executor, atomic .part -> .wav rename before the row is marked succeeded, cancel events checked at every sentence boundary, and an in-memory SSE subscriber registry that replays the current state on connect. Also adds TTS_FAULT=engine mid-run failure injection for the AC11/AC12 end-to-end specs, and records the T1.6 decisions and downstream contracts for T2.2 and T4.3 in docs/TASKS.md.
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.
Task T1.6 from
docs/ARCHITECTURE.mdsection 14.What was built
Implements the
jobscomponent of ARCHITECTURE.md section 7.8:src/tts/jobs/manager.py—JobManager(dal, settings)withsubmit,cancel,subscribeand the module-levelbootstrap(settings, dal). AThreadPoolExecutor(max_workers=1)runs one generation at a time, so two submissions never synthesize concurrently (ADR-8).src/tts/jobs/sse.py— in-memory subscriber registry, theretry: 3000line and theevent:/data:wire format of section 9.2. A new subscriber is replayed the current state, so a reconnect is stateless-safe.src/tts/jobs/__init__.py— package marker (a package needs one; thetimingandsubtitlespackages ship the same).Key behaviours
{id}.wav.part; the file is closed andos.replaced to{id}.wavonly after the timings and cues are derived, and the row is setsucceededonly after that rename (section 1, section 10.1, NFR-03). A failure or a cancellation removes the.part.threading.Eventchecked after every sentence. A job that never started is cancelled outright; a running job reportscancellinguntil the worker confirms it.failedwith anENGINE_ERROR/INTERNAL_ERRORcode, and publishes afailedevent. A generation that renders no audio at all fails instead of succeeding with an unplayable empty WAV.TTS_FAULT=engineinjects a mid-run engine failure for the AC11/AC12 end-to-end specs (section 11, section 15). A cancel requested first wins over the injected fault.first_word_idxtriplets forbuild_cues(T1.3's contract),evict_to_limitcalled with every in-flight id (T1.5's contract).Decisions
jobs/manager.py(split_sentences): section 7.4 forbids the engine from splitting text and no other component owns a splitter. A terminator ends a sentence only when followed by whitespace or end-of-text; decimals and abbreviations/initials do not split.bootstrap(settings, dal)is implemented here because section 7.8 lists it in theJobManagerinterface; T2.3 owns the wiring and the lazy settings seeding.TTS_FAULTis read injobs/manager.pyrather thanconfig.py: section 14.2 assigns the implementation to T1.6 whileconfig.pybelongs to T0.2/T4.3, so the file-ownership guardrail wins over section 7.1. T4.3 owns the follow-up that folds it intoSettings.cancel()returnscancellingfor a job that was alreadycancelling. Section 9.2 literally reads "alreadycancelling" as a200withstatus: cancelled; jobs reports the truthful state and T2.2 owns the HTTP mapping.The full list of decisions and downstream contracts is recorded in
docs/TASKS.md(Notes).Verification
ruff check src/tts tests— cleanruff format --check src/tts tests— cleanmypy src/tts— clean (strict, 25 source files)pytest tests/unit— 140 passed (37 new)pytest tests/integration— 13 passed (7 new) against the realen_US-lessac-mediumvoicegit diff --check— cleanAcceptance criteria (section 14.2, T1.6)
test_real_voice_job_reports_progress_and_succeeds.wav, statusfailed,.partremovedtest_injected_engine_fault_leaves_no_audio; unit:test_engine_failure_leaves_no_audio_and_marks_failedcancelled, no filetest_cancel_mid_run_leaves_no_audio; unit:test_cancel_mid_run_cancels_the_job_and_removes_the_outputtest_two_jobs_run_strictly_sequentially,test_a_second_job_does_not_start_before_the_first_finishes; unit:test_two_jobs_run_strictly_sequentiallyManual checks
wavemodule: mono, 16-bit, 22050 Hz, non-zero frame count..partfile is absent after both success and failure; the final.wavexists only after success.first_word_idxcontract.Environment note
The integration suite renders with the downloaded voice but keeps its database and audio in a
tmp_path. On this Windows clonepytestneeds--basetemp .venv/ptmp-*because the default system temp directory is inaccessible (pre-existing, see the T0.2 note).prettier --checkfails locally only becausecore.autocrlf=truegives the working tree CRLF endings; the committed blobs are LF and CI'slintjob is green.Suggested merge method: squash merge with branch deletion.