{"record":{"id":"4b6aa8aa28a7126b","repo":"jackwener/OpenCLI","slug":"instagram-post-feed-no-longer-shows-the-expected-p","errorCode":null,"errorMessage":"Instagram post feed no longer shows the expected post ${expectedPost.code} at index ${index}","messagePattern":"Instagram post feed no longer shows the expected post (.+?) at index (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/instagram/_shared/post-like.js","lineNumber":160,"sourceCode":"async function readPostSnapshot(page, username, index, command) {\n    const feed = unwrapEvaluateResult(await page.evaluate(buildReadPostsJs(username, index)));\n    return normalizeFeedSnapshot(feed, command, username);\n}\n\nfunction pickPost(snapshot, username, index, command) {\n    const post = snapshot.posts[index - 1];\n    if (!post) {\n        throw new EmptyResultError(command, snapshot.posts.length === 0\n            ? `No visible posts for ${username}; check the username and whether the account is private.`\n            : `Post index ${index} not found; ${username} has ${snapshot.posts.length} recent posts.`);\n    }\n    return post;\n}\n\nasync function confirmPersistedState(page, username, index, command, expectedPost, shouldLike) {\n    const confirmed = pickPost(await readPostSnapshot(page, username, index, command), username, index, command);\n    if (confirmed.code !== expectedPost.code || confirmed.pk !== expectedPost.pk) {\n        throw new CommandExecutionError(\n            `Instagram post feed no longer shows the expected post ${expectedPost.code} at index ${index}`,\n            'The profile feed may have re-rendered or changed order; retry after checking the post in the browser.',\n        );\n    }\n    if (confirmed.liked !== shouldLike) {\n        throw new CommandExecutionError(\n            `Instagram did not persist the ${shouldLike ? 'like' : 'unlike'} on ${expectedPost.code}`,\n            'The action may have been rejected. Retry later, or check the post in the browser.',\n        );\n    }\n    return confirmed;\n}\n\nexport async function setInstagramPostLike(page, kwargs, shouldLike) {\n    const username = String(kwargs.username || '').trim();\n    const index = kwargs.index;\n    const command = shouldLike ? 'instagram like' : 'instagram unlike';\n    if (!username) {","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/_shared/post-like.js#L142-L178","documentation":"confirmPersistedState re-reads the post feed after clicking like/unlike and verifies the post at the same index still matches the originally selected post (code and pk). This throw fires on mismatch: the feed re-rendered or reordered between the initial read and the verification read, so the identity check cannot confirm the action applied to the intended post.","triggerScenarios":"Instagram's profile grid re-rendering between readPostSnapshot calls (new posts loaded, pinned-post reorder, infinite-scroll shifting rows), or a slow page causing a second snapshot to reflect different content at the same index.","commonSituations":"Accounts actively posting during automation; infinite-scroll feeds that shift positions; flaky/slow browser environments where the DOM settles late; concurrent tabs acting on the same profile.","solutions":["Simply retry the whole command — the check exists to prevent acting on the wrong post, and a fresh run re-selects safely","Avoid automating accounts that are actively posting or whose feed reorders during the run","Use a direct post URL instead of index-based selection if the library exposes one","Increase page settle/sleep time so the grid is stable before reading"],"exampleFix":"// before: tight sequence allowing mid-run re-render\nconst post = pickPost(await readPostSnapshot(page, username, index, command), ...);\nawait clickLike();\n// after: re-verify identity before clicking\nconst before = pickPost(await readPostSnapshot(page, username, index, command), ...);\nawait page.sleep(1);\nconst after = pickPost(await readPostSnapshot(page, username, index, command), ...);\nif (before.code !== after.code) throw new Error('feed unstable; retry');\nawait clickLike();","handlingStrategy":"retry","validationCode":"// verify feed stability before acting\nconst a = (await readPostSnapshot(page, username, index, command)).posts[index - 1];\nawait page.sleep(2);\nconst b = (await readPostSnapshot(page, username, index, command)).posts[index - 1];\nif (!a || !b || a.code !== b.code || a.pk !== b.pk) throw new Error('feed unstable; abort');","typeGuard":null,"tryCatchPattern":"try { await setInstagramPostLike(page, kwargs, true); } catch (e) { if (/no longer shows the expected post/.test(e.message)) { await sleep(5000); return setInstagramPostLike(page, kwargs, shouldLike); } throw e; }","preventionTips":["Don't automate accounts that post or reorder during the run","Add settle sleeps so infinite-scroll finishes before reading","Prefer direct post URLs over index-based selection when available","Run actions sequentially, never concurrently, on the same profile"],"tags":["instagram","race-condition","consistency-check"],"backgroundTag":"stale-read-race","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}