jackwener/OpenCLI · error · CommandExecutionError

Instagram post share failed

Error message

Instagram post share failed

What it means

waitForPublishSuccess polls the Instagram composer page up to 90 times with a DOM probe (buildPublishStatusProbeJs). When the probe detects an explicit failure state in the publish dialog, it throws this CommandExecutionError after saving a debug screenshot. It means Instagram itself reported the share as failed (e.g. an in-dialog 'Couldn't post' message), not that the CLI timed out.

Source

Thrown at clis/instagram/post.js:1247

async function ensureCaptionFilled(page, content) {
    for (let attempt = 0; attempt < 6; attempt++) {
        if (await captionMatches(page, content)) {
            return;
        }
        if (attempt < 5) {
            await page.wait({ time: 0.5 });
        }
    }
    await page.screenshot({ path: '/tmp/instagram_post_caption_fill_debug.png' });
    throw new CommandExecutionError('Instagram caption did not stick before sharing', 'Inspect /tmp/instagram_post_caption_fill_debug.png for the caption editor state');
}
async function waitForPublishSuccess(page) {
    let settledStreak = 0;
    for (let attempt = 0; attempt < 90; attempt++) {
        const result = await page.evaluate(buildPublishStatusProbeJs());
        if (result?.failed) {
            await page.screenshot({ path: '/tmp/instagram_post_share_debug.png' });
            throw new CommandExecutionError('Instagram post share failed', 'Inspect /tmp/instagram_post_share_debug.png for the share failure state');
        }
        if (result?.ok) {
            return result.url || '';
        }
        if (result?.settled) {
            settledStreak += 1;
            if (settledStreak >= 3)
                return '';
        }
        else {
            settledStreak = 0;
        }
        if (attempt < 89) {
            await page.wait({ time: 1 });
        }
    }
    await page.screenshot({ path: '/tmp/instagram_post_share_debug.png' });
    throw new CommandExecutionError('Instagram post share confirmation did not appear', 'Inspect /tmp/instagram_post_share_debug.png for the final publish state');

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Open /tmp/instagram_post_share_debug.png to see the exact failure state Instagram showed in the dialog
  2. Wait and retry later if the dialog shows a rate-limit / 'try again later' message (action block)
  3. Re-encode/rescale the media (valid JPG/PNG/MP4 within Instagram limits) and retry
  4. Verify the logged-in session is valid and not restricted (log in manually in the browser session)
  5. Re-run with OPENCLI_INSTAGRAM_CAPTURE=1 to inspect captured protocol responses for the failing request

Example fix

// before: immediate throw on first failed probe
if (result?.failed) {
  await page.screenshot({ path: '/tmp/instagram_post_share_debug.png' });
  throw new CommandExecutionError('Instagram post share failed', hint);
}
// after: allow a short retry streak before giving up
if (result?.failed) {
  failedStreak += 1;
  if (failedStreak >= 3) {
    await page.screenshot({ path: '/tmp/instagram_post_share_debug.png' });
    throw new CommandExecutionError('Instagram post share failed', hint);
  }
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Before posting, confirm the session can reach Instagram's composer without dialogs
const hasDialog = await page.evaluate(`!!document.querySelector('div[role="dialog"]')`);
if (hasDialog) throw new Error('Dismiss open dialogs before posting');

Type guard

function isPublishProbeResult(r) {
  return r !== null && typeof r === 'object' && ('ok' in r || 'failed' in r || 'settled' in r);
}

Try / catch

try {
  await postToInstagram(media, caption);
} catch (e) {
  if (e instanceof CommandExecutionError && e.message === 'Instagram post share failed') {
    // inspect /tmp/instagram_post_share_debug.png, back off, and retry later
    await sleep(rateLimitBackoff);
    return retryPost(media, caption);
  }
  throw e;
}

Prevention

When it happens

Trigger: During clis/instagram/post.js share flow: the in-page probe returns result.failed because the publish dialog shows a failure notice after clicking Share — e.g. media upload rejected, rate limit, or Instagram-side post creation error.

Common situations: Instagram rate-limiting or action-block on the account; unsupported media (size/format) rejected server-side; network drop mid-upload; transient Instagram UI/API changes so the probe misreads the dialog; account flagged for suspicious automation.

Related errors


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