Skip to content

feat(mkv-music): stop cleanly on Ctrl+C and pass a context to every child process and Plex request - #311

Merged
robrich82 merged 4 commits into
mainfrom
fix/noctx-mkv-music
Dec 6, 2026
Merged

robrich82 merged 4 commits into
mainfrom
fix/noctx-mkv-music

Conversation

@robrich82

Copy link
Copy Markdown
Owner

Part of #294

Problem

Ctrl+C killed mkv-music wherever it was, including mid-tag-copy or mid-Plex-refresh. It also passed no context.Context to its children (mkvmerge, mkvextract, exiftool) or Plex requests, which noctx needs. This ports the cbz-fix/mkv-audit design (#304, #306) to mkv-music.

Change

  • mkv-music/interrupt.go, command*.go and their tests: copied from mkv-audit, with names, notices and test helper env vars adapted.
  • mkv-music/processor.go:
    • Run checks ctx in the walk and before each video, and after every prompt, before the answer is used. A prompt the Ctrl+C lands on prints [STOP] and changes nothing.
    • A prompt that gets no answer (end of input or a read error) skips and lists its video, as the old Scanner prompter's blank answer did.
    • Tagging: only the kill's own context.Canceled counts as a stop. A stopped step prints [STOP] and is listed under TAGGING INTERRUPTED as <path> (stopped: tags|timestamps); the Tags line adds , N stopped. A step that fails on its own during the kill is still a failure.
    • Plex refresh runs on the kill context. The first Ctrl+C finishes the artist in progress and lists the rest as not refreshed; the second abandons the request in flight, though a refresh or analyze that already succeeded still counts.
  • tags.go, tags_mka.go: every read goes through command(ctx, …); mkvpropedit runs on context.Background(), so it is never killed. CopyTagsToMKV checks the kill after its reads and edits nothing if it fired, and TagsMatchMKV reports the kill instead of a match.
  • audio_timestamps.go: exiftool is killable, and the pass stops at the next file once interrupted.
  • plex.go: requests use http.NewRequestWithContext; the token stays in the header.
  • prompt.go: mkv-audit's prompter, returning the answer with only the line ending trimmed, so ignore patterns keep their spaces.
  • main.go: the audio pass is skipped (with a notice) once interrupted; the exiftool warning now names the lookup error, so exec.ErrDot is visible. The summary is headed INTERRUPTED, drops the "nothing skipped" all-clear, and the exit code is 130.
  • README.md: the Ctrl+C behaviour.

Behavior

Before: Ctrl+C killed mkv-music and its children at once; a Plex refresh or tag copy in flight was cut off unreported.

After:

  • One Ctrl+C starts no new video and stops at a prompt without acting on it. The video past its prompt is finished, tags and all. Then the unrefreshed artists are listed, the audio sync is skipped, the summary prints and the exit code is 130.
  • A second Ctrl+C (or SIGTERM, or SIGHUP on Unix) also kills mkvmerge, mkvextract and exiftool and abandons the Plex request. A step it stops leaves the file as it was and is listed for a rerun with a covering --cutoff-date.
  • A third Ctrl+C quits at once.

Left for #294: sw-update, mkv-tvshow, mkv-movie, re-raising the signal instead of exiting 130, and enabling noctx.

Verification

mise run vet        # 0 issues
mise run vet-linux  # 0 issues
mise run test       # ok mkv-music
mise run build      # ok
  • Linux: the test binary passes in WSL, also under nohup.
  • Kill paths use real helper processes. One-line mutants of each interrupt check, Plex rule and summary line are all caught (one survivor is equivalent).
  • The real Plex client was run against an httptest server with the kill at each point; it behaves as the test fake models.
  • golangci-lint run --enable-only noctx reports 0 issues for mkv-music, Windows and Linux.

AI assistance

Written with Claude Code (Claude Opus 5.5). It self-reviewed the diff over four rounds and ran the checks above.

@robrich82
robrich82 merged commit ea0a966 into main Dec 6, 2026
5 checks passed
@robrich82
robrich82 deleted the fix/noctx-mkv-music branch December 6, 2026 05:16
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