From a3a701e0fc93833e5e829200243ef029ad5aefd4 Mon Sep 17 00:00:00 2001 From: tomi Date: Fri, 13 Nov 2026 21:57:15 +0100 Subject: [PATCH 1/4] fix(browser): ignore nonmodal dialogs during Stop recovery (cherry picked from commit 87468d682c9229b919d18ae79563f991c33c343e) --- browser-companion/src/chatgpt-driver.ts | 6 +++++- browser-companion/tests/pairing-submit.test.ts | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/browser-companion/src/chatgpt-driver.ts b/browser-companion/src/chatgpt-driver.ts index 509eab6d..216e813d 100644 --- a/browser-companion/src/chatgpt-driver.ts +++ b/browser-companion/src/chatgpt-driver.ts @@ -97,7 +97,11 @@ async function visibleStopDialogs(page:Page):Promise { for(const frame of page.frames()) { try { if(await visibleChatGptFrame(frame)) { - dialogs.push(...await frame.locator('[role="dialog"], [role="alertdialog"]').filter({visible:true}).all()); + // ChatGPT exposes non-modal suggestion menus and tool popovers with + // role=dialog even after the prior response has finished. They are + // not Stop confirmations. Only a genuinely modal dialog may block + // Stop recovery; all real Stop/approval confirmations remain guarded. + dialogs.push(...await frame.locator('[role="dialog"][aria-modal="true"], [role="alertdialog"][aria-modal="true"]').filter({visible:true}).all()); } } catch(error) { if(!frame.isDetached())throw error; diff --git a/browser-companion/tests/pairing-submit.test.ts b/browser-companion/tests/pairing-submit.test.ts index 1d79f099..3d100f03 100644 --- a/browser-companion/tests/pairing-submit.test.ts +++ b/browser-companion/tests/pairing-submit.test.ts @@ -978,6 +978,21 @@ test.skipIf(!native)("offline messages and goals stop lingering generation befor } },25_000); +test.skipIf(!native)("finished responses ignore non-modal ChatGPT popovers rather than treating them as Stop confirmation",async()=>{ + for(const aria of [' aria-modal="false"',''] as const){ + const driver=await fixture(); + // Search and tool menus can use role=dialog without modal semantics. + // They must not be interpreted as a Stop approval when no Stop button exists. + await page.evaluate(aria=>document.body.insertAdjacentHTML('beforeend', + '
Suggestions
'),aria); + const offline=offlineRequest(); + await executeFixture(driver,{request:offline,renderedPrompt:renderActionPrompt(offline.prompt),signal:new AbortController().signal,emit:()=>{}}); + expect(await page.locator('body').getAttribute('data-sends')).toBe('1'); + expect(await page.locator('body').getAttribute('data-stops')).toBe('0'); + expect(await page.locator('[data-testid="nonmodal-menu"]').count()).toBe(1); + } +},18_000); + test.skipIf(!native)("offline Stop confirms an optional localized dialog before sending once",async()=>{ const prompts:ExecuteActionRequest["prompt"][]=[ {kind:"offline_chat",batchId:"dialog-batch",messages:[{id:"dialog-message",markdown:"Continue"}]}, From cd6e8d987a776fb46c38601d342b9c1ad8f8d3a9 Mon Sep 17 00:00:00 2001 From: tomi Date: Sat, 14 Nov 2026 07:04:06 +0100 Subject: [PATCH 2/4] fix(ci): simplify existing goal retry eligibility predicate --- src/agent_automation/store.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/agent_automation/store.rs b/src/agent_automation/store.rs index a00f59b3..7eee3834 100644 --- a/src/agent_automation/store.rs +++ b/src/agent_automation/store.rs @@ -420,7 +420,7 @@ impl AutomationTaskState { return false; }; let action = &self.action; - if goal.status != GoalStatus::Active + !(goal.status != GoalStatus::Active || action.goal_revision != Some(goal.revision) || action.id.is_none() || action.status == AutomationActionStatus::Idle @@ -437,11 +437,7 @@ impl AutomationTaskState { || action.kind == Some(AutomationActionKind::OfflineCombined) && action.status != AutomationActionStatus::Cancelled && action.send_accepted == Some(true) - && action.messages_fenced) - { - return false; - } - true + && action.messages_fenced)) } pub(crate) fn goal_retry_at_ms(&self) -> Option { From 3cbed096e696181f4b14e62014f120cb54a95277 Mon Sep 17 00:00:00 2001 From: tomi Date: Sat, 14 Nov 2026 20:32:44 +0100 Subject: [PATCH 3/4] fix(browser): handle response delivery timeouts without replaying Send Recognize localized timeout notices on application-owned error surfaces while leaving ambiguous or accepted messages unresent. Cover alert and plain-card variants plus quoted-text and unrelated-error negatives in isolated Chromium CI. Wait for the mobile back navigation control to appear in the new-chat WebKit fixture before reopening the sidebar, preventing a hydration race. --- .github/workflows/ci.yml | 1 + browser-companion/src/browser-session.ts | 39 ++++++++- .../tests/response-delivery-timeout.test.ts | 80 +++++++++++++++++++ scripts/test-owner-chat.mjs | 6 +- 4 files changed, 122 insertions(+), 4 deletions(-) create mode 100644 browser-companion/tests/response-delivery-timeout.test.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 76abc472..f6a11c37 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,6 +56,7 @@ jobs: bun run install:chrome CODEXIFY_TEST_BROWSER_COMPANION_CHROME=1 xvfb-run -a bun test ./tests/chrome-surface.test.ts ./tests/capability-discovery.test.ts ./tests/picker-layouts.test.ts ./tests/account-settings.test.ts CODEXIFY_TEST_BROWSER_COMPANION_CHROME=1 xvfb-run -a bun test ./tests/conversation-approval.test.ts + CODEXIFY_TEST_BROWSER_COMPANION_CHROME=1 xvfb-run -a bun test ./tests/response-delivery-timeout.test.ts CODEXIFY_TEST_BROWSER_COMPANION_CHROME=1 xvfb-run -a bun test ./tests/conversation-unavailable.test.ts -t 'transcript API 429s' CODEXIFY_TEST_BROWSER_COMPANION_CHROME=1 xvfb-run -a bun test ./tests/pairing-submit.test.ts -t 'offline Stop resumes the captured|late Stop dialog during message preparation|Japanese lazy picker|conversation length|conversation-length|task continuation|re-pairing sends' bun run package diff --git a/browser-companion/src/browser-session.ts b/browser-companion/src/browser-session.ts index ba0d0014..430e77d9 100644 --- a/browser-companion/src/browser-session.ts +++ b/browser-companion/src/browser-session.ts @@ -27,6 +27,40 @@ const terminalErrorAlert = (page: Page): Locator => page .filter({hasText:uiLabelPattern("terminalFailure",false)}) .filter({hasText:/help\.openai\.com/i}).filter({visible:true}).last(); +// These notices are failures of the previous *response*, not permission to +// resubmit its already accepted user message via the UI's Retry button. +// The supervisor owns any later goal continuation and its idempotency key. +export const deliveryTimeoutText = /(?:message delivery (?:has )?timed out|timed out (?:while )?delivering (?:the )?message|\u010das za dostavo sporo\u010dila se je iztekel)/iu; + +export async function previousResponseDeliveryTimedOut(page:Page):Promise { + const url = new URL(page.url()); + if(url.origin !== "https://chatgpt.com" || !/^\/(?:g\/[^/]+\/)?c\/[^/]+\/?$/.test(url.pathname))return false; + const failures=page.locator('[role="alert"], [data-testid="conversation-turn-error"], [data-testid="conversation-error"], [data-error-code]') + .filter({hasText:deliveryTimeoutText}).filter({visible:true}); + if(await failures.evaluateAll(nodes=>nodes.some(node=>{ + if(node.closest('[data-user-message-bubble], [data-conversation-role], [data-message-author-role], article, [data-turn-key], [data-turn-id], pre, code, [hidden], [inert], [aria-hidden="true"]'))return false; + for(let parent:Element|null=node;parent;parent=parent.parentElement)if(getComputedStyle(parent).opacity==="0")return false; + return true; + })))return true; + // Some localized response cards lack an ARIA alert. In that case require + // the app's exact regeneration control AND a short adjacent timeout message. + // Never scan the whole conversation or click the regeneration control. + return page.getByTestId("regenerate-thread-error-button").filter({visible:true}).evaluateAll((buttons,patternSource)=>{ + const timeoutPattern=new RegExp(patternSource,"iu"); + return buttons.some(button=>{ + if(button.closest('[data-user-message-bubble], [data-conversation-role], [data-message-author-role], article, [data-turn-key], [data-turn-id], pre, code, [hidden], [inert]'))return false; + for(let parent:Element|null=button;parent;parent=parent.parentElement)if(getComputedStyle(parent).opacity==="0")return false; + const parent=button.parentElement, grandparent=parent?.parentElement; + return [parent,grandparent].some(node=>{ + if(!node || node.matches('html, body, main, article, form, [data-app-shell-focus-area], [data-conversation-role], [data-message-author-role]'))return false; + if(node.querySelector('article, [data-user-message-bubble], [data-conversation-role], [data-message-author-role], [data-turn-key], [data-turn-id]'))return false; + const message=node?.textContent?.trim(); + return Boolean(message && message.length<=350 && timeoutPattern.test(message)); + }); + }); + },deliveryTimeoutText.source); +} + export async function conversationUnavailableVisible(page: Page): Promise { const url = new URL(page.url()); if (url.origin !== "https://chatgpt.com" || !/^\/(?:g\/[^/]+\/)?c\/[^/]+\/?$/.test(url.pathname)) return false; @@ -113,8 +147,9 @@ export async function throwIfSessionAttention(page: Page): Promise { if(conversationLoadWasRateLimited(page))throw new BrowserCompanionError("ChatGPT conversation loading is temporarily rate limited; wait before retrying","conversation_load_rate_limited"); throw new BrowserCompanionError("ChatGPT conversation temporarily not accessible", "conversation_unavailable"); } - if (await page.getByTestId("regenerate-thread-error-button").last().isVisible().catch(() => false) - || await terminalErrorAlert(page).isVisible().catch(() => false)) { + const responseTimedOut=await previousResponseDeliveryTimedOut(page); + if ((await page.getByTestId("regenerate-thread-error-button").last().isVisible().catch(() => false) + || await terminalErrorAlert(page).isVisible().catch(() => false)) && !responseTimedOut) { throw new BrowserCompanionError("ChatGPT displayed a terminal response error.", "failed"); } } diff --git a/browser-companion/tests/response-delivery-timeout.test.ts b/browser-companion/tests/response-delivery-timeout.test.ts new file mode 100644 index 00000000..04856f53 --- /dev/null +++ b/browser-companion/tests/response-delivery-timeout.test.ts @@ -0,0 +1,80 @@ +import {afterAll, beforeAll, expect, test} from "bun:test"; +import {mkdtemp,rm} from "node:fs/promises"; +import {tmpdir} from "node:os"; +import {join} from "node:path"; +import {chromium,type BrowserContext,type Page} from "patchright"; +import {privateChromeExecutable} from "../src/chrome-executable"; +import {deliveryTimeoutText,previousResponseDeliveryTimedOut,throwIfSessionAttention} from "../src/browser-session"; + +const localizedTimeouts=[ + "Cas za dostavo sporocila se je iztekel. Poskusite znova.", // ASCII is not the real locale; must not match + "\u010cas za dostavo sporo\u010dila se je iztekel. Poskusite znova.", + "Message delivery timed out. Please try again.", + "Message delivery has timed out. Retry.", +] as const; + +test("recognized response-delivery timeout text is narrowly localized",()=>{ + expect(deliveryTimeoutText.test(localizedTimeouts[0])).toBe(false); + for(const text of localizedTimeouts.slice(1))expect(deliveryTimeoutText.test(text)).toBe(true); + for(const text of [ + "Delivery will take longer than expected", + "Your message was not sent. Please retry.", + "The connection timed out while reading the repository.", + "You have reached a conversation limit.", + ])expect(deliveryTimeoutText.test(text)).toBe(false); +}); + +const native=process.env.CODEXIFY_TEST_BROWSER_COMPANION_CHROME==="1"; +let context:BrowserContext; +let page:Page; +let profile:string; + +beforeAll(async()=>{ + if(!native)return; + profile=await mkdtemp(join(tmpdir(),"codexify-delivery-timeout-")); + const executablePath=await privateChromeExecutable(join(import.meta.dirname,"../.browsers",`${process.platform}-${process.arch}`)); + context=await chromium.launchPersistentContext(profile,{channel:"chrome",executablePath,headless:true}); + page=context.pages()[0]!; + await context.route("https://chatgpt.com/c/timeout-fixture",route=>route.fulfill({contentType:"text/html",body:"
"})); + await page.goto("https://chatgpt.com/c/timeout-fixture"); +},60_000); + +afterAll(async()=>{ + await context?.close(); + if(profile)await rm(profile,{recursive:true,force:true,maxRetries:6,retryDelay:500}); +}); + +test.skipIf(!native)("localized timeout in app-owned alert permits new continuation, never clicks Retry",async()=>{ + for(const message of localizedTimeouts.slice(1)){ + await page.setContent(`
+
Existing accepted user message
+
${message}
`); + expect(await previousResponseDeliveryTimedOut(page)).toBe(true); + await throwIfSessionAttention(page); + expect(await page.getByTestId("regenerate-thread-error-button").count()).toBe(1); + } +},60_000); + +test.skipIf(!native)("quoted user content cannot masquerade as an app-owned delivery timeout",async()=>{ + await page.setContent(`
+
${localizedTimeouts[1]}
+
`); + expect(await previousResponseDeliveryTimedOut(page)).toBe(false); + await expect(throwIfSessionAttention(page)).rejects.toMatchObject({code:"failed"}); +},60_000); + +test.skipIf(!native)("visible app Retry button and adjacent localized message work without alert role",async()=>{ + await page.setContent(`
+

\u010cas za dostavo sporo\u010dila se je iztekel. Poskusite znova.

+
`); + expect(await previousResponseDeliveryTimedOut(page)).toBe(true); + await throwIfSessionAttention(page); + expect(await page.locator("body").getAttribute("data-clicked")).toBeNull(); +},60_000); + +test.skipIf(!native)("unrelated terminal failure remains a blocker",async()=>{ + await page.setContent(`
+
The response failed.
`); + expect(await previousResponseDeliveryTimedOut(page)).toBe(false); + await expect(throwIfSessionAttention(page)).rejects.toMatchObject({code:"failed"}); +},60_000); diff --git a/scripts/test-owner-chat.mjs b/scripts/test-owner-chat.mjs index e6255429..7d27720f 100644 --- a/scripts/test-owner-chat.mjs +++ b/scripts/test-owner-chat.mjs @@ -1423,8 +1423,10 @@ for (const [engineName, engine] of [["Chromium",chromium],["WebKit",webkit]]) { const dialog=page.getByRole('dialog',{name:'New chat'}); const open=async()=>{ const back=page.locator('#chat-host').getByRole('button',{name:'Back to chats',exact:true}); - if(await back.isVisible())await back.click(); - await page.getByRole('button',{name:'New chat',exact:true}).click(); + // On mobile the sidebar becomes visible only after the chat header hydrates. + const newChat=page.getByRole('button',{name:'New chat',exact:true}); + if(!(await newChat.isVisible())){await back.waitFor({state:'visible'});await back.click();} + await newChat.click(); await dialog.getByRole('button',{name:'Existing repo',exact:true}).waitFor(); await dialog.locator('#new-chat-model:enabled').waitFor(); assert.deepEqual(await dialog.getByLabel('Reasoning effort').locator('option').allTextContents(),['Pro','Extra High','High','Medium','Instant']); From e78b82890129688981dbb63905fbd9c7d26ba6e1 Mon Sep 17 00:00:00 2001 From: Paul Date: Sun, 15 Nov 2026 13:11:05 +0100 Subject: [PATCH 4/4] Limit response timeout exemptions to their own error cards --- browser-companion/src/browser-session.ts | 62 +++++++++++-------- .../tests/response-delivery-timeout.test.ts | 13 ++++ 2 files changed, 48 insertions(+), 27 deletions(-) diff --git a/browser-companion/src/browser-session.ts b/browser-companion/src/browser-session.ts index 430e77d9..44f20db1 100644 --- a/browser-companion/src/browser-session.ts +++ b/browser-companion/src/browser-session.ts @@ -22,43 +22,52 @@ const subscriptionFailureAlert = (page: Page): Locator => page // Error semantics and the support destination are stable across UI languages. // Scope the fallback to alerts/error surfaces so ordinary answer links do not match. +const RESPONSE_ERROR_SELECTOR = '[role="alert"], [data-testid="conversation-turn-error"], [data-testid="conversation-error"], [data-error-code]'; const terminalErrorAlert = (page: Page): Locator => page - .locator('[role="alert"], [data-testid="conversation-turn-error"], [data-testid="conversation-error"], [data-error-code]') + .locator(RESPONSE_ERROR_SELECTOR) .filter({hasText:uiLabelPattern("terminalFailure",false)}) - .filter({hasText:/help\.openai\.com/i}).filter({visible:true}).last(); + .filter({hasText:/help\.openai\.com/i}).filter({visible:true}); // These notices are failures of the previous *response*, not permission to // resubmit its already accepted user message via the UI's Retry button. // The supervisor owns any later goal continuation and its idempotency key. export const deliveryTimeoutText = /(?:message delivery (?:has )?timed out|timed out (?:while )?delivering (?:the )?message|\u010das za dostavo sporo\u010dila se je iztekel)/iu; -export async function previousResponseDeliveryTimedOut(page:Page):Promise { +async function responseDeliveryTimeoutMatches(page:Page,surfaces:Locator):Promise { const url = new URL(page.url()); - if(url.origin !== "https://chatgpt.com" || !/^\/(?:g\/[^/]+\/)?c\/[^/]+\/?$/.test(url.pathname))return false; - const failures=page.locator('[role="alert"], [data-testid="conversation-turn-error"], [data-testid="conversation-error"], [data-error-code]') - .filter({hasText:deliveryTimeoutText}).filter({visible:true}); - if(await failures.evaluateAll(nodes=>nodes.some(node=>{ - if(node.closest('[data-user-message-bubble], [data-conversation-role], [data-message-author-role], article, [data-turn-key], [data-turn-id], pre, code, [hidden], [inert], [aria-hidden="true"]'))return false; - for(let parent:Element|null=node;parent;parent=parent.parentElement)if(getComputedStyle(parent).opacity==="0")return false; - return true; - })))return true; - // Some localized response cards lack an ARIA alert. In that case require - // the app's exact regeneration control AND a short adjacent timeout message. - // Never scan the whole conversation or click the regeneration control. - return page.getByTestId("regenerate-thread-error-button").filter({visible:true}).evaluateAll((buttons,patternSource)=>{ + if(url.origin !== "https://chatgpt.com" || !/^\/(?:g\/[^/]+\/)?c\/[^/]+\/?$/.test(url.pathname))return surfaces.evaluateAll(nodes=>nodes.map(()=>false)); + return surfaces.evaluateAll((nodes,{patternSource,errorSelector})=>{ const timeoutPattern=new RegExp(patternSource,"iu"); - return buttons.some(button=>{ - if(button.closest('[data-user-message-bubble], [data-conversation-role], [data-message-author-role], article, [data-turn-key], [data-turn-id], pre, code, [hidden], [inert]'))return false; - for(let parent:Element|null=button;parent;parent=parent.parentElement)if(getComputedStyle(parent).opacity==="0")return false; - const parent=button.parentElement, grandparent=parent?.parentElement; - return [parent,grandparent].some(node=>{ - if(!node || node.matches('html, body, main, article, form, [data-app-shell-focus-area], [data-conversation-role], [data-message-author-role]'))return false; - if(node.querySelector('article, [data-user-message-bubble], [data-conversation-role], [data-message-author-role], [data-turn-key], [data-turn-id]'))return false; - const message=node?.textContent?.trim(); + const content='[data-user-message-bubble], [data-conversation-role], [data-message-author-role], article, [data-turn-key], [data-turn-id], pre, code'; + const excluded=content+', [hidden], [inert], [aria-hidden="true"]'; + const owned=(node:Element)=>{ + if(node.closest(excluded))return false; + for(let parent:Element|null=node;parent;parent=parent.parentElement)if(getComputedStyle(parent).opacity==="0")return false; + return true; + }; + return nodes.map(surface=>{ + if(!owned(surface))return false; + // An alert can exempt only itself and the Retry control inside it. + const alert=surface.closest(errorSelector); + if(alert)return owned(alert)&&!alert.querySelector(errorSelector)&&!alert.querySelector(content) + &&timeoutPattern.test((alert as HTMLElement).innerText??alert.textContent??''); + if(!surface.matches('[data-testid="regenerate-thread-error-button"]'))return false; + // Some cards have no alert semantics. Their short adjacent text belongs + // to this control only if the container has no other errors or retries. + return [surface.parentElement,surface.parentElement?.parentElement].some(node=>{ + if(!node || !owned(node) || node.matches('html, body, main, article, form, [data-app-shell-focus-area]'))return false; + if(node.querySelector(content)||node.querySelector(errorSelector) + ||node.querySelectorAll('[data-testid="regenerate-thread-error-button"]').length!==1)return false; + const message=((node as HTMLElement).innerText??node.textContent)?.trim(); return Boolean(message && message.length<=350 && timeoutPattern.test(message)); }); }); - },deliveryTimeoutText.source); + },{patternSource:deliveryTimeoutText.source,errorSelector:RESPONSE_ERROR_SELECTOR}); +} + +export async function previousResponseDeliveryTimedOut(page:Page):Promise { + const surfaces=page.locator(RESPONSE_ERROR_SELECTOR).or(page.getByTestId("regenerate-thread-error-button")).filter({visible:true}); + return (await responseDeliveryTimeoutMatches(page,surfaces)).some(Boolean); } export async function conversationUnavailableVisible(page: Page): Promise { @@ -147,9 +156,8 @@ export async function throwIfSessionAttention(page: Page): Promise { if(conversationLoadWasRateLimited(page))throw new BrowserCompanionError("ChatGPT conversation loading is temporarily rate limited; wait before retrying","conversation_load_rate_limited"); throw new BrowserCompanionError("ChatGPT conversation temporarily not accessible", "conversation_unavailable"); } - const responseTimedOut=await previousResponseDeliveryTimedOut(page); - if ((await page.getByTestId("regenerate-thread-error-button").last().isVisible().catch(() => false) - || await terminalErrorAlert(page).isVisible().catch(() => false)) && !responseTimedOut) { + const failures=page.getByTestId("regenerate-thread-error-button").filter({visible:true}).or(terminalErrorAlert(page)); + if ((await responseDeliveryTimeoutMatches(page,failures)).some(timeout=>!timeout)) { throw new BrowserCompanionError("ChatGPT displayed a terminal response error.", "failed"); } } diff --git a/browser-companion/tests/response-delivery-timeout.test.ts b/browser-companion/tests/response-delivery-timeout.test.ts index 04856f53..24952e84 100644 --- a/browser-companion/tests/response-delivery-timeout.test.ts +++ b/browser-companion/tests/response-delivery-timeout.test.ts @@ -78,3 +78,16 @@ test.skipIf(!native)("unrelated terminal failure remains a blocker",async()=>{ expect(await previousResponseDeliveryTimedOut(page)).toBe(false); await expect(throwIfSessionAttention(page)).rejects.toMatchObject({code:"failed"}); },60_000); + +const timeoutCard=`
${localizedTimeouts[2]}
`; +const terminalCard='
Something went wrong. See help.openai.com.
'; +for(const [name,cards] of [ + ['timeout before terminal',timeoutCard+terminalCard], + ['terminal before timeout',terminalCard+timeoutCard], + ['separate Retry in a shared wrapper',`
${localizedTimeouts[2]}
`], + ['timeout without ARIA alert',`

${localizedTimeouts[2]}

`+terminalCard], +] as const)test.skipIf(!native)(`a previous timeout never exempts a different error: ${name}`,async()=>{ + await page.setContent(`
${cards}
`); + expect(await previousResponseDeliveryTimedOut(page)).toBe(true); + await expect(throwIfSessionAttention(page)).rejects.toMatchObject({code:"failed"}); +},30_000);