chatboxai/chatbox · error

Session contains a duplicate resource id: ${session.id}

Error message

Session contains a duplicate resource id: ${session.id}

What it means

Thrown when a session's resourceIds array lists the same resource more than once. The session-to-resource link must be unique within a single session.

Source

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

    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)
      if (!session?.resourceIds.includes(resource.id)) {
        throw new Error(`Resource/session mapping is inconsistent: ${resource.id}/${sessionId}`)
      }
    }
  }
  if (
    manifest.stats.sessionCount !== manifest.sessions.length ||
    manifest.stats.resourceCount !== manifest.resources.length ||

View on GitHub (pinned to 81571269ad)

Solutions

  1. Dedupe resourceIds within each session.
  2. Re-export.
  3. Audit the exporter's resource-attachment loop.

Example fix

// before
validateBackupManifestGraph(manifest)

// after
for (const s of manifest.sessions) {
  s.resourceIds = [...new Set(s.resourceIds)]
}
Defensive patterns

Strategy: validation

Validate before calling

function sessionsHaveUniqueResourceRefsLocally(manifest: BackupManifest): boolean {
  return manifest.sessions.every((s) => new Set(s.resourceIds).size === s.resourceIds.length)
}

Try / catch

try {
  validateBackupManifestGraph(manifest)
} catch (error) {
  if (/Session contains a duplicate resource id/.test((error as Error).message)) dedupeSessionResourceIds(manifest)
  throw error
}

Prevention

When it happens

Trigger: session.resourceIds contains a repeated resourceId for one session entry.

Common situations: Exporter appended the same resource link twice; merge artifact; attachments concatenated without dedupe.

Related errors


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