Skip to content

feat(mkv-audit): stop cleanly on Ctrl+C and pass a context to every child process and TMDB request - #306

Merged
robrich82 merged 5 commits into
mainfrom
fix/noctx-mkv-audit
Dec 5, 2026
Merged

robrich82 merged 5 commits into
mainfrom
fix/noctx-mkv-audit

Conversation

@robrich82

Copy link
Copy Markdown
Owner

Part of #294

Problem

Ctrl+C killed mkv-audit wherever it was, including mid-conversion or mid-trim, and it could accept a prompt's default on the way out. It also passed no context.Context to its children or TMDB requests, which noctx needs. This ports the cbz-fix design (#304) to mkv-audit.

Change

  • mkv-audit/interrupt.go, command*.go and their tests: copied from cbz-fix, with names, notices and test helper env vars adapted.
  • mkv-audit/runner.go:
    • ctx is checked before each conversion, lookup, file and remux, and after every prompt, before the answer is used.
    • mkvpropedit runs on context.Background(), so it is never killed. mkvmerge and mkvextract run on command(ctx, …).
    • A file the kill stops prints [STOP] and isn't counted as failed.
    • After an interrupt, the failure list keeps every earlier failure except files every phase got through: main pass, langfix and trim. A converted source counts as done once its MKV does. The list skips the gone-file check, since a cut-short walk can't tell a gone file from an offline drive. Both paths now list a file at most once.
  • prompt.go: the read runs in a goroutine and the prompt returns on Ctrl+C. EOF waits 250 ms for an interrupt, then latches, as the old Scanner did.
  • convert.go, remux.go, mka_date.go: a killed mkvmerge removes its temp file and leaves the source alone. It counts as the interrupt even though on Windows it exits 1, the code for warnings.
  • tmdb.go: requests use http.NewRequestWithContext; errors still pass through redactAPIKey.
  • main.go: the summary is headed INTERRUPTED and the exit code is 130.
  • README.md: the Ctrl+C behaviour.

Behavior

Before: Ctrl+C killed mkv-audit and its mkvmerge at once, and could leave a temp file behind.

After:

  • One Ctrl+C starts nothing new and stops at the next prompt without acting on it. A file already read still gets its fixes, and a conversion or trim in progress finishes. The summary prints and the exit code is 130.
  • A second Ctrl+C (or SIGTERM, or SIGHUP on Unix) also kills mkvmerge/mkvextract. The file is left as it was.
  • A third Ctrl+C quits at once.

Left for #294: the other four modules, re-raising the signal instead of exiting 130, and enabling noctx. Out of scope and already on main: with stdin closed, the und prompt applies the default IETF tag.

Verification

mise run vet        # 0 issues
mise run vet-linux  # 0 issues
mise run test       # ok mkv-audit
mise run build      # ok
  • Linux: the test binary passes in WSL, also under nohup.
  • The interrupt tests use real helper processes for the kill paths. One-line mutants of each interrupt check and each failure-list rule are all caught.
  • golangci-lint run --enable-only noctx reports 0 issues for mkv-audit.

AI assistance

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

…hild process and TMDB request

The first Ctrl+C stops before the next file or at a prompt without taking
its default; the second kills mkvmerge and mkvextract, never mkvpropedit.
Interrupted files are not recorded as failures, and the run exits 130.

Part of #294
…p re-waiting on EOF, and pin the interrupt paths

An interrupted run now takes the failures it got through, and those that are
gone, off the retry list. Once stdin has ended, prompts return at once
instead of each waiting for an interrupt. A file the interrupt skips prints
a [STOP] line, and an ID whose lookup finished is still saved. Tests now
cover the post-prompt checks, auto-all loops, mux and mkvextract kills, and
fail rather than hang.
… failure once, and say nothing about a TMDB match an interrupt cut short
… finished, and pin new and repeated failures in the list
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