{"record":{"id":"49a29a515ccd9d78","repo":"siyuan-note/siyuan","slug":"injectagent-v","errorCode":null,"errorMessage":"injectAgent: %v","messagePattern":"injectAgent: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/plugin/api_agent.go","lineNumber":49,"sourceCode":"\n// pluginCapabilityModelName 构造内核插件能力向模型暴露的函数名。\nfunc pluginCapabilityModelName(pluginName, capabilityName string) string {\n\tname := fmt.Sprintf(\"plugin__%s__%s\", util.SanitizeName(pluginName), util.SanitizeName(capabilityName))\n\thash := sha256.Sum256([]byte(pluginName + \"\\x00\" + capabilityName))\n\tsuffix := fmt.Sprintf(\"__%x\", hash[:6])\n\tif len(name) > maxCapabilityModelNameLen-len(suffix) {\n\t\tname = name[:maxCapabilityModelNameLen-len(suffix)]\n\t}\n\treturn name + suffix\n}\n\nconst maxCapabilityModelNameLen = 64\n\n// injectAgent 将 siyuan.agent 注入插件 JS 沙箱。\nfunc injectAgent(p *KernelPlugin, rt *goja.Runtime, siyuan *goja.Object) (err error) {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\terr = fmt.Errorf(\"injectAgent: %v\", r)\n\t\t}\n\t}()\n\n\tagentAPI := rt.NewObject()\n\n\t// siyuan.agent.registerCapability(name, config, handler) 返回 Promise<IRegisteredCapability>。\n\tlo.Must0(agentAPI.Set(\"registerCapability\", rt.ToValue(func(call goja.FunctionCall, rt *goja.Runtime) goja.Value {\n\t\tpromise, resolve, reject := rt.NewPromise()\n\n\t\tvar name string\n\t\tvar title string\n\t\tvar description string\n\t\tvar effects *tools.ToolEffects\n\t\tvar actionEffects map[string]tools.ToolEffects\n\t\tvar inputSchema *tools.ToolSchema\n\t\tvar outputSchema *tools.ToolSchema\n\t\tvar handler goja.Callable\n","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/plugin/api_agent.go#L31-L67","documentation":"injectAgent wraps siyuan.agent sandbox injection for a kernel plugin's goja runtime in a recover() that converts any panic during injection into the error 'injectAgent: %v'. It indicates an unexpected runtime failure (goja exception, nil object, value conversion panic) while installing the agent API into the plugin sandbox — plugin initialization for the agent subsystem failed.","triggerScenarios":"Plugin load/enable where building the siyuan.agent object or registering its methods panics — e.g. goja runtime in a bad state, a ToValue/Set failure, or a panic inside jsCapabilitySchemaToGoSchema helpers during injection.","commonSituations":"A corrupted or incompatible plugin bundle triggering goja panics during bootstrap; a kernel bug or version mismatch between plugin API expectations and the runtime; low-memory or runtime-shutdown races during plugin teardown/load.","solutions":["Read the wrapped '%v' detail in kernel logs to find the panicking step, then fix the plugin code or report the kernel bug","Disable or reinstall the offending plugin to rule out a corrupted bundle","Update the kernel/plugin to matching versions and retry loading the plugin"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := injectAgent(p, rt, siyuan); err != nil {\n    logging.LogErrorf(\"plugin [%s] agent injection failed: %s\", p.Name, err)\n    // mark the plugin's agent API as unavailable instead of failing the whole load\n}","preventionTips":["Check kernel logs for the wrapped panic detail to identify the failing injection step","Keep kernel and plugin API versions in sync","Reinstall corrupted plugins before assuming a kernel bug","Guard plugin-load paths against runtime teardown races"],"tags":["plugin","goja","sandbox","agent","panic"],"backgroundTag":"module-init-failed","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"}