Skip to content

Fix ChatGPT turn detection after DOM role selector change - #55

Open
lekthailtd-bit wants to merge 2 commits into
Octo-Lex:masterfrom
lekthailtd-bit:fix/conversation-projection-endpoint
Open

lekthailtd-bit wants to merge 2 commits into
Octo-Lex:masterfrom
lekthailtd-bit:fix/conversation-projection-endpoint

Conversation

@lekthailtd-bit

Copy link
Copy Markdown

Live regression fix: current ChatGPT DOM no longer exposes data-message-author-role on turn nodes, leaving phase-1 completion detection stuck even after a successful send. This adds compatibility selectors for current data-content-search-unit-key/data-chatgpt-search-unit-key markup while retaining legacy selectors, and aligns anchored projection with the unpaginated conversation-detail endpoint. Focused tests pass; live MCP probe returned normally with backend end_turn recognition and exactly one turn.

@gitwire-hq gitwire-hq Bot added the size/S label Sep 27, 2026

@gitwire-hq gitwire-hq Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Code Review — ✅ Approved

Confidence: high · Findings: 3
AI judgment: APPROVE · Evidence: COMPLETE · Authority: advisory
Evidence complete · 6/6 changed files accounted for

Other findings (3)

  • [low] New selector test asserts on source text rather than behavior
  • [medium] No test validates that the embedded CDP JavaScript is syntactically valid ⚠️ unverified
  • [low] Single hard-coded selector with no fallback means the next ChatGPT DOM change re-breaks detection ⚠️ unverified

🔮 Devil's Advocate (2 turns): 2 missed risks found · 1 upheld


GitWire AI Review Gate (bundle-driven v2) · Structured schema · Scope-validated · Devil's Advocate · AI recommendation — maintainers and repository policy retain authority

Finding details (not annotatable inline)

  • [MEDIUM] No test validates that the embedded CDP JavaScript is syntactically valid

    The source-text test cannot catch a quoting error in the JS embedding of the selectors (e.g., unescaped double quotes in [data-testid="..."] inside a single-quoted JS string, or a malformed attribute selector). Such a bug passes the entire suite and only surfaces at runtime inside Runtime.evaluate — potentially silently if CDP exceptions are swallowed — causing turn detection to hang or never fire, which is the exact production symptom this hotfix addresses. Eval'ing the assembled JS string (or running it through a JS parser) in a unit test would close this gap without requiring a ChatGPT DOM fixture, making it a cheaper and more valuable improvement than the behavioral test suggested in Finding #0.

  • [LOW] Single hard-coded selector with no fallback means the next ChatGPT DOM change re-breaks detection

    The PR replaces one exact selector with another, leaving turn detection coupled to a single point of failure in a third-party DOM that has already changed at least once. If the code supported a fallback list of selectors (old + new, or role + data-testid variants), the next upstream change would degrade gracefully instead of silently breaking completion detection. Understandable out of scope for a hotfix, but the review should have noted this as the structural root cause rather than treating the selector swap as a one-off fix.


def test_current_chatgpt_role_selectors_are_supported():
src = inspect.getsource(CDPDriver) + inspect.getsource(CompletionDetector)
assert "data-content-search-unit-key$=\\\":assistant\\\"" in src

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[LOW] New selector test asserts on source text rather than behavior

tests/test_current_dom_role_selectors.py uses inspect.getsource() and substring matching to verify the new selectors exist in CDPDriver/CompletionDetector source. This is a valid smoke guard against revert regressions, but it is brittle in both directions: (1) it passes even if the selectors appear in dead code, comments, or malformed JS that never executes, and (2) it will spuriously fail if the JS string quoting/escaping is ever reformatted (e.g., switching to single-quoted attribute selectors), even when behavior is unchanged. Since the selectors are static strings with no runtime injection surface, a behavioral test (e.g., running the compiled JS against a small fixture DOM via the existing CDP test harness/mocks) would pin actual querySelectorAll semantics. Acceptable to merge as-is for a live hotfix, but consider tightening later.

Alajmah commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Maintainer-first baseline review — 2026-11-20, before ACT-aria implementation

Pinned head: 4dcebbe492c5caeea5e712534d51ccaf7df9fc86 (PR #55). Reviewed completion_detector.py, cdp_driver.py, backend projection/client, send baseline/ack, end_turn policy tests, PR patch and CI, and the 56-line supplied pr55-act-aria-patch-spec.md. This is not merge approval.

  1. F1/P0 confirmed source defect: Phase-1 polls only old role/search-unit selectors; Phase-2 also requires them before extracting text; all were live-observed absent. Copy and Edit message button counts are supplied as live-verified alternative signals. The ACT testid family is absent. This explains the live phase_1_appear stall despite a rendered response.
  2. Stale response invariant: do not reset baseline to zero on an observation error; do not read the previous assistant's text after a new user appearance. Both the send baseline and Phase-2 text extraction must correlate to a newly observed turn. A post-send Copy count delta must compare against the pre-send baseline, not just presence.
  3. Correctness ordering: Edit message delta can trigger the Phase-1 observation phase (the user turn appeared), but cannot by itself establish an assistant turn or completed response. Only anchored backend end_turn or a new Copy after stable usable content can terminate. A backend not_ready remains authoritative and may not be overridden by a DOM false-positive.
  4. DOM evolution: new role/search-unit keys from the current Fix ChatGPT turn detection after DOM role selector change #55 diff are themselves absent per the provided live evidence; retain them only as legacy compatibility. .markdown cannot be the sole text source. Fail closed if neither a fresh assistant text container nor an anchored backend text can be verified.
  5. Verification gaps: existing test_current_dom_role_selectors.py checks source strings rather than executing JS. Add a Node-vm fixture for current aria-only and legacy DOM, syntactic validity, stale prior Copy, hidden menu/script-text noise, and backend-not-ready gating; preserve existing end_turn and stop behavior. Existing Fix ChatGPT turn detection after DOM role selector change #55 CI failed; classify and correct independent lint findings, never reinterpret an older green SHA as evidence for new HEAD.
  6. F2 separate: PR fix: fail closed on fresh-chat navigation and ambiguous Send/Stop control #56's _expected_send_context rebinding after the streaming loop is skipped on streaming failure; keep its finally/rebind work on fix: fail closed on fresh-chat navigation and ambiguous Send/Stop control #56, not quietly introduce it in Fix ChatGPT turn detection after DOM role selector change #55. Live REST certification/target ownership is downstream.

Plan: implement aria+legacy signal counts, user-appearance phase-1 gate, Copy-delta completion with stable text and an anchored text fallback, tests + current markup fixture. Do not merge protected master, mutate #56, or ask Codex for discovery before completing this first pass.

Alajmah commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

PR #55 ACT-aria revision location (maintainer edit constraint)

The requested 2026-11-20 aria-label completion/baseline revision is implemented on an upstream-owned branch based on this exact PR head 4dcebbe492c5caeea5e712534d51ccaf7df9fc86 and opened as draft PR #57: #57

Why not push directly here: this PR's actual head is the fork lekthailtd-bit/ChatGPT-Web2API:fix/conversation-projection-endpoint; a direct GitHub Contents write returned 403 Resource not accessible by integration despite maintainer_can_modify=true. No claim that this fork branch has changed.

#57 contains this PR's original endpoint fix and role selector compatibility code (same ancestor commit) plus the ACT-aria revision with current/legacy count signals, phase-1 user-appearance gate, Copy-delta/stable-text completion, anchored backend text recovery, and Node-vm DOM fixtures. CI and independent review are gates; do not merge #55 and #57 separately, or land #55 without its revision. Keep both open while #57 is validated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants