{"record":{"id":"f22d396cc3ff671b","repo":"chatboxai/chatbox","slug":"session-scoped-resource-must-reference-exactly-one","errorCode":null,"errorMessage":"Session-scoped resource must reference exactly one session: ${resource.id}","messagePattern":"Session-scoped resource must reference exactly one session: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/renderer/packages/backup/types.ts","lineNumber":119,"sourceCode":"  }\n  for (const resource of manifest.resources) {\n    if (resourceIds.has(resource.id)) throw new Error(`Duplicate resource id in manifest: ${resource.id}`)\n    resourceIds.add(resource.id)\n    const ownResourceKeys = new Set<string>()\n    for (const key of resource.originalStorageKeys) {\n      if (ownResourceKeys.has(key)) throw new Error(`Resource contains a duplicate storage key: ${resource.id}`)\n      ownResourceKeys.add(key)\n      if (resourceKeys.has(key)) throw new Error(`Duplicate resource storage key in manifest: ${key}`)\n      resourceKeys.add(key)\n    }\n    const ownSessionIds = new Set<string>()\n    for (const sessionId of resource.sessionIds) {\n      if (ownSessionIds.has(sessionId)) throw new Error(`Resource contains a duplicate session id: ${resource.id}`)\n      ownSessionIds.add(sessionId)\n      if (!sessionIds.has(sessionId)) throw new Error(`Resource references an unknown session: ${sessionId}`)\n    }\n    if (resource.scope === 'session' && resource.sessionIds.length !== 1) {\n      throw new Error(`Session-scoped resource must reference exactly one session: ${resource.id}`)\n    }\n    if (resource.scope === 'global' && resource.sessionIds.length !== 0) {\n      throw new Error(`Global resource must not reference a session: ${resource.id}`)\n    }\n  }\n  const resourcesById = new Map(manifest.resources.map((resource) => [resource.id, resource]))\n  const sessionsById = new Map(manifest.sessions.map((session) => [session.id, session]))\n  for (const session of manifest.sessions) {\n    const ownResourceIds = new Set<string>()\n    for (const resourceId of session.resourceIds) {\n      if (ownResourceIds.has(resourceId)) throw new Error(`Session contains a duplicate resource id: ${session.id}`)\n      ownResourceIds.add(resourceId)\n      if (!resourceIds.has(resourceId)) throw new Error(`Session references an unknown resource: ${resourceId}`)\n      if (!resourcesById.get(resourceId)?.sessionIds.includes(session.id)) {\n        throw new Error(`Session/resource mapping is inconsistent: ${session.id}/${resourceId}`)\n      }\n    }\n  }","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/chatboxai/chatbox/blob/81571269addb6bafb589a920b2883f1e1e084fd1/src/renderer/packages/backup/types.ts#L101-L137","documentation":"Thrown when a resource has scope 'session' but its sessionIds length is not exactly 1. Session-scoped resources must be bound to one and only one session.","triggerScenarios":"resource.scope === 'session' and resource.sessionIds.length is 0 or >= 2.","commonSituations":"Scope mislabeled; a shared resource incorrectly marked session-scoped; exporter set scope before finalizing session links.","solutions":["Set scope to 'shared' if the resource legitimately belongs to multiple sessions.","Attach exactly one sessionId if it is truly session-scoped.","Re-export with correct scope assignment."],"exampleFix":"// before\n// scope 'session' with 0 or 2+ sessionIds\n\n// after\nfor (const r of manifest.resources) {\n  if (r.scope === 'session' && r.sessionIds.length !== 1) {\n    r.scope = r.sessionIds.length === 0 ? 'global' : 'shared'\n  }\n}","handlingStrategy":"validation","validationCode":"function sessionScopedResourcesAreValid(manifest: BackupManifest): boolean {\n  return manifest.resources.every((r) => r.scope !== 'session' || r.sessionIds.length === 1)\n}","typeGuard":null,"tryCatchPattern":"try {\n  validateBackupManifestGraph(manifest)\n} catch (error) {\n  if (/Session-scoped resource/.test((error as Error).message)) fixSessionScope(manifest)\n  throw error\n}","preventionTips":["Decide scope from the number of attached sessions at export (1 => session, >1 => shared, 0 => global).","Re-validate after changing a resource's scope or session links."],"tags":["backup","manifest","validation","scope"],"backgroundTag":null,"analyzedSha":"81571269addb6bafb589a920b2883f1e1e084fd1","analyzedAt":"2026-08-12T21:51:44.981Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}