siyuan-note/siyuan · error

kernel log path is unavailable

Error message

kernel log path is unavailable

What it means

scanAgentLog opens util.LogPath to search the kernel log for agent-log tools (stat/tail/read/search). This error is returned when util.LogPath is empty, meaning the kernel was started in a mode or environment where no log file path was configured, so there is no log file to scan. It guards against calling os.Open("").

Source

Thrown at kernel/mcp/tools/log.go:240

			if len(before) > contextLines {
				before = before[len(before)-contextLines:]
			}
		}
		return matches < matchLimit || number < pendingUntil
	})
	if err != nil {
		return agentLogError("search kernel log failed: " + err.Error()), nil
	}
	if matches == 0 {
		return agentLogResult("No matches found in the kernel log."), nil
	}
	header := fmt.Sprintf("Kernel log search found %d match(es), with %d context line(s):", matches, contextLines)
	return agentLogResult(formatAgentLogLines(header, resultLines)), nil
}

func scanAgentLog(visit func(number int, line string) bool) (int, error) {
	if util.LogPath == "" {
		return 0, fmt.Errorf("kernel log path is unavailable")
	}
	file, err := os.Open(util.LogPath)
	if err != nil {
		return 0, err
	}
	defer file.Close()

	scanner := bufio.NewScanner(file)
	scanner.Buffer(make([]byte, 64*1024), agentLogMaxLineBytes)
	lineCount := 0
	for scanner.Scan() {
		lineCount++
		line := strings.TrimSuffix(scanner.Text(), "\r")
		if !visit(lineCount, line) {
			break
		}
	}
	return lineCount, scanner.Err()

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Start the kernel with file logging enabled so util.LogPath is set (default desktop/server launches set it)
  2. If embedding the kernel, initialize the log path variable before serving MCP tools
  3. In containers, mount a log directory and configure the kernel to write logs there
  4. Fall back to reading stdout/stderr of the process if file logging cannot be enabled

Example fix

// before (embedding)
util.LogPath = "" // file logging never configured
// after
util.LogPath = filepath.Join(workspaceDir, "logs", "siyuan.log") // enable before MCP server starts
Defensive patterns

Strategy: fallback

Validate before calling

// verify logging is configured before using log tools
const ws = await fetchPost('/api/system/getConf', {});
if (!ws.data.conf.logFile && process.env.SIYUAN_LOG_PATH === undefined) throw new Error('kernel log file not configured');

Type guard

const logAvailable = (logPath) => typeof logPath === 'string' && logPath.length > 0;

Try / catch

try {
  return await callMcp('agentLogTail', { lines: 100 });
} catch (e) {
  if (String(e.message).includes('kernel log path is unavailable')) {
    return readProcessStdoutLog(); // fall back to captured stdout
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling any agent log MCP tool (agentLogStat, agentLogTail, agentLogRead, agentLogSearch) on a kernel instance whose util.LogPath was never set — e.g. mobile/embedded runs or a container started with logging redirected away from a file.

Common situations: Running the kernel in Docker with stdout-only logging and no --logtofile equivalent; a mobile/gomobile build where LogPath is not initialized; a misconfigured startup that disables file logging.

Understand the failure class

Background: "missing required config value" errors: why libraries refuse to start when a configuration key is empty, unset, or blank — this error's family across 48 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11). Data as JSON: /api/errors/8ab2fd940c792c85. Report an issue: GitHub.