Skip to content

Wait on the pooled fetch itself in the closed-request browser test - #12835

Merged
danielhanchen merged 1 commit into
mainfrom
ci/browser-cancel-test-race
Oct 6, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
ci/browser-cancel-test-race

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Problem

studio/backend/tests/test_browser_routes.py::test_a_closed_request_cancels_the_fetch failed on #12816 with KeyError: 'cancelled'. That PR does not touch the browser route, and the test passes on main 5 of 5 locally, so it is a race in the test. It came in with #12347 (in-app browser panel).

The route returns 499 on a client disconnect without waiting for its pool task, which is correct: it sets the cancel event and lets the worker wind down. The test then tried to wait for that worker by submitting one no-op per pool worker and waiting on each. That does not wait for the fetch: idle workers finish the no-ops while the fetch's own thread can still be before the line that records what it saw. On a loaded CI worker the test read an empty dict.

Fix

The fake fetch sets a threading.Event once it has recorded the cancel, in a finally, and the test waits on that event (10 s) before asserting. No product change.

Verification

  • tests/test_browser_routes.py: 22 passed.
  • With a 0.5 s sleep at the start of _fetch_and_build, which widens the window CI hit:
    • the test from main fails;
    • this version passes.
  • Sabotage of the product: if the route never sets cancel_event on disconnect, this version fails on seen["cancelled"] is True. The guard still checks the behaviour it was written for.
  • tests/test_formatter_fixed_point.py passes.

test_a_closed_request_cancels_the_fetch returned 499 and then drained the
fetch pool with no-ops before reading what the fake fetch saw. Idle workers
finish those no-ops while the fetch's own thread may not have recorded
anything yet, so a loaded CI worker read an empty dict (KeyError 'cancelled'
on #12816, which does not touch the browser route). The fake fetch now sets
an event when it is done and the test waits on that.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 6, 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-06T08:16:19.773089Z 0e1a524 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

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 0e1a5248cb

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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