{"record":{"id":"23c24820f0ed00d9","repo":"chatboxai/chatbox","slug":"session-resource-mapping-is-inconsistent-sessio","errorCode":null,"errorMessage":"Session/resource mapping is inconsistent: ${session.id}/${resourceId}","messagePattern":"Session/resource mapping is inconsistent: (.+?)/(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/renderer/packages/backup/types.ts","lineNumber":134,"sourceCode":"      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  }\n  for (const resource of manifest.resources) {\n    for (const sessionId of resource.sessionIds) {\n      const session = sessionsById.get(sessionId)\n      if (!session?.resourceIds.includes(resource.id)) {\n        throw new Error(`Resource/session mapping is inconsistent: ${resource.id}/${sessionId}`)\n      }\n    }\n  }\n  if (\n    manifest.stats.sessionCount !== manifest.sessions.length ||\n    manifest.stats.resourceCount !== manifest.resources.length ||\n    manifest.stats.warningCount !== manifest.warnings.length\n  ) {\n    throw new Error('Backup manifest statistics do not match its entries')\n  }","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/chatboxai/chatbox/blob/81571269addb6bafb589a920b2883f1e1e084fd1/src/renderer/packages/backup/types.ts#L116-L152","documentation":"Thrown for a forward-link mismatch: session S lists resource R, but R.sessionIds does not include S. The session-to-resource and resource-to-session edges must be symmetric.","triggerScenarios":"resourcesById.get(resourceId).sessionIds does not include session.id, even though session.resourceIds includes resourceId.","commonSituations":"One side of a bidirectional link was edited without the other; exporter wrote resourceIds but forgot sessionIds; a merge that updated only one direction.","solutions":["Make the links bidirectional: ensure each resource lists the sessions that reference it and vice versa.","Re-export so the exporter writes both directions.","Repair by adding session.id to the resource's sessionIds."],"exampleFix":"// before\n// session->resource link exists, but resource->session does not\n\n// after\nconst resourcesById = new Map(manifest.resources.map((r) => [r.id, r]))\nfor (const s of manifest.sessions) {\n  for (const rid of s.resourceIds) {\n    const r = resourcesById.get(rid)\n    if (r && !r.sessionIds.includes(s.id)) r.sessionIds.push(s.id)\n  }\n}","handlingStrategy":"try-catch","validationCode":"function forwardLinksAreSymmetric(manifest: BackupManifest): boolean {\n  const resourcesById = new Map(manifest.resources.map((r) => [r.id, r]))\n  return manifest.sessions.every((s) =>\n    s.resourceIds.every((rid) => resourcesById.get(rid)?.sessionIds.includes(s.id))\n  )\n}","typeGuard":null,"tryCatchPattern":"try {\n  validateBackupManifestGraph(manifest)\n} catch (error) {\n  if (/Session\\/resource mapping is inconsistent/.test((error as Error).message)) symmetrizeLinks(manifest)\n  throw error\n}","preventionTips":["Write both directions of every link in the same exporter code path.","Re-validate after any link edit on either side.","Avoid manual manifest edits; regenerate instead."],"tags":["backup","manifest","validation","referential-integrity"],"backgroundTag":null,"analyzedSha":"81571269addb6bafb589a920b2883f1e1e084fd1","analyzedAt":"2026-08-12T21:51:44.981Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}