chatboxai/chatbox · error

Global resource must not reference a session: ${resource.id}

Error message

Global resource must not reference a session: ${resource.id}

What it means

Thrown when a resource has scope 'global' but references one or more sessions. Global resources must be session-agnostic, so any sessionId entry is invalid.

Source

Thrown at src/renderer/packages/backup/types.ts:122

    resourceIds.add(resource.id)
    const ownResourceKeys = new Set<string>()
    for (const key of resource.originalStorageKeys) {
      if (ownResourceKeys.has(key)) throw new Error(`Resource contains a duplicate storage key: ${resource.id}`)
      ownResourceKeys.add(key)
      if (resourceKeys.has(key)) throw new Error(`Duplicate resource storage key in manifest: ${key}`)
      resourceKeys.add(key)
    }
    const ownSessionIds = new Set<string>()
    for (const sessionId of resource.sessionIds) {
      if (ownSessionIds.has(sessionId)) throw new Error(`Resource contains a duplicate session id: ${resource.id}`)
      ownSessionIds.add(sessionId)
      if (!sessionIds.has(sessionId)) throw new Error(`Resource references an unknown session: ${sessionId}`)
    }
    if (resource.scope === 'session' && resource.sessionIds.length !== 1) {
      throw new Error(`Session-scoped resource must reference exactly one session: ${resource.id}`)
    }
    if (resource.scope === 'global' && resource.sessionIds.length !== 0) {
      throw new Error(`Global resource must not reference a session: ${resource.id}`)
    }
  }
  const resourcesById = new Map(manifest.resources.map((resource) => [resource.id, resource]))
  const sessionsById = new Map(manifest.sessions.map((session) => [session.id, session]))
  for (const session of manifest.sessions) {
    const ownResourceIds = new Set<string>()
    for (const resourceId of session.resourceIds) {
      if (ownResourceIds.has(resourceId)) throw new Error(`Session contains a duplicate resource id: ${session.id}`)
      ownResourceIds.add(resourceId)
      if (!resourceIds.has(resourceId)) throw new Error(`Session references an unknown resource: ${resourceId}`)
      if (!resourcesById.get(resourceId)?.sessionIds.includes(session.id)) {
        throw new Error(`Session/resource mapping is inconsistent: ${session.id}/${resourceId}`)
      }
    }
  }
  for (const resource of manifest.resources) {
    for (const sessionId of resource.sessionIds) {
      const session = sessionsById.get(sessionId)

View on GitHub (pinned to 81571269ad)

Solutions

  1. Clear resource.sessionIds to [] if the resource is truly global.
  2. Change scope to 'shared' if the session links are intentional.
  3. Re-export.

Example fix

// before
// scope 'global' but sessionIds is non-empty

// after
for (const r of manifest.resources) {
  if (r.scope === 'global') r.sessionIds = []
}
Defensive patterns

Strategy: validation

Validate before calling

function globalResourcesAreUnscoped(manifest: BackupManifest): boolean {
  return manifest.resources.every((r) => r.scope !== 'global' || r.sessionIds.length === 0)
}

Try / catch

try {
  validateBackupManifestGraph(manifest)
} catch (error) {
  if (/Global resource must not/.test((error as Error).message)) clearGlobalSessionRefs(manifest)
  throw error
}

Prevention

When it happens

Trigger: resource.scope === 'global' and resource.sessionIds.length !== 0.

Common situations: A previously session-scoped resource was promoted to global without clearing its links; exporter didn't clear sessionIds on global promotion.

Related errors


AI-assisted analysis of chatboxai/chatbox@81571269ad (2026-08-12). Data as JSON: /api/errors/638900b51194799f. Report an issue: GitHub.