Tencent/WeKnora · error

workspace ID not found in context

Error message

workspace ID not found in context

What it means

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.

Source

Thrown at internal/agent/tools/web_search.go:152

			Success: false,
			Error:   "query parameter is required",
		}, fmt.Errorf("query parameter is required")
	}

	logger.Infof(ctx, "[Tool][WebSearch] Searching with query: %s, max_results: %d", query, t.maxResults)

	// Get tenant ID from context
	tenantID := uint64(0)
	if tid, ok := ctx.Value(types.TenantIDContextKey).(uint64); ok {
		tenantID = tid
	}

	if tenantID == 0 {
		logger.Errorf(ctx, "[Tool][WebSearch] Workspace ID not found in context")
		return &types.ToolResult{
			Success: false,
			Error:   "workspace ID not found in context",
		}, fmt.Errorf("workspace ID not found in context")
	}

	// Get tenant info from context (same approach as search.go)
	var tenant *types.Tenant
	if tenantValue := ctx.Value(types.TenantInfoContextKey); tenantValue != nil {
		tenant, _ = tenantValue.(*types.Tenant)
	}

	// Resolve provider ID: tool-level (set from agent config, which already resolved default)
	resolvedProviderID := t.providerID

	// Create a copy of the effective web search config with maxResults from agent config.
	searchConfig := types.EffectiveWebSearchConfig(nil)
	if tenant != nil {
		searchConfig = types.EffectiveWebSearchConfig(tenant.WebSearchConfig)
	}
	searchConfig.MaxResults = t.maxResults

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Ensure the middleware/handler injects TenantIDContextKey into the context
  2. Verify the tool is invoked within an authenticated request path
  3. Fail fast at tool construction if the context lacks tenant identity
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/agent/tools/web_search.go:152 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/f7cae11d291900b2. Report an issue: GitHub.