From 888f61e6866478978c07138a4283096ca3f53c2f Mon Sep 17 00:00:00 2001 From: youdie006 Date: Fri, 30 Oct 2026 17:06:41 +0900 Subject: [PATCH] fix: do not save the page's render error as the answer When ChatGPT's newer answer renderer cannot draw an answer, it shows div[role=status][data-dil-render-failed] reading "This response couldn't load" in its place. prodex read that sentence as the answer: the consult reported done with its request verified, and `pro browser recover` saved it again because the tab was already on the thread and was not reloaded. Measured 2026-10-30 in the browser container, where Chromium could not start threads: the conversation held the finished answer while the page showed the error. - answerExpression reports answerRenderFailed for the paired assistant turn. - hasFreshChatGptAnswer and hasPartialChatGptAnswer refuse such a turn. - A send stops as answer_render_failed (not retryable, names recover with the thread and request id) after two reads showing it. - Recovery marks the document, loads the thread once more, and reads the new document; if the error persists it stops as answer_render_failed. Verified: tsc, build, npm test (1846 passed, 3 skipped). Live on WSL with the measured markup injected: 0.40.48 recovered the error text; this build recovered "OK" after one reload, blocked a send whose answer was marked failed, stopped recovery while the failure persisted, and recovered the answer once it no longer did. Claude-Session: https://claude.ai/code/session_01EMqNwnnhHXznd2P2PDsaDV --- CHANGELOG.md | 5 ++ src/chatgpt-browser.ts | 72 +++++++++++++++++-- tests/chatgpt-browser.test.ts | 126 ++++++++++++++++++++++++++++++++++ 3 files changed, 199 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 782a099c..4918cc47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed +- When ChatGPT's page could not draw an answer, prodex saved the page's own error, "This response couldn’t load", as the answer, and the consult reported done with its request verified. `pro browser recover` saved the same sentence again, because the tab was already on the thread and was not loaded again. Found 2026-10-30 in the browser container: Chromium could not start threads there, and ChatGPT held the finished answer ("OK") while the page showed the error in its place. A send now stops as `answer_render_failed` and names the `recover` command. Recovery loads the thread once more when it finds the error, and returns the answer drawn after that. If the error is still there, recovery stops as `answer_render_failed` instead of saving it. Checked live on WSL by marking an answer the way the failed page did: 0.40.48 recovered the error text; the fix blocked the send, then recovered "PROBE7731" once the page could draw it. + ## 0.40.48 ### Fixed diff --git a/src/chatgpt-browser.ts b/src/chatgpt-browser.ts index 1ce43228..35878451 100644 --- a/src/chatgpt-browser.ts +++ b/src/chatgpt-browser.ts @@ -361,6 +361,8 @@ interface ChatGptAnswerState { lastUserCollapsed?: boolean; /** A generated image follows the last user turn and no assistant turn does. */ nonTextAnswer?: boolean; + /** The page could not draw the answer and shows its own error in its place. */ + answerRenderFailed?: boolean; /** ChatGPT's own tag for the model that produced the last answer. */ modelSlug?: string; textSample: string; @@ -1490,9 +1492,10 @@ export function shouldRecoverThreadNavigation(args: { export function hasFreshChatGptAnswer( previousAssistantMessageCount: number, - state: Pick + state: Pick ): boolean { - return state.assistantMessageCount > previousAssistantMessageCount && isUsableChatGptAnswer(state.answer) && !state.generating; + return state.assistantMessageCount > previousAssistantMessageCount && isUsableChatGptAnswer(state.answer) && !state.generating && + state.answerRenderFailed !== true; } // Like hasFreshChatGptAnswer but WITHOUT requiring generation to have finished: @@ -1551,9 +1554,10 @@ export function acceptanceTimeoutError(ctx: AcceptanceTimeoutContext): Error { export function hasPartialChatGptAnswer( previousAssistantMessageCount: number, - state: Pick + state: Pick ): boolean { - return state.assistantMessageCount > previousAssistantMessageCount && isUsableChatGptAnswer(state.answer); + return state.assistantMessageCount > previousAssistantMessageCount && isUsableChatGptAnswer(state.answer) && + state.answerRenderFailed !== true; } /** @@ -2014,6 +2018,22 @@ export function chatGptBlockerFromAnswerState(state: { return detectChatGptPageBlocker(state); } +/** + * The answer exists, but the page shows "This response couldn’t load" in + * its place. Measured 2026-10-30 in the browser container, where Chromium could + * not start threads: the conversation held the finished answer, and loading + * the thread again drew it. + */ +export function answerRenderFailedBlocker(thread?: string): NonNullable { + return { + code: "answer_render_failed", + message: "ChatGPT answered, but the page could not display the answer (it shows \"This response couldn’t load\"). No answer was returned.", + retryable: false, + next_step: "Recovery loads the conversation again and reads the answer.", + ...(thread ? { thread } : {}) + }; +} + function submittedRequestBlocker( blocker: NonNullable, requestId: string, @@ -4580,6 +4600,8 @@ export async function recoverChatGptAnswerFromThread( let lastAnswer = ""; let lastObservedUrl = ""; let completed = false; + let renderFailed = false; + let reloadedForRenderFailure = false; try { await cdp.send("Runtime.enable"); // In-tab navigation (location.assign, not Page.navigate which has crashed the @@ -4629,6 +4651,21 @@ export async function recoverChatGptAnswerFromThread( thread: url }); } + // The tab may already be on the thread with the page's error in place + // of the answer, so recovery loads the thread once more to draw it. + if (state.answerRenderFailed && !state.generating && state.assistantMessageCount > 0) { + renderFailed = true; + stableRuns = 0; + lastAnswer = ""; + if (!reloadedForRenderFailure) { + reloadedForRenderFailure = true; + await evaluateOnPage(page.page, markDocumentForReloadExpression()); + await navigateIdleChatGptPage(page.page, url); + await waitForReloadedDocument(page.page, deadline); + } + continue; + } + renderFailed = false; // Require a REAL assistant message, not answerExpression's page-chrome // fallback (empty assistant returns sidebar/nav text): the thread's // conversation loads asynchronously after navigation, so keep polling. @@ -4651,6 +4688,13 @@ export async function recoverChatGptAnswerFromThread( } if (!completed) { const targetMatched = Boolean(state && chatGptUrlsReferToSameTarget(state.url, url)); + if (targetMatched && renderFailed) { + throw new ChatGptBrowserBlockerError({ + ...answerRenderFailedBlocker(url), + retryable: true, + next_step: "The page still could not display the answer after loading the conversation again. Check that the browser is not short of memory or processes, then rerun recovery." + }); + } const hasUsableAnswer = Boolean(state && state.assistantMessageCount > 0 && isUsableChatGptAnswer(state.answer)); const code = !targetMatched ? "thread_target_mismatch" @@ -5185,6 +5229,7 @@ export async function sendChatGptPrompt(options: SendChatGptPromptOptions): Prom expandingPolls = 0; let nonTextPolls = 0; let nonTextSettled = false; + let renderFailedPolls = 0; const answerIsStable = createChatGptAnswerStabilityTracker(); while (Date.now() - started < timeoutMs) { await sleep(1000); @@ -5250,6 +5295,19 @@ export async function sendChatGptPrompt(options: SendChatGptPromptOptions): Prom continue; } nonTextPolls = 0; + // Two reads in a row, so a failure the renderer is about to replace does + // not end the send. + if (finalState.answerRenderFailed && !finalState.generating && finalState.assistantMessageCount > beforeSubmit.assistantMessageCount) { + renderFailedPolls += 1; + if (renderFailedPolls >= 2) { + throw attachSendWarnings( + new ChatGptBrowserBlockerError(submittedRequestBlocker(answerRenderFailedBlocker(pinnedThreadUrl), requestId, pinnedThreadUrl)), + sendWarnings + ); + } + continue; + } + renderFailedPolls = 0; if (!hasFreshChatGptAnswer(beforeSubmit.assistantMessageCount, finalState)) continue; // A "fresh" answer must also be stable: ChatGPT can momentarily look done // mid-stream, and the streaming caret renders as a literal trailing @@ -7548,6 +7606,12 @@ export function answerExpression(): string { return Boolean(lastUser.node.compareDocumentPosition(img) & Node.DOCUMENT_POSITION_FOLLOWING); }); })(), + // The newer answer renderer, when it cannot draw an answer, puts + // div[role=status][data-dil-render-failed] reading "This response + // couldn’t load" in its place (measured 2026-10-30, while ChatGPT + // held the finished answer), and that sentence was saved as the answer. + answerRenderFailed: Boolean(assistant && [assistant.textNode, assistant.node].some((node) => + node && typeof node.querySelector === "function" && node.querySelector("[data-dil-render-failed]"))), // ChatGPT tags each assistant message with the model that produced it - // the only ground truth for "did the Pro selection actually take". modelSlug: assistant ? assistant.modelSlug : undefined, diff --git a/tests/chatgpt-browser.test.ts b/tests/chatgpt-browser.test.ts index d7d0275b..83f2c0f3 100644 --- a/tests/chatgpt-browser.test.ts +++ b/tests/chatgpt-browser.test.ts @@ -40,6 +40,7 @@ import { getChatGptBrowserStatus, hasChatGptPromptAcceptance, hasFreshChatGptAnswer, + hasPartialChatGptAnswer, isFreshChatGptPage, menuItemLabelMatches, chunkComposerText, @@ -217,6 +218,34 @@ Show more`; await expect(send).resolves.toMatchObject({ url: thread, answer: "the requested answer" }); }); + it("stops on an answer the page failed to render instead of returning its error text", async () => { + // The prompt has posted and ChatGPT holds the answer, so this must not be + // retried; recovery reloads the thread and reads it again. + vi.useFakeTimers(); + const thread = "https://chatgpt.com/c/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; + const failed = { ...fakeAnswerState(thread, "This response couldn’t load", false), answerRenderFailed: true }; + installFakeChatGptSendCdp(thread, [ + { ...fakeAnswerState(thread, "", false), assistantMessageCount: 0, userMessageCount: 0 }, + { ...fakeAnswerState(thread, "", true), assistantMessageCount: 0, userMessageCount: 1 }, + failed, + failed, + failed, + failed + ]); + + const send = sendChatGptPrompt({ port: 19338, prompt: "answer this", targetUrl: thread, timeoutMs: 20_000 }); + const rejection = expect(send).rejects.toMatchObject({ + blocker: { + code: "answer_render_failed", + retryable: false, + thread, + next_step: expect.stringMatching(new RegExp(`prodex pro browser recover --target-url ${thread} --request-id [a-f0-9]{32}`)) + } + }); + await vi.advanceTimersByTimeAsync(20_000); + await rejection; + }); + it("does not resend or navigate when the observed Cloudflare 502 appears after submit", async () => { vi.useFakeTimers(); const thread = "https://chatgpt.com/c/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; @@ -732,6 +761,40 @@ Show more`; expect(state.answer).toBe(""); }); + it("answerExpression reports an answer the page failed to render", async () => { + // Measured 2026-10-30 in the browser container: ChatGPT finished the answer + // ("OK", finished_successfully on its side), but the page drew + // div[role=status][data-dil-render-failed] reading "This response couldn’t + // load" in its place, and that sentence was saved as the answer. + const browser = await import("../src/chatgpt-browser.js"); + const answerExpression = (browser as { answerExpression: () => string }).answerExpression; + type AnswerState = { answer: string; answerRenderFailed?: boolean }; + const message = (role: string, text: string, renderFailed = false): FakeElement => { + const el = new FakeElement("div"); + el.setAttribute("data-message-author-role", role); + el.innerText = text; + Object.assign(el, { + querySelector: (selector: string) => (renderFailed && selector === "[data-dil-render-failed]" ? new FakeElement("div") : null) + }); + return el; + }; + const doc = new FakeDocument([], []); + doc.messages = [message("user", "q"), message("assistant", "This response couldn’t load", true)]; + expect(evaluateBrowserStatusExpression(answerExpression(), doc).answerRenderFailed).toBe(true); + doc.messages = [message("user", "q"), message("assistant", "OK")]; + expect(evaluateBrowserStatusExpression(answerExpression(), doc).answerRenderFailed).toBe(false); + // An earlier answer that failed to render is not the answer to the new question. + doc.messages = [message("user", "q1"), message("assistant", "This response couldn’t load", true), message("user", "q2"), message("assistant", "OK")]; + expect(evaluateBrowserStatusExpression(answerExpression(), doc).answerRenderFailed).toBe(false); + }); + + it("never takes an answer the page failed to render for the answer, finished or partial", () => { + const failed = { answer: "This response couldn’t load", assistantMessageCount: 1, generating: false, answerRenderFailed: true }; + expect(hasFreshChatGptAnswer(0, failed)).toBe(false); + expect(hasPartialChatGptAnswer(0, failed)).toBe(false); + expect(hasFreshChatGptAnswer(0, { ...failed, answer: "OK", answerRenderFailed: false })).toBe(true); + }); + it("does not mistake ChatGPT's interruption notice for an answer", () => { // Measured after killing the browser mid-stream: the thread rendered // "Pro thinking / Connection interrupted. Waiting for the complete answer", @@ -888,6 +951,69 @@ Show more`; }); }); + it("reloads a thread whose answer failed to render and reads it again", async () => { + // Measured 2026-10-30: recovery of a thread showing "This response + // couldn’t load" left the tab where it was, since it was already on the + // thread, and saved the same sentence as the recovered answer. + vi.useFakeTimers(); + const target = "https://chatgpt.com/c/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; + const requestId = "c".repeat(32); + const lastUserText = `our question\n[prodex-request:${requestId}]`; + const failed = { ...fakeAnswerState(target, "This response couldn’t load", false), lastUserText, answerRenderFailed: true }; + const rendered = { ...fakeAnswerState(target, "OK", false), lastUserText }; + const evaluations = installFakeChatGptCdp([failed], { url: target }); + const base = FakeCdpWebSocket.evaluate; + let marked = false; + let reloaded = false; + FakeCdpWebSocket.evaluate = (expression) => { + if (expression.includes("__prodexReloadMark") && expression.includes("= true; return true")) { + marked = true; + return true; + } + if (expression.includes("location.assign(")) { + base(expression); + reloaded = marked; + return true; + } + if (expression.includes("__prodexReloadMark")) return reloaded; + if (expression.includes("assistantMessageCount")) { + evaluations.push(expression); + return reloaded ? rendered : failed; + } + return base(expression); + }; + + const recovery = recoverChatGptAnswerFromThread({ targetUrl: target, port: 19337, timeoutMs: 10_000, requestId }); + void recovery.catch(() => undefined); + await vi.advanceTimersByTimeAsync(15_000); + await expect(recovery).resolves.toMatchObject({ answer: "OK", requestId, requestVerified: true }); + expect(evaluations.filter((expression) => expression.includes(`location.assign(\"${target}\")`))).toHaveLength(1); + }); + + it("does not return a render failure as the recovered answer when a reload does not fix it", async () => { + vi.useFakeTimers(); + const target = "https://chatgpt.com/c/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; + const failed = { ...fakeAnswerState(target, "This response couldn’t load", false), answerRenderFailed: true }; + const evaluations = installFakeChatGptCdp([failed], { url: target }); + const base = FakeCdpWebSocket.evaluate; + let marked = false; + FakeCdpWebSocket.evaluate = (expression) => { + if (expression.includes("__prodexReloadMark") && expression.includes("= true; return true")) { + marked = true; + return true; + } + if (expression.includes("__prodexReloadMark")) return marked; + return base(expression); + }; + + const recovery = recoverChatGptAnswerFromThread({ targetUrl: target, port: 19337, timeoutMs: 5_000 }); + const rejection = expect(recovery).rejects.toMatchObject({ blocker: { code: "answer_render_failed", thread: target } }); + await vi.advanceTimersByTimeAsync(10_000); + await rejection; + // One reload, not one per poll. + expect(evaluations.filter((expression) => expression.includes("location.assign("))).toHaveLength(1); + }); + it("freezes canonical metadata to the accepted conversation identity", async () => { const conversationId = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; const projectThread = `https://chatgpt.com/g/g-p-abcd-project/c/${conversationId}?model=gpt-5`;