{"record":{"id":"f7cae11d291900b2","repo":"Tencent/WeKnora","slug":"workspace-id-not-found-in-context","errorCode":null,"errorMessage":"workspace ID not found in context","messagePattern":"workspace ID not found in context","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/tools/web_search.go","lineNumber":152,"sourceCode":"\t\t\tSuccess: false,\n\t\t\tError:   \"query parameter is required\",\n\t\t}, fmt.Errorf(\"query parameter is required\")\n\t}\n\n\tlogger.Infof(ctx, \"[Tool][WebSearch] Searching with query: %s, max_results: %d\", query, t.maxResults)\n\n\t// Get tenant ID from context\n\ttenantID := uint64(0)\n\tif tid, ok := ctx.Value(types.TenantIDContextKey).(uint64); ok {\n\t\ttenantID = tid\n\t}\n\n\tif tenantID == 0 {\n\t\tlogger.Errorf(ctx, \"[Tool][WebSearch] Workspace ID not found in context\")\n\t\treturn &types.ToolResult{\n\t\t\tSuccess: false,\n\t\t\tError:   \"workspace ID not found in context\",\n\t\t}, fmt.Errorf(\"workspace ID not found in context\")\n\t}\n\n\t// Get tenant info from context (same approach as search.go)\n\tvar tenant *types.Tenant\n\tif tenantValue := ctx.Value(types.TenantInfoContextKey); tenantValue != nil {\n\t\ttenant, _ = tenantValue.(*types.Tenant)\n\t}\n\n\t// Resolve provider ID: tool-level (set from agent config, which already resolved default)\n\tresolvedProviderID := t.providerID\n\n\t// Create a copy of the effective web search config with maxResults from agent config.\n\tsearchConfig := types.EffectiveWebSearchConfig(nil)\n\tif tenant != nil {\n\t\tsearchConfig = types.EffectiveWebSearchConfig(tenant.WebSearchConfig)\n\t}\n\tsearchConfig.MaxResults = t.maxResults\n","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/agent/tools/web_search.go#L134-L170","documentation":"Context guard in WebSearchTool.Execute: the tenant/workspace ID could not be read from the request context (types.TenantIDContextKey missing or zero), so the search cannot be scoped or billed to a workspace. It fires when the tool is invoked outside an authenticated request pipeline that injects the tenant ID.","triggerScenarios":"Thrown at internal/agent/tools/web_search.go:152 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the middleware/handler injects TenantIDContextKey into the context","Verify the tool is invoked within an authenticated request path","Fail fast at tool construction if the context lacks tenant identity"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}