Skip to content

🔥 refactor(collect): remove dead Engine.Stop() (HYG-01-FUP) - #180

Merged
konih merged 1 commit into
mainfrom
fix/hyg-01-fup-remove-engine-stop
Aug 3, 2026
Merged

konih merged 1 commit into
mainfrom
fix/hyg-01-fup-remove-engine-stop

Conversation

@konih

@konih konih commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Lane HYG-01-FUP (P3) — remove the dead, hazardous Engine.Stop()

internal/collect/engine.go had an exported Engine.Stop() with zero callers. Post-REL-04 the real shutdown path is engine ctx-cancel: Start() wires the manager context into stopFn via a watcher goroutine, which drains and terminates every dispatch worker.

Zero-callers evidence (from the origin/main worktree)

$ rg 'Engine\.Stop|\.Stop\(\)' internal/ cmd/
internal/collect/engine.go:  defer timer.Stop()        # timer, not Engine
internal/collect/scale_envtest_test.go:  testEnv.Stop() # envtest
# (+ testEnv/webhookEnv/consumeCtx .Stop in other pkgs)

No caller of Engine.Stop() anywhere in internal/ or cmd/.

Latent hazards removed (were it ever wired)

  • A producer blocked on a full dispatchCh selects only on the manager runCtx; Stop() without a manager-ctx cancel would block that goroutine forever.
  • A Stop() racing the first dispatch() before dispatchOnce could panic WaitGroup is reused before previous Wait has returned.

Scope

  • Deleted only Stop() and trimmed the constructor comment's "explicit Stop()" clause.
  • stopFn, stopCtx, workersWG are kept — all used by the live ctx-cancel path (Start goroutine, dispatchWorker, startDispatchWorkers).
  • Live-path coverage unchanged: engine_shutdown_test.go (REL-04) drives workersWG.Wait() directly and never called Stop().
  • gosec G118: with the direct stopFn() call in Stop() gone, gosec no longer traces the remaining call (inside Start's goroutine closure), so an honest //nolint:gosec documents that stopFn is invoked there.

Gate matrix (all green)

  • go build ./... OK · go vet ./... OK
  • task lint 0 issues + arch-lint OK
  • task test all pass (collect 89.2%)
  • task verify ok
  • task coverage 85.6% (floor 85%)

Minimal diff: +2 / -11 in one file. No changes to worker/dispatch/ctx-cancel behavior.

Engine.Stop() had zero callers. REL-04 made dispatch workers exit on
engine ctx cancel (Start wires the manager ctx into stopFn via a
watcher goroutine), which is the real shutdown path. The dead method
carried latent hazards if ever wired: a producer blocked on a full
dispatchCh only selects on the manager runCtx, so Stop() without a
manager-ctx cancel would block that goroutine forever; and a Stop()
racing the first dispatch() before dispatchOnce could panic
"WaitGroup is reused before previous Wait has returned".

Zero-callers evidence (origin/main worktree):
  rg 'Engine\.Stop|\.Stop\(\)' internal/ cmd/
  -> only timer.Stop / testEnv.Stop / consumeCtx.Stop / webhookEnv.Stop
     (envtest + timers); no Engine.Stop caller anywhere.

stopFn, stopCtx, and workersWG remain used by the live ctx-cancel path
(Start goroutine, dispatchWorker, startDispatchWorkers) and are kept.
The ctx-cancel shutdown test (engine_shutdown_test.go) drives
workersWG.Wait() directly and never called Stop(), so live-path
coverage is unchanged. gosec G118 no longer sees the direct stopFn()
call inside Stop(); the remaining call lives in Start's goroutine
closure, so an honest //nolint:gosec documents that stopFn is invoked
there.
Copilot AI review requested due to automatic review settings August 3, 2026 15:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes the exported but unused Engine.Stop() from the collection engine, relying solely on the established manager-context cancellation path for shutdown (REL-04) and documenting the remaining stopFn invocation for gosec.

Changes:

  • Deleted the dead (*Engine).Stop() method and its doc comment.
  • Updated the constructor comment to describe only the ctx-cancel shutdown path.
  • Added an inline //nolint:gosec annotation on context.WithCancel to document gosec’s G118 trace behavior around stopFn.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@sonarqubecloud

sonarqubecloud Bot commented Aug 3, 2026

Copy link
Copy Markdown

@konih
konih merged commit b9ee537 into main Aug 3, 2026
30 of 31 checks passed
@konih
konih deleted the fix/hyg-01-fup-remove-engine-stop branch August 3, 2026 16:04
konih added a commit that referenced this pull request Aug 3, 2026
…nches (COV-90-S03)

Lock the collector's lifecycle and filtering edges with behavior-asserting
table tests:

- runner: NewRunner discovery-mapper construction + invalid rest.Config,
  ExtractionFailure.Error() identity formats, profile-not-found/transient
  skips, fatal per-target namespace-resolution errors, cluster-scoped
  (namespace-less) list path, redactExtractionReason truncation,
  sortExtractionFailures full key order, labelSelectorString determinism
  (sorted output, fail-safe empty on nil/invalid selector)
- prune: nil object, malformed RFC 6901 pointers as no-ops, slice-index
  pointer semantics (nil-in-place, out-of-range/non-numeric/negative
  no-ops, recursion into elements), unsupported JSONPath wildcards and
  filters as deliberate no-ops, rejected jsonPathTokens shapes
- helmdecode: structural secret errors, legacy uncompressed-JSON fallback,
  EDGE: every malformed payload (corrupt/truncated gzip, non-JSON) yields
  a wrapped decode error and never panics, denied-path prefixes, absent
  fields return nil without error
- collection_filter: MatchIntentNamespaces include/selector/exclude gates,
  CompileResourceRules error table, per-rule skip branches (GVR/namespace
  mismatch, unknown namespace, cluster-scoped default fallback), legacy
  selector fail-closed, evalMatchPolicy result shapes via stub cel.Program,
  sortedUniqueStrings, ScopeCeilingFromClusterScope copy semantics
- extractor: optional-attribute error skip, empty CEL expression wrapping,
  JSONPath eval-error wrapping vs not-found, empty range result,
  celValueToGo null handling

internal/collect coverage 89.2% -> 95.6%; uncovered lines 139 -> 58.

Spec note: the tasks.md item for idempotent double Engine.Stop() is
obsolete - Engine.Stop() was removed in PR #180 (HYG-01-FUP); skipped.
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.

2 participants