{"record":{"id":"0a066e802a24b3f3","repo":"jackwener/OpenCLI","slug":"codex-extract-diff-returned-an-invalid-payload","errorCode":null,"errorMessage":"Codex extract-diff returned an invalid payload.","messagePattern":"Codex extract-diff returned an invalid payload\\.","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/codex/extract-diff.js","lineNumber":43,"sourceCode":"            });\n        });\n\n        // If no structured diffs found, try to find any code blocks labeled as patches\n        if (results.length === 0) {\n            const codeBlocks = document.querySelectorAll('pre code.language-diff, pre code.language-patch');\n            codeBlocks.forEach((code, index) => {\n                results.push({\n                    File: \\`Patch_\\${index+1}\\`,\n                    Diff: code.innerText || code.textContent\n                });\n            });\n        }\n        \n        return results;\n      })()\n    `));\n        if (!Array.isArray(diffs)) {\n            throw new CommandExecutionError('Codex extract-diff returned an invalid payload.');\n        }\n        if (diffs.length === 0) {\n            throw new EmptyResultError('codex extract-diff', 'No Codex diffs were visible. Run opencli codex send \"/review\" --pick \"Review Agent\" and retry.');\n        }\n        return diffs;\n    },\n});\n","sourceCodeStart":25,"sourceCodeEnd":51,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/codex/extract-diff.js#L25-L51","documentation":"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.","triggerScenarios":"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.","commonSituations":"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`.","solutions":["Re-run the command after confirming the Codex review page is fully loaded and stable (no pending navigation).","Check that you are authenticated to Codex in the automated browser and not on a login/redirect page.","Retry on a fresh session; if it persists, check for a Codex UI update that breaks the injected script and update opencli.","Capture the raw evaluate() payload (log before the Array.isArray check) to identify what the harness actually returned."],"exampleFix":"// before\ndiffs = unwrapEvaluateResult(await page.evaluate(script));\nif (!Array.isArray(diffs)) throw new CommandExecutionError('Codex extract-diff returned an invalid payload.');\n// after\ndiffs = unwrapEvaluateResult(await page.evaluate(script));\nif (diffs == null) throw new CommandExecutionError('Codex extract-diff returned no payload (page may have reloaded). Retry.');\nif (!Array.isArray(diffs)) throw new CommandExecutionError('Codex extract-diff returned an invalid payload.', JSON.stringify(diffs));","handlingStrategy":"try-catch","validationCode":"// verify the Codex page is ready before extracting\nconst title = await page.evaluate('document.readyState');\nif (title !== 'complete') await page.waitForLoadState?.('complete');","typeGuard":"function isDiffArray(v) { return Array.isArray(v) && v.every(d => d && typeof d.File === 'string' && typeof d.Diff === 'string'); }","tryCatchPattern":"try {\n  const diffs = await extractDiffs(page);\n} catch (err) {\n  if (err instanceof CommandExecutionError && /invalid payload/.test(err.message)) {\n    // page likely reloaded/blocked — retry once on a fresh page\n  } else throw err;\n}","preventionTips":["Ensure the Codex review page is fully loaded before running extract-diff","Avoid navigating/reloading the Codex tab while automation runs","Keep opencli updated for Codex UI changes that break the injected script","Log raw evaluate() payloads when debugging payload mismatches"],"tags":["browser-automation","ui-scraping","payload-validation","codex"],"backgroundTag":"invalid-payload-returned","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}