Skip to content

fix(controller): preserve channel configs and agent model fallbacks on redeploy#1337

Merged
jeanduplessis merged 4 commits intomainfrom
fix/preserve-channel-and-model-configs-on-redeploy
Mar 23, 2026
Merged

fix(controller): preserve channel configs and agent model fallbacks on redeploy#1337
jeanduplessis merged 4 commits intomainfrom
fix/preserve-channel-and-model-configs-on-redeploy

Conversation

@kilo-code-bot
Copy link
Contributor

@kilo-code-bot kilo-code-bot bot commented Mar 20, 2026

Summary

The controller's generateBaseConfig() was overwriting channel configs (channels.telegram, channels.discord, channels.slack) and the agent model default (agents.defaults.model) with fresh object literals on every restart/redeploy. This destroyed user customizations such as Discord guild configs, Slack slash commands, Telegram group policies, DM allowlists, and model fallback settings.

Fix: Switch from full object assignment to the null-coalescing init + field-level set pattern (already used elsewhere in generateBaseConfig for gateway, tools, browser, plugins.entries, etc.). On redeploy, existing config objects are preserved via config.channels.X = config.channels.X ?? {} and only env-derived fields (botToken, enabled, dmPolicy, etc.) are updated. User-added keys are left untouched. Initial bootstrap still sets all defaults because the config starts empty.

Changes in config-writer.ts:

  • Telegram (lines 224-236): replaced config.channels.telegram = { ... } with field-level sets
  • Discord (lines 243-254): replaced config.channels.discord = { ... } with field-level sets; also preserves dm sub-object
  • Slack (lines 260-266): replaced config.channels.slack = { ... } with field-level sets
  • Agent model (lines 184-189): replaced config.agents.defaults.model = { primary: ... } with config.agents.defaults.model.primary = ..., preserving fallback and other user-set keys

Verification

  • pnpm typecheck — passed (0 errors)
  • pnpm test -- controller/src/config-writer.test.ts — 47 tests passed
  • pnpm test (full suite) — 948 tests passed across 42 files
  • pnpm lint (kiloclaw) — 0 warnings, 0 errors

Visual Changes

N/A

Reviewer Notes

  • The fix follows the exact same null-coalescing + field-level set pattern already used for config.gateway, config.tools, config.browser, and config.plugins.entries in the same function — no new patterns introduced.
  • Four new tests verify that user customizations survive a restart for each channel (Telegram, Discord, Slack) and for agent model fallback settings.
  • The writeBaseConfig (fresh install / config restore) path is unaffected because config starts empty, so the ?? {} initializers create fresh objects and all fields are set — identical behavior to before.

Built for Florian by Kilo for Slack

…n redeploy

Channel configs (Telegram, Discord, Slack) and agent model defaults were
being overwritten with fresh object literals on every restart/redeploy,
destroying user customizations. Switch to null-coalescing init + field-level
set pattern (consistent with the rest of generateBaseConfig) so existing
config keys are preserved and only env-derived fields are updated.
@kilo-code-bot
Copy link
Contributor Author

kilo-code-bot bot commented Mar 20, 2026

Code Review Summary

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0

Fix these issues in Kilo Cloud

Issue Details (click to expand)

CRITICAL

File Line Issue
N/A N/A None

WARNING

File Line Issue
kiloclaw/controller/src/config-writer.ts 233 Telegram allowFrom still persists across redeploys because this branch only rewrites the field when TELEGRAM_DM_ALLOW_FROM is set or the key is missing, so removing the env var or tightening TELEGRAM_DM_POLICY leaves the previous allowlist in place.
kiloclaw/controller/src/config-writer.ts 254 Discord dm.allowFrom is still only initialized when missing, so a machine that was previously deployed with DISCORD_DM_POLICY=open keeps stale DM access after later redeploys tighten the policy.

SUGGESTION

File Line Issue
N/A N/A None
Other Observations (not in diff)

Issues found in unchanged code that cannot receive inline comments:

N/A

Files Reviewed (2 files)
  • kiloclaw/controller/src/config-writer.ts - 2 issues
  • kiloclaw/controller/src/config-writer.test.ts

Reviewed by gpt-5.4-20260305 · 1,144,798 tokens

…dits

The previous field-level set pattern unconditionally overwrote allowFrom
on every redeploy, which destroyed user-customized DM allowlists.

Telegram: TELEGRAM_DM_ALLOW_FROM env override still always wins; without
it, allowFrom is only written when the key is absent (first boot).

Discord: allowFrom is only seeded when the key is absent; subsequent
redeploys leave the user's value untouched.
@jeanduplessis jeanduplessis enabled auto-merge March 23, 2026 07:07
@jeanduplessis jeanduplessis merged commit 668a846 into main Mar 23, 2026
18 checks passed
@jeanduplessis jeanduplessis deleted the fix/preserve-channel-and-model-configs-on-redeploy branch March 23, 2026 07:10
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