{"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/8641553a1f07374001902d3ce773285db1292b2d/kernel/mcp/tools/log.go#L222-L258","documentation":"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(\"\").","triggerScenarios":"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.","commonSituations":"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.","solutions":["Start the kernel with file logging enabled so util.LogPath is set (default desktop/server launches set it)","If embedding the kernel, initialize the log path variable before serving MCP tools","In containers, mount a log directory and configure the kernel to write logs there","Fall back to reading stdout/stderr of the process if file logging cannot be enabled"],"exampleFix":"// before (embedding)\nutil.LogPath = \"\" // file logging never configured\n// after\nutil.LogPath = filepath.Join(workspaceDir, \"logs\", \"siyuan.log\") // enable before MCP server starts","handlingStrategy":"fallback","validationCode":"// verify logging is configured before using log tools\nconst ws = await fetchPost('/api/system/getConf', {});\nif (!ws.data.conf.logFile && process.env.SIYUAN_LOG_PATH === undefined) throw new Error('kernel log file not configured');","typeGuard":"const logAvailable = (logPath) => typeof logPath === 'string' && logPath.length > 0;","tryCatchPattern":"try {\n  return await callMcp('agentLogTail', { lines: 100 });\n} catch (e) {\n  if (String(e.message).includes('kernel log path is unavailable')) {\n    return readProcessStdoutLog(); // fall back to captured stdout\n  }\n  throw e;\n}","preventionTips":["Run the kernel with file logging enabled when agent log tools will be used","Mount/persist a log directory in containers","Initialize the log path before starting the MCP server in embedded deployments"],"tags":["mcp","logging","configuration","kernel"],"backgroundTag":"missing-config-value","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}