Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased

### Fixed
- Every consult sent through the browser container failed with `request_mismatch` ("The latest visible user turn could not be verified against this prodex request"), although the prompt had posted and been answered. Found 2026-11-17, after four blocked consults in a row, the last a one-word probe: ChatGPT now keys each message as `<turn id>:<position>:<role>`, the turn named by a UUID, where it used to write `fallback-turn-<n>:<position>:<role>`, and the container's transcript reader accepted only the numbered form, so it counted no messages, took the page's move to the new conversation as the prompt being accepted, and then found no user turn carrying the request marker. Turns named by an id are now read in page order; a page that mixes both kinds of key still reads as no transcript. Checked read-only on the live page: the reader sees the user turn with its marker and the answer.
- The browser container omitted ripgrep, so `repo_search` failed with "ripgrep (rg) is required on PATH for repo_search" even when the host had `rg` installed. The runtime image now installs ripgrep. The account-free container MCP smoke test checks a matching search and an empty result through two separate clients, so a healthy browser alone cannot mask this missing dependency.
- `docs/container-browser.md` said only that WSL starts when something on Windows starts it. It left out that WSL shuts an idle distro down 15 seconds after its last `wsl.exe` ends, docker and the browser container with it. Found 2026-11-10 from the WSL host's logs: after a Windows restart, a logon shortcut running `wsl.exe ... -- true` started the distro twice, it shut down 18 seconds later each time, and the container stayed down until a terminal was opened 11 minutes after logon. The doc now says to set `instanceIdleTimeout=-1` under `[general]` in `.wslconfig`.
- `scripts/container-client.mjs` started through a symlinked path exited 0 and did nothing: found 2026-11-10 when it was run from `/tmp` on macOS, which links to `/private/tmp`. Its check for being the main module compared Node's resolved module URL with the unresolved path, so an MCP entry pointing through a symlink would have failed to connect without a word. The check now resolves the path first.
Expand Down
32 changes: 24 additions & 8 deletions src/chatgpt-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,10 @@ interface ChatGptPageStatus extends ChatGptPageTextState {
// Text/buttons for login and status detection: exclude message bodies and the
// composer, but KEEP the sidebar/nav - the logged-in signals ("New chat",
// "Projects", the profile button, the plan hint) live there.
// A unit key is "fallback-turn-<n>:<position>:<role>" or, measured 2026-11-17,
// "<turn uuid>:<position>:<role>"; the page script checks the exact shape.
export const CHATGPT_FALLBACK_TRANSCRIPT_MESSAGE_SELECTOR =
'[data-content-search-unit-key^="fallback-turn-"][data-content-search-unit-key$=":user"],' +
'[data-content-search-unit-key^="fallback-turn-"][data-content-search-unit-key$=":assistant"]';
'[data-content-search-unit-key$=":user"],[data-content-search-unit-key$=":assistant"]';
export const CHATGPT_TRANSCRIPT_MESSAGE_SELECTOR =
`[data-message-author-role],${CHATGPT_FALLBACK_TRANSCRIPT_MESSAGE_SELECTOR}`;
export const CHATGPT_USER_MESSAGE_BUBBLE_SELECTOR = '[data-user-message-bubble="true"]';
Expand Down Expand Up @@ -6549,7 +6550,9 @@ function chatGptTranscriptExpressionHelpers(): string {
return `${CHATGPT_RENDERED_MESSAGE_TEXT_JS}${CHATGPT_EXPAND_USER_TURN_JS}
const transcriptMessageSelector = ${transcriptMessageSelector};
const userMessageBubbleSelector = ${userMessageBubbleSelector};
const fallbackMessageKeyPattern = /^fallback-turn-(\\d+):(\\d+):(user|assistant)$/;
// The turn is numbered ("fallback-turn-3") or, measured 2026-11-17, named
// by its id (a UUID); a named turn's order is its place on the page.
const fallbackMessageKeyPattern = /^(?:fallback-turn-(\\d+)|([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})):(\\d+):(user|assistant)$/;
const readChatGptTranscriptMessage = (node) => {
const legacyRole = node.getAttribute('data-message-author-role');
const fallbackKey = node.getAttribute('data-content-search-unit-key') || "";
Expand All @@ -6558,13 +6561,15 @@ function chatGptTranscriptExpressionHelpers(): string {
let source;
let role;
let turn;
let turnId;
let position;
if (fallbackMatch) {
source = "fallback";
role = fallbackMatch[3];
turn = Number(fallbackMatch[1]);
position = Number(fallbackMatch[2]);
if (!Number.isSafeInteger(turn) || !Number.isSafeInteger(position)) return { invalid: true, source, turn, position };
role = fallbackMatch[4];
turnId = fallbackMatch[2];
turn = turnId === undefined ? Number(fallbackMatch[1]) : undefined;
position = Number(fallbackMatch[3]);
if ((turnId === undefined && !Number.isSafeInteger(turn)) || !Number.isSafeInteger(position)) return { invalid: true, source, turn, position };
if (legacyRole !== null && legacyRole !== role) return { invalid: true, source, turn, position };
} else if (legacyMessageRole) {
source = "legacy";
Expand All @@ -6591,7 +6596,7 @@ function chatGptTranscriptExpressionHelpers(): string {
body?.tagName?.toLowerCase() === "div";
if (measuredAssistantShape && !selection) messageText = renderedMessageText(body);
}
return { source, role, turn, position, text: messageText, modelSlug, node };
return { source, role, turn, turnId, position, text: messageText, modelSlug, node };
};
const isInsideChatGptTranscriptMessage = (node) => {
if (!node || typeof node.closest !== "function") return false;
Expand All @@ -6618,6 +6623,17 @@ function chatGptTranscriptExpressionHelpers(): string {
if (legacyMessageNodes.some((node) => !fallbackNodes.includes(node))) return [];
const fallbackMessages = fallbackNodes.map(readChatGptTranscriptMessage);
if (fallbackMessages.some((message) => !message || message.invalid)) return [];
// Named turns are numbered in page order. A page mixing both kinds of
// key has no order prodex can trust, so it reads as no transcript.
const named = fallbackMessages.filter((message) => message.turnId !== undefined);
if (named.length > 0) {
if (named.length !== fallbackMessages.length) return [];
const order = [];
for (const message of named) {
if (!order.includes(message.turnId)) order.push(message.turnId);
message.turn = order.indexOf(message.turnId);
}
}
const coordinates = new Set();
for (const message of fallbackMessages) {
const coordinate = message.turn + ":" + message.position;
Expand Down
54 changes: 52 additions & 2 deletions tests/chatgpt-browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2760,6 +2760,49 @@ Show more`;
expect(state.modelSlug).toBeUndefined();
});

