affaan-m/ECC · error · Error
Could not allocate a snapshot filename for session
Error message
Could not allocate a snapshot filename for session ${session.sessionId} What it means
When writing per-session snapshot files, the allocator tries to build a unique filename from the session id, retrying with an incremented attempt counter if the name collides. If it exhausts its attempts without finding a free, valid name it throws 'Could not allocate a snapshot filename for session <sessionId>'. This is a defensive invariant: in practice it indicates pathological session ids or a saturated output directory naming scheme.
Solutions
- Inspect the reported sessionId for unusual characters or extreme length and sanitize/shorten it at the source.
- Point --write-dir at a fresh directory to reduce name collisions from existing snapshots.
- Update the script to increase the attempt limit or include a hash/random suffix in the filename.
- Retry the run; a transient collision with concurrently written snapshots may resolve on the next attempt.
Example fix
// before node scripts/loop-status.js --write-dir ./snapshots # pathological sessionId // after rm -rf ./snapshots && node scripts/loop-status.js --write-dir ./snapshots # or patch allocator to append a random suffix
Defensive patterns
Strategy: try-catch
Validate before calling
if (!/^[-\w.]{1,64}$/.test(session.sessionId)) sanitize or reject the session id before snapshotting; Type guard
const isSafeSessionId = (id) => typeof id === 'string' && id.length > 0 && id.length <= 128 && !id.includes('/'); Try / catch
try { writeStatusSnapshots(payload, dir); } catch (e) { if (e.message.startsWith('Could not allocate a snapshot filename')) { console.error('Snapshot naming failed; clean the output dir or shorten the session id'); } else throw e; } Prevention
- Use fresh output directories per run
- Sanitize session ids from third-party tools
- Patch the allocator to add a random/hash suffix instead of failing
When it happens
Trigger: Calling writeStatusSnapshots with --write-dir where a session id produces a filename that cannot be made unique after all retry attempts (e.g. extremely long session ids colliding after truncation, or a hostile/odd sessionId string).
Common situations: Session ids containing path-unsafe or extremely long characters from a third-party tool, or thousands of snapshots in one directory hitting naming limits.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- stable source snapshot write made no progress
- all overlays must be readable local files
- all takes must be readable local files
- apply_local produced an invalid report
- artifact byte count exceeded during reading
AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16).
Data as JSON: /api/errors/28df09f8b9de2ecc.
Report an issue: GitHub.
Appendix: source
Thrown at scripts/loop-status.js:674
}
}
function getSnapshotPath(outputDir, session, usedNames) {
const baseName = sanitizeSnapshotName(session.sessionId);
const hashSuffix = hashString(session.transcriptPath || session.sessionId).slice(0, 8);
let attempt = 0;
while (attempt < 1000) {
const suffix = attempt === 0 ? '' : `-${hashSuffix}${attempt === 1 ? '' : `-${attempt}`}`;
const fileName = `${baseName}${suffix}.json`;
if (!usedNames.has(fileName)) {
usedNames.add(fileName);
return path.join(outputDir, fileName);
}
attempt += 1;
}
throw new Error(`Could not allocate a snapshot filename for session ${session.sessionId}`);
}
function writeStatusSnapshots(payload, writeDir) {
if (!writeDir) {
return null;
}
const outputDir = path.resolve(writeDir);
fs.mkdirSync(outputDir, { recursive: true });
const usedNames = new Set(['index.json']);
const sessions = payload.sessions.map(session => {
const snapshotPath = getSnapshotPath(outputDir, session, usedNames);
atomicWriteJson(snapshotPath, {
generatedAt: payload.generatedAt,
schemaVersion: 'ecc.loop-status.session.v1',
session,
});View on GitHub (pinned to 8321021c54)