Skip to content

feat(history): complete dal delete and eviction consistency - #11

Merged
prateekchaplot merged 3 commits into
mainfrom
arch/tts/t1.5
Nov 20, 2026
Merged

prateekchaplot merged 3 commits into
mainfrom
arch/tts/t1.5

Conversation

@prateekchaplot

Copy link
Copy Markdown
Owner

Task T1.5 from docs/ARCHITECTURE.md §14.

What was built

Completes the history DAL beyond the T0.4 skeleton: transactional delete-with-file, eviction ordering, and settings seeding, with the NFR-05 property tests the task's acceptance criteria call for.

  • Row deleted before its file. §7.7 requires the DAL to "never leave a row referencing a missing audio file". The skeleton deleted the file first, so a failure of the row delete left a row pointing at a missing WAV. The row is now removed in a transaction and the file afterwards, both under the one RLock.
  • ActiveGenerationError. §7.7's Must-not ("delete a row whose id is active") is binding, so delete() now refuses a queued/running/cancelling row instead of relying on the caller.
  • Deferred file removal. A file the OS refuses to unlink (Windows file lock) is remembered and retried on the next delete, eviction, or close(), so deletion stays real (§8.5).
  • Deterministic ordering. The system clock is too coarse to order rapid inserts (2000 datetime.now() calls produced 3 distinct values on this machine), so created_at is now emitted strictly increasing. History order (newest first) and eviction order (oldest first) follow insertion order rather than an arbitrary UUID tiebreaker.
  • Settings key set. put_settings rejects keys outside {defaultVoiceId, rate, volume} and get_settings ignores unknown stored keys, enforcing §8.2 in the DAL. seed_settings(default_voice_id) provides the §8.2 lazy seeding for T2.3 — the DAL cannot import voices, so the caller supplies the voice id.
  • Architecture doc. §7.7 documents the new public interface; §8.5 now says the caller must pass every in-flight id to evict_to_limit.

Verification

  • pytest tests/unit — 103 passed (16 new in tests/unit/test_dal_consistency.py), stable over 5 consecutive runs
  • ruff check src/tts tests — clean
  • ruff format --check src/tts tests — 34 files already formatted
  • mypy --strict src/tts — no issues in 22 source files
  • pytest tests/integration — 5 passed, 1 failed (pre-existing, unrelated — see below)
  • npm run lint, npm run typecheck, npm run test — clean, 34 vitest tests pass
  • git diff --check — clean

New tests cover: a forced row-delete failure (SQLite RAISE(ABORT) trigger) leaving row and file intact; a forced file-delete failure leaving no dangling row and retrying the removal; retry after failure; refusal of active rows; eviction leaving no dangling rows; concurrent delete/eviction; the settings key set; and insertion ordering across a restart.

Known issue (pre-existing, not from this PR)

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). piper 1.8's duration predictor is stochastic. It comes from T1.2 and this PR does not touch that file; the fix is tracked as a separate maintenance PR so this task does not edit a file owned by another task (§16).

Decisions

  • Row-before-file ordering, superseding T0.4's "file first" comment — required by §7.7's invariant.
  • delete() raising ActiveGenerationError supersedes T0.4's "active-row gating is the caller's job" note; §7.7's Must-not governs.
  • Eviction still protects exactly the ids passed in active_ids (the merged T0.4 test pins this), so T1.6 must pass every in-flight id, not just the new one.

Downstream contracts

  • T1.6 — pass every in-flight id to evict_to_limit(active_ids).
  • T2.2 — catch ActiveGenerationError from dal.delete() and map it to 409 GENERATION_BUSY, not 404.
  • T2.3 — use dal.seed_settings(default_voice_id) for lazy §8.2 seeding.

Suggested merge

Squash merge with branch deletion.

- delete the row before its audio file so a failure in between can never leave a row referencing a missing file (ARCHITECTURE 7.7)
- refuse to delete in-flight generations via ActiveGenerationError
- defer and retry file removals the OS refuses (Windows file locks)
- guarantee strictly increasing created_at so history and eviction order follow insertion order
- enforce the 8.2 settings key set and add seed_settings for lazy seeding
Track T1.5 on branch arch/tts/t1.5 (Doing until the PR is merged), drop the finished T1.4/T1.5 rows from Remaining, and record the ordering, deletion, and settings decisions plus their downstream contracts for T1.6, T2.2, and T2.3.
Record PR #12 on branch fix/integration-rate-flake as the separate maintenance fix for the pre-existing stochastic duration-predictor flake.
@prateekchaplot
prateekchaplot merged commit 171c08c into main Nov 20, 2026
5 checks passed
@prateekchaplot
prateekchaplot deleted the arch/tts/t1.5 branch November 20, 2026 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant