{"record":{"id":"6005907183ca2d1d","repo":"OpenNHP/opennhp","slug":"trustedapplication-not-found-please-register-firs","errorCode":null,"errorMessage":"TrustedApplication not found, please register first","messagePattern":"TrustedApplication not found, please register first","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"endpoints/agent/ta.go","lineNumber":139,"sourceCode":"\tta.Ctx = ctx\n\tta.Cancel = cancel\n\tta.Client = c\n\n\tif _, exists := bufferedTaMap[tadId]; !exists {\n\t\tbufferedTaMap[tadId] = ta\n\t}\n\n\treturn ta, nil\n}\n\nfunc GetTrustedApplication(trustedAppUuid string) (*TrustedApplication, error) {\n\tbufferedTaLock.Lock()\n\tdefer bufferedTaLock.Unlock()\n\n\tif ta, exists := bufferedTaMap[trustedAppUuid]; exists {\n\t\treturn ta, nil\n\t} else {\n\t\treturn nil, fmt.Errorf(\"TrustedApplication not found, please register first\")\n\t}\n}\n\nfunc (ta *TrustedApplication) GetSupportedFunctions() []TAFunction {\n\treturn ta.Functions\n}\n\nfunc (ta *TrustedApplication) CallFunction(function string, params map[string]any) (string, error) {\n\tcallRequest := mcp.CallToolRequest{\n\t\tParams: mcp.CallToolParams{\n\t\t\tName:      function,\n\t\t\tArguments: params,\n\t\t},\n\t}\n\n\tcallResponse, err := ta.Client.CallTool(ta.Ctx, callRequest)\n\tif err != nil {\n\t\treturn \"\", err","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/OpenNHP/opennhp/blob/6e04ca5ff03222a699c24205cd4bf8fee9af7ffe/endpoints/agent/ta.go#L121-L157","documentation":"GetTrustedApplication looks up a TrustedApplication by UUID in the in-memory bufferedTaMap (protected by bufferedTaLock). If the TA was never registered (or the buffer was cleared/restarted), it returns this error instead of a nil struct, telling the caller to register the TA before calling its functions.","triggerScenarios":"CallTrustedApplication invoking GetTrustedApplication with a trustedAppUuid absent from bufferedTaMap — typically before RegisterTrustedApplication has completed or after a process restart wiped the buffer.","commonSituations":"Calling TA functions without running the register step first; using a stale UUID from a previous agent session; TA registration failed silently earlier; calling from a different process than the one that registered.","solutions":["Call the TA registration API for that UUID before invoking functions on it.","Verify the UUID matches the one returned at registration time (no stale/hardcoded UUID).","Re-register after any agent restart, since bufferedTaMap is in-memory only.","Persist the UUID in config if you must reuse it across restarts, and re-register at startup."],"exampleFix":"// before\nta, _ := GetTrustedApplication(uuid)\nta.CallFunction(...)\n\n// after\nta, err := GetTrustedApplication(uuid)\nif err != nil {\n    ta, err = RegisterTrustedApplication(uuid, ...)\n    if err != nil { return err }\n}\nresult, err := CallTrustedApplication(ta, fn, args)","handlingStrategy":"type-guard","validationCode":"ta, err := GetTrustedApplication(uuid)\nif err != nil {\n    ta, err = RegisterTrustedApplication(uuid, ...)\n    if err != nil { return err }\n}","typeGuard":"func taRegistered(uuid string) bool {\n    bufferedTaLock.Lock()\n    defer bufferedTaLock.Unlock()\n    _, ok := bufferedTaMap[uuid]\n    return ok\n}","tryCatchPattern":"ta, err := GetTrustedApplication(uuid)\nif err != nil {\n    return fmt.Errorf(\"ta %s: %w (register first)\", uuid, err)\n}","preventionTips":["Always register the TA immediately after agent startup, before any function calls.","Never persist and reuse UUIDs across restarts without re-registering.","Store the registration UUID in one place and use it consistently."],"tags":["trusted-application","state","lifecycle","go"],"backgroundTag":"entity-not-found","analyzedSha":"6e04ca5ff03222a699c24205cd4bf8fee9af7ffe","analyzedAt":"2026-09-07T15:44:59.941Z","contentChangedAt":"2026-09-07T15:44:59.941Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}