DEV Community

Cover image for A routine deploy lost a 58-minute therapy session recording
Yoseph Eikelman
Yoseph Eikelman

Posted on Originally published at yussieik.com

A routine deploy lost a 58-minute therapy session recording

ClinicLog records a therapy session and turns it into a transcript, which the clinical note is drafted from. A session is an hour of someone’s therapy. It cannot be recorded again, and by the time it is processed the therapist is with the next client. Losing a well-recorded session is the failure nobody can undo.

On 20 October 2026 a routine software update, a deploy, restarted the program that was transcribing a 58-minute pilot session, and the session was lost. [1]

The quick fixes would be to hold deploys until every session is processed, or to keep the audio longer so it can be sent again. The fix I shipped does neither. Here is the same deploy, before and after.

Figure: Example of one session’s path, drawn from the code before the fix and after it. The deploy lands at the same point in both runs; durations are not to scale. The 3.5 min and 2.4 h were measured once, in a test run with a worker killed outright, not in a deploy. See the animated figure in the original note.

The calls I made

I kept deleting the audio early, and let one rule bend. Keeping recordings longer would have made a retry trivial. It would also have left a client’s therapy hour on our server longer than the work needs it. Our copy is still deleted the moment the speech service has it. What changed is the order: before our copy goes, we write down the one thing that reaches the speech service’s copy, its job id. The rule I bent: a run that was cut off used to delete the speech service’s copy on its way out. Now it leaves that copy, because the next run resumes from it, and a sweep deletes any job of ours left there for more than six hours. [2]

A deploy waits 10 minutes for a running job, not until the work is done. Holding deploys until every session is processed protects against deploys and nothing else. A worker can also run out of memory, or its machine can crash, and no schedule prevents that. So a deploy now gives a running job 10 minutes to finish and restarts the two workers one at a time. [3] Whatever is still cut off starts again from its last saved stage.

I capped the retries and chose a plain transcript over none. A session gets 5 runs. The model passes that make the transcript read well take minutes, so they are the likeliest part to be cut off; after the third run they are skipped and the transcript is published as the speech service heard it. [2] If all 5 runs fail, the therapist is told plainly that processing was cut off.

What happened

Before shipping, I ran the fix end to end on separate workers with synthetic audio, and killed a worker outright, the case with no warning at all. A sweep had its session back on the queue in 3.5 minutes. The queue on its own would have kept it marked as in progress for 2.4 hours, with nobody working on it. [1]

Under the hood

What the deploy did

Four reasonable decisions added up to the loss:

  • Our copy of the audio was deleted as soon as it was submitted to the speech recognizer. Less patient audio on our disk is a privacy win.
  • The worker deleted the recognizer’s copy on its way out, also for privacy.
  • The transcript lived only in the worker’s memory until the final publish.
  • The job was allowed one try.

Each is defensible alone. Together they meant that the only way back to the session was in the memory of a process we had just restarted.

Three stages, each one written down before the next

  1. Recognize. Submit the audio and save the recognizer’s job id to the stored result. Only then delete our copy of the audio.
  2. Checkpoint. Save the recognizer’s speaker turns before any model touches them. Only then delete the recognizer’s copy.
  3. Polish and publish. The readability pass, speaker roles, the split per client, ready.

A run that starts finds whatever the last one left and continues from there. The order is the whole design. Here is the line that matters, with its comment, as it is in the code:

# **Saved before our copy goes**, because from the next line the
# vendor's job is the only copy of the session and this id is how
# a resumed run reaches it. A run cut off between the submit and
# this write resubmits from the audio still on disk, and the job
# it orphaned is the stranded-job sweep's.
result.provider_job_id = job_id
try:
    await _checkpoint(captures, results, result, lease)
except _LeaseLostError:
    # Lost between the check above and the submit. The other run
    # never learns this job id, so nothing would fetch or delete
    # it; it goes now rather than at the stranded sweep.
    await forget_upstream(result)
    raise

# The moment Speechmatics has it, our copy is redundant - on disk
# and in memory both. Deleted here rather than at the end because
# this is the earliest point it can be, and every extra minute is
# a client's therapy hour sitting on a shared volume.
audio_path.unlink(missing_ok=True)
Enter fullscreen mode Exit fullscreen mode

A killed worker is the case the queue sees last

A deploy is polite: it sends a stop signal, the worker stops taking new jobs, and a job cut off after the 10 minutes is cancelled, saves its checkpoint, and is run again. A worker killed outright (out of memory, a host that crashes) gets no signal. Our job queue keeps treating its job as in progress until a marker expires, and that marker lives as long as the longest job timeout on the worker, not this job’s: a whole morning’s notes may run 2.4 hours, measured.

So each run now holds a lease: a short-lived key with a 60-second lifetime, renewed every 15 seconds. A killed worker stops renewing it. A sweep runs every minute and queues again any session that still has work outstanding, no lease, and no write for 3 minutes. [4] Queuing twice is safe because every run takes the lease first and starts from the checkpoint; a duplicate that finds the lease held does nothing.

Bounding the retries

Three runs with model passes, not one, because one deploy can cancel the same job twice: each worker drains in turn, and the second can pick up what the first let go. The first version of the fix let a saved transcript lift the run limit; review caught it within the hour. After the fifth run the saved transcript is deleted too.

The pipeline’s two test files run 100 tests, and the resume, lease and sweep cases are among them. [5]

What transfers

  • Privacy and durability are separate decisions. Deleting early was right. Deleting before anything was written down was the bug.
  • Write the state down before you delete the copy. Every delete in a pipeline should come after something durable that replaces it.
  • Your queue sees a dead worker only when its longest timeout runs out. A lease with a heartbeat sees it in a minute. Make re-queuing safe and let a sweep do it.

Sources

  1. The fix, 20 Oct 2026: 11 files changed the same day, five review fixes by the next morning. In its test run a killed worker was back in 3.5 min, not 2.4 h
  2. 1 Nov 2026: up to 5 runs per recording, model passes only in the first 3; a sweep deletes any job left at the speech service after 6 hours
  3. Deploy settings, 1 Nov 2026: a running job gets 10 minutes to finish, and the two workers restart one at a time
  4. Lease settings, 1 Nov 2026: a 60 s lease renewed every 15 s; a session with no lease and no write for 3 minutes is queued again
  5. 100 tests on the transcription worker and the lease, passing on 1 Nov 2026

Originally published at yussieik.com, where the figures are animated.

Top comments (0)