Repository navigation
fix(trajectory-replay): fix WebArena readiness, audit, CDP wait and import-time bugs - #125
Merged
Merged
Conversation
urlopen raises HTTPError for 4xx and 5xx, so the URLError handler retried every 4xx until the readiness deadline. Inspect HTTPError status and treat 200 <= status < 500 as ready, as the loop intended. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…udit fails The report caught ResultAuditError and a task-scope mismatch, then rendered the result set with the audit marked unavailable. Run the audit once at the write_latest_report boundary, let its error propagate before any page is written, and pass the passing audit to the home and review pages. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… responses _wait_cdp only slept after an OSError, so a non-200 /json/version response ran its 300 probes back to back and timed out almost immediately instead of waiting about 30 seconds. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Both replay runners called tiktoken.get_encoding at import time. A cold tiktoken cache downloads the BPE file, so importing a runner (including CLI --help) needed network access. Load the encoding lazily and cache it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
lanyue-llk
commented
Oct 30, 2026
lanyue-llk
left a comment
Contributor
Author
There was a problem hiding this comment.
Independent review, round 1
Reviewed head ce11dbdc. No P0-P2 defects found.
What I verified
- Rainbond
_wait_site(src/harness/environments/webarena/rainbond.py:588): theHTTPErrorhandler comes before the(OSError, URLError)handler, so 4xx responses now count as ready and 5xx responses still retry. The timeout message now reportsHTTP <code>. - Public WebArena report fails closed (
src/harness/trajectory_replay/public_webarena/report.py:2034):audit_result_setruns beforemkdiror any write, so a rejected audit leaves no pages behind._available_result_audithas been removed, with no aliases left. Both the summary page and the review page now require the passing audit. The only production caller that was not already auditing first ispublic_webarena/runner.py:1142. That call is skipped for qualification and trajectory-authoring runs, andmanifest["suite"]is built fromrunnable_tasks, so a filtered formal run still matches the audit's task scope. Core evidence is written before the report, so an audit failure now ends the run with an error and the evidence is kept. That is the intended fail-closed behavior.publication.pyandmanifest_repair.pyalready audited before rendering, and they still do. _wait_cdp(src/harness/trajectory_replay/remote_execution.py:263): it now sleeps after every probe that does not succeed. The checks for process exit and for a 200 response are unchanged.- tiktoken loaded lazily (
trajectory_replay/runner.py,public_webarena/runner.py):ENCODINGhas no other users (grep), and@cachegives the same single load. - Rejected or deferred suspects: I read
har.py._record_playwright_requeststores the request object next to itsid()key, so the rejection reasoning holds. Thelocals().getandservice._submitrejections are also reasonable. The port-0 race is listed as remaining under "Part of #94", which matches the scope that is still open. - Tests: ruff gates pass.
pytest tests/trajectory_replay tests/test_golden_reports.py tests/test_resource_accounting.py -n 2gives 2061 passed and 5 skipped. The golden route hashes are unchanged, which fits a change that only alters behavior on failure. I put the base (8b8aa30f)src/back under the new tests and all 9 new or updated regression tests failed (rainbond 3, report fail-closed plus 2 signature updates, wait_cdp 1, tiktoken import 2), so they do catch the bugs. - CI: every check passes on
ce11dbdc, including "Tests and static checks".
Nits
- P3
tests/trajectory_replay/public_webarena/test_rainbond_slices.py:1063:monkeypatch.setattr("harness.environments.webarena.rainbond.time.monotonic", ...)resolves to the globaltimemodule. For the whole test, it replacestime.monotoniceverywhere with a 4-value iterator. Any extra call raisesStopIterationand makes the test fragile. A cleaner option is to patch the module attribute with a stub namespace (for examplemonkeypatch.setattr(rainbond, "time", SimpleNamespace(monotonic=..., sleep=time.sleep))) or to make the clock injectable the waysleepalready is.
🤖 Generated with Claude Code
Replace the global time.monotonic patch, backed by an exhaustible iterator, with a stub time namespace on the rainbond module whose clock holds past the deadline instead of raising StopIteration. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
Author
|
Review round 1 follow-up: Fixed
Disputed
Local runs: |
This was referenced Nov 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issues
Closes #94. This PR covers the WebArena environment and trajectory-replay items. Other agents are handling the rest of #94 in separate PRs:
process.wait()after a best-effort kill (web_fetch/providers/headless.py,moli.py)browser_use/runner.py)wcxb_scoring.py,lexbench/report.py)web_search/review.pykill/activecleanup,browser_use/backend.pyport race,browser_use/runtime.pydocker client leak andassertpreconditiontrajectory_replay/catalog_runner.pyandremote_execution.py(see below)Summary
There is one commit per bug, and each comes with a regression test. I confirmed that every test fails on the pre-fix code.
environments/webarena/rainbond.py_wait_site).urlopenraisesHTTPErrorfor 4xx and 5xx, and theURLErrorhandler retried it. The loop now checks theHTTPErrorcode and treats200 <= status < 500as ready. 5xx still retries, and the timeout message now readsHTTP <status>.trajectory_replay/public_webarena/report.py)._available_result_auditcaughtResultAuditErrorand also skipped the audit when the task scope did not match. In both cases it rendered the results with the audit markedunavailable. I removed that helper.write_latest_reportnow runsaudit_result_setonce, before it writes any page, and lets the error propagate. It passes the passing audit to the home and review pages. The golden route hashes are unchanged. Three existing renderer tests use partial fixtures that cannot pass a full audit, so they now use an explicitauditedfixture that stubs the audit. The new testtest_report_fails_closed_when_result_audit_rejects_resultscovers the failure path._wait_cdpdid not sleep on non-200 responses (trajectory_replay/remote_execution.py). Confirmed: the function only slept after anOSError, so a 2xx response other than 200 ran all 300 probes back to back and timed out almost at once instead of after about 30 s. It now sleeps after every probe that does not succeed.tiktoken.get_encodingran at import time (trajectory_replay/runner.py,public_webarena/runner.py). Confirmed: the CLIs import these runners, so with a cold tiktoken cache even--helphad to download the BPE file. Each runner now loads the encoding on first use through a cached_encoding().Suspected items not changed
environments/webarena/har.pykeys requests byid(request): rejected._record_playwright_requeststores the request object itself in_playwright_request_objects[key]alongside the key. Responses keep their request reachable through the stored Response object. A tracked request therefore cannot be garbage-collected while the recorder holds its id, so the id cannot be reused.trajectory_replay/webarena_replay.pylocals().get("readiness_retries", 0)andservice._submit: rejected as bugs.locals().getreturns the bound value when the assignment ran and0when it did not, which is the intended behavior on CPython 3.11 through 3.13. It is a style issue and there is no failing test to write for it.service._submitis the only way the cowagent BrowserTool service exposes to run work on its Playwright thread, and about ten other call sites use it. Replacing it means changing the upstream API, not fixing a bug here.catalog_runner.pyandremote_execution.py: confirmed, deferred. The port is released before the browser binds it, andcatalog_runnerreuses the same port for every browser restart during a run. If another process takes the port,_wait_cdpcould accept that process's CDP endpoint. A real fix needs an ownership handoff for each engine. For Chromium that means--remote-debugging-port=0plus readingDevToolsActivePort. Moli, Lightpanda and Obscura each need their own mechanism. This also overlaps the host/port rework in Use a single registry for WebArena hosts, ports and site credentials #96, so it stays open in Fix confirmed runtime bugs found in the codebase audit #94.Test plan
ruff check --config 'include=["*.py"]' --select F,TID252 .andruff check: passpytest tests/trajectory_replay/ tests/test_golden_reports.py tests/test_resource_accounting.py -n 2: 2061 passed, 5 skipped; golden route hashes unchangedpytest tests/trajectory_replay/test_runner.py tests/trajectory_replay/public_webarena/test_runner.py tests/test_resource_accounting.py: 62 passedtest_wait_site_treats_client_error_responses_as_ready(3 cases),test_report_fails_closed_when_result_audit_rejects_results,test_wait_cdp_pauses_between_non_ready_responses,test_runner_import_does_not_load_the_token_encoding(2 modules)🤖 Generated with Claude Code