Skip to content

refactor: remove redundant config default fallbacks in server and launcher#3032

Merged
lpcox merged 3 commits intomainfrom
refactor/config-defaults-dedup-2983
Apr 1, 2026
Merged

refactor: remove redundant config default fallbacks in server and launcher#3032
lpcox merged 3 commits intomainfrom
refactor/config-defaults-dedup-2983

Conversation

@lpcox
Copy link
Copy Markdown
Collaborator

@lpcox lpcox commented Apr 1, 2026

Summary

Removes duplicated config default logic identified in #2983 / #2984. Consumer code in unified.go and launcher.go re-implemented config field defaults that the config loading layer already guarantees.

Changes

New: Config.EnsureGatewayDefaults() (config_core.go)

Exported method that guarantees cfg.Gateway is non-nil and all gateway-level + feature defaults are applied. This makes the config loading contract explicit and safe for any consumer — including test code that constructs configs manually without going through LoadFromFile/LoadFromStdin.

Simplified: internal/server/unified.go

Before (3 nil-guard + fallback blocks, 18 lines):

payloadDir := config.DefaultPayloadDir
if cfg.Gateway != nil && cfg.Gateway.PayloadDir != "" {
    payloadDir = cfg.Gateway.PayloadDir
}
// ... repeated for PayloadPathPrefix, PayloadSizeThreshold

After (direct field access, 3 lines):

cfg.EnsureGatewayDefaults()
payloadDir := cfg.Gateway.PayloadDir
payloadPathPrefix := cfg.Gateway.PayloadPathPrefix
payloadSizeThreshold := cfg.Gateway.PayloadSizeThreshold

Simplified: internal/launcher/launcher.go

Before (nil-guard + fallback + branch logging, 8 lines):

startupTimeout := time.Duration(config.DefaultStartupTimeout) * time.Second
if cfg.Gateway != nil && cfg.Gateway.StartupTimeout > 0 {
    startupTimeout = time.Duration(cfg.Gateway.StartupTimeout) * time.Second
}

After (direct access, 2 lines):

cfg.EnsureGatewayDefaults()
startupTimeout := time.Duration(cfg.Gateway.StartupTimeout) * time.Second

Updated: launcher_test.go

Updated test name and comment for TestLauncher_TimeoutWithNilGateway to document that EnsureGatewayDefaults now handles the nil case.

Why EnsureGatewayDefaults instead of just removing nil-guards?

100+ test files construct config.Config{} without setting Gateway. Rather than touching all of them, EnsureGatewayDefaults() provides a single defensive call that makes the contract explicit while keeping existing tests working.

Closes #2983
Closes #2984

…ncher

Add Config.EnsureGatewayDefaults() that guarantees cfg.Gateway is non-nil
with all defaults applied. Call it from NewUnified() and launcher.New()
to replace the per-field nil-guard + fallback blocks that duplicated
defaults already established by the config loading layer.

This removes ~20 lines of redundant defensive code across unified.go
(3 blocks for PayloadDir, PayloadPathPrefix, PayloadSizeThreshold) and
launcher.go (1 block for StartupTimeout).

Closes #2983
Closes #2984

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 1, 2026 23:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 duplicated “fallback default” logic in server/launcher consumers by introducing a config-level helper that guarantees cfg.Gateway is non-nil and defaulted, then switching call sites to rely on direct field access.

Changes:

  • Added (*config.Config).EnsureGatewayDefaults() to centralize Gateway nil-safety + default application.
  • Updated internal/server/unified.go and internal/launcher/launcher.go to call EnsureGatewayDefaults() and read cfg.Gateway.* directly.
  • Adjusted launcher tests/comments to reflect that launcher.New now handles a nil Gateway.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
internal/config/config_core.go Adds exported helper to ensure Gateway exists and applies gateway + feature defaults.
internal/server/unified.go Removes local default fallbacks for payload config; relies on defaulted cfg.Gateway fields.
internal/launcher/launcher.go Removes local startup-timeout fallback; relies on defaulted cfg.Gateway.StartupTimeout.
internal/launcher/launcher_test.go Updates test setup/commentary for nil-gateway defaulting behavior.

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

lpcox and others added 2 commits April 1, 2026 16:20
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants