Skip to content

Commit 40c29db

Browse files
localai-botmudler
andauthored
fix(logs): capture backend logs by default in single mode (#10742)
Backend log capture into the per-model BackendLogStore (which feeds the UI "Backend Logs" page and /api/backend-logs) was opt-in and off by default in single mode, while worker/distributed mode force-enables it via SetBackendLoggingEnabled(true). There was no CLI flag either, so the only way to populate the store was the Settings UI toggle - and the page was silently empty out of the box. Distributed "just worked"; single mode looked broken. Default EnableBackendLogging to true in NewApplicationConfig so single mode matches worker mode. The store is a small in-memory ring buffer, so the cost is negligible. Now that the default is on, loadRuntimeSettingsFromFile's usual "only flip false->true" merge would ignore a persisted false and revert the UI toggle-off on every restart. There is no env var/CLI flag for this setting, so an explicit persisted value is now authoritative in both directions, letting the toggle-off survive a restart. Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Co-authored-by: Ettore Di Giacinto <mudler@localai.io>
1 parent 0aaf7cc commit 40c29db

3 files changed

Lines changed: 46 additions & 6 deletions

File tree

core/application/runtime_settings_branding_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,35 @@ var _ = Describe("loadRuntimeSettingsFromFile", func() {
261261
Expect(cfg.AgentPool.AgentHubURL).To(Equal("https://hub.acme.io"))
262262
})
263263
})
264+
265+
// Backend logging capture. Worker/distributed mode force-enables it
266+
// (core/services/worker.SetBackendLoggingEnabled(true)); single mode used
267+
// to leave it off by default with no CLI flag, so the UI "Backend Logs"
268+
// page was silently empty unless the operator found the Settings toggle.
269+
// It now defaults on in single mode too. Because the default is on, the
270+
// loader must let a persisted enable_backend_logging=false (the UI
271+
// toggle-off) win over the default - the sticky "only flip false->true"
272+
// merge used for env-backed flags would otherwise ignore it and revert
273+
// the toggle on every restart.
274+
Describe("backend logging capture", func() {
275+
It("captures backend logs by default in single mode", func() {
276+
cfg := config.NewApplicationConfig()
277+
Expect(cfg.EnableBackendLogging).To(BeTrue(),
278+
"single mode should capture backend logs out of the box, matching worker mode")
279+
})
280+
281+
It("honors a persisted enable_backend_logging=false across restart (toggle-off wins over default-on)", func() {
282+
cfg := config.NewApplicationConfig() // default-on boot state
283+
cfg.DynamicConfigsDir = seedSettings(`{"enable_backend_logging": false}`)
284+
loadRuntimeSettingsFromFile(cfg)
285+
Expect(cfg.EnableBackendLogging).To(BeFalse(),
286+
"a UI toggle-off persisted to runtime_settings.json must survive a restart")
287+
})
288+
289+
It("loads a persisted enable_backend_logging=true", func() {
290+
cfg := &config.ApplicationConfig{DynamicConfigsDir: seedSettings(`{"enable_backend_logging": true}`)}
291+
loadRuntimeSettingsFromFile(cfg)
292+
Expect(cfg.EnableBackendLogging).To(BeTrue())
293+
})
294+
})
264295
})

core/application/startup.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -698,10 +698,12 @@ func loadRuntimeSettingsFromFile(options *config.ApplicationConfig) {
698698
}
699699
}
700700

701+
// Backend logging defaults on in single mode (NewApplicationConfig), so
702+
// the usual "only flip false->true" merge would ignore a persisted false
703+
// and revert the UI toggle-off on every restart. There is no env var/CLI
704+
// flag for it, so an explicit persisted value is authoritative here.
701705
if settings.EnableBackendLogging != nil {
702-
if !options.EnableBackendLogging {
703-
options.EnableBackendLogging = *settings.EnableBackendLogging
704-
}
706+
options.EnableBackendLogging = *settings.EnableBackendLogging
705707
}
706708

707709
// Tracing settings

core/config/application_config.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,16 @@ type AppOption func(*ApplicationConfig)
246246

247247
func NewApplicationConfig(o ...AppOption) *ApplicationConfig {
248248
opt := &ApplicationConfig{
249-
Context: context.Background(),
250-
UploadLimitMB: 15,
251-
Debug: true,
249+
Context: context.Background(),
250+
UploadLimitMB: 15,
251+
Debug: true,
252+
// Capture backend process stdout/stderr into the per-model
253+
// BackendLogStore by default so the UI "Backend Logs" page works out
254+
// of the box in single mode, matching worker/distributed mode (which
255+
// force-enables it). It's a small in-memory ring buffer; the Settings
256+
// toggle can still turn it off (a persisted false wins - see
257+
// loadRuntimeSettingsFromFile).
258+
EnableBackendLogging: true,
252259
AgentJobRetentionDays: 30, // Default: 30 days
253260
LRUEvictionMaxRetries: 30, // Default: 30 retries
254261
LRUEvictionRetryInterval: 1 * time.Second, // Default: 1 second

0 commit comments

Comments
 (0)