siyuan-note/siyuan · error

kernel log path is unavailable

Error message

kernel log path is unavailable

What it means

scanAgentLog reads util.LogPath to search the kernel log for agent log tools; if util.LogPath is empty the kernel was not configured with a log file path and the scan cannot proceed, so it fails with this error. It is a preflight guard before os.Open so callers get a clear message instead of a confusing open failure.

Solutions

  1. Start the kernel normally so util.LogPath is set during boot, or set util.LogPath explicitly in the harness before calling the agent log tools
  2. If embedding, replicate the boot-time log initialization that assigns util.LogPath
  3. In tests, point util.LogPath at a temporary log file in setup

Example fix

// before (test)
scanAgentLog(visit) // util.LogPath == ""
// after (test setup)
util.LogPath = filepath.Join(t.TempDir(), "siyuan.log")
scanAgentLog(visit)
Defensive patterns

Strategy: validation

Validate before calling

if (!util.LogPath || util.LogPath === '') {
  throw new Error('kernel log path is unavailable: initialize logging before scanning');
}

Type guard

function hasKernelLogPath() {
  return typeof util.LogPath === 'string' && util.LogPath.length > 0;
}

Try / catch

try {
  const result = await callMcpTool('agentLogSearch', { query });
} catch (e) {
  if (e.message.includes('kernel log path is unavailable')) {
    // start/verify the kernel with file logging enabled, then retry
  }
}

Prevention

When it happens

Trigger: Calling agentLogStat, agentLogTail, agentLogRead, or agentLogSearch in an environment where util.LogPath was never initialized (empty string) — e.g. an embedded/mobile-style boot path or a kernel started without log-file output enabled.

Common situations: Running the MCP tools against a kernel instance launched without file logging; custom boot code that skips log setup; tests that do not set util.LogPath; log output redirected to stdout only.

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@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/8ab2fd940c792c85. Report an issue: GitHub.

Appendix: 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 9f775e8a12)