Skip to content

Test the history writes the quit-time flush depends on (#338) - #389

Merged
alexkroman merged 5 commits into
mainfrom
test/issue-338-history-writes
Nov 25, 2026
Merged

alexkroman merged 5 commits into
mainfrom
test/issue-338-history-writes

Conversation

@alexkroman

Copy link
Copy Markdown
Collaborator

Fixes #338.

All three bugs in the issue are fixed on main by #357, which went in without linking the issue:

  1. Quit corrupts the recording and drops the live transcript. applicationWillTerminate calls TranscriptsModel.prepareForExit(). That stops the recorder, whose teardown() → writer.close() finalizes the .m4a, and saves the live transcript (Keep failed recordings in Library for retry, not deletion #363 also keeps a silent recording, as an untranscribed entry).
  2. Saves within 300 ms of quitting are lost. flushHistory() cancels the pending debounced save and writes synchronously, merging in the saved history first if it hasn't been read yet.
  3. Concurrent saves race. Every history write goes through one serial queue, so an older list can't land last.

This PR

Points 2 and 3 had no tests, because the Mac app has no unit-test target. To make them testable, the serial write queue and the quit-time merge move unchanged from TranscriptsModel into the engine as TranscriptWriter:

  • save(_:): queued.
  • saveNow(_:mergingSaved:): synchronous, behind every queued write.

It keeps the same queue label. TranscriptsModel calls it where it used the queue directly, and store goes back to private. Behavior is unchanged.

New TranscriptWriterTests:

  • Order: five large older lists are queued, then saveNow(newest). The newest is what's on disk, both immediately and 500 ms later.
  • Merge: a history that hasn't been read in is merged, with this session's copy of an entry winning. mergingSaved: false writes the list as-is.

Both tests fail 3/3 against the pre-#357 behavior (detached writes, no merge) and pass 3/3 with it.

Verified:

  • Full swift test passes.
  • Merged with Build the engine under the strictest compiler settings #384's strict compiler settings, the build is clean and the tests pass.
  • swift-format and SwiftLint (strict) are clean.
  • The swift6-concurrency-reviewer found no issues: Sendable is checked, and the queue.sync at quit can't deadlock.

🤖 Generated with Claude Code

alexkroman-assembly and others added 2 commits November 24, 2026 19:03
-warn-long-function-bodies / -warn-long-expression-type-checking measure
how long the compiler took, which varies with a CI runner's load; with
every warning an error they made the build nondeterministic. They failed
#384's merge-queue compile on a test that took 729 ms against the 500 ms
limit, while the run beside it passed. Every remaining strict setting gives
the same answer on every machine.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PR #357 serialised history writes and made the quit-time write merge a
history not yet read in, but both lived in TranscriptsModel, in the app
target, which has no unit-test target, so neither was covered. Move them,
unchanged, into the engine as TranscriptWriter beside TranscriptStore, and
test them under swift test:

- an older list queued before the quit-time write never lands after it
  (fails with the pre-#357 detached writes);
- the quit-time write merges the saved history when it hasn't been read in,
  this session's copy of an entry winning (fails without the merge).

No behaviour change: the debounce and prepareForExit stay in the model.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alexkroman
alexkroman enabled auto-merge November 25, 2026 03:04
alexkroman-assembly and others added 3 commits November 24, 2026 19:44
Its writes moved to TranscriptWriter and its one read (the launch load)
uses the initializer's parameter, so periphery flagged the property as
assigned but never used.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alexkroman
alexkroman added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit 02ea9cb Nov 25, 2026
15 checks passed
@alexkroman
alexkroman deleted the test/issue-338-history-writes branch November 25, 2026 05: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.

App termination corrupts active .m4a recordings, drops live transcripts, and loses/races debounced history.json saves

2 participants