Skip to content

refactor(config): dedupe sidecar path resolution and env overrides - #1161

Merged
edenreich merged 2 commits into
mainfrom
refactor/dedupe-sidecar-config-helpers
Sep 2, 2026
Merged

edenreich merged 2 commits into
mainfrom
refactor/dedupe-sidecar-config-helpers

Conversation

@edenreich

Copy link
Copy Markdown
Contributor

Summary

Closes #1154.

  • Replaces the eleven copy-pasted getEffective<X>ConfigPath() functions in cmd/runtime/config.go with a single sidecarPath(fileName) resolver (project .infer/ first, then ~/.infer/, then the project default).
  • Replaces the nine hand-rolled apply<X>EnvOverrides functions (channels, heartbeat, judge, computer_use, browser_use, memory, hooks, reminders, plugins) with applySidecarEnv(cfg, prefix), which runs the existing viper-backed resolveViperEnvironmentVariables walker over each sidecar struct. It uses an env-only viper instance, so the mapstructure:"-" guarantee that legacy blocks in config.yaml cannot leak into sidecars still holds.
  • applyPromptsEnvOverrides and applyKeybindingEnvOverrides are different shapes and are untouched.

Net: 50 insertions, 557 deletions.

Behaviour notes

Sidecar env parsing now matches how every other INFER_* key already behaves:

  • an invalid int/bool value (INFER_JUDGE_TIMEOUT=abc) yields 0/false instead of being silently ignored
  • INFER_PLUGINS_DIR is no longer trimmed or skipped when blank
  • fields that never had a hand-rolled line (for example plugins.max_instructions_chars, reminders.merge) are now env-overridable

Test plan

  • go test ./cmd/runtime/... ./config/...
  • task precommit:run (mod tidy, mocks, fmt, lint) clean
  • Existing coverage exercised: daemon_overlay_test.go (env wins over ~/.infer/channels.yaml, legacy config.yaml block stays inert, path precedence), config_memory_test.go, config_reminders_test.go, config_pointer_env_test.go, userspace_first_test.go

Replace the eleven copy-pasted getEffective<X>ConfigPath functions with one
sidecarPath(fileName) resolver, and the nine hand-rolled apply<X>EnvOverrides
functions with applySidecarEnv, which runs the existing viper-backed
resolveViperEnvironmentVariables walker over each sidecar using an env-only
viper instance so legacy blocks in config.yaml still cannot leak in.

Closes #1154
@edenreich
edenreich requested a review from a team as a code owner September 2, 2026 20:22
@edenreich

Copy link
Copy Markdown
Contributor Author

@infer Can you review this PR? use /ponytail:ponytail /ponytail:ponytail-review /cobra-viper

@inference-gateway-maintainer

inference-gateway-maintainer Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Model: ollama_cloud/glm-5.3-flash · View Job

Todos

Pull Request

#1161

✅ Infer Result: Success

All checks done. The prompts config also has full snake_case tags, which confirms one optional follow-up shrink. Writing up the review now:

Review complete. Here are my findings:


PR #1161 review (ponytail / ponytail-review / cobra-viper)

Verdict: approve. This is the right kind of lazy - it deletes 557 lines of copy-paste and reuses the walker the main config already trusts. I traced every deleted hand-rolled function against the sidecar structs' mapstructure tags and found no regressions. One behavior delta deserves a conscious sign-off, and two optional shrinks remain.

What I verified

  • Env var names are preserved. Every field the deleted functions set has an explicit snake_case mapstructure tag (initial_delay, cdp_endpoint, commit_message, max_actions_per_minute, ...), so resolveViperEnvironmentVariables reproduces the old env names exactly, including the nested INFER_CHANNELS_TELEGRAM_BOT_TOKEN and INFER_MEMORY_BACKEND_GIT_SYNC_ON_START paths. No env var was renamed.
  • No coverage lost; only additions. Everything the old functions covered is still covered; newly live: channels.telegram.media.*, plugins.max_instructions_chars/lines, reminders.merge, browser_use.tools.screenshot/tabs.enabled.
  • The mapstructure:"-" isolation guarantee holds. The env-only viper means legacy channels:/judge: blocks in config.yaml still cannot leak in; daemon_overlay_test.go still pins that contract.
  • AllowEmptyEnv(true) correctly matches the old os.LookupEnv set-but-empty semantics. The unexported path field on PluginsConfig is correctly skipped by CanSet, and plugins stays userspace-only.

