Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions docs/TASKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Statuses: done (PR merged) · doing (branch open, pending review) · remaining

| ID | Task | Branch | Verification | Status |
|---|---|---|---|---|
| _(empty — next up: T1.6 on branch `arch/tts/t1.6`)_ | | | | |
| T1.6 | Jobs manager | `arch/tts/t1.6` | 140 unit tests (37 new); 13 integration tests (7 new) vs `en_US-lessac-medium` (progress ≥ 1 → succeeded, injected engine failure → no `.wav`/`.part` + status `failed`, cancel mid-run → status `cancelled` + no file, two submits strictly sequential); Ruff check/format; strict mypy; `git diff --check`; PR CI green (lint, unit ubuntu+windows, integration, e2e) | [#13](https://github.com/prateekchaplot/tts/pull/13) open — awaiting review |

## Remaining

Expand All @@ -37,9 +37,7 @@ _All P0 tasks done._

### P1 — Service layer

| ID | Task | Files | Deps | Acceptance criteria (summary) |
|---|---|---|---|---|
| T1.6 | Jobs manager | `src/tts/jobs/` | T1.2, T1.3, T1.4, T1.5 | Progress/success, atomic failure cleanup, cancellation, sequential jobs |
_T1.6 in progress on `arch/tts/t1.6`; P1 is otherwise complete._

### P2 — HTTP surface

Expand Down Expand Up @@ -103,3 +101,15 @@ _All P0 tasks done._
- T1.5 eviction ordering: the system clock is far too coarse to order rapid inserts (2000 `datetime.now()` calls on this machine produced 3 distinct values), so `created_at` is now emitted strictly increasing — the clock value is nudged forward by 1 µs when it would repeat, and a reopened DAL resumes after the newest stored row. History order (newest first) and eviction order (oldest first) therefore follow insertion order instead of an arbitrary UUID tiebreaker. `created_at` stays ISO-8601 UTC; the stored format gained microsecond precision.
- T1.5 settings: `put_settings` now rejects keys outside `{defaultVoiceId, rate, volume}` with `ValueError` and `get_settings` ignores unknown stored keys, enforcing §8.2's key set in the DAL. Lazy seeding stays in the API layer (T2.3), as T0.4 decided.
- T1.5 environment finding: `tests/integration/test_piper_engine.py::test_rate_scales_duration_within_ten_percent` is flaky (measured ratio 0.814–0.913 over 10 attempts against the [0.72, 0.88] band; 6/10 pass) because piper 1.8's duration predictor is stochastic. It was pre-existing (T1.2) and unrelated to T1.5, so that task did not edit a file owned by T1.2 (§16); the fix merged as PR #12 (squash `6910a09`, branch `fix/integration-rate-flake`, 7 runs per rate, band [0.78, 0.93] around the measured 0.87) before T1.5 merged.
- T1.6 decisions: **sentence segmentation lives in `jobs/manager.py` (`split_sentences`)** — §7.4 forbids the engine from splitting text, the caller supplies `char_offset_map`, and no other component owns a splitter, so jobs owns it. Rule: a terminator (`.!?…`) plus optional closing punctuation ends a sentence only when followed by whitespace or end-of-text; a decimal point (`3.14`) and an abbreviation or initial (`Dr.`, `e.g.`, `J. Smith`) do not end one. §16 ambiguity rule: recorded here because §14.2 does not specify a splitter.
- T1.6 write order: PCM frames are streamed per sentence into `{id}.wav.part` (§11 "streamed to disk per sentence"), the file is closed and `os.replace`d to `{id}.wav` only **after** the timings and cues are derived (§10.1 order), and the row is set `succeeded` only after that rename (§1, NFR-03). A failure or cancellation removes the `.part`. On Windows the WAV is closed before the rename because an open file cannot be renamed.
- T1.6 downstream contract (T1.3): `build_cues` receives one `(char_start, char_end, first_word_idx)` triplet per sentence, and `first_word_idx` is built from **per-sentence** `derive_word_timings` calls, so a sentence that collapses to one unaligned entry contributes exactly one index. Assuming one entry per token would mis-index every later sentence.
- T1.6 downstream contract (T1.5): `evict_to_limit` is called from `submit` right after the insert with **every** in-flight id (`set(self._jobs)`), not just the new one, because the DAL protects exactly the ids it is given (§8.5).
- T1.6 downstream contract (T2.2): `JobManager.submit` raises `voices.store.VoiceNotFoundError` for an unknown voice and creates the row itself (§7.8's signature returns the id). The API must map that to 422 `VOICE_NOT_FOUND` and must check for an empty store first to answer 409 `NO_VOICES_INSTALLED`. `subscribe`/`cancel` raise `GenerationNotFoundError` (→ 404 `GENERATION_NOT_FOUND`) and `cancel` raises `GenerationNotCancellableError` on a terminal row (→ 409 `GENERATION_BUSY`).
- T1.6 SSE contract (T2.2): `jobs/sse.py` exposes `RETRY_LINE` (`"retry: 3000\n\n"`) and `SseEvent.to_wire()`, which emits `event: <name>` + `data: <json>` + a blank line. The route sends `RETRY_LINE` once on connect and then yields `subscriber.events()` until the terminal event; the manager already replays the current state to a new subscriber, so a reconnect is stateless-safe (§9.2).
- T1.6 ambiguity (T2.2 to decide): `cancel()` returns `cancelling` both when the job was `running` and when it was already `cancelling`. §9.2 literally says a job that was "already `cancelling`" answers `200 {"status":"cancelled"}`, while §7.8 and §10.2 only allow the two states `cancelled`/`cancelling` and describe `cancelling` as "the worker confirms via `cancelled` SSE + row update". Jobs reports the truthful state; the API layer owns the §9.2 mapping.
- T1.6 deviation (§7.1): `TTS_FAULT` is read in `jobs/manager.py` rather than `config.py`. §14.2 assigns the `TTS_FAULT` implementation to T1.6, while `config.py` is owned by T0.2 and later T4.3, and the skill's ownership guardrail forbids editing another task's file. §7.1 ("`config` is the only reader of environment variables") is therefore bent for this one variable; **T4.3 owns the follow-up that folds it into `Settings`**. The fault fires after the first sentence, and a cancel that was requested first wins over the injected fault (so AC11 and AC12 can share the env var).
- T1.6 decision: `bootstrap(settings, dal)` is implemented here because §7.8 lists it in the `JobManager` interface and §14.2 T1.6 says "per §7.8"; **T2.3 owns the wiring** (app startup) and the settings route, including §8.2's lazy `dal.seed_settings(default_voice_id)` seeding that the T1.5 note assigned to it. The `dal` argument is accepted for interface stability and is currently unused.
- T1.6 decision: a generation that renders **no audio at all** fails with `ENGINE_ERROR` ("The speech engine produced no audio for this text.") instead of succeeding with a valid but empty WAV that no player can use (§1 "degrade honestly"). The API still rejects empty input with 422 `EMPTY_INPUT`, so this only guards text that the engine renders as silence.
- T1.6 test layout: unit and integration test files use distinct basenames (`tests/unit/test_jobs_manager.py`, `tests/unit/test_jobs_sse.py`, `tests/integration/test_jobs_pipeline.py`) because a bare `pytest` run fails when `tests/unit` and `tests/integration` share a basename and neither directory is a package (see the T1.2 note).
- T1.6 environment note: the integration suite renders with the real voice but keeps the database and the audio in a `tmp_path`; the manager points the voice store at its own data directory, so the fixture calls `ensure_data_dirs()` again with the real settings afterwards. `pytest` needs `--basetemp .venv/ptmp-*` on this machine (the default system temp directory is inaccessible — see the T0.2 note).
1 change: 1 addition & 0 deletions src/tts/jobs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Job execution: one generation at a time, atomically, with progress events."""
Loading