Skip to content

Derive runs purge context from the command instead of context.Background() - #5

Merged
itseffi merged 1 commit into
mainfrom
fix/runs-purge-command-context
Aug 5, 2026
Merged

itseffi merged 1 commit into
mainfrom
fix/runs-purge-command-context

Conversation

@itseffi

@itseffi itseffi commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Problem

newRunsPurgeCommand's RunE used context.Background() — the only RunE in
internal/cli that did. Its two siblings in the same file (runs.go:39, runs.go:61)
use signalCommandContext(cmd), which derives from cmd.Context() when set and wraps
it in signal.NotifyContext.

So runs purge discarded both signal handling and any embedder-supplied context. That
context is not decorative — it flows into cancellable work, including
daemon.LoadRunLifecycleSettings(ctx) and globaldb.Open(ctx, ...), so a purge blocked
on the database could not be interrupted with Ctrl-C.

Fix

Two lines in internal/cli/runs.go: context.Background() becomes
signalCommandContext(cmd) with defer stop(), and the now-unused context import is
dropped. No other behaviour changed.

Test

Adds TestRunsPurgeCommandHonorsCanceledCommandContext. It isolates HOME to a temp
dir and builds the home layout so the purge would otherwise succeed, sets an
already-cancelled context via cmd.SetContext(ctx), runs runs purge, and asserts
errors.Is(err, context.Canceled) and that no "purged" line was printed.

Red-green confirmed: with context.Background() restored the test fails with
runs purge error = <nil>, want context.Canceled.

Verification

make verify passes end to end — golangci-lint fmt, golangci-lint run with zero
issues, 3666 tests, and the build. Also verified merged together with #(the replay fix)
on an integration branch: 3669 tests, gate green.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@itseffi
itseffi merged commit bc369f9 into main Aug 5, 2026
4 checks passed
@itseffi
itseffi deleted the fix/runs-purge-command-context branch August 5, 2026 10:18
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