toeverything/AFFiNE · error

INVALID_CONTEXT

INVALID_CONTEXT

Error message

Missing retrieval scope.

What it means

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.

Source

Thrown at packages/backend/server/src/plugins/copilot/tools/artifact.ts:27

const logger = new Logger('ArtifactTool');

export const createArtifactSearchTool = (
  retrieval: ArtifactRetrievalService,
  options: CopilotChatOptions
) =>
  defineTool({
    description:
      'Search workspace artifacts and message attachments within the current retrieval scope. This tool never searches documents or the web.',
    inputSchema: z
      .object({
        query: z.string().trim().min(1).max(2000),
        limit: z.number().int().min(1).max(10).optional(),
      })
      .strict(),
    execute: async ({ query, limit }, execution) => {
      if (!options?.user || !options.workspace || !options.retrievalScope) {
        return toolError('Artifact Search Failed', 'Missing retrieval scope.', {
          code: 'INVALID_CONTEXT',
          retryable: false,
        });
      }
      const result = await retrieval.search({
        userId: options.user,
        workspaceId: options.workspace,
        query,
        retrieval: options.retrievalScope,
        limit: limit ?? 5,
        messageId: options.billingUnitId,
        signal: execution.signal,
      });
      return {
        degraded: result.degraded,
        hits: result.hits.map(hit => ({
          artifact_id: hit.artifactId,
          excerpt: hit.content,
          distance: hit.distance,

View on GitHub (pinned to b4c8548c09)

Solutions

  1. Provide a retrieval scope when invoking the artifact tool.
  2. Select documents to define the scope.
Defensive patterns

Strategy: validation

When it happens

Trigger: Returned as INVALID_CONTEXT by the artifact search tool when user, workspace, or retrievalScope is missing from the copilot options.

Common situations: An artifact search ran without a proper chat context, e.g. scope not initialized. Restart the chat session so the retrieval scope is set.


AI-assisted analysis of toeverything/AFFiNE@b4c8548c09 (2026-08-18). Data as JSON: /api/errors/3199844f508f65b3. Report an issue: GitHub.