Repository navigation
Description
Overview
Analyzed 217 non-test Go files (about 38.8k lines, 1,383 function declarations) under internal/. No open [refactor] issues existed, so none were closed. Many earlier findings were already fixed (util.IsASCII and util.HashForLog are now shared; see Closes #17105 and #16716). The remaining issues are about 25 production functions with no non-test callers, a hash-length inconsistency in delegation audit logs, a few inline duplicates of util helpers, and three direct env reads that cannot move to envutil without an import cycle.
No code was changed. Dead-code claims come from a repo-wide name search that excludes comments and definitions. Check interface, reflection, and external use before deleting anything.
Full Report
1. Dead or test-only production functions (zero non-test references)
| File | Functions | Note |
|---|---|---|
internal/sys/docker.go |
CheckDockerAccessible, CheckContainerRuntimeAccessible |
Callers use the *AccessError variants |
internal/sys/container.go |
extractContainerIDFromCgroup |
DetectContainerID calls extractContainerIDFromCgroupFiles directly |
internal/config/validation_env.go |
ValidateExecutionEnvironment, ValidateContainerizedEnvironment |
cmd/root.go uses the ForRuntime variants |
internal/config/gateway_env.go |
GetGatewayPortFromEnv, GetGatewayDomainFromEnv |
Unused |
internal/server/middleware_auth.go |
authMiddleware |
applyAuthIfConfiguredWithDelegation is the live path |
internal/server/hmac.go |
computeHMAC |
Verifier uses hmacMessage + hmacutil.Verify |
internal/server/session.go |
getSessionKeys |
Debug helper with no caller |
internal/proxy/graphql_rewrite.go |
InjectGuardFields, injectPRGuardFields |
Live path is injectGuardFields → injectPRGuardFieldsParsed |
internal/delegation/store.go |
markReconciled, IsRecoveryIncomplete |
MarkReconciledAndSaveState inlines the same logic |
internal/githubhttp/visibility.go |
VerifySinkVisibility |
Server uses EffectiveSinkVisibility plus its own lookup |
internal/difc/reflect.go |
BuildReflectResponse |
No importers |
internal/difc/evaluator.go |
NewEvaluator |
Unused |
internal/logger/rpc_logger.go |
LogRPCMessage, LogRPCRequest, LogRPCResponse |
*ForSession variants are used |
internal/logger/jsonl_logger.go |
LogRPCMessageJSONL |
Unused |
internal/logger/slog_adapter.go |
NewSlogLogger |
NewSlogLoggerWithHandler is used |
internal/server/unified_lifecycle.go |
GetPayloadSizeThreshold, IsDIFCEnabled |
Unused |
internal/auth/header.go |
ValidateAgentID |
Unused outside comments |
internal/auth/id.go |
GenerateRandomAgentID |
Unused, despite the startup-generation comment |
internal/httputil/tls.go |
TLSTrustEnvKeys |
Test-only |
internal/mcp/connection.go |
NewHTTPConnection |
Launcher calls NewHTTPConnectionWithCA |
internal/server/unified_lifecycle.go |
RegisterTestTool, SetTestMode |
Test seams in production code |
internal/guard/registry.go RegisterGuardType has no production caller. CreateGuard only resolves noop unless a guard is registered, so confirm the intended registration path before cleaning this up.
2. Duplicates and near-duplicates
- Hash-length drift (behavior decision needed):
internal/delegation/audit.gohashForAudituses 32 hex characters.control_handler.go,proxy/delegation.go, andserver/delegation.gocallutil.HashForLog(x, 16, ""). The sameRunIDtherefore appears at two lengths across audit and debug logs. Pick one length before unifying, because this changes log output. lowercaseASCII(internal/config/guard_policy_validation.go:268): Not interchangeable withutil.NormalizeStringCI, which trims and uses full UnicodeToLower. Move it intoutilas an explicitly ASCII helper instead of collapsing it.- Inline lowercase and trim (
internal/oidc/azure.go:62): Duplicatesutil.NormalizeStringCI.oidccan importutilwithout a cycle. - Inline truncation (
internal/sys/docker.go:101-102):detail[:N] + "..."duplicatesutil.TruncateWithSuffix. - Hand-rolled map copy (
internal/mcp/schema.gocopySchemaWithKey): Could useutil.ShallowCloneMapplus one assignment.
3. Placement and layering
- Direct env reads bypass
envutil:internal/logger/logger.go:40,181(DEBUG,DEBUG_COLORS) andinternal/sanitize/payload_redaction.go:96(raw payload opt-in).envutilimportsloggerandsanitize, so these files cannot import it without a cycle. Consolidating needs a lower-level env helper package first. - Test seams in production:
RegisterTestToolandSetTestModelive inunified_lifecycle.go. Consider moving them to a test-only file.
Recommendations
- Low risk: Delete confirmed dead production wrappers and move test-only helpers into
_test.gofiles. Re-runmake agent-finishedafter each package. - Decision needed: Choose a single hash length for
HashForLogin delegation audit output. - Low risk: Move
lowercaseASCIItoutil. Replace the inline truncation insys/docker.goand the inline normalization inoidc/azure.gowithutilhelpers. - Medium: Add a low-level env helper package to resolve the
envutilcycle, then move the three direct env reads.
Analysis metadata
- Non-test Go files: 217 (about 38.8k lines)
- Function declarations: 1,383 (1,276 unique names)
- Dead or test-only functions flagged: about 25
- Duplicate groups flagged: 5
- Method: Repo-wide name search, call-site inspection, and import-graph checks
- Code changes: none
References: §45264742054
Generated by Semantic Function Refactoring · copilot · routed: haiku55 xhigh · ~82 AIC · ⊞ 7.4K · ◷
Activity