make gateway aware of config.json change#1187
Conversation
There was a problem hiding this comment.
Pull request overview
Adds gateway-side awareness of config.json changes by introducing a polling watcher that hot-reloads configuration and recreates the LLM provider/agent registry at runtime.
Changes:
- Add polling-based
config.jsonwatcher ingatewayCmdto trigger live reloads. - Add
AgentLoop.SetProviderto swap provider/config during runtime reload. - Extend
pkg/loggerwith formatted helper functions used by the gateway hot-reload path.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
cmd/picoclaw/internal/gateway/helpers.go |
Adds config polling watcher + main loop to reload config and recreate provider on change. |
pkg/agent/loop.go |
Adds SetProvider to update agent loop config/provider via registry rebuild. |
pkg/logger/logger.go |
Adds formatted logging helper functions used by gateway reload logging. |
go.mod |
Promotes github.com/h2non/filetype to a direct dependency. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
PR #1187 Review: Make Gateway Aware of config.json Changes📋 OverviewThis PR implements configuration hot-reload functionality: when Changed Files:
✅ What's Done Well
|
| Aspect | Rating | Notes |
|---|---|---|
| Functionality | ⭐⭐⭐⭐ | Core feature implemented, but limited scope |
| Code Quality | ⭐⭐⭐⭐ | Clean structure, proper error handling |
| Safety | ⭐⭐⭐ | Possible race condition |
| Maintainability | ⭐⭐⭐⭐ | Readable code, some hardcoded values |
Overall: A useful feature improvement, but suggest addressing the above issues before merging.
|
I have some opinion on this approach, I think the UNIX way of solving this problem is to expect a SIGHUP in the code, and when kill this process with SIGHUP, we will trigger a function to reload config. |
I think when you modify the config.json on fly with bot, you don't want to go to the terminal and send SIGHUP... |
I mean it should be explicit, but not be automatic. For example, you can have a skill to update the config then send a signal to the process. |
then you will need the process id, and has permission to send SIGHUP... |
|
@xiaket fix lint now, please check again. btw, the new released launcher will work perfect with this pr. |
Code Review SummaryThanks for implementing the config hot-reload feature! The overall design approach is solid. However, I found some issues that need to be addressed before merging. 🔴 Critical Issue: Incomplete Thread SafetyThe PR adds From my analysis, there are 20+ places with direct unguarded access: // loop.go:242 - unguarded access
if al.cfg.Tools.IsToolEnabled("mcp") { ... }
// loop.go:255 - unguarded access
defaultAgent := al.registry.GetDefaultAgent()
// loop.go:343, 384-385, 400, 541, 631, 640, 642, 704, 760, etc.Impact: During hot-reload, if Suggested Fix: Replace all direct accesses with thread-safe getters: // Before (unsafe)
agent := al.registry.GetDefaultAgent()
// After (safe)
agent := al.GetRegistry().GetDefaultAgent()Or use a snapshot pattern when atomic access to multiple fields is needed: func (al *AgentLoop) getSnapshot() (*config.Config, *AgentRegistry) {
al.mu.RLock()
defer al.mu.RUnlock()
return al.cfg, al.registry
}🟡 Medium Issues1. Panic Handling Could Be ClearerIn go func() {
defer func() {
if r := recover(); r != nil {
logger.ErrorCF(...) // Only logs
}
close(done)
}()
registry = NewAgentRegistry(cfg, provider)
}()The error message 2.
|
done |
Code reviewFound 1 issue:
Lines 48 to 55 in fbf940d 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
done. |
alexhoshina
left a comment
There was a problem hiding this comment.
This PR only rebuilds the config object related to the Provider. For modules like channels, they still hold pointers to the old config, so consistency might need to be considered
refactor and use rebuild all services including channels mechanism. |
Code ReviewThis PR implements config hot-reload functionality. The overall design is sound, but there are blocking issues that need to be addressed. 🔴 Blocking Issues1. Logger changes conflict with main branch (zerolog refactor) PR #1239 (refactor logger to zerolog) was merged on 2026-03-11. This PR's logger changes are based on the old logger implementation and will cause conflicts.
2. // Current code - Done() won't execute if Chat() panics
for attempt := 0; attempt < maxRetries; attempt++ {
al.activeRequests.Add(1)
resp, err = agent.Provider.Chat(...)
al.activeRequests.Done()
...
}
// Should be:
for attempt := 0; attempt < maxRetries; attempt++ {
al.activeRequests.Add(1)
resp, err = func() (*providers.LLMResponse, error) {
defer al.activeRequests.Done()
return agent.Provider.Chat(...)
}()
...
}🟡 Suggestions
✅ What's Done Well
🤖 Generated with Claude Code |
done, beside 3... it's changed from fsnotify.... |
Conflicts resolved: - helpers.go: merged import sections (io, log, net/http + sync) - config.go: merged AgentDefaults with Schedule, SafetyLevel, BirthYear Upstream features merged: - Config hot reload (PR sipeed#1187) - Anthropic Messages protocol (PR sipeed#1284) - Enhanced Skill Installer v2 (PR sipeed#1252) - Model command CLI (PR sipeed#1250) - ModelScope provider (PR sipeed#1486) - LINE webhook DoS protection (PR sipeed#1413)
|
@cytown Making the gateway react to config.json changes on the fly is a useful improvement, saves having to restart every time you tweak settings. We've got a PicoClaw Dev Group on Discord for contributors. If you want to join, send an email to |
I am already in there. This one?
|
* make gateway aware of config.json change * fix according to code review * fix lint * fix review comment * fix for review * refactor to fix review * fix for review * fix for review
* make gateway aware of config.json change * fix according to code review * fix lint * fix review comment * fix for review * refactor to fix review * fix for review * fix for review
* make gateway aware of config.json change * fix according to code review * fix lint * fix review comment * fix for review * refactor to fix review * fix for review * fix for review

📝 Description
make gateway command aware of config.json change
🗣️ Type of Change
🤖 AI Code Generation
🔗 Related Issue
📚 Technical Context (Skip for Docs)
🧪 Test Environment
📸 Evidence (Optional)
Click to view Logs/Screenshots
☑️ Checklist