Skip to content

fix(nvkit): give shutdown signals a typed error consumers can test - #1450

Open
kristinapathak wants to merge 2 commits into
mainfrom
fix/nvkit-shutdown-signal-sentinel
Open

fix(nvkit): give shutdown signals a typed error consumers can test#1450
kristinapathak wants to merge 2 commits into
mainfrom
fix/nvkit-shutdown-signal-sentinel

Conversation

@kristinapathak

@kristinapathak kristinapathak commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

TL;DR

The servers run group reports a shutdown signal as fmt.Errorf("received signal %s", sig), with no sentinel to test against. That forces every consumer to string-match, and four of them still match on the SIGINT wording alone and therefore panic on SIGTERM. This adds pkg/nvkit/shutdown — a typed SignalError, an ErrSignal sentinel, and an IsSignalError predicate — and wires servers to return it.

This is step 1 of 2 and changes no service behavior on its own. It lands separately so the pseudo-version exists before consumers depend on it; see For the Reviewer for why the split is load-bearing.

Additional Details

service.Run() and friends have to distinguish a graceful stop from a crash, but the run group hands both to the caller through the same channel: a non-nil error whose only distinguishing feature is its text. Each consumer wrote its own check, and each compared against "received signal interrupt". syscall.SIGTERM stringifies as terminated, so the error reads received signal terminated, does not match, and falls through to zap.S().Panic. SIGTERM is how Kubernetes asks a container to stop and SIGINT essentially never arrives there, so the checks excuse the signal that does not happen in production and panic on the one that always does.

#1319 fixed worker-utils by deriving the match from signal names instead of one hard-coded string, but deliberately left the design issue in place. This is that follow-up.

pkg/nvkit/shutdown

  • SignalError + ErrSignal — a stop is now recognizable with errors.Is, not by inspecting a message. Error() deliberately preserves the historical wording; it is part of the contract, not an implementation detail.
  • IsSignalError — prefers errors.Is, falls back to matching on the signal names. The fallback is what lets a consumer adopt this immediately, before its own producer is on the typed error.
  • Signals() — the set a server installs a handler for and the set callers forgive now come from one list and cannot drift.

servers

grpc.go returns shutdown.NewSignalError(sig) and takes its signal.Notify list from shutdown.Signals(). The run group's signal actor moves into a named awaitShutdownSignal so the behavior is testable without signalling the test process; the extraction is mechanical and the select is unchanged.

For the Reviewer

Why the fallback is permanent, not a shim. vanity-gateway takes its servers package from github.com/NVIDIA/nvcf-go, a separate module, so it can never receive this sentinel. It can still import the predicate. Consumers pinned to older lib revisions are in the same position until their pins move.

Why this is split into two PRs. All five affected services are registered in tools/ci/github-release-subprojects.json, so a fix: commit touching them auto-cuts a release tag on merge. Converting the call sites in this PR would tag modules whose go.mod still pins a lib revision without pkg/nvkit/shutdown — green here, because Bazel resolves lib locally through go.work.bazel, but broken for external consumers like the GitLab go-nvcf-worker repo, which resolves the pin. src/libraries/go/lib is not a released subproject, so this PR cuts no tags. The follow-up carries the lib pin bumps and the call-site conversions together, keeping every tag it cuts self-consistent.

Worth a close look: SignalError.Error() (wording is contract), and IsSignalError's fallback, which is text matching and so cannot be exact — an unrelated error embedding received signal terminated reads as a shutdown. The doc comment says so and points producers at NewSignalError.

BUILD.bazel srcs/deps entries were added by hand because Bazel was not available in the environment used to prepare this change. Please confirm bazel run //:gazelle produces no diff.

For QA

No QA needed — no service behavior changes until the follow-up.

Verified in src/libraries/go/lib with the flags CI uses (GOWORK=off GOFLAGS=-mod=vendor):

  • go build ./..., go vet ./pkg/nvkit/servers/... ./pkg/nvkit/shutdown/..., and gofmt -l are clean.
  • go test -race ./pkg/nvkit/shutdown/... ./pkg/nvkit/servers/... passes, as does the full ./pkg/nvkit/... sweep.
  • go.mod/go.sum and the vendor tree are untouched; the new package imports only the standard library.

Tests were written before the implementation and confirmed failing first.

  • pkg/nvkit/shutdown/shutdown_test.goIsSignalError across typed SIGTERM/SIGINT, wrapped, untyped historical wording (both signals, and wrapped), a signal-shaped message for a signal we do not handle, an unrelated failure, and nil; sentinel matching under errors.Is; the wording contract; errors.As recovering the signal; a zero value not panicking; and Signals() returning the right list as a copy.
  • pkg/nvkit/servers/shutdown_test.goawaitShutdownSignal reports both signals as errors.Is-matchable, returns nil when the run group interrupts it instead, and blocks until something actually happens.

Issues

Relates to #1449

Checklist

  • I am familiar with the Contributing Guidelines.
  • I have signed off my commits for Developer Certificate of Origin (DCO) compliance.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added consistent handling for graceful shutdown through SIGINT and SIGTERM.
    • Added clear classification of shutdown signals versus genuine application failures.
    • Improved propagation and identification of shutdown-related errors.
  • Bug Fixes

    • Services now correctly distinguish cancellation from signal-triggered termination.
    • Shutdown handling is more reliable and avoids treating expected termination as a fatal failure.