// Measured 2026-11-17: the unit key carries the turn's id instead of
// "fallback-turn-N" (`<turn uuid>:0:user`, `<turn uuid>:2:assistant`), and
// prodex counted no messages at all: every send posted, then failed as
// request_mismatch because the user turn it had just sent was not found.
it("answerExpression reads turns keyed by turn ids, in page order", () => {
const doc = new FakeDocument([], []);
doc.body.innerText = "ChatGPT\nPro";
const firstTurn = "f1d0c9b8-0a1b-4c2d-8e3f-405162738495";
const secondTurn = "0a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d";
const user1 = turnKeyedTranscriptMessage(firstTurn, 0, "user", "first question");
const assistant1 = turnKeyedTranscriptMessage(firstTurn, 2, "assistant", "first answer");
const user2 = turnKeyedTranscriptMessage(secondTurn, 0, "user", "second question");
const assistant2 = turnKeyedTranscriptMessage(secondTurn, 2, "assistant", "second answer");
doc.searchUnitMessages = [user1, assistant1, user2, assistant2];

const state = evaluateBrowserStatusExpression<AnswerStateWithModel>(answerExpression(), doc);
expect(state.userMessageCount).toBe(2);
expect(state.assistantMessageCount).toBe(2);
expect(state.lastUserText).toBe("second question");
expect(state.answer).toBe("second answer");
});

it("acknowledges a request whose turn is keyed by its turn id", () => {
const requestId = "c24a5dc8ee93d8a54df431bc340d9925";
const marker = `[prodex-request:${requestId}]`;
const expression = chatGptPromptPostedExpression(requestId);
const doc = new FakeDocument([], []);
doc.searchUnitMessages = [turnKeyedTranscriptMessage("20c89963-f50d-58af-8872-7292f2f88cf8", 0, "user", `Reply with OK.\n\n${marker}`)];
expect(evaluateBrowserStatusExpression<boolean>(expression, doc)).toBe(true);
doc.searchUnitMessages.push(turnKeyedTranscriptMessage("7e95033d-2778-47e6-8e05-46790e4c79b0", 0, "user", "another question"));
expect(evaluateBrowserStatusExpression<boolean>(expression, doc)).toBe(false);
});

it("reads nothing from a page that mixes numbered and turn-id keys", () => {
const doc = new FakeDocument([], []);
doc.searchUnitMessages = [
fallbackTranscriptMessage(0, 0, "user", "numbered question"),
turnKeyedTranscriptMessage("7e95033d-2778-47e6-8e05-46790e4c79b0", 0, "user", "turn-id question")
];
const state = evaluateBrowserStatusExpression<AnswerStateWithModel>(answerExpression(), doc);
expect(state.userMessageCount).toBe(0);
});

it("acknowledges only the latest unambiguous user request in either transcript layout", () => {
const requestId = "b0f3c430e8694f61be27709a2c65a9f0";
const marker = `[prodex-request:${requestId}]`;
Expand Down Expand Up @@ -3098,6 +3141,13 @@ function fallbackTranscriptMessage(turn: number, position: number, role: "user"
return element;
}

function turnKeyedTranscriptMessage(turnId: string, position: number, role: "user" | "assistant", messageText: string): FakeElement {
const element = new FakeElement("div");
element.setAttribute("data-content-search-unit-key", `${turnId}:${position}:${role}`);
element.innerText = messageText;
return element;
}

function installFakeChatGptCdp(states: ReturnType<typeof fakeAnswerState>[], statusOverride: Record<string, unknown> = {}): string[] {
const evaluations: string[] = [];
let answerIndex = 0;
Expand Down Expand Up @@ -3403,14 +3453,14 @@ class FakeDocument {
return nodes.filter((node) => {
if (node.getAttribute("data-message-author-role") !== null) return true;
const key = node.getAttribute("data-content-search-unit-key") ?? "";
return /^fallback-turn-\d+:\d+:(?:user|assistant)$/.test(key);
return /:(?:user|assistant)$/.test(key);
});
}
if (selector === "[data-message-author-role]") return this.messages;
if (selector.includes("[data-content-search-unit-key")) {
return this.searchUnitMessages.filter((node) => {
const key = node.getAttribute("data-content-search-unit-key") ?? "";
return /^fallback-turn-\d+:\d+:(?:user|assistant)$/.test(key);
return /:(?:user|assistant)$/.test(key);
});
}
if (selector.includes("menuitemradio") || selector.includes('[role="menuitem"]')) return this.menuItems;
Expand Down
Loading