One delta to consciously accept

  • INFER_CHANNELS_REQUIRE_APPROVAL=maybe now yields false (approval gate silently disabled) where the old code ignored the bad value and kept the file's true. Same family: INFER_JUDGE_TIMEOUT=30s becomes 0 (benign - Effective() falls back to 30), and whitespace-padded values like " true " or " 9 " no longer trim, so they parse as false/0. This is consistent with how every main-config INFER_* int/bool already behaves via viper's cast, and the PR documents it, so I won't block - but require_approval is the one knob where a typo flips a safety default rather than failing loudly. If you ever revisit, a one-line warning on unparseable env values in the walker would cover all sidecars at once.

Minor trivia, no action needed: INFER_REMINDERS_MERGE is applied after MergeWithDefaults already ran, so the env flag can't change merge behavior - it only matters for readers of the flag, of which there are none post-load. Harmless.

ponytail-review findings

The diff is the deletion: -557/+50. Two optional cuts left:

  • cmd/runtime/config.go:L365-412: shrink: the 45-line prompts env map duplicates the walker. applySidecarEnv(&cfg.Prompts, "prompts")` - PromptsConfig already carries matching snake_case tags for every entry. Follow-up PR material, not a blocker (tests call the function directly and would need updating).
  • cmd/runtime/config.go:L232-360: shrink (borderline): the ten identical 7-line load blocks could collapse into one generic helper (load func(string) (*T, error)`, defaults func, prefix). Only do it if it stays boring - the explicit blocks are readable, and funlen already forces a nolint here. Skip without guilt.

net: -45 lines possible. Beyond that: lean already.

cobra-viper lens

The env-only viper instance is exactly the right idiom: one typed-config path, env applied after load so env > file > defaults precedence holds, and no scattering of os.Getenv calls. Reusing the proven walker instead of a second env-parsing mechanism is the correct reuse over rewrite.

Test evidence

  • go test ./cmd/runtime/... ./config/...: everything passes except TestPointerDefaultsSurviveWithoutEnvOverride and TestPointerOptionPrecedence - these are the known environmental failures in Actions-runner sandboxes (write/edit/delete require_approval pointer flips true to false) that fail identically on main; the walker and tests they exercise are untouched by this PR.
  • go vet -tags purego ./cmd/runtime/... ./config/...: clean.

Follow-up notes

  • The newly env-overridable knobs (channels.telegram.media.*, plugins.max_instructions_*, reminders.merge, browser screenshot/tabs tool toggles) are not yet in docs/configuration-reference.md - worth a small docs pass, ideally in this PR or a follow-up.
  • Commit message is correctly lowercase conventional (refactor(config): ...) for semantic-release.

Model: ollama_cloud/glm-5.3-flash · Exit Code: 0 · Duration: 4m 6s

Tokens: 931,725 in · 18,466 out · 950,191 total (16 requests)

Tool calls: 35 total · 100% success rate

Traces
Session: 1788380776-7d4cacee

