Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(daemon): make the daemon log path discoverable (#6884)

Bohan Jiange4ebd41def74
diff --git a/CLI_AND_DAEMON.md b/CLI_AND_DAEMON.md
index dc6c143338..77a42a402a 100644
--- a/CLI_AND_DAEMON.md
+++ b/CLI_AND_DAEMON.md
@@ -101,7 +101,23 @@ The daemon is the local agent runtime. It detects available AI CLIs on your mach
multica daemon start
```
-By default, the daemon runs in the background and logs to `~/.multica/daemon.log`.
+By default, the daemon runs in the background and writes its log into the state
+directory of the profile it was started with — **not always `~/.multica/`**:
+
+| Profile | State directory |
+| --- | --- |
+| Default (no `--profile`) | `~/.multica/` |
+| Named (`--profile <name>`) | `~/.multica/profiles/<name>/` |
+
+That directory holds `daemon.log` (the log), `daemon.pid` (the background
+daemon's PID), and `daemon.err.log` (raw crash output; near-empty on a healthy
+daemon, since normal logging goes to `daemon.log`).
+
+The Desktop app runs its own named profile, so on a machine that has ever run
+both, `~/.multica/daemon.log` and `~/.multica/profiles/<name>/daemon.log` both
+exist and both read as plausible logs — only one is being written to. Don't
+guess: `multica daemon logs` prints the absolute path it resolved (see
+[Logs](#logs)).
To run in the foreground (useful for debugging):
@@ -158,7 +174,29 @@ Shows PID, uptime, detected agents, and watched workspaces.
multica daemon logs # Last 50 lines
multica daemon logs -f # Follow (tail -f)
multica daemon logs -n 100 # Last 100 lines
+multica daemon logs --profile staging
+```
+
+Every run first prints the absolute path it resolved, so you always know which
+profile's log you are looking at:
+
```
+$ multica daemon logs -n 100
+Reading /Users/you/.multica/profiles/desktop-mbp/daemon.log (profile: desktop-mbp)
+...
+```
+
+That line goes to stderr, before the tail starts — so it also shows up under
+`-f`, and piping or redirecting the command still yields log content only:
+
+```bash
+multica daemon logs -n 500 | grep ERROR # the path line is not in the pipe
+```
+
+Without `--profile`, the default profile's log is read. If it doesn't exist the
+command says so and names the path it looked for, which is the fastest way to
+find out that the daemon you care about is running on a different profile —
+`multica daemon status --profile <name>` confirms which one is live.
### Supported Agents
@@ -374,7 +412,7 @@ multica daemon start --profile staging
multica daemon start
```
-Each profile gets its own config directory (`~/.multica/profiles/<name>/`), daemon state, health port, and workspace root.
+Each profile gets its own config directory (`~/.multica/profiles/<name>/`), daemon state, health port, and workspace root. Daemon state means that profile's own `daemon.log`, `daemon.err.log`, and `daemon.pid` live in that directory too — see [Start](#start) for the layout, and pass `--profile <name>` to `daemon status` / `daemon logs` to act on it.
## Workspaces
diff --git a/apps/docs/content/docs/troubleshooting.ja.mdx b/apps/docs/content/docs/troubleshooting.ja.mdx
index 78b851ea01..ebb4181e0b 100644
--- a/apps/docs/content/docs/troubleshooting.ja.mdx
+++ b/apps/docs/content/docs/troubleshooting.ja.mdx
@@ -203,6 +203,8 @@ netstat -ano | findstr :8080 # Windows
| Docker backend | `docker compose -f docker-compose.selfhost.yml logs -f backend` |
| ブラウザ | 開発者ツールの Console と Network |
+どのファイルが現在有効なログかは、デーモンを起動したプロファイルによって決まります。以前のデーモンが残した古いログもそのまま読めてしまうため、誤ったファイルを調べてしまいがちです。当て推量でファイルを開かないでください: `multica daemon logs` は内容を流す前に、解決した絶対パスを表示します。名前付きプロファイルのログを読むときは `--profile <name>` を付けます。
+
デーモンの起動過程を直接観察したい場合は、フォアグラウンドで実行します:
```bash
diff --git a/apps/docs/content/docs/troubleshooting.ko.mdx b/apps/docs/content/docs/troubleshooting.ko.mdx
index ec6643501e..7a539327b9 100644
--- a/apps/docs/content/docs/troubleshooting.ko.mdx
+++ b/apps/docs/content/docs/troubleshooting.ko.mdx
@@ -203,6 +203,8 @@ netstat -ano | findstr :8080 # Windows
| Docker backend | `docker compose -f docker-compose.selfhost.yml logs -f backend` |
| 브라우저 | 개발자 도구의 Console과 Network |
+어떤 파일이 현재 사용 중인 로그인지는 데몬을 시작한 profile에 따라 달라집니다. 이전 데몬이 남긴 오래된 로그도 문제없이 읽히기 때문에 엉뚱한 파일을 보게 되기 쉽습니다. 추측으로 파일을 열지 말고 `multica daemon logs`를 사용하세요. 내용을 출력하기 전에 해석한 절대 경로를 먼저 표시합니다. 이름 있는 profile의 로그는 `--profile <name>`을 붙여서 확인합니다.
+
데몬 시작 과정을 직접 확인해야 한다면 foreground에서 실행합니다.
```bash
diff --git a/apps/docs/content/docs/troubleshooting.mdx b/apps/docs/content/docs/troubleshooting.mdx
index bfe8d28fb0..2d0588247e 100644
--- a/apps/docs/content/docs/troubleshooting.mdx
+++ b/apps/docs/content/docs/troubleshooting.mdx
@@ -203,6 +203,8 @@ If it is another Multica checkout, run `make stop` in that directory first. Othe
| Docker backend | `docker compose -f docker-compose.selfhost.yml logs -f backend` |
| Browser | Console and Network in the developer tools |
+Which of those files is the live one depends on the profile the daemon was started with, and a stale log from an earlier daemon still reads perfectly — the easiest way to debug the wrong file. Don't open one by guess: `multica daemon logs` prints the absolute path it resolved before streaming it. Add `--profile <name>` to read a named profile's log.
+
To observe the daemon's startup directly, run it in the foreground instead:
```bash
diff --git a/apps/docs/content/docs/troubleshooting.zh.mdx b/apps/docs/content/docs/troubleshooting.zh.mdx
index 31d9d05970..723151f0da 100644
--- a/apps/docs/content/docs/troubleshooting.zh.mdx
+++ b/apps/docs/content/docs/troubleshooting.zh.mdx
@@ -203,6 +203,8 @@ netstat -ano | findstr :8080 # Windows
| Docker backend | `docker compose -f docker-compose.selfhost.yml logs -f backend` |
| 浏览器 | 开发者工具中的 Console 和 Network |
+哪个文件是当前活跃的日志,取决于守护进程启动时使用的 profile;早前守护进程残留的旧日志同样能正常读出来,最容易让人调错文件。不要靠猜去开文件:`multica daemon logs` 会在输出日志内容前先打印它解析到的绝对路径。读命名 profile 的日志时加上 `--profile <name>`。
+
需要直接观察守护进程启动过程时,可以改为前台运行:
```bash
diff --git a/server/cmd/multica/cmd_daemon.go b/server/cmd/multica/cmd_daemon.go
index 81d9ee4a45..cd48191ff3 100644
--- a/server/cmd/multica/cmd_daemon.go
+++ b/server/cmd/multica/cmd_daemon.go
@@ -1495,6 +1495,36 @@ func printDaemonStatusReport(w io.Writer, label string, health map[string]any) {
// --- daemon logs ---
+// tailLog is the seam tests replace to observe `daemon logs` without spawning
+// the platform tail implementation.
+var tailLog = tailLogFile
+
+// profileLabel names a profile for humans; the default profile has no name.
+func profileLabel(profile string) string {
+ if profile == "" {
+ return "default"
+ }
+ return profile
+}
+
+// daemonLogSourcePath resolves the daemon.log path for a profile —
+// ~/.multica/daemon.log for the default profile,
+// ~/.multica/profiles/<name>/daemon.log for a named one — and guarantees it is
+// absolute, because this path is shown to the user to paste into an editor or
+// another shell.
+//
+// A relative result means daemonDirForProfile could not resolve the home
+// directory and swallowed the error, leaving a bare "daemon.log". That is
+// reported instead of returned: it would resolve against the caller's cwd and
+// name a file with nothing to do with the daemon.
+func daemonLogSourcePath(profile string) (string, error) {
+ logPath := daemonLogPathForProfile(profile)
+ if !filepath.IsAbs(logPath) {
+ return "", fmt.Errorf("cannot resolve the state directory for profile %q", profileLabel(profile))
+ }
+ return logPath, nil
+}
+
func runDaemonLogs(cmd *cobra.Command, _ []string) error {
if err := requireHumanLocalCommand("daemon logs"); err != nil {
return err
@@ -1503,7 +1533,10 @@ func runDaemonLogs(cmd *cobra.Command, _ []string) error {
if err := requireKnownProfile(profile); err != nil {
return err
}
- logPath := daemonLogPathForProfile(profile)
+ logPath, err := daemonLogSourcePath(profile)
+ if err != nil {
+ return err
+ }
if _, err := os.Stat(logPath); os.IsNotExist(err) {
return fmt.Errorf("no log file found at %s\nThe daemon may not have been started in background mode", logPath)
}
@@ -1511,7 +1544,14 @@ func runDaemonLogs(cmd *cobra.Command, _ []string) error {
follow, _ := cmd.Flags().GetBool("follow")
lines, _ := cmd.Flags().GetInt("lines")
- return tailLogFile(logPath, lines, follow)
+ // Name the file before streaming it. Which daemon.log is live is otherwise
+ // unknowable — a stale default-profile log reads fine and looks current —
+ // and this command is the only thing that knows the answer. It goes to
+ // stderr and is written before the tail starts so `-f` output and any
+ // downstream pipe stay clean.
+ fmt.Fprintf(cmd.ErrOrStderr(), "Reading %s (profile: %s)\n", logPath, profileLabel(profile))
+
+ return tailLog(logPath, lines, follow)
}
// daemonAlive reports whether a health response indicates a live daemon
diff --git a/server/cmd/multica/cmd_daemon_logs_test.go b/server/cmd/multica/cmd_daemon_logs_test.go
new file mode 100644
index 0000000000..8dcd565103
--- /dev/null
+++ b/server/cmd/multica/cmd_daemon_logs_test.go
@@ -0,0 +1,225 @@
+package main
+
+import (
+ "bytes"
+ "os"
+ "path/filepath"
+ "strconv"
+ "strings"
+ "testing"
+
+ "github.com/spf13/cobra"
+)
+
+// daemonLogsCmdFor builds a cobra command carrying the flags runDaemonLogs
+// reads, wired to a buffer so what the command tells the user is observable.
+func daemonLogsCmdFor(t *testing.T, profile string, lines int, follow bool) (*cobra.Command, *bytes.Buffer) {
+ t.Helper()
+ cmd := daemonStatusCmdFor(t, profile, "")
+ cmd.Flags().BoolP("follow", "f", false, "")
+ cmd.Flags().IntP("lines", "n", 50, "")
+ if err := cmd.Flags().Set("lines", strconv.Itoa(lines)); err != nil {
+ t.Fatalf("set lines flag: %v", err)
+ }
+ if follow {
+ if err := cmd.Flags().Set("follow", "true"); err != nil {
+ t.Fatalf("set follow flag: %v", err)
+ }
+ }
+ var errOut bytes.Buffer
+ cmd.SetErr(&errOut)
+ return cmd, &errOut
+}
+
+// tailCall records what runDaemonLogs handed to the platform tail, plus what
+// the user had already been told at that moment.
+type tailCall struct {
+ called bool
+ path string
+ lines int
+ follow bool
+ stderrAtCall string
+}
+
+// stubTailLog replaces the tail seam so the test observes the command without
+// spawning `tail` (and without a follow-mode run that never returns).
+func stubTailLog(t *testing.T, errOut *bytes.Buffer) *tailCall {
+ t.Helper()
+ rec := &tailCall{}
+ prev := tailLog
+ t.Cleanup(func() { tailLog = prev })
+ tailLog = func(path string, lines int, follow bool) error {
+ rec.called = true
+ rec.path, rec.lines, rec.follow = path, lines, follow
+ rec.stderrAtCall = errOut.String()
+ return nil
+ }
+ return rec
+}
+
+func seedDaemonLog(t *testing.T, path string) {
+ t.Helper()
+ if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
+ t.Fatalf("create log dir: %v", err)
+ }
+ if err := os.WriteFile(path, []byte("hello from the daemon\n"), 0o644); err != nil {
+ t.Fatalf("seed daemon log: %v", err)
+ }
+}
+
+// The default profile and a named one resolve to different files, and only the
+// named-profile layout was missing from the docs — a Desktop install logs to
+// ~/.multica/profiles/<name>/daemon.log while ~/.multica/daemon.log may still
+// hold a readable, stale log from an earlier default-profile daemon (#6038).
+func TestDaemonLogSourcePathResolvesPerProfile(t *testing.T) {
+ t.Run("default profile", func(t *testing.T) {
+ home := mkProfiles(t)
+
+ got, err := daemonLogSourcePath("")
+ if err != nil {
+ t.Fatalf("daemonLogSourcePath(\"\") = %v, want nil", err)
+ }
+ want := filepath.Join(home, ".multica", "daemon.log")
+ if got != want {
+ t.Fatalf("daemonLogSourcePath(\"\") = %q, want %q", got, want)
+ }
+ })
+
+ t.Run("named profile", func(t *testing.T) {
+ home := mkProfiles(t, "desktop-api.multica.ai")
+
+ got, err := daemonLogSourcePath("desktop-api.multica.ai")
+ if err != nil {
+ t.Fatalf("daemonLogSourcePath = %v, want nil", err)
+ }
+ want := filepath.Join(home, ".multica", "profiles", "desktop-api.multica.ai", "daemon.log")
+ if got != want {
+ t.Fatalf("daemonLogSourcePath = %q, want %q", got, want)
+ }
+ })
+
+ t.Run("result is absolute", func(t *testing.T) {
+ mkProfiles(t, "dev")
+ for _, profile := range []string{"", "dev"} {
+ got, err := daemonLogSourcePath(profile)
+ if err != nil {
+ t.Fatalf("daemonLogSourcePath(%q) = %v, want nil", profile, err)
+ }
+ if !filepath.IsAbs(got) {
+ t.Fatalf("daemonLogSourcePath(%q) = %q, want an absolute path", profile, got)
+ }
+ }
+ })
+}
+
+// The success path used to be silent about which file it was reading, so the
+// only command that knows the answer withheld it exactly when it worked. Both
+// profile layouts must announce the absolute path, for plain reads and for
+// -n / -f alike.
+func TestRunDaemonLogsAnnouncesResolvedPath(t *testing.T) {
+ cases := []struct {
+ name string
+ profile string
+ label string
+ lines int
+ follow bool
+ }{
+ {"default profile", "", "default", 50, false},
+ {"default profile with lines", "", "default", 100, false},
+ {"named profile", "desktop-api.multica.ai", "desktop-api.multica.ai", 50, false},
+ {"named profile following", "desktop-api.multica.ai", "desktop-api.multica.ai", 50, true},
+ }
+ for _, tc := range cases {
+ t.Run(tc.name, func(t *testing.T) {
+ clearDaemonTaskEnv(t)
+ mkProfiles(t, "desktop-api.multica.ai")
+
+ wantPath, err := daemonLogSourcePath(tc.profile)
+ if err != nil {
+ t.Fatalf("daemonLogSourcePath: %v", err)
+ }
+ seedDaemonLog(t, wantPath)
+
+ cmd, errOut := daemonLogsCmdFor(t, tc.profile, tc.lines, tc.follow)
+ rec := stubTailLog(t, errOut)
+
+ if err := runDaemonLogs(cmd, nil); err != nil {
+ t.Fatalf("runDaemonLogs = %v, want nil", err)
+ }
+
+ if !strings.Contains(errOut.String(), wantPath) {
+ t.Errorf("daemon logs output = %q, want the resolved path %q", errOut.String(), wantPath)
+ }
+ if !strings.Contains(errOut.String(), tc.label) {
+ t.Errorf("daemon logs output = %q, want the profile label %q", errOut.String(), tc.label)
+ }
+
+ if !rec.called {
+ t.Fatal("runDaemonLogs did not tail the log")
+ }
+ if rec.path != wantPath {
+ t.Errorf("tailed %q, want %q — the announced path must be the one read", rec.path, wantPath)
+ }
+ if rec.lines != tc.lines || rec.follow != tc.follow {
+ t.Errorf("tail(lines=%d, follow=%v), want (lines=%d, follow=%v)", rec.lines, rec.follow, tc.lines, tc.follow)
+ }
+ // In follow mode the tail never returns, so a path announced
+ // afterwards would never be seen; it must already be out.
+ if !strings.Contains(rec.stderrAtCall, wantPath) {
+ t.Errorf("path was not announced before tailing started (stderr at call = %q)", rec.stderrAtCall)
+ }
+ })
+ }
+}
+
+// The announcement goes to stderr, so `multica daemon logs | grep ...` and a
+// redirect to a file keep seeing log content only.
+func TestRunDaemonLogsAnnouncementDoesNotPolluteStdout(t *testing.T) {
+ clearDaemonTaskEnv(t)
+ mkProfiles(t, "dev")
+
+ wantPath, err := daemonLogSourcePath("dev")
+ if err != nil {
+ t.Fatalf("daemonLogSourcePath: %v", err)
+ }
+ seedDaemonLog(t, wantPath)
+
+ cmd, errOut := daemonLogsCmdFor(t, "dev", 50, false)
+ var out bytes.Buffer
+ cmd.SetOut(&out)
+ stubTailLog(t, errOut)
+
+ stdout, err := captureStdout(t, func() error { return runDaemonLogs(cmd, nil) })
+ if err != nil {
+ t.Fatalf("runDaemonLogs = %v, want nil", err)
+ }
+ if strings.Contains(stdout, wantPath) || strings.Contains(out.String(), wantPath) {
+ t.Errorf("the path must not go to stdout (os.Stdout=%q, cmd out=%q)", stdout, out.String())
+ }
+}
+
+// The missing-file error already named a path; it must name the absolute one
+// for the profile that was asked for, not the default profile's.
+func TestRunDaemonLogsMissingFileNamesProfilePath(t *testing.T) {
+ clearDaemonTaskEnv(t)
+ home := mkProfiles(t, "desktop-api.multica.ai")
+
+ // A readable log for the DEFAULT profile exists — the exact trap from
+ // #6038. The error must still point at the requested profile's path.
+ seedDaemonLog(t, filepath.Join(home, ".multica", "daemon.log"))
+
+ cmd, errOut := daemonLogsCmdFor(t, "desktop-api.multica.ai", 50, false)
+ rec := stubTailLog(t, errOut)
+
+ err := runDaemonLogs(cmd, nil)
+ if err == nil {
+ t.Fatal("runDaemonLogs = nil, want the missing-log-file error")
+ }
+ want := filepath.Join(home, ".multica", "profiles", "desktop-api.multica.ai", "daemon.log")
+ if !strings.Contains(err.Error(), want) {
+ t.Errorf("error = %q, want it to name %q", err, want)
+ }
+ if rec.called {
+ t.Error("runDaemonLogs tailed a file it had just reported missing")
+ }
+}