The servers run group reports a shutdown signal by returning
fmt.Errorf("received signal %s", sig), so a graceful stop and a genuine
failure reach callers through the same channel with nothing but message
text to tell them apart. Every consumer therefore wrote its own check,
and each one compared against the SIGINT wording. SIGTERM stringifies as
"terminated" rather than "interrupt", so those checks classify every
SIGTERM as a crash -- and SIGTERM is how Kubernetes asks a container to
stop, so the checks excuse the signal that never arrives in production
and panic on the one that always does.

#1319 fixed this in worker-utils by matching on signal names instead of
one hard-coded string, but left the underlying design issue in place:
there is no sentinel to test against, so every other consumer still
string-matches, and four of them still get it wrong.

Add pkg/nvkit/shutdown as the single place that decision lives:

- SignalError plus the ErrSignal sentinel, so a stop is recognizable
  with errors.Is rather than by inspecting a message. Error() keeps the
  historical wording, which consumers pinned to an older lib revision,
  and consumers whose servers package comes from the separate nvcf-go
  module, still depend on.
- IsSignalError, which prefers errors.Is and falls back to matching on
  the signal names. The fallback is what lets a caller adopt this before
  its own producer is on the typed error.
- Signals(), so the set a server installs a handler for and the set
  callers forgive cannot drift apart.

servers now returns the typed error and takes its signal list from the
same place. The run group's signal actor moves into a named function so
the behavior is testable without signalling the test process.

This lands on its own so the pseudo-version exists before consumers
depend on it. Converting the remaining call sites, along with the lib
pin bumps those modules need, follows in a second change.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Kristina Pathak <kpathak@nvidia.com>
@kristinapathak
kristinapathak requested a review from a team as a code owner September 1, 2026 17:11
The predicate each consumer actually needs is "should I panic on this?",
which is err != nil && !IsSignalError(err). Spelled out by hand that has
a footgun: IsSignalError(nil) is false, so dropping the nil guard turns
a clean exit into a panic. Five call sites are about to be converted;
giving them one call rather than one expression is the difference
between consolidating the logic and copying it again.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Kristina Pathak <kpathak@nvidia.com>
@coderabbitai

coderabbitai Bot commented Sep 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 8827c5ee-cdac-4edc-96fb-f4da30cdf441

📥 Commits

Reviewing files that changed from the base of the PR and between 2729b24 and 82cfb68.

📒 Files selected for processing (7)
  • src/libraries/go/lib/pkg/nvkit/servers/BUILD.bazel
  • src/libraries/go/lib/pkg/nvkit/servers/grpc.go
  • src/libraries/go/lib/pkg/nvkit/servers/shutdown.go
  • src/libraries/go/lib/pkg/nvkit/servers/shutdown_test.go
  • src/libraries/go/lib/pkg/nvkit/shutdown/BUILD.bazel
  • src/libraries/go/lib/pkg/nvkit/shutdown/shutdown.go
  • src/libraries/go/lib/pkg/nvkit/shutdown/shutdown_test.go
🚧 Files skipped from review as they are similar to previous changes (7)
  • src/libraries/go/lib/pkg/nvkit/servers/shutdown.go
  • src/libraries/go/lib/pkg/nvkit/shutdown/BUILD.bazel
  • src/libraries/go/lib/pkg/nvkit/servers/shutdown_test.go
  • src/libraries/go/lib/pkg/nvkit/servers/grpc.go
  • src/libraries/go/lib/pkg/nvkit/servers/BUILD.bazel
  • src/libraries/go/lib/pkg/nvkit/shutdown/shutdown_test.go
  • src/libraries/go/lib/pkg/nvkit/shutdown/shutdown.go

Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review.


📝 Walkthrough

Walkthrough

The change adds a shared Go shutdown package with typed signal errors and fatal-error classification. The gRPC server uses the package to handle SIGINT, SIGTERM, and run-group cancellation through a common helper. Bazel targets and tests cover the new behavior.

Changes

Shutdown handling

Layer / File(s) Summary
Shutdown API and classification
src/libraries/go/lib/pkg/nvkit/shutdown/shutdown.go
Defines handled signals, SignalError, ErrSignal, compatibility matching, IsSignalError, and IsFatal.
Server shutdown integration
src/libraries/go/lib/pkg/nvkit/servers/grpc.go, src/libraries/go/lib/pkg/nvkit/servers/shutdown.go
The gRPC server uses shutdown.Signals() and awaitShutdownSignal for OS signals and run-group cancellation.
Build wiring and validation
src/libraries/go/lib/pkg/nvkit/shutdown/BUILD.bazel, src/libraries/go/lib/pkg/nvkit/shutdown/shutdown_test.go, src/libraries/go/lib/pkg/nvkit/servers/BUILD.bazel, src/libraries/go/lib/pkg/nvkit/servers/shutdown_test.go
Adds Bazel targets and tests for signal errors, signal-list copying, fatal classification, cancellation, and blocking behavior.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Merge Risk: ⚪ Minimal · up to 82cfb

The change adds typed shutdown-signal errors while preserving existing signal behavior, with no actionable merge-blocking risk remaining after normal checks and review.

Suggested reviewers: vrv3814

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title follows Conventional Commits syntax and accurately describes the shutdown error change, but fix does not match the primary nature of this diff. The PR adds a new public API and typed error… Change the title prefix to feat, for example: feat(nvkit): give shutdown signals a typed error consumers can test.
Docstring Coverage ⚠️ Warning Docstring coverage is 31.25% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title follows Conventional Commits syntax and accurately describes the shutdown error change, but fix does not match the primary nature of this diff. The PR adds a new public API and typed error capability without intended service behavior changes.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/nvkit-shutdown-signal-sentinel

Comment @coderabbitai help to get the list of available commands.

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