{"record":{"id":"8ab2fd940c792c85","repo":"siyuan-note/siyuan","slug":"kernel-log-path-is-unavailable","errorCode":null,"errorMessage":"kernel log path is unavailable","messagePattern":"kernel log path is unavailable","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/mcp/tools/log.go","lineNumber":240,"sourceCode":"\t\t\tif len(before) > contextLines {\n\t\t\t\tbefore = before[len(before)-contextLines:]\n\t\t\t}\n\t\t}\n\t\treturn matches < matchLimit || number < pendingUntil\n\t})\n\tif err != nil {\n\t\treturn agentLogError(\"search kernel log failed: \" + err.Error()), nil\n\t}\n\tif matches == 0 {\n\t\treturn agentLogResult(\"No matches found in the kernel log.\"), nil\n\t}\n\theader := fmt.Sprintf(\"Kernel log search found %d match(es), with %d context line(s):\", matches, contextLines)\n\treturn agentLogResult(formatAgentLogLines(header, resultLines)), nil\n}\n\nfunc scanAgentLog(visit func(number int, line string) bool) (int, error) {\n\tif util.LogPath == \"\" {\n\t\treturn 0, fmt.Errorf(\"kernel log path is unavailable\")\n\t}\n\tfile, err := os.Open(util.LogPath)\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\tdefer file.Close()\n\n\tscanner := bufio.NewScanner(file)\n\tscanner.Buffer(make([]byte, 64*1024), agentLogMaxLineBytes)\n\tlineCount := 0\n\tfor scanner.Scan() {\n\t\tlineCount++\n\t\tline := strings.TrimSuffix(scanner.Text(), \"\\r\")\n\t\tif !visit(lineCount, line) {\n\t\t\tbreak\n\t\t}\n\t}\n\treturn lineCount, scanner.Err()","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/mcp/tools/log.go#L222-L258","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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","If embedding, replicate the boot-time log initialization that assigns util.LogPath","In tests, point util.LogPath at a temporary log file in setup"],"exampleFix":"// before (test)\nscanAgentLog(visit) // util.LogPath == \"\"\n// after (test setup)\nutil.LogPath = filepath.Join(t.TempDir(), \"siyuan.log\")\nscanAgentLog(visit)","handlingStrategy":"validation","validationCode":"if (!util.LogPath || util.LogPath === '') {\n  throw new Error('kernel log path is unavailable: initialize logging before scanning');\n}","typeGuard":"function hasKernelLogPath() {\n  return typeof util.LogPath === 'string' && util.LogPath.length > 0;\n}","tryCatchPattern":"try {\n  const result = await callMcpTool('agentLogSearch', { query });\n} catch (e) {\n  if (e.message.includes('kernel log path is unavailable')) {\n    // start/verify the kernel with file logging enabled, then retry\n  }\n}","preventionTips":["Boot the kernel through its normal startup so util.LogPath is populated","In tests/embedded use, set util.LogPath to a temp file in setup","Confirm file logging (not stdout-only) before calling agent log tools"],"tags":["logging","configuration","environment","preflight"],"backgroundTag":"missing-config-value","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}