session (headless, success)                                                  3m59s
├── chat ollama_cloud/glm-5.3-flash                                           3.6s
│   ╰── POST /v1/chat/completions [inference-gateway]                         3.6s
│       ╰── POST /proxy/ollama_cloud/chat/completions [inference-gateway]     3.6s [error: *errors.errorString]
│           ╰── POST /proxy/:provider/*path [inference-gateway]               3.6s
│               ╰── POST /v1/chat/completions [inference-gateway]             3.6s [error: *errors.errorString]
├── execute_tool Read call_xrxqqg87                                          184µs
├── execute_tool Read call_qjhzdjir                                          155µs
├── execute_tool Bash call_y0367m73                                            4ms
├── chat ollama_cloud/glm-5.3-flash                                           3.6s
│   ╰── POST /v1/chat/completions [inference-gateway]                         3.6s
│       ╰── POST /proxy/ollama_cloud/chat/completions [inference-gateway]     3.6s [error: *errors.errorString]
│           ╰── POST /proxy/:provider/*path [inference-gateway]               3.6s
│               ╰── POST /v1/chat/completions [inference-gateway]             3.6s [error: *errors.errorString]
├── execute_tool TodoWrite call_8ws9sn5g                                      56µs
├── execute_tool Bash call_3oxr1ax3                                            4ms
├── chat ollama_cloud/glm-5.3-flash                                           2.9s
│   ╰── POST /v1/chat/completions [inference-gateway]                         2.9s
│       ╰── POST /proxy/ollama_cloud/chat/completions [inference-gateway]     2.8s [error: *errors.errorString]
│           ╰── POST /proxy/:provider/*path [inference-gateway]               2.8s
│               ╰── POST /v1/chat/completions [inference-gateway]             2.8s [error: *errors.errorString]
├── execute_tool Grep call_2muhkt5t                                           92ms
├── execute_tool Bash call_4owper2s                                            4ms
├── chat ollama_cloud/glm-5.3-flash                                           3.7s
│   ╰── POST /v1/chat/completions [inference-gateway]                         3.7s
│       ╰── POST /proxy/ollama_cloud/chat/completions [inference-gateway]     3.7s [error: *errors.errorString]
│           ╰── POST /proxy/:provider/*path [inference-gateway]               3.7s
│               ╰── POST /v1/chat/completions [inference-gateway]             3.7s [error: *errors.errorString]
├── execute_tool TodoWrite call_5q0kzqo7                                      41µs
├── execute_tool Read call_fme4n4uq                                          263µs
├── chat ollama_cloud/glm-5.3-flash                                          27.8s
│   ╰── POST /v1/chat/completions [inference-gateway]                        27.8s
│       ╰── POST /proxy/ollama_cloud/chat/completions [inference-gateway]    27.8s [error: *errors.errorString]
│           ╰── POST /proxy/:provider/*path [inference-gateway]              27.8s
│               ╰── POST /v1/chat/completions [inference-gateway]            27.8s [error: *errors.errorString]
├── execute_tool Read call_c5lq33f5                                          216µs
├── execute_tool Grep call_c2dt4u6t                                          457ms
├── chat ollama_cloud/glm-5.3-flash                                           5.9s
│   ╰── POST /v1/chat/completions [inference-gateway]                         5.9s
│       ╰── POST /proxy/ollama_cloud/chat/completions [inference-gateway]     5.9s [error: *errors.errorString]
│           ╰── POST /proxy/:provider/*path [inference-gateway]               5.9s
│               ╰── POST /v1/chat/completions [inference-gateway]             5.9s [error: *errors.errorString]
├── execute_tool Read call_fux48s8i                                          133µs
├── execute_tool Read call_bw81fldq                                          205µs
├── execute_tool Read call_4atel2bi                                          219µs
├── chat ollama_cloud/glm-5.3-flash                                          19.7s
│   ╰── POST /v1/chat/completions [inference-gateway]                        19.7s
│       ╰── POST /proxy/ollama_cloud/chat/completions [inference-gateway]    19.7s [error: *errors.errorString]
│           ╰── POST /proxy/:provider/*path [inference-gateway]              19.7s
│               ╰── POST /v1/chat/completions [inference-gateway]            19.7s [error: *errors.errorString]
├── execute_tool Grep call_uewabfg3                                            2ms
├── execute_tool Read call_ekf8h2ea                                          144µs
├── execute_tool Read call_2oudxejm                                          133µs
├── chat ollama_cloud/glm-5.3-flash                                           9.1s
│   ╰── POST /v1/chat/completions [inference-gateway]                         9.1s
│       ╰── POST /proxy/ollama_cloud/chat/completions [inference-gateway]     9.1s [error: *errors.errorString]
│           ╰── POST /proxy/:provider/*path [inference-gateway]               9.1s
│               ╰── POST /v1/chat/completions [inference-gateway]             9.1s [error: *errors.errorString]
├── execute_tool Read call_sjh48qic                                          149µs
├── execute_tool Grep call_e9z676ew                                            3ms
├── chat ollama_cloud/glm-5.3-flash                                           3.5s
│   ╰── POST /v1/chat/completions [inference-gateway]                         3.5s
│       ╰── POST /proxy/ollama_cloud/chat/completions [inference-gateway]     3.5s [error: *errors.errorString]
│           ╰── POST /proxy/:provider/*path [inference-gateway]               3.5s
│               ╰── POST /v1/chat/completions [inference-gateway]             3.5s [error: *errors.errorString]
├── execute_tool Grep call_qoy15j8q                                            3ms
├── chat ollama_cloud/glm-5.3-flash                                           4.9s
│   ╰── POST /v1/chat/completions [inference-gateway]                         4.9s
│       ╰── POST /proxy/ollama_cloud/chat/completions [inference-gateway]     4.9s [error: *errors.errorString]
│           ╰── POST /proxy/:provider/*path [inference-gateway]               4.9s
│               ╰── POST /v1/chat/completions [inference-gateway]             4.9s [error: *errors.errorString]
├── execute_tool Read call_6506dfrp                                          148µs
├── execute_tool Read call_93svyrod                                          148µs
├── execute_tool Read call_6bwi2m97                                          164µs
├── execute_tool Read call_q2e6fkmq                                          172µs
├── chat ollama_cloud/glm-5.3-flash                                          31.4s
│   ╰── POST /v1/chat/completions [inference-gateway]                        31.4s
│       ╰── POST /proxy/ollama_cloud/chat/completions [inference-gateway]    31.4s [error: *errors.errorString]
│           ╰── POST /proxy/:provider/*path [inference-gateway]              31.4s
│               ╰── POST /v1/chat/completions [inference-gateway]            31.4s [error: *errors.errorString]
├── execute_tool TodoWrite call_mr00l7zy                                      89µs
├── execute_tool Grep call_pjm3cshw                                          563µs
├── execute_tool Grep call_n22mhg0e                                          664µs
├── chat ollama_cloud/glm-5.3-flash                                           7.7s
│   ╰── POST /v1/chat/completions [inference-gateway]                         7.7s
│       ╰── POST /proxy/ollama_cloud/chat/completions [inference-gateway]     7.6s [error: *errors.errorString]
│           ╰── POST /proxy/:provider/*path [inference-gateway]               7.6s
│               ╰── POST /v1/chat/completions [inference-gateway]             7.6s [error: *errors.errorString]
├── execute_tool Read call_i6osn7jf                                          130µs
├── execute_tool Bash call_zct2ibea                                          22.7s [error: tool_error]
├── chat ollama_cloud/glm-5.3-flash                                          17.6s
│   ╰── POST /v1/chat/completions [inference-gateway]                        17.6s
│       ╰── POST /proxy/ollama_cloud/chat/completions [inference-gateway]    17.6s [error: *errors.errorString]
│           ╰── POST /proxy/:provider/*path [inference-gateway]              17.6s
│               ╰── POST /v1/chat/completions [inference-gateway]            17.6s [error: *errors.errorString]
├── execute_tool Memory call_6s3c4tha                                         90µs
├── execute_tool Bash call_fcxb32sg                                          378ms [error: tool_error]
├── chat ollama_cloud/glm-5.3-flash                                          29.5s
│   ╰── POST /v1/chat/completions [inference-gateway]                        29.5s
│       ╰── POST /proxy/ollama_cloud/chat/completions [inference-gateway]    29.5s [error: *errors.errorString]
│           ╰── POST /proxy/:provider/*path [inference-gateway]              29.5s
│               ╰── POST /v1/chat/completions [inference-gateway]            29.5s [error: *errors.errorString]
├── execute_tool Grep call_mu9whbp6                                            3ms
├── execute_tool TodoWrite call_ldumbsst                                      54µs
├── execute_tool Bash call_95nwup7q                                           9.1s
├── chat ollama_cloud/glm-5.3-flash                                          18.5s
│   ╰── POST /v1/chat/completions [inference-gateway]                        18.5s
│       ╰── POST /proxy/ollama_cloud/chat/completions [inference-gateway]    18.5s [error: *errors.errorString]
│           ╰── POST /proxy/:provider/*path [inference-gateway]              18.5s
│               ╰── POST /v1/chat/completions [inference-gateway]            18.5s [error: *errors.errorString]
├── execute_tool TodoWrite call_z1dxovt1                                      76µs
╰── chat ollama_cloud/glm-5.3-flash                                          13.5s
    ╰── POST /v1/chat/completions [inference-gateway]                        13.4s
        ╰── POST /proxy/ollama_cloud/chat/completions [inference-gateway]    13.4s [error: *errors.errorString]
            ╰── POST /proxy/:provider/*path [inference-gateway]              13.4s
                ╰── POST /v1/chat/completions [inference-gateway]            13.4s [error: *errors.errorString]
Stats
Tool Calls

╭───────────┬───────┬───────┬────────╮
│ Tool      │ Calls │ Fail% │ Avg    │
├───────────┼───────┼───────┼────────┤
│ Read      │ 15    │ 0%    │ 0ms    │
│ Grep      │ 8     │ 0%    │ 70ms   │
│ Bash      │ 6     │ 33%   │ 5366ms │
│ TodoWrite │ 5     │ 0%    │ 0ms    │
│ Memory    │ 1     │ 0%    │ 0ms    │
╰───────────┴───────┴───────┴────────╯

Token Usage

╭────────────────────────────┬────────┬────────┬────────────┬────────┬──────╮
│ Model                      │ Prompt │ Cached │ Completion │ Total  │ Cost │
├────────────────────────────┼────────┼────────┼────────────┼────────┼──────┤
│ ollama_cloud/glm-5.3-flash │ 931725 │ 0      │ 18466      │ 950191 │ -    │
╰────────────────────────────┴────────┴────────┴────────────┴────────┴──────╯

Sessions

╭───────────┬──────────┬──────────╮
│ Execution │ Mode     │ Sessions │
├───────────┼──────────┼──────────┤
│ headless  │ headless │ 1        │
╰───────────┴──────────┴──────────╯

Triggered by edenreich · Infer Action · OSS

Trim and strictly parse bool/int/uint/float env values in the shared
viper walker so a typo like INFER_CHANNELS_REQUIRE_APPROVAL=maybe keeps
the file value rather than silently flipping the safety gate to false.
Restores the semantics of the hand-rolled sidecar overrides for every
sidecar at once.
@edenreich

Copy link
Copy Markdown
Contributor Author

Addressed the require_approval delta: setScalarFromViper now trims and parses bool/int/uint/float strictly and skips on failure, so INFER_CHANNELS_REQUIRE_APPROVAL=maybe or " true " keeps the file value instead of casting to false. Covered by TestApplySidecarEnv_StrictScalars. Prompts shrink and docs pass left for a follow-up.

@edenreich
edenreich merged commit 3ad2feb into main Sep 2, 2026
1 check passed
@edenreich
edenreich deleted the refactor/dedupe-sidecar-config-helpers branch September 2, 2026 21:06
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.188.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TASK] Refactor dedupe sidecar config path and env override helpers in cmd/runtime

1 participant