chatboxai/chatbox · error
Could not allocate a resource key for: ${originalKey}
Error message
Could not allocate a resource key for: ${originalKey} What it means
Thrown by findAvailableCollisionKey after 100 attempts to mint a free resource key all failed - each random UUID candidate either was already in the reserved set or already existed in storage (getBlob !== null). With UUID v4 the probability is negligible, so hitting this almost always points to a faulty storage backend, not real key exhaustion. Propagates after rollback.
Source
Thrown at src/renderer/packages/backup/import-backup.ts:124
async function readStagedResource(storage: BackupStorage, plan: Pick<ResourceWritePlan, 'resource' | 'tempKey'>) {
const base64 = await storage.getBlob(plan.tempKey)
if (base64 === null) throw new Error(`Staged resource is missing: ${plan.resource.path}`)
return decodeStoredBlob(base64ToBytes(base64), plan.resource.encoding, plan.resource.mimeType)
}
async function findAvailableCollisionKey(storage: BackupStorage, originalKey: string, reserved: Set<string>) {
for (let attempt = 0; attempt < 100; attempt++) {
let candidatePrefix = 'resource:imported'
for (const prefix of ['picture:', 'file:', 'link:', 'parseFile-', 'parseUrl-']) {
if (originalKey.startsWith(prefix)) {
candidatePrefix = `${prefix}imported`
break
}
}
const candidate = `${candidatePrefix}:${uuidv4()}`
if (!reserved.has(candidate) && (await storage.getBlob(candidate)) === null) return candidate
}
throw new Error(`Could not allocate a resource key for: ${originalKey}`)
}
async function createResourcePlans(
manifest: BackupManifest,
stagedEntries: Map<string, StagedEntry>,
storage: BackupStorage
) {
const plans: ResourceWritePlan[] = []
const resourceKeyMap = new Map<string, string>()
const reserved = new Set<string>()
for (const resource of manifest.resources) {
const staged = stagedEntries.get(resource.path)
if (!staged?.tempKey) throw new Error(`Resource was not staged: ${resource.path}`)
const restoredValue = await readStagedResource(storage, { resource, tempKey: staged.tempKey })
const targets: ResourceWritePlan['targets'] = []
for (const originalKey of resource.originalStorageKeys) {
const existingValue = await storage.getBlob(originalKey)
let targetKey = originalKeyView on GitHub (pinned to 81571269ad)
Solutions
- Verify storage.getBlob returns null for genuinely absent keys (test the backend directly).
- Increase the attempt budget in findAvailableCollisionKey if your storage legitimately cannot guarantee uniqueness.
- Clear conflicting keys in the target namespace (picture:/file:/link:/parseFile-/parseUrl-) before import.
- File a bug - real exhaustion is astronomically unlikely.
Defensive patterns
Strategy: try-catch
Validate before calling
// Sanity-check the storage backend before import: getBlob must return null for absent keys.
const probe = '__chatbox_collision_probe:' + uuidv4()
if ((await storage.getBlob(probe)) !== null) {
throw new Error('Storage backend is faulty: getBlob returns non-null for absent keys')
} Try / catch
try {
await importBackupArchive(file, options)
} catch (error) {
if (error instanceof Error && error.message.startsWith('Could not allocate a resource key')) {
// Almost certainly a faulty storage backend; not real key exhaustion.
throw new Error('Storage backend failed key allocation; check getBlob correctness', { cause: error })
}
throw error
} Prevention
- In storage mocks/stubs, make getBlob return null for unwritten keys.
- Clear conflicting keys in picture:/file:/link:/parseFile-/parseUrl- namespaces before import.
- Treat this error as a backend bug first and a capacity problem only second.
When it happens
Trigger: 100 consecutive candidates of the form '<prefix>imported:<uuid>' collide against the reserved set or storage.getBlob(candidate) !== null.
Common situations: A storage mock/stub whose getBlob always returns a non-null value; a corrupted storage layer; an adversarially seeded store. Practically never in production with correct UUID v4.
Related errors
- Backup manifest entry list is incomplete
- Staged resource is missing: ${plan.resource.path}
- Resource was not staged: ${resource.path}
- Backup entry is too large: ${entry.path}
- Managed resource is missing from blob storage
AI-assisted analysis of chatboxai/chatbox@81571269ad (2026-08-12).
Data as JSON: /api/errors/6af53d5ce77b5e0e.
Report an issue: GitHub.