toeverything/AFFiNE · error

DOC_SCOPE_DENIED

DOC_SCOPE_DENIED

Error message

The document is outside the user-selected document scope.

What it means

isDocumentInScope rejected the requested docId: the document is outside the document scope the user attached to the conversation, so the getter refuses to read it and returns a non-retryable DOC_SCOPE_DENIED tool error with a doc_id locator.

Source

Thrown at packages/backend/server/src/plugins/copilot/tools/doc-canvas-read.ts:219

  return async (
    options: CopilotChatOptions,
    docId: string,
    target: CanvasTarget,
    cursorValue: string | undefined,
    requestedLimit: number | undefined
  ) => {
    if (!options?.user || !options.workspace) {
      return toolError('Doc Canvas Read Failed', 'Missing workspace or user.', {
        code: 'INVALID_CONTEXT',
        retryable: false,
      });
    }
    if (!isDocumentInScope(documentScope, docId)) {
      return toolError(
        'Doc Canvas Read Failed',
        'The document is outside the user-selected document scope.',
        {
          code: 'DOC_SCOPE_DENIED',
          retryable: false,
          locator: { doc_id: docId },
        }
      );
    }
    if (!(await models.workspace.get(options.workspace))) {
      return workspaceSyncRequiredError();
    }
    const canAccess = await ac
      .user(options.user)
      .workspace(options.workspace)
      .doc(docId)
      .can('Doc.Read');
    if (!canAccess) {
      return toolError('Doc Canvas Read Failed', 'Document access denied.', {
        code: 'DOC_ACCESS_DENIED',
        retryable: false,
        locator: { doc_id: docId },

View on GitHub (pinned to b4c8548c09)

Solutions

  1. Add the document to the user-selected scope.
  2. Choose a document inside the selected scope.
Defensive patterns

Strategy: validation

When it happens

Trigger: Returned as DOC_SCOPE_DENIED when the requested docId is not in the user-selected document scope enforced by isDocumentInScope.

Common situations: The copilot referenced a canvas outside the documents the user granted access to. Add the document to the chat scope to allow reading it.


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