jackwener/OpenCLI · error · CommandExecutionError

Instagram post feed no longer shows the expected post

Error message

Instagram post feed no longer shows the expected post ${expectedPost.code} at index ${index}

What it means

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.

Solutions

  1. Simply retry the whole command — the check exists to prevent acting on the wrong post, and a fresh run re-selects safely
  2. Avoid automating accounts that are actively posting or whose feed reorders during the run
  3. Use a direct post URL instead of index-based selection if the library exposes one
  4. Increase page settle/sleep time so the grid is stable before reading

Example fix

// before: tight sequence allowing mid-run re-render
const post = pickPost(await readPostSnapshot(page, username, index, command), ...);
await clickLike();
// after: re-verify identity before clicking
const before = pickPost(await readPostSnapshot(page, username, index, command), ...);
await page.sleep(1);
const after = pickPost(await readPostSnapshot(page, username, index, command), ...);
if (before.code !== after.code) throw new Error('feed unstable; retry');
await clickLike();
Defensive patterns

Strategy: retry

Validate before calling

// verify feed stability before acting
const a = (await readPostSnapshot(page, username, index, command)).posts[index - 1];
await page.sleep(2);
const b = (await readPostSnapshot(page, username, index, command)).posts[index - 1];
if (!a || !b || a.code !== b.code || a.pk !== b.pk) throw new Error('feed unstable; abort');

Try / catch

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; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/4b6aa8aa28a7126b. Report an issue: GitHub.

Appendix: source

Thrown at clis/instagram/_shared/post-like.js:160

async function readPostSnapshot(page, username, index, command) {
    const feed = unwrapEvaluateResult(await page.evaluate(buildReadPostsJs(username, index)));
    return normalizeFeedSnapshot(feed, command, username);
}

function pickPost(snapshot, username, index, command) {
    const post = snapshot.posts[index - 1];
    if (!post) {
        throw new EmptyResultError(command, snapshot.posts.length === 0
            ? `No visible posts for ${username}; check the username and whether the account is private.`
            : `Post index ${index} not found; ${username} has ${snapshot.posts.length} recent posts.`);
    }
    return post;
}

async function confirmPersistedState(page, username, index, command, expectedPost, shouldLike) {
    const confirmed = pickPost(await readPostSnapshot(page, username, index, command), username, index, command);
    if (confirmed.code !== expectedPost.code || confirmed.pk !== expectedPost.pk) {
        throw new CommandExecutionError(
            `Instagram post feed no longer shows the expected post ${expectedPost.code} at index ${index}`,
            'The profile feed may have re-rendered or changed order; retry after checking the post in the browser.',
        );
    }
    if (confirmed.liked !== shouldLike) {
        throw new CommandExecutionError(
            `Instagram did not persist the ${shouldLike ? 'like' : 'unlike'} on ${expectedPost.code}`,
            'The action may have been rejected. Retry later, or check the post in the browser.',
        );
    }
    return confirmed;
}

export async function setInstagramPostLike(page, kwargs, shouldLike) {
    const username = String(kwargs.username || '').trim();
    const index = kwargs.index;
    const command = shouldLike ? 'instagram like' : 'instagram unlike';
    if (!username) {

View on GitHub (pinned to 49907e53dc)