Remove dead code identified by reachability analysis - #395
Conversation
Codacy's report prompted a look at what the tree contains that nothing calls. Running `deadcode` from each service entry point found 94 functions unreachable from the collector, server and alerter binaries. Comparing that set against the v1.0.0 tag showed every one of them was already unreachable at that release two months ago, so none is recent work waiting for a caller. Four functions that were dead at v1.0.0 have since been adopted, which is a fair argument for removing on evidence rather than case-by-case optimism. This change takes the safe subset of that set: 47 functions, 698 lines of production code, and the 2,110 lines of tests that existed only to exercise them. Each deletion was applied and verified individually, and kept only where the resulting breakage was confined to tests whose own names target the deleted function; anything else was reverted automatically and is left for follow-up. That guard matters, because a first pass without it removed entire integration suites, such as the auth handler login and rate-limiting tests, which cover live code and merely call a dead method during cleanup. Two removals went further than single functions. The alerter's `secretManager` had no callers and no remaining implementation of the `SecretManager` interface, so both go. The resource `Registry` type, its constructor and its methods were used only by their own tests; the `Resource` and `Handler` types declared in the same file stay, because the MCP resource definitions use them. On the client, the unused `HeaderStatusIndicator` component goes along with the `@dnd-kit/sortable` and `@dnd-kit/utilities` packages. Only `@dnd-kit/core` is imported, and it remains. Coverage is essentially unmoved, because the deleted code and the deleted tests cancel out: collector holds at 85.5%, server goes from 55.5% to 55.3%, and alerter from 65.9% to 65.6%. No new code is added, so there is nothing new to cover. Left for follow-up, deliberately: 42 further dead functions whose tests need editing rather than deleting, the two superseded handler constructors whose test suites must be repointed at the `...WithSecurity` variants, and three test helpers in non-test files that ship in the binaries and want extracting into a test-only package.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (51)
💤 Files with no reviewable changes (50)
WalkthroughThis change removes unused APIs, implementations, tests, client dependencies, and the web status indicator across the alerter, collector, server, and client. The changelog records the removals. Existing retained functionality remains unchanged. ChangesAlerter and client cleanup
Collector cleanup
Server cleanup
Documentation
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | -171 |
| Duplication | -4 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
What this is
Following on from the Codacy review, I looked at what the tree contains
that nothing calls. Running
deadcodefrom each service entry pointfound 94 functions unreachable from the collector, server and
alerter binaries.
Cross-checking against the v1.0.0 tag settled whether any of it was
work-in-progress: every one of the 94 was already unreachable at that
release two months ago, so none is recent code awaiting a caller. Worth
noting the converse, though: four functions that were dead at v1.0.0
have since been adopted (
EstimateTokens,EstimateTotalTokens,GetBriefDescription,HasToolResults), which is a decent argument forremoving on evidence rather than case-by-case optimism.
This PR takes the mechanically safe subset. Two follow-ups are noted at
the bottom.
Scope
Two removals went beyond single functions:
secretManagerhad no callers, and with it gone theSecretManagerinterface ininterfaces.gohad no implementation andno users either, so both are deleted.
Registrytype, its constructor and its methods wereused only by their own tests.
ResourceandHandler, declared inthe same file, stay: the MCP resource definitions in
pg_system_info.gouse them.On the client, the unused
HeaderStatusIndicatorcomponent goes, alongwith
@dnd-kit/sortableand@dnd-kit/utilities. Only@dnd-kit/coreis imported and it remains.
How the deletions were validated
Each function was deleted and verified individually, and kept only
where the resulting breakage was confined to test functions whose own
names target the deleted symbol. Anything else was reverted
automatically.
That guard is the most important thing in this PR. A first pass without
it deleted 262 test functions and 11,382 lines, including entire
integration suites such as the auth handler login, rate-limiting and
secure-cookie tests, and the alert
Unacknowledgetests. Those coverlive code and broke only because they call a dead method during cleanup
or use a private setter as an injection seam. I had allowed a test to be
removed when its name mentioned the receiver type, which is far too
loose; the rule now requires the function name itself.
Coverage
Essentially unmoved, because the deleted code and its deleted tests
cancel out:
mainNo new code is added, so there is nothing new to cover and the 90%
floor for new and modified code does not bite. The server sitting below
the 60% repository goal is pre-existing rather than introduced here,
and closing that 4.7-point gap is a substantial separate piece of work
rather than something to bolt onto a deletion.
Verification
gofmt,golangci-lintandgo vetclean on all three modules.golangci-lintcaught one genuine follow-on, an orphanedreWordregexp left behind by deleting
CountWords, now removed.are the two pre-existing
vector(3)fixture failures from Gemini provider: (1) knowledge base search silently falls back to OpenAI due to missing gemini_embedding column in search_knowledgebase.go; (2) session startup fails with 400 "empty Part" error #337,which reproduce identically on unmodified
main.files pass.
One note for anyone re-running this locally: the suites must be run with
-p=1, as the sub-project Makefiles do. I first ran them without it andgot a spray of
deadlock detectedandrelation already existsfailures, because the integration tests all build the same schema in one
shared database. Incidentally
collector/Makefiledoes not set-p=1whereserver/Makefiledoes, which looks like an oversight wortha separate look.
Deliberately left for follow-up
deleting. These cluster usefully: the ten notification-channel CRUD
methods in the alerter all share one
TestNotificationQueriesReturnErrorOnClosedPool, theinternal/loggingfaçade shares
TestLogLevelFiltering, and several are test seams likeAuthHandler.CloseandAlertHandler.setAlertResolver.NewConnectionHandlerand
NewNotificationChannelHandler.cmd/mcp-servercalls the...WithSecurityvariants; the test suites still use the old ones, so32 tests need repointing at the live constructors first.
NewTestClient,NewTestDatastoreWithSecret,NewTestDatastore). They compile intothe shipped binaries but are used across package boundaries by tests,
so they cannot simply become
_test.gofiles; the right fix isextracting them into a test-only package, which is import churn rather
than deletion.
Summary by CodeRabbit