Skip to content

feat(daemon): centralize daemon, worker, channel and connection logs - #1424

Merged
edenreich merged 2 commits into
mainfrom
fix/issue-1402
Sep 30, 2026
Merged

edenreich merged 2 commits into
mainfrom
fix/issue-1402

Conversation

@inference-gateway-maintainer

@inference-gateway-maintainer inference-gateway-maintainer Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #1402

Centralizes daemon, worker, channel and connection logs: the daemon owns one tagged log stream and the processes it starts keep no log file of their own.

Summary

Session workers and one-shot job runs (scheduled fires, heartbeat ticks) now log JSON to stderr only and create no app-<date>.log of their own. The daemon collects their stderr into ~/.infer/logs/daemon-<date>.log as they run, with every line tagged project_dir, conversation_id (the AG-UI threadId) and worker_pid, so one request crossing daemon, worker and client leaves one trail. Client connect and disconnect and the browser extension's attach and detach are logged on that path too, and routing errors carry the thread tags when the frame reached one.

A [DOCS] ticket in inference-gateway/docs (issue 872) tracks the mirrored daemon docs. Streaming logs to clients over the binding stays out of scope per the issue.

Changes

  • internal/platform/logger: ChildStderrJSONEnv (INFER_LOG_STDERR_JSON) makes a child process log JSON to stderr and skip its log file. The flag is read once and cleared, so it reaches the direct child only and the processes a worker starts through its Bash tool keep their own log files
  • internal/platform/logger: CollectChildStderr merges a child's JSON stderr lines into the host's log (child keeps msg, fields and level, raw lines log as-is) enriched with the collector tags. The level stops at error, since re-logging a fatal or panic line would end the daemon. The collector adds no caller or stacktrace of its own, so the child's stay readable. It returns the last plain line, the child's own error
  • internal/sessions/infrastructure.LaunchWorker: sets the child env flag, pipes the worker's stderr through CollectChildStderr with project_dir, conversation_id and worker_pid (was cmd.Stderr = os.Stderr), closes the pipe after collection, and tags the worker-exit warning with worker_pid
  • internal/platform/agentrunner: Run sets the child env flag and collects the run's stderr as it runs, tagged project_dir, conversation_id and worker_pid. Result.Stderr holds only the last plain line, so a failed run's stored error (run.Error, job.LastError) stays the run's own error and not its whole log stream
  • internal/scheduler (cron fires) and scheduler/heartbeat (ticks): their daemon-side lines use conversation_id in place of session_id
  • internal/protocols/agui: a Conn answers HelloAttr with the other fields its hello declared (minus the token). The binding logs client connects and disconnects with client and protocol_version
  • internal/browser/infrastructure.ExtensionRelay: logs the extension attaching and detaching with extension_version (read from the hello, which the binding never named), and warns when a browser command has no extension to route through
  • internal/sessions.Registry: route returns the thread, so routing failures (unknown thread, launch failure, send to a dead worker) log with project_dir and conversation_id. A failed worker browser command is logged with the thread's tags
  • internal/presentation/telegram: the channel's message routing, render delivery, dropped frames and interrupt answers log with project_dir and conversation_id alongside sender_id
  • docs: docs/commands-reference.md says where the daemon log lives. Sessions and agui READMEs updated

Verification

  • go test ./... (purego tag) passes, and the touched packages pass under -race
  • task precommit:run passes
  • New tests: a fatal and a panic child line are collected at error level, the env flag is cleared after it is read, agentrunner.Run returns only the last plain stderr line, and the hello token is not readable through HelloAttr
  • Not run: a live daemon session with a worker

Started children (session workers, scheduled fires, heartbeat runs) log JSON to stderr and keep no log file of their own. The daemon collects their stderr into the daemon log with project_dir, conversation_id and worker_pid tags, logs client connects and disconnects with client and protocol_version, logs the extension attach and detach with extension_version, and tags routing errors and channel threads with project_dir and conversation_id. The daemon docs name the log location.
A child log line at fatal or panic level ended the daemon, because the collector re-logged it at the child's own level. The level now stops at error.

The collector no longer adds its own caller and stacktrace to a collected line. They duplicated the child's keys and the collector's stacktrace shadowed the real one.

The stderr JSON flag is read once and cleared, so the processes a worker starts through its Bash tool keep their own log files and stop writing JSON logs into the tool output.

agentrunner collects a run's stderr as it runs, tagged with project_dir, conversation_id and worker_pid. Job runs keep their real timestamps and survive a daemon stop mid-run. Result.Stderr holds only the last plain line, so a failed run's stored error is the run's own error again and not its whole log stream.

The worker's stderr pipe is closed after collection. The scheduler's daemon-side lines and the remaining telegram thread lines carry conversation_id. The binding logs protocol_version the same way on connect and disconnect.
@edenreich
edenreich merged commit 36659ce into main Sep 30, 2026
12 checks passed
@edenreich
edenreich deleted the fix/issue-1402 branch September 30, 2026 11:04
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.219.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 30, 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.

[FEATURE] Centralize daemon, worker, channel and connection logs

1 participant