Skip to content

cua: the hello goes out once the connection is counted (browser-cua :493, an inspector-interrupt race) - #327

Merged
SSFSKIM merged 5 commits into
masterfrom
fix/cua-hello-after-count
Oct 29, 2026
Merged

SSFSKIM merged 5 commits into
masterfrom
fix/cua-hello-after-count

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

The flake

e2e/browser-cua.spec.ts's orphaned-connector case read connections: 0, refused: 0 at :493, right after the trusted fake host heard MAWS's hello, on hosted Macs (40299148379; 40751164658 flaky; 40771309800 red on the try and its retry; 40794571273 flaky). The tracker row's reading was an accepted connection that closed between the hello and the first read. It was not a close.

Root cause (proven on hosted Macs)

The e2e reads main through Playwright's electronApp.evaluate, which runs over Node's inspector (--inspect=0, Runtime.callFunctionOn). Node dispatches inspector messages at the next V8 interrupt, which can fall between two calls inside main's synchronous JS, not only between event-loop tasks. The server wrote the hello inside CuaConnection's constructor, before decide added the connection to its set. When main's thread stalls inside that write, as it can on a loaded 3-vCPU hosted VM, the test gets the hello and sends its read, and the read then runs before the add.

Evidence:

  • Hosted diagnostic runs 40804905622 and 40804905353 on a throwaway tree. Main recorded each step with its time ("hello writing", "hello written", "added", and every inspect together with the step it ran after), and a 40-launch loop of the :493 read ran on that tree, with Playwright's retry. Of 160 launches, 13 read 0 (4+4 and 3+2). In every one of the 13, the read ran after "hello writing" and before "hello written", inside the hello's own write and before the add. A second read right after returned connections: 1 each time, and the fake host's socket was still open. No connection had closed.
  • Locally, a plain Node probe with --inspect and a WebSocket client confirmed the mechanism. A Runtime.evaluate sent after the target's "write" read a global set before the write. It ran while the target was still inside synchronous code, before the target set the global's next value.

The fix

  • src/main/browser/cua/index.ts, connection.ts: the connection is counted first, then greeted (greet(), moved out of the constructor), then read. A refused peer is counted and logged before its socket is destroyed. The refusal has the same race at :520, where the test reads refused after the orphan sees the close.
  • Each connection's close is now one [browser] line naming the session, how long the connection lasted, and the cause: why MAWS ended it, the socket error code, or "the host ended it". Until now a closed connection left nothing in main's log. Like the existing lines, it names no params and no content.
  • The :483 case keeps a witness: main's output from launch (collectMainOutput via onLaunched), the first read with the fake host's new socketState(), and a second read when the first misses. An afterEach prints the witness and attaches it only when the case failed and the app has closed, so a future red carries main's [browser] lines and the socket state in the job log.

Tests written to fail first (src/main/browser/cua/admission.test.ts). The node:net mock now sees each accepted socket before the server does, and wraps write or destroy to read inspect() at the moment the peer could first observe the hello or the close. Before the fix both read 0 (commits 859725c, 15356be); after it, 1. A third test pins the close line's cause for the host's end and for a removed session.

Runs

  • Before the fix: the hosted diagnostic runs above, 13 of 160 launches missed.
  • On the fix: the same 40-launch loop (throwaway tree f32a4cd) read 0 of 40 in 40806081237 and 0 of 40 in 40807335206, so 0 of 80. At the measured 13-in-160 rate, 80 clean launches by chance is about a 1-in-900 event.
  • Final head cc2bc8b, five hosted e2e:browser-cua runs, each 7 passed with no retry and no flaky: line: 40806888425, 40807460959, 40807965478, 40808110234, 40808764645. The case now sits at :499, and its first read is at :510.
  • Class 1a on the final head (pool): 40807164514 green. A first attempt, 40806648287, was red in an unrelated unit test: src/main/org/org-session.test.ts › "a focus whose window is gone by the time Touch ID would ask…", ENOTEMPTY on its temp-directory teardown.
  • The witness on a red: 40809489834 ran a throwaway tree (9f9a338) that forces the first read to expect 2. Both the try and the retry printed [browser-cua witness] … into the job log, with the read, the fake host's socket state and main's [browser] lines (in that run, the new close line from the case's own cleanup).

Review

doperpowers:reviewer-medium returned no findings. The reviewer separately reproduced the inspector ordering with a standalone probe.

Left over

  • The other reads in this spec that follow a reply (leased after debugger.attach) are safe, because the handler records the lease before it returns. The same write-before-bookkeeping shape could exist elsewhere in MAWS wherever an e2e reads main right after a side effect that main makes visible before finishing its own bookkeeping. This change does not audit for it.
  • The tracker row and the gate-offload record are left to the architect.

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)

…ed (fails: it reads 0)

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
… :493 case keeps a witness

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
…fails: it reads 0)

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T03:06:40.510110Z cc2bc8b PR opened
ℹ️ 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.

@SSFSKIM
SSFSKIM merged commit eae8a75 into master Oct 29, 2026
SSFSKIM added a commit that referenced this pull request Oct 29, 2026
…ke was an inspector read inside main's synchronous code (#327); its tracker row closed

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
SSFSKIM added a commit that referenced this pull request Oct 29, 2026
…'s start

rows.ts keeps O8 M5's memberNames import and takes repoProjectId from @shared/machine/project-ids, where M3 moved it.

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
SSFSKIM added a commit that referenced this pull request Oct 29, 2026
…c lever

Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)
SSFSKIM added a commit that referenced this pull request Oct 29, 2026
…rds at 3d1f3ff) into p5-o3-c at M6

Conflicts, each resolved so both sides hold:
- src/main/index.ts: M4's side. O9's lane A block sat in the stretch of startMain that M4 moved into startSpine (the
  index, attention and the index source it reads are the spine root's now), so it and its three imports leave main's
  root here; the fold that follows composes lane A in startSpine (O3-C D20, O3 Decision Log 13). At this commit lane A
  is not composed.
- src/main/attention/notifier.ts: both comments; the notifier reads through the view (R1) and keeps lane A's in-app-only
  rule (O9 M6, Q5).
- eslint.config.js: M3's narrowed MACHINE_BOUND (and its tests' list) gains lane-a while it is under src/main/.

Beyond the conflicts: lane A's imports of paths M3 moved are re-pointed (atomic-write to @shared/fs, git's runner to
src/services/git/, the two value imports marked as rule B's exception until the fold moves lane A); O9's new notifier
case drives the fake view rather than a read model writer.

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
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