jackwener/OpenCLI · error · CommandExecutionError

Codex extract-diff returned an invalid payload.

Error message

Codex extract-diff returned an invalid payload.

What it means

The `codex extract-diff` command scrapes the Codex web UI for diff blocks (`.diff-editor`, `.monaco-diff-editor`, `[data-testid="diff-view"]`, or diff/patch code blocks) via an in-page script. This CommandExecutionError is thrown when the script's return value is not an array, meaning the browser automation layer returned an unexpected payload (e.g. null, an error object, or a wrapped evaluation result) instead of the collected results array. It is a defensive integrity check by the library, signaling the page scrape did not execute as expected rather than simply finding no diffs.

Source

Thrown at clis/codex/extract-diff.js:43

            });
        });

        // If no structured diffs found, try to find any code blocks labeled as patches
        if (results.length === 0) {
            const codeBlocks = document.querySelectorAll('pre code.language-diff, pre code.language-patch');
            codeBlocks.forEach((code, index) => {
                results.push({
                    File: \`Patch_\${index+1}\`,
                    Diff: code.innerText || code.textContent
                });
            });
        }
        
        return results;
      })()
    `));
        if (!Array.isArray(diffs)) {
            throw new CommandExecutionError('Codex extract-diff returned an invalid payload.');
        }
        if (diffs.length === 0) {
            throw new EmptyResultError('codex extract-diff', 'No Codex diffs were visible. Run opencli codex send "/review" --pick "Review Agent" and retry.');
        }
        return diffs;
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-run the command after confirming the Codex review page is fully loaded and stable (no pending navigation).
  2. Check that you are authenticated to Codex in the automated browser and not on a login/redirect page.
  3. Retry on a fresh session; if it persists, check for a Codex UI update that breaks the injected script and update opencli.
  4. Capture the raw evaluate() payload (log before the Array.isArray check) to identify what the harness actually returned.

Example fix

// before
diffs = unwrapEvaluateResult(await page.evaluate(script));
if (!Array.isArray(diffs)) throw new CommandExecutionError('Codex extract-diff returned an invalid payload.');
// after
diffs = unwrapEvaluateResult(await page.evaluate(script));
if (diffs == null) throw new CommandExecutionError('Codex extract-diff returned no payload (page may have reloaded). Retry.');
if (!Array.isArray(diffs)) throw new CommandExecutionError('Codex extract-diff returned an invalid payload.', JSON.stringify(diffs));
Defensive patterns

Strategy: try-catch

Validate before calling

// verify the Codex page is ready before extracting
const title = await page.evaluate('document.readyState');
if (title !== 'complete') await page.waitForLoadState?.('complete');

Type guard

function isDiffArray(v) { return Array.isArray(v) && v.every(d => d && typeof d.File === 'string' && typeof d.Diff === 'string'); }

Try / catch

try {
  const diffs = await extractDiffs(page);
} catch (err) {
  if (err instanceof CommandExecutionError && /invalid payload/.test(err.message)) {
    // page likely reloaded/blocked — retry once on a fresh page
  } else throw err;
}

Prevention

When it happens

Trigger: Running `opencli codex extract-diff` when the in-page evaluate() returns a non-array value — typically when unwrapEvaluateResult yields null/undefined because the script was blocked, the page context was destroyed mid-eval, or a future Codex UI change makes the IIFE throw so the harness returns an error object instead of results.

Common situations: Codex tab navigated or reloaded while extraction was in flight; the extract-diff page failed to load fully (blank page, auth redirect); a browser-automation adapter returning wrapped/error payloads the unwrap step doesn't recognize; a Codex UI version where the injected script throws before `return results`.

Related errors


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