Skip to content

fix: fail closed on fresh-chat navigation and ambiguous Send/Stop control - #56

Draft
Alajmah wants to merge 21 commits into
masterfrom
fix/fresh-chat-navigation-fail-closed-20261113
Draft

Alajmah wants to merge 21 commits into
masterfrom
fix/fresh-chat-navigation-fail-closed-20261113

Conversation

@Alajmah

@Alajmah Alajmah commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Scope and evidence

Pinned base: master@497527dceabfa3f95961e23c291e618c5570f1ac. This is a focused fail-closed navigation and explicit-Send guard, not a replay/idempotency fix or Phase 8 refactor.

First-pass findings (independently inspected before editing)

  • NAV-01 P0: navigate_new_chat exhausted 30 readiness polls and returned without establishing a composer.
  • NAV-02 P0: substring URL check ("chatgpt.com" in actual_url) accepted a page without proving the exact fresh-chat route or target project.
  • NAV-03 P0 conditional: broad button[type=submit] fallback could select Stop on an active generation.
  • NAV-04 P1: previous _current_conv_id was only cleared after the navigation loop; failures could retain stale continuation identity.
  • NAV-05 P1 separate: click_send on master still uses soft mutating _js; fix: add no-replay send mutations and opt-in single-send semantics (#51) #52 addresses CDP no-replay and remains draft.
  • NAV-06 P1 residual: displacement after navigation completion but before typing remains a separate operation ownership/lease concern; this patch does not claim to eliminate that race.

Changes

  • Clear continuation identity before new navigation. Validate explicit Page.navigate errors.
  • Require HTTPS chatgpt.com exact origin and exact fresh-chat route (/ or the requested /g/{gizmo_id}/project). Query/trailing slash may normalize; no /c/{id} acceptance.
  • Probe document.readyState, visible/enabled composer and visible Stop; require two consecutive readiness confirmations. Exhaustion raises typed SendReadinessError rather than proceeding.
  • Remove the broad submit-type fallback. Scope explicit Send controls to their visible composer form and check Stop inside the same JS evaluation as the click; fail closed on unknown controls.
  • Add deterministic tests for spoofed URL, wrong conversation/project, no composer, active Stop, hydration and displacement, old identity, navigation transport error, MCP propagation, and Stop changing between readiness and action.

Constraints / known limits

Review gates

Alajmah commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Frozen maintainer first pass — 2026-11-20 (before any second reviewer)

Inspected base: master@497527d and candidate head: f69e1c2c1c5df6e73d4bbfa9161755e55469f0db. This is a source-grounded first-pass review and not a merge approval.

Mitigations in this branch: NAV-01 navigation timeout now raises; NAV-02 exact HTTPS origin/fresh route; NAV-03 no broad submit-button fallback and no click if any visible Stop exists (including disabled and second-matching controls); NAV-04 stale conversation identity cleared before navigation. New Node-vm behavioral fixtures execute the embedded CDP JavaScript rather than only matching expression strings; they remain fake-DOM evidence, not live account qualification.

Open findings (retain, do not silently clear):

  • NAV-05 / P0 / separate PR: click_send still uses replayable soft _js on this branch. PR fix: add no-replay send mutations and opt-in single-send semantics (#51) #52 introduces the separate _js_mutation no-replay contract; combined-head verification is mandatory. Do not claim exactly-once, durable idempotency, or replay safety here.
  • NAV-06 / P1: route/tab ownership is sampled at navigation readiness, but not proven again at the precise typing/mutation boundary. A displaced tab with a valid composer and explicit Send can still be the wrong target. Requires operation-scoped route and target proof.
  • NAV-07 / P1 / adjacent path: navigate_gpt() still has the older fail-open poll; GPT safety must be tracked separately.
  • NAV-08 / P1 conditional: the five synthetic mouse events target one button; a synchronous event handler could change the control after pointerdown and before click. This is a static race hypothesis, not a demonstrated production failure; needs a forced DOM mutation fixture and correct unknown-effect semantics.
  • NAV-09 / P2: no authorized current-UI live certification for composer/project-path/Stop semantics. Node vm tests exercise JavaScript in a minimal synthetic DOM only.

Evidence ceiling: Previous GitHub CI run #43340768119 succeeded on 6aad109b. This 2026-11-20 head has its own CI run; passing a previous SHA does not certify the current one. No live browser/account operation performed. PR stays Draft; merging or closing issue #51 is not authorized by this note.

Independent second-pass request on exactly f69e1c2: review control-flow, browser target/route ownership, unsafe mutation replay, source JS execution, stop-button TOCTOU, cancellation, integration with PR #52, and test evidence. Please distinguish reproduced bugs from conditional risks.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-20T04:47:22.493958Z
We couldn’t complete this review. Comment @codex review to try again.
f69e1c2 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

Alajmah commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Independent first-pass addendum — NAV-08 isolated JS counterexample

I executed a reduced Node.js fixture matching ChatGPTDom.click_send's current five-event dispatch. The simulated handler changes the same button from aria-label="Send message" to aria-label="Stop generating" synchronously on pointerdown. Because stopLike/stopPresent are sampled before the loop, the implementation continues through mousedown → pointerup → mouseup → click on that now-Stop button. The fake DOM reports one Stop click.

Evidence class: isolated-experiment of the JavaScript sequence, not a live ChatGPT/React reproduction, CDP test, or observed cancellation of someone's work. This is a reproducible counterexample if the live control changes state synchronously, and warrants an adversarial DOM-runtime test.

Gate: Do not claim action-time Send/Stop safety from a single pre-loop check. Revalidate control/action before later events and preserve possible-effect UNKNOWN semantics if an earlier event could have submitted. Coordinate with PR #52 no-replay rather than making post-event failures look like safe-to-retry pre-send failures. Keep PR #56 Draft until a combined-head and site-scoped verification can bound this behavior.

This addendum updates NAV-08's evidence from static hypothesis to isolated event-sequence proof only.

Alajmah commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Post-verification delta — 2026-11-20: route proof at the mutation boundary

CI update (immutable old SHA): GitHub Actions run #44676431825 completed success on f69e1c2c: lint, secret-scan, all six Ubuntu/macOS/Windows × Python 3.11/3.12 test jobs, and build passed. This supersedes the earlier "in progress" observation, but is not certification for the newly changed head.

New branch delta: The fresh/conversation navigation paths now establish _expected_send_context only after verified readiness. Navigation errors, reconnect/reattach, and close invalidate prior route authority. The existing-conversation URL helper now requires the exact HTTPS ChatGPT origin. ChatGPTDom checks the expected path/conversation ID and exact HTTPS origin in the same JavaScript evaluation as composer focus and as the Send event dispatch, refusing a displaced route without an event. New Node vm fixtures execute this guard against valid/foreign-origin, foreign conversation, and wrong-project routes. The legacy GPT path still has only an origin guard until NAV-07 is repaired.

NAV-08 experimental scope, per external verification: The current five-event sequence was demonstrated to continue after a synthetic synchronous Send→Stop mutation of the same node. The fixture now models both same-node relabeling and node replacement, with two xfail(strict=True) future-safety tests asserting no subsequent click. These are known unresolved defects/expected failures, not passing protection; the node-replacement fake is not a claim about React's actual event targeting. If an earlier pointer event might already have submitted, eventual abort must carry UNKNOWN/do-not-replay semantics — integrate with #52 rather than treating an interrupted sequence as a safe failed send.

Remaining merge gates: (1) newest-head CI, (2) route proof/target lease correctness in concurrency and after Input.insertText (NAV-06 is reduced, not closed), (3) #52's _js_mutation no-replay integration and UNKNOWN effect propagation, (4) NAV-08 event-sequence reconciliation, (5) authenticated live validation of current DOM, (6) independent second review (Codex review on prior SHA was blocked by quota). master is untouched; PR #56 stays Draft.

Proposed integration order: review/land #52's transport no-replay semantics, rebase #56 and explicitly preserve its in-page route/Stop guards when swapping _js to _js_mutation, then reconcile #55 selector fixes. Require full CI + adversarial JS fixtures on each actual merged/rebased SHA, and no silent resolution of known xfails.

@Alajmah

Alajmah commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Live certification of this branch + October-DOM findings (2026-11-20)

Scope/authorization: full protocol E1-E4 on the authorized disposable project (conv 6affe00a), 4 short sends, in-process bridge on 8081 from a worktree at this head c080565. Raw evidence + JSON: local harness C:/Next-Era/w2a-pr56-live-experiments/ (results files + run logs + a conversation screenshot).

Results for this branch's guards (live account, real sends):

  • E1 PASS — fresh-chat navigation + readiness in 4.2s on the current DOM: composer / form-scoped Send / readiness selectors all match the live UI.
  • E2 PASS — route guard passed at typing AND at dispatch (same-eval recheck confirmed in behavior); message submitted (identity listener captured uuid=5a7b2e76); the model replied the exact sentinel, verified by direct DOM read + screenshot. REST still returned 504 — root cause is F1 below, not this branch.
  • E2b PASS — continuation send dispatched (unbound-guard caveat → F2).
  • E4a race MEASURED LIVE: forced synchronous relabel Send → "Stop generating" + data-testid="stop-button" at pointerdown; all five synthetic events dispatched onto the now-Stop-labeled control (timestamped timeline captured, click included) and the message still submitted and rendered. The app keys on React state, not the label — the NAV-08 label-geometry hazard does not materialize on the live app. Node-replacement geometry remains untested live (E4b inconclusive at idle composer); the xfail(strict=True) fixtures remain the guard there.
  • Cleanup verified: recorder/handler/globals removed; xfails untouched.

F1 — completion detector is blind on the current DOM (blocks ALL response collection; not a regression of this branch)

  • completion_detector.py:380 (phase_1_appear), :477, :487 and cdp_driver.py:1586/1591/1698 count messages via [data-message-author-role=...] and .markdown — attributes removed in the October migration. Live proof: user_count=0 in every send baseline; 90s stall → GenerationStuckError → 504 while the response had visibly rendered.
  • Repo-wide sweep: 6 executable-dead sites total (4 counters + 2 extraction gates), 8 stale comment lines, and zero test files exercising the dead selectors — CI structurally cannot catch this drift.
  • The ACT action-button completion family (*-turn-action-button, [data-testid*="copy"]) matches zero elements on the current DOM too: the per-turn action row is now aria-label-based — aria-label="Copy" appears exactly once per completed assistant turn (live-verified: 4 turns → 4 "Copy" buttons; same for Read aloud / Share / More actions).
  • Ranked completion signals for the current UI: (1) aria-label="Copy" scoped to the last turn (or count-delta vs a send-time baseline), (2) backend end_turn flag (conv id is probeable from the URL within ~1s of send), (3) Stop-button absence as precondition only (Stop flickers between batches — documented in this repo's own detector comments), (4) innerText stability as tie-breaker.
  • Carrier: PR Fix ChatGPT turn detection after DOM role selector change #55 (already touches completion_detector.py + cdp_driver.py and adds test_current_dom_role_selectors.py) — but Fix ChatGPT turn detection after DOM role selector change #55's current diff does not cover the ACT/aria layer; its revision should add it. Merge order should put Fix ChatGPT turn detection after DOM role selector change #55 first: until it lands, every send 504s and no live validation of fix: add no-replay send mutations and opt-in single-send semantics (#51) #52/fix: fail closed on fresh-chat navigation and ambiguous Send/Stop control #56 is possible.

F2 — conv-id rebind is skipped on any streaming failure (this branch's send path)

  • The post-send /c/{id} rebind (cdp_driver.py ~1915-1927) sits after the stream loop; GenerationStuckError propagates before it runs. Live-proven: after successful sends with the tab URL already at /c/{id}, _expected_send_context stayed None, so later sends ran with the origin-only guard into an existing conversation. Recommend moving the rebind into a finally (or rebind before outcome classification).

CI + gate status

  • Run 44680052959 completed success on c080565 (lint, secret-scan, 6 OS/Python jobs, build).
  • Gate updates: newest-head CI ✓; NAV-08 downgraded for label geometry (keep xfails for node replacement); live DOM validation partially satisfied for navigation/guard/send; response collection unblocks only after Fix ChatGPT turn detection after DOM role selector change #55's revision merges; NAV-05/NAV-06 unchanged; second review still pending (Codex quota).

PR stays Draft.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant