{"record":{"id":"3199844f508f65b3","repo":"toeverything/AFFiNE","slug":"invalid-context","errorCode":"INVALID_CONTEXT","errorMessage":"Missing retrieval scope.","messagePattern":"Missing retrieval scope\\.","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/backend/server/src/plugins/copilot/tools/artifact.ts","lineNumber":27,"sourceCode":"const logger = new Logger('ArtifactTool');\n\nexport const createArtifactSearchTool = (\n  retrieval: ArtifactRetrievalService,\n  options: CopilotChatOptions\n) =>\n  defineTool({\n    description:\n      'Search workspace artifacts and message attachments within the current retrieval scope. This tool never searches documents or the web.',\n    inputSchema: z\n      .object({\n        query: z.string().trim().min(1).max(2000),\n        limit: z.number().int().min(1).max(10).optional(),\n      })\n      .strict(),\n    execute: async ({ query, limit }, execution) => {\n      if (!options?.user || !options.workspace || !options.retrievalScope) {\n        return toolError('Artifact Search Failed', 'Missing retrieval scope.', {\n          code: 'INVALID_CONTEXT',\n          retryable: false,\n        });\n      }\n      const result = await retrieval.search({\n        userId: options.user,\n        workspaceId: options.workspace,\n        query,\n        retrieval: options.retrievalScope,\n        limit: limit ?? 5,\n        messageId: options.billingUnitId,\n        signal: execution.signal,\n      });\n      return {\n        degraded: result.degraded,\n        hits: result.hits.map(hit => ({\n          artifact_id: hit.artifactId,\n          excerpt: hit.content,\n          distance: hit.distance,","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/b4c8548c09da21b2898443559a5b846f0ccf5dd8/packages/backend/server/src/plugins/copilot/tools/artifact.ts#L9-L45","documentation":"Generic context guard at the top of the artifact search tool's execute: CopilotChatOptions lacks options.user or options.workspace, so the retrieval scope cannot be established and the tool returns a structured tool error before querying ArtifactRetrievalService.","triggerScenarios":"Returned as INVALID_CONTEXT by the artifact search tool when user, workspace, or retrievalScope is missing from the copilot options.","commonSituations":"An artifact search ran without a proper chat context, e.g. scope not initialized. Restart the chat session so the retrieval scope is set.","solutions":["Provide a retrieval scope when invoking the artifact tool.","Select documents to define the scope."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b4c8548c09da21b2898443559a5b846f0ccf5dd8","analyzedAt":"2026-08-18T21:16:52.546Z","contentChangedAt":"2026-08-18T21:16:52.546Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}