{"record":{"id":"87a42363315a0f75","repo":"jackwener/OpenCLI","slug":"twitter-bookmarks-resume-file-filepath-count-do","errorCode":null,"errorMessage":"Twitter bookmarks resume file ${filePath} count does not match its in-memory tweets","messagePattern":"Twitter bookmarks resume file (.+?) count does not match its in-memory tweets","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/twitter/bookmarks.js","lineNumber":132,"sourceCode":"    }\n    const count = parsed?.count;\n    const cursor = parsed?.cursor == null ? null : String(parsed.cursor);\n    const outputFile = parsed?.outputFile ? path.resolve(String(parsed.outputFile)) : null;\n    if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)\n        || !Number.isInteger(count) || count < 0\n        || (parsed.cursor != null && typeof parsed.cursor !== 'string')\n        || (cursor !== null && !cursor.trim())) {\n        throw new CommandExecutionError(`Twitter bookmarks resume file ${filePath} has an invalid shape`);\n    }\n    if (expected) {\n        if (parsed.source !== expected.source)\n            throw new ArgumentError(`Resume file source mismatch: expected ${expected.source}, found ${parsed.source || 'unknown'}`);\n        if (outputFile !== expected.outputFile)\n            throw new ArgumentError(`Resume file output mismatch: expected ${expected.outputFile || 'in-memory mode'}, found ${outputFile || 'in-memory mode'}`);\n        if (!expected.outputFile && !Array.isArray(parsed.tweets))\n            throw new CommandExecutionError(`Twitter bookmarks resume file ${filePath} is missing in-memory tweets`);\n        if (!expected.outputFile && parsed.tweets.length !== count)\n            throw new CommandExecutionError(`Twitter bookmarks resume file ${filePath} count does not match its in-memory tweets`);\n        if (parsed.complete)\n            throw new CommandExecutionError(`Twitter bookmarks resume file ${filePath} is already marked complete`);\n    }\n    return {\n        cursor,\n        count,\n        tweets: Array.isArray(parsed.tweets) ? parsed.tweets : [],\n        complete: Boolean(parsed.complete),\n        source: parsed.source || null,\n        outputFile,\n        updatedAt: parsed.updatedAt || null,\n    };\n}\n\n// Keep this in sync with twitter/likes; wording is command-specific, so the\n// atomic tmp-write/rename cleanup sequence intentionally remains local.\nfunction writeResumeFile(filePath, payload) {\n    if (!filePath)","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/twitter/bookmarks.js#L114-L150","documentation":"For in-memory resume files, the `count` field must exactly equal `tweets.length`. A mismatch means the state file is internally inconsistent, so readResumeFile throws this CommandExecutionError rather than resume with unreliable data.","triggerScenarios":"Resuming a file where `count` was hand-edited, tweets were added/removed without updating `count`, or the file mixes fields from different runs (e.g. overwritten partially).","commonSituations":"Manual deduplication of the tweets array; truncated copy of the resume file; concurrent writes to the same resume file from two processes.","solutions":["Fix `count` to match the actual length of `tweets` (only if you trust the file).","Delete the resume file and restart the --all sync.","Avoid editing resume files by hand; use --output-file mode where the JSONL archive is the source of truth."],"exampleFix":"// before: {\"count\": 10, \"tweets\": [ /* 8 items */ ]}\n// after: set count to actual length or regenerate\n{\"count\": 8, \"tweets\": [ /* 8 items */ ], ...}","handlingStrategy":"validation","validationCode":"const parsed = JSON.parse(fs.readFileSync(resumeFile, 'utf8'));\nif (!parsed.outputFile && Array.isArray(parsed.tweets) && parsed.count !== parsed.tweets.length) {\n  parsed.count = parsed.tweets.length; // or discard the file\n  fs.writeFileSync(resumeFile, JSON.stringify(parsed, null, 2));\n}","typeGuard":"function countMatchesTweets(v) {\n  return v.outputFile || (Array.isArray(v.tweets) && v.count === v.tweets.length);\n}","tryCatchPattern":"try {\n  await run(args);\n} catch (e) {\n  if (String(e.message).includes('count does not match its in-memory tweets')) {\n    fs.rmSync(resumeFile, { force: true });\n    await run(args);\n  } else throw e;\n}","preventionTips":["Never manually edit `count` or `tweets` in the resume file.","Run only one sync process per resume file to avoid concurrent writes.","Verify integrity after copying resume files between machines.","Prefer --output-file mode where count is derived from the archive."],"tags":["resume-file","consistency","cli"],"backgroundTag":"resume-file-count-mismatch","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}