Skip to content

refactor(trajectory-replay): share executor and Docker runner code between tracks - #204

Merged
lanyue-llk merged 11 commits into
mainfrom
refactor/trajectory-replay-shared-executor
Nov 4, 2026
Merged

lanyue-llk merged 11 commits into
mainfrom
refactor/trajectory-replay-shared-executor

Conversation

@lanyue-llk

@lanyue-llk lanyue-llk commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

What, why and how of this PR

Issues

Closes #201

Summary

The curated and public replay tracks each kept a copy of their executor helpers and Docker runner code. That code now lives once under src/harness/trajectory_replay/core/, and each track keeps only its own behaviour on top. Neither track is retired, and #103 keeps that decision.

  • core/executor.py owns body_text, actionability_probe, judge_outputs and validate_outputs. Their callers import them from there, with no re-exports from the track modules.
  • core/docker_runner.py owns engine startup (EngineRuntime, start_engine), the browser state reset, opening the task page, the fixture server, resource results, attempt row fields, process validation, the environment receipt and run artifact writing.
  • catalog_runner.py now imports only public names from remote_execution: run_replay_task and stop_browser.

No action semantics, canonical input, result, denominator or report target changes.

What the audit got wrong

#103 and #201 say catalog_runner.py imports _browser_command, _run_task and _wait_cdp. On the current code it imports _run_task and _stop_browser. _browser_command and _wait_cdp are only used inside remote_execution.py, behind the public start_local_browser, so they stay private.

I named the function run_replay_task and not run_task because catalog_runner.main has a local run_task function. With the shorter name, the nested execute_task would have called that local function instead.

Most of execute_steps and the track _run_task functions is not a copy, so these stay in each track:

Behaviour Curated Public WebArena
execute_steps actions 12 those 12 plus 10 more
Target lookup page.locator(selector).first locator_for, with tabs and geometry waits
Default action timeout 30 s navigate, 10 s back and forward, 5 s otherwise 30 s, within a task budget
Origins cleared on reset visited plus the current page visited plus every open page
Pages closed before a task the current page every page in the context
Task viewport 1280x900 1280x720 for WebArena tasks, otherwise 1280x900
Environment receipt image id and tags also the image build source labels
Default browser images configured_browser_images() DEFAULT_BROWSER_IMAGES

The failure block in both execute_steps functions also stays in place. In the public track, action_page can be unbound when that block runs, and the error is recorded as actionability_probe_error. Moving the block into a helper would change that recorded evidence.

Frozen bindings

No file had to be left alone.

  • I searched evaluation/, src/, tests/, configs/ and research/ for the current SHA-256 of runner.py, executor.py, their public counterparts, catalog_runner.py and remote_execution.py, and found no match.
  • remote_execution.py does hash itself into each cohort as runner and remote_execution. cohort_reference_hashes only compares those values within one run, and webarena_results.py does not check those two keys. Historical receipts keep their recorded hashes and still verify.
  • A cohort started after this change records a different remote_execution.py hash, as it would after any earlier edit to that file.

Test plan

  • Lint: both gates pass.
  • tests/trajectory_replay, tests/test_resource_accounting.py, tests/environments/test_webarena_topology.py, tests/test_explicit_utf8_io.py and tests/test_golden_reports.py: 2329 passed, 5 skipped. Route-hash snapshots are unchanged. I did not run the rest of tests/ locally, so CI is the gate for it.
  • Tests changed:
    • Stubs now patch the shared module where the code moved.
    • Tests that ran the same shared function once per track now run once.
    • test_shared_core.py adds tests that the tracks keep their own reset scope, page replacement and environment receipt, and that a failed engine start keeps started resources for cleanup.
    • test_shared_core.py also checks on mocks what reset_browser_state clears, including when a call fails, that start_engine resets the warm-up page before publishing it, and the fields returned by attempt_identity and manifest_task. Mutating these behaviours one at a time made the tests fail (14 of 14, one-off script, not committed).
  • Tests added after review round 2: test_shared_core.py, test_resource_accounting.py and test_webarena_topology.py now pin the origins recorded for the next reset, the fixture server bind address, the start_browser_container arguments, the per-second network rates and output_volume. Each of 11 one-at-a-time mutations of these behaviours made a test fail (one-off script, not committed).
  • Tests added after review round 3: engine start, the fixture bind address and root, measured output volumes, the recorded ground truth validation fields, body text truncation and process validation on public task rows.
  • Tests added after review round 4: test_shared_core.py now asserts the exact docker_environment dictionary with both browser version fallbacks, the exact non-ASCII bytes and hashes from write_run_artifacts, and that start_engine reloads the container before reading its published endpoint. The fixture server test now stops the server through stop_fixture_server and checks that it waits for the thread and closes the socket. Each of 13 one-at-a-time mutations of these behaviours made a test fail (one-off script, not committed).
  • Comparison against the base commit (one-off script, not committed): I ran run_evaluation from d894600d and from this branch on the same mocks, for both tracks and five scenarios: plain, ground-truth evidence, no fixtures, a failed engine start and a failing click.
    • The clock, UUID and traceback text were fixed so runs could be compared byte for byte.
    • I compared attempts.jsonl, summary.json, manifest.json, stdout, and every call made to the page, container, Docker client and Playwright mocks. The only normalization masked the mock ids and the listener function's repr, which changes with its new name.
    • All 10 comparisons were identical.
    • This uses mocks only. No real browser or Docker container ran.

@lexmount-ocr lexmount-ocr 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.

✅ Review complete · fa9fa03

No findings in this review.

@lanyue-llk lanyue-llk left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Independent review, round 1

Reviewed head fa9fa03b against base d894600d. I found no correctness, behaviour or rule defects. There is one test gap (P2) and one small test cleanup (P3).

Findings

P2: the new shared reset and engine-start code has no test of what it does

src/harness/trajectory_replay/core/docker_runner.py:71, :102, :291, :148, :326

reset_browser_state and start_engine are now the single implementation behind task isolation in both tracks, but no test checks that they clear anything. test_tracks_keep_their_own_reset_scope stubs out reset_browser_state, so it only checks which origins reach it. test_tracks_keep_their_own_page_replacement and the run_evaluation tests stub _reset_state.

I applied each mutation below to core/docker_runner.py and ran tests/trajectory_replay, tests/test_resource_accounting.py, tests/environments/test_webarena_topology.py and tests/test_golden_reports.py. All four mutations survived (2244 passed, 5 skipped):

Mutation Effect if shipped
for origin in sorted(origins) becomes for origin in () Visited origins keep their storage between tasks
The warm-up reset_state(page, {"https://example.com"}) in start_engine is removed The warm-up origin's state reaches the first task
attempt_identity always writes is_retry: False Retry rows are recorded as first attempts
manifest_task omits source Run manifests lose each task's source

This is not a regression, because the old per-track copies had no such tests either. It still matters more now that one edit changes both tracks.

Suggested fix: add to test_shared_core.py:

  • a test that runs reset_browser_state on a mock page and asserts Storage.clearDataForOrigin is sent once per sorted origin, the cookie and cache calls are made, and the page ends on about:blank, including when a CDP call fails;
  • a test that start_engine calls reset_state before it publishes runtime.pages[engine];
  • direct assertions on the fields returned by attempt_identity and manifest_task.

P3: dead monkeypatch in the reset-scope test

tests/trajectory_replay/test_shared_core.py:208

The patch of docker_runner.reset_browser_state has no effect. Both runners import the name directly and the test patches those bindings separately. Removing it makes clearer what the test covers.

What I verified

  • Moved helpers: I compared the AST of _http_origin, _resource_result, _start_fixture_server, _write_run_artifacts, _QuietFixtureHandler, _encoding, _body_text, _actionability_probe, judge_outputs and validate_outputs from both tracks at base against their core/ versions. All are identical. The reset body from the public track at base matches reset_browser_state under a text diff, and I read the curated copy's removed lines in the PR diff.
  • Composed helpers, by reading the diff:
    • start_engine keeps the order of calls and of resource recording.
    • docker_environment plus the public _environment keeps the image key order.
    • process_validation gives the same values and key order. It still runs before the evaluate_result trace entry is appended.
    • main_frame_origin_recorder is safe because _run_task never rebinds page.
    • open_task_page and print_attempt_progress match the old code.
  • My own comparison of base and head: I ran each track's _run_task on mocks with a fixed clock, once passing and once with a failing click, and compared the rows as JSON. The only differences were the worktree path in tracebacks and mock ids. This used mocks only, with no real browser or Docker. I did not rerun the PR's run_evaluation comparison.
  • Two small differences with no observable effect:
    • materialize_task now keeps evaluator, environment and trajectory on curated tasks, where the old code dropped them. Curated runner.py never reads those fields, and its manifest is built from suite.tasks.
    • In the public track, ENGINE_IMAGES[engine] is now read before the network is created. run_evaluation validates engines earlier, so this lookup cannot fail.
  • Tracebacks in new runs: a failure inside a moved helper now names its core/ frame in the row's error text. I found no code in the diagnostics or metrics modules that parses those frames.
  • Scope of Closes #201:
    • No function or class definition remains identical between the track runners or between the track executors.
    • catalog_runner.py imports only public names from remote_execution.
    • No references to the removed private names remain in the tree.
    • Short identical blocks remain inside execute_steps, _run_task and run_evaluation (at most 14 consecutive lines). The PR explains why, and I read action_page as assigned inside the step's try, which supports its reason for keeping the failure block in place. I am not asking for more extraction.
  • PR table: the action counts (12, and 22 in public) and the task viewports match the code.
  • Frozen bindings: the SHA-256 of each of the six changed source files, at base and at head, appears nowhere in the tracked tree. cohort_reference_hashes compares remote_execution.py only within a run. webarena_results.py and catalog_contracts.py do not refer to the remote_execution or command_entry keys.
  • Tests that do catch breakage: mutations to start_engine resource recording, process_validation, materialize_task, the public reset scope and write_run_artifacts each failed tests.
  • Rules: no compatibility aliases or re-exports, no workflow or evaluation files changed, and golden snapshots unchanged.
  • Local runs: both lint gates pass. The targeted tests above gave 2244 passed, 5 skipped.
  • CI on fa9fa03b: all checks pass, including "Tests and static checks" and "Installation and packaging".

@lanyue-llk

Copy link
Copy Markdown
Contributor Author

Review round 1 fixes, both findings fixed and none disputed.

  • P2, untested task isolation (74899ed): test_shared_core.py now runs reset_browser_state on a mock page. It checks that Storage.clearDataForOrigin is sent once per sorted origin, that the cookie, permission and cache calls are made, and that the page ends on about:blank. It also covers a failing origin, a failing page.evaluate, a failing CDP clear, a failing history reset and a missing CDP session. start_engine is tested to call reset_state before it publishes runtime.pages[engine], and a failed reset leaves the page unpublished. attempt_identity and manifest_task are compared against their exact returned fields.
  • P3, ineffective monkeypatch (0aaabda): removed the docker_runner.reset_browser_state patch from test_tracks_keep_their_own_reset_scope. Both runners import the name directly, and the test already patches those bindings.

Checks

  • Mutations: I applied 14 mutations to docker_runner.py one at a time, using a one-off script that is not committed, and test_shared_core.py caught all of them. They include the four from the review: emptying the origin loop, removing the warm-up reset, forcing is_retry to False and dropping source.
  • Lint: both gates pass.
  • Tests: tests/trajectory_replay, tests/test_resource_accounting.py, tests/environments/test_webarena_topology.py and tests/test_golden_reports.py give 2257 passed, 5 skipped. Route-hash snapshots are unchanged.

This round changes tests only, with no change to source code or rendered output. These tests use mocks only, so they do not show that a real browser clears its state.

@lexmount-ocr lexmount-ocr 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.

ℹ️ Review skipped · 0aaabda

No reviewable content was selected for this run.

@lanyue-llk lanyue-llk left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Independent review, round 2

Reviewed head 0aaabda6. The production refactor looks correct and I found no behaviour change. Two test-coverage findings remain, one P2 and one P3. Neither is a regression, because the base commit had no such tests either.

Findings

P2: src/harness/trajectory_replay/core/docker_runner.py:58 (main_frame_origin_recorder)

Problem: No test checks the origin recorder, which is the remaining untested part of task isolation. It supplies the origins that reset_browser_state clears for the next task. The round 1 tests pass the origins in directly, so they never exercise this step. I applied two mutations, and each survived tests/trajectory_replay, tests/test_resource_accounting.py and tests/environments/test_webarena_topology.py:

  • Removing visited_origins.add(origin). A task that navigates from origin A to origin B would then leave A's storage in place for the next task, because reset only adds the current page's origin.
  • Removing the frame != page.main_frame check, so subframe origins are recorded too.

Fix: Add a test to test_shared_core.py that:

  • calls the listener with a main frame and asserts its HTTP origin is recorded;
  • calls it with a subframe and asserts nothing is recorded;
  • calls it with about:blank and asserts nothing is recorded.

P3: src/harness/trajectory_replay/core/docker_runner.py:209 and :281 (fixture binding and start_engine arguments)

Problem: The base-commit comparison in the PR description was a one-off script and was not committed, so nothing protects these behaviours in future. These mutations also survived the same suite:

  • Binding the fixture server to 127.0.0.1, which the comment on that line says makes it unreachable from containers.
  • Dropping network=network.name from start_browser_container.
  • Hard-coding cpus=1.
  • Computing network_rx_bytes_per_second from the tx counter in resource_result.
  • Setting output_chars to 0 in output_volume.

Fix: Assert the start_browser_container keyword arguments in the existing _start_engine helper test, the server address in test_fixture_server_keeps_the_host_alias_origin, and exact values from resource_result and output_volume.

What I verified

  • Moved code: I compared the AST of each moved function against both base copies. _http_origin, _resource_result, _start_fixture_server, _write_run_artifacts, record_origin, the fixture handler, _body_text, _actionability_probe, judge_outputs and validate_outputs match apart from names.
  • materialize_task: It differs on purpose by using dataclasses.replace. The curated copy used to drop evaluator, environment and trajectory, but curated tasks load with no evaluator and the curated runner reads none of the three, so this has no effect.
  • Other helpers, read side by side against the base diff:
    • reset_browser_state, open_task_page, start_engine and docker_environment keep their order and output. The public build_source key still comes last in each image.
    • process_validation runs where the old expressions ran, before evaluate_result is appended to the trace, so it gives the same result.
    • attempt_identity, output_volume, manifest_task and ground_truth_validation keep their key order.
  • Track differences: The per-track table in the PR description matches the code for reset scope, pages closed, viewport and receipt. It also has the right action counts: 12 curated and 22 public.
  • Scope of #201: catalog_runner.py now imports only public names, and no references to the removed names remain in src, scripts, docs, examples or .agents, apart from a separate _http_origin in playwright_tool.py that this PR did not touch. No function with the same name in both tracks is still a copy. The remaining shared line blocks are at most 21 lines and are mostly import lists, call sites and manifest fields.
  • Frozen bindings: The base SHA-256 of all six replaced files appears nowhere in the base tree. I found no non-test code outside remote_execution.py that reads the runner or remote_execution cohort hashes. No non-test files under evaluation/ or research/ changed.
  • Local checks: Both ruff gates pass. tests/trajectory_replay, tests/test_resource_accounting.py, tests/environments/test_webarena_topology.py and tests/test_golden_reports.py gave 2257 passed, 5 skipped, and golden snapshots are unchanged.
  • CI on 0aaabda6: All checks pass, including Tests and static checks, Installation and packaging, and Rendered reference and report checks.

These checks used mocks and static comparison only. I did not run a real browser or Docker container.

@lanyue-llk

lanyue-llk commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Review round 2 findings are fixed, and none are disputed. Only tests changed, so route-hash snapshots are unchanged.

P2: main_frame_origin_recorder had no test (119cd79). test_origin_recorder_keeps_every_top_level_http_origin_for_the_next_reset calls the listener with a subframe and about:blank, which record nothing, and with two main-frame HTTP origins, which are both kept.

P3: behaviours protected only by the one-off comparison (ef21e85).

  • start_engine: _start_engine now returns its mocks. A new test asserts the exact start_browser_container keyword arguments and the bridge network name and labels.
  • Fixture server: test_fixture_server_keeps_the_host_alias_origin asserts the 0.0.0.0 bind address.
  • resource_result: a new test asserts exact CPU, receive and transmit rates, and that they are omitted at zero duration. It sits apart from the existing parametrized test because the WebArena resource_summary does not report per-second network rates.
  • output_volume: a new test asserts exact token and character totals across outputs, using a stub encoder so it needs no BPE download.

Checks

  • Mutations: each mutation below made a test fail, run one at a time with a one-off script that is not committed. This includes all seven the review listed as surviving; hard-coding memory, the transmit rate, the rate scale and tool_output_tokens are additional.
    • removing visited_origins.add
    • removing the main-frame check
    • binding to 127.0.0.1
    • replacing network=network.name
    • hard-coding cpus
    • hard-coding memory
    • receive rate from the transmit counter
    • transmit rate from the receive counter
    • wrong rate scale
    • output_chars set to 0
    • tool_output_tokens set to 0
  • Local tests: tests/trajectory_replay, tests/test_resource_accounting.py, tests/environments/test_webarena_topology.py and tests/test_golden_reports.py gave 2262 passed, 5 skipped.
  • Lint: both gates pass.

@lexmount-ocr lexmount-ocr 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.

ℹ️ Review skipped · ef21e85

No reviewable content was selected for this run.

@lanyue-llk lanyue-llk left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Independent review, round 3

Reviewed head ef21e85d against base d894600d. main has not moved. I found no correctness, behaviour or rule defects in the production code. There is one test-coverage finding (P3). It is not a regression, because the base commit had no such tests either.

Findings

P3: four recorded or exposed behaviours in the shared code still have no test

I applied each mutation below on its own and ran tests/trajectory_replay, tests/test_resource_accounting.py and tests/environments/test_webarena_topology.py. All four survived.

Location Mutation Effect if shipped
src/harness/trajectory_replay/core/docker_runner.py:340 (ground_truth_validation) Remove human_review or source_commit from the key list Run manifests lose that provenance, and both reports read this block
src/harness/trajectory_replay/core/docker_runner.py:206 (start_fixture_server) directory=str(root) becomes directory="." The server, bound to 0.0.0.0, serves the working directory instead of the fixtures
src/harness/trajectory_replay/public_webarena/runner.py:373 (_run_task) "process_validation": process_check becomes {} Public attempt rows lose the field result_audit.py and the report read. The same mutation in the curated runner fails a test
src/harness/trajectory_replay/core/executor.py:13 (body_text) Remove [:limit] max_chars stops limiting navigate and snapshot output, which changes the recorded output volume

Fix:

  • Assert the exact returned dictionary from ground_truth_validation, and None for no evidence.
  • In test_fixture_server_keeps_the_host_alias_origin, fetch a file from tmp_path through the server.
  • Assert process_validation on a public _run_task row.
  • Assert that body_text truncates to limit.

The other survivors I do not consider worth a test: the progress line fields, fixture server shutdown calls, container.reload(), the warm-up wait_until value, and two judge_outputs mutations that only change the recorded actual value or are equivalent on string outputs.

What I verified

  • Moved helpers: AST comparison against both base copies, allowing only for the rename, is identical for _encoding, http_origin, resource_result, write_run_artifacts, _QuietFixtureHandler, body_text, actionability_probe, judge_outputs and validate_outputs. I compared the rest by reading the diff: reset_browser_state and its JavaScript, open_task_page, process_validation (same boolean result and key order), attempt_identity, manifest_task, docker_environment (same images key order with build_source added last), start_engine (same call order) and materialize_task. materialize_task now keeps evaluator, environment and trajectory on curated tasks, but the curated runner and its manifest do not use them, so no output changes.
  • Real browser: I ran both tracks' _prepare_page, the origin recorder and the fixture server in locally installed headless Chrome, using two origins. Cookies and localStorage were cleared for both origins, the page ended on about:blank with the expected viewport (1280x900 curated, 1280x720 public), and the fixture server served bytes and stopped. This did not use the benchmark browser images or Docker, and no full run_evaluation ran.
  • Scope of Closes #201:
    • catalog_runner.py has no private imports left.
    • No function or class is AST-identical across the track modules.
    • Same-named functions remaining in both tracks are _reset_state, _prepare_page, _run_task, run_evaluation and execute_steps, and each differs for a stated reason.
    • The curated track is not retired.
  • PR description: I confirmed the audit correction, the 12 curated actions, the extra public actions set and the task viewports.
  • Frozen bindings: the base-commit SHA-256 of runner.py, executor.py, their public counterparts, catalog_runner.py, remote_execution.py and public_webarena/evaluators.py matches nothing tracked in the repository. No path references bind those files outside tests. The self-hash in remote_execution.py is as the PR describes.
  • Stale references: no removed names remain. The _http_origin in playwright_tool.py is a separate function with a different return type, and the _run_task string in test_webarena_review.py is a traceback fixture.
  • Tests: both lint gates pass. tests/trajectory_replay, tests/test_resource_accounting.py, tests/environments/test_webarena_topology.py and tests/test_golden_reports.py give 2262 passed, 5 skipped. Golden snapshots are unchanged. I did not run the rest of tests/ locally.
  • CI on ef21e85d: all checks pass, including Tests and static checks, Installation and packaging, and Rendered reference and report checks.

@lanyue-llk

Copy link
Copy Markdown
Contributor Author

Review round 3: the one P3 finding is fixed with tests only; nothing is disputed. No production code changed.

  • ground_truth_validation: exact returned dictionary, with undeclared keys dropped and missing keys as None, and None without evidence (b11b905).
  • body_text: truncates to limit and passes the timeout (eb58b19).
  • start_fixture_server: test_fixture_server_keeps_the_host_alias_origin now fetches a file from the fixture root through the server (9773895).
  • Public _run_task: exact process_validation on the row (e8d66da).

I reapplied each mutation from the finding (removing human_review, removing source_commit, directory=".", process_validation: {}, removing [:limit]). Each one now fails exactly one test.

Local run: tests/trajectory_replay, tests/test_resource_accounting.py, tests/environments/test_webarena_topology.py and tests/test_golden_reports.py gave 2265 passed, 5 skipped. Golden route hashes are unchanged and ruff is clean. Linux CI is the full-suite gate for this head.

@lexmount-ocr lexmount-ocr 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.

ℹ️ Review skipped · e8d66da

No reviewable content was selected for this run.

@lanyue-llk lanyue-llk left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Independent review, round 4

Head reviewed: e8d66dab. CI on this head fails, and one of the two failures comes from this PR.

Findings

P0: tests/environments/test_webarena_topology.py:295: the new fixture server fetch breaks the UTF-8 guard, so CI is red

  • Problem: commit 97738957 added with direct.open(url, timeout=5). tests/test_explicit_utf8_io.py::test_every_text_read_and_write_names_its_encoding treats a .open call on a name outside OTHER_OPENERS as a text open with no encoding. CI reports tests/environments/test_webarena_topology.py: 1 as a new violation, which fails "Tests and static checks" and "Python 3.11". It also fails locally on this head. The test is not in the known local failures, and the targeted suite does not include it, so the targeted run did not show this.
  • Fix: rename the variable to opener on lines 293 and 295. opener is already in OTHER_OPENERS, and the call is a binary HTTP read, so no exemption is needed. I tried this rename in my review worktree: tests/test_explicit_utf8_io.py and tests/environments/test_webarena_topology.py gave 97 passed. I did not push it.

P3: src/harness/trajectory_replay/core/docker_runner.py:296: some recorded evidence and cleanup in the shared code still has no test

Not a regression, and it should not block merge once the P0 is fixed. I ran 36 one-at-a-time mutations against tests/trajectory_replay, tests/test_resource_accounting.py and tests/environments/test_webarena_topology.py. 16 survived. These are the ones worth pinning, because both tracks now depend on one copy:

  • docker_environment (line 296): removing or blanking runner_platform, docker_cpus or cgroup_version, and the exit N, no output and unavailable: ... version fallbacks.
  • write_run_artifacts (line 363): dropping ensure_ascii=False changes the bytes of attempts.jsonl, and so its recorded hash, for non-ASCII tasks.
  • stop_fixture_server (line 220): removing shutdown, server_close or join each survives. test_fixture_server_keeps_the_host_alias_origin stops the server by hand instead of calling this helper.
  • start_engine (line 284): removing container.reload() survives, although published_endpoint reads the container's ports straight after it.

Fix: assert the exact docker_environment dictionary, including both fallbacks. Write a non-ASCII row and check the bytes. Call stop_fixture_server in the fixture test and assert that the thread has stopped and the socket is closed. Assert in the _start_engine helper test that reload runs before published_endpoint.

The other survivors I would leave alone: the print_attempt_progress fields, the warm-up wait_until, the 500-character probe text limit, and daemon=True. Replacing isinstance(expected, str) and actual == expected with actual == expected makes no practical difference, because actual is always a string.

CI on e8d66dab

Check Result
Tests and static checks fail: 2 failed, 19798 passed, 157 skipped
Python 3.11 (aggregate) fail, because of the check above
Installation and packaging pass
Rendered reference and report checks pass
  • test_every_text_read_and_write_names_its_encoding: caused by this PR (the P0 above).
  • tests/test_native_cdp_port.py::test_port_check_ignores_the_log_of_an_earlier_attempt: DID NOT RAISE RuntimeError. This looks like an existing timing race and not an effect of this PR, though I did not reproduce it. The PR does not touch harness/web_fetch or this test, and the test does not import replay code. The stubbed handshake can return before the fake server exits, so a loaded runner can see the server as still alive. It passed 5 of 5 local runs, and CI passed on the earlier heads fa9fa03b, 0aaabda6 and ef21e85d. If it fails again after the P0 fix, it needs its own issue.

Verified, no defects found

  • Helper swaps: I compared the old and new code in both tracks. Row key order, process_validation results, the reset sequence, engine start order, the fixture server, artifact bytes and the public build_source addition all match.
  • Two differences, neither affects results:
    • Curated materialize_task now keeps evaluator, environment and trajectory through dataclasses.replace, where the old code dropped them. The curated _run_task and manifest do not read those fields.
    • ENGINE_IMAGES[engine] is now read before the network is created. This only matters for an unknown engine, which fails either way.
  • Scope of Closes #201: complete.
    • An AST comparison finds no identical function or class left between the track runners or between the track executors. The same-named _prepare_page, _reset_state, _run_task, run_evaluation and execute_steps all differ.
    • catalog_runner.py imports no private names from remote_execution.
    • The track executors do not re-export the moved helpers, and no references to the removed names remain. _http_origin in playwright_tool.py is a separate function with a different return type.
  • Hash bindings: cohort_reference_hashes does not list the track runners or executors, so moving code out of them removes nothing from that binding. remote_execution.py does change, and its hash is compared only within a run.
  • Local runs on this head:
    • Both lint gates pass.
    • tests/trajectory_replay, tests/test_resource_accounting.py, tests/environments/test_webarena_topology.py and tests/test_golden_reports.py: 2265 passed, 5 skipped.
    • Golden route hashes are unchanged, and the PR changes no snapshots.

Not verified: these checks use mocks only, and no real browser or Docker container ran. I did not rerun the author's base-commit comparison. The mutation sweep ran the targeted suite, not the whole of tests/.

PR description

The test plan still says 2262 passed and does not mention the round 3 tests. Please update it when pushing the fix.

@lexmount-ocr lexmount-ocr 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.

ℹ️ Review skipped · 3dd9d56

No reviewable content was selected for this run.

@lanyue-llk

Copy link
Copy Markdown
Contributor Author

Review round 4 fixes, head 3dd9d56. Nothing disputed.

  • P0, encoding guard failure: a4cf4b3 renames the variable in test_webarena_topology.py to opener, which the guard already allows. No exemption was needed.
  • P3, untested evidence and cleanup: 3dd9d56 adds tests for:
    • the exact docker_environment dictionary, including both browser version fallbacks
    • the exact non-ASCII bytes and hashes from write_run_artifacts
    • stop_fixture_server, which must wait for the thread and close the socket
    • container.reload() running before published_endpoint

Each of 13 one-at-a-time mutations of these behaviours made a test fail (one-off script, not committed). These were only the mutations listed in the finding, not the other survivors from the review's run of 36.

The PR test plan is updated: 2329 passed, 5 skipped on the targeted suite, with route-hash snapshots unchanged. CI on this head is still running.

@lanyue-llk lanyue-llk left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Independent review, round 5

Head reviewed: 3dd9d56c. No defects found. I checked out this head in a fresh worktree and did not push anything.

CI

All checks pass on this head: "Tests and static checks", "Installation and packaging", "Rendered reference and report checks" and "Python 3.11". This includes tests/test_explicit_utf8_io.py, which failed in round 4. tests/test_native_cdp_port.py::test_port_check_ignores_the_log_of_an_earlier_attempt, the possible timing race from round 4, also passed in CI, so no follow-up issue is needed for now.

What I verified

  • Local gates: both lint gates pass. tests/trajectory_replay, tests/test_resource_accounting.py, tests/environments/test_webarena_topology.py, tests/test_explicit_utf8_io.py and tests/test_golden_reports.py gave 2329 passed, 5 skipped, which matches the test plan. The PR changes no route-hash snapshot and nothing under evaluation/, configs/ or research/. It does not touch .github/.
  • Base: main is still d894600d, so the PR is current.
  • Round 4 fixes: the opener rename is in place, and the guard passes with no exemption. The new tests for the environment receipt, artifact bytes, fixture server shutdown and container.reload() order assert exact values.
  • Old and new code, read line by line:
    • Reset, page replacement, engine start, the fixture server, resource results, attempt rows, process validation, progress output, the environment receipt, manifest tasks and artifact writing all match the base commit in behaviour and key order.
    • process_validation gives the same passed value as the old expression, including for an empty trace.
    • _run_task never rebinds page, so moving the origin listener out of its closure changes nothing.
    • image=ENGINE_IMAGES[engine] is now evaluated before the network is created, not after. That only matters for an unknown engine, and it then creates less to clean up.
  • materialize_task: this is the one place the shared code differs from the old curated copy. dataclasses.replace keeps evaluator, environment and trajectory, which the old curated copy dropped. Curated load_suite never sets those fields, and the curated runner and executor never read them, so curated results do not change.
  • Scope of Closes #201:
    • catalog_runner.py imports no private names from any module.
    • An AST comparison of both track runners, both track executors, remote_execution.py and the core modules found no remaining identical function bodies, and no identical statements of 5 lines or more.
    • The behaviour left in each track matches the table in the PR description, as far as the track diffs show it. I did not recount the execute_steps actions.
  • Removed names: the old private helpers have no remaining references. _http_origin in playwright_tool.py is a separate helper with different behaviour, and _run_task still exists in each track's runner. The remote_execution.py traceback string in test_webarena_review.py is test data. There are no re-exports or compatibility aliases.
  • Frozen bindings: none of the base SHA-256 values of the changed runner, executor, evaluator, catalog_runner.py or remote_execution.py files appears anywhere in the base tree. No file under evaluation/, configs/ or research/ names those files. cohort_reference_hashes only compares values within one run, and webarena_results.py does not read the runner or remote_execution keys.
  • Mutations: I ran 14 new one-at-a-time mutations against the targeted suite (not all of tests/), and 12 made a test fail. Neither survivor is worth a test:
    • judge_outputs without isinstance(expected, str) behaves the same, because actual is always a string.
    • print_attempt_progress choosing the first error line instead of the last only affects console progress, not recorded evidence.
  • PR text: no attribution lines in the commits or PR body, Closes #201 is justified, and the test plan numbers match my run.

Limits

This review used mocks only, as the author's tests do. No real browser or Docker container ran. I did not repeat the author's byte-for-byte comparison against the base commit; I compared the code by reading it and with the AST check instead. I did not run the rest of tests/ locally, so CI is the gate for it.

lanyue-llk added a commit that referenced this pull request Nov 4, 2026
@lanyue-llk
lanyue-llk force-pushed the refactor/trajectory-replay-shared-executor branch from 3dd9d56 to 02059d8 Compare November 4, 2026 01:36

@lexmount-ocr lexmount-ocr 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.

✅ Review complete · 02059d8

No findings in this review.

@lanyue-llk
lanyue-llk merged commit 4bb926b into main Nov 4, 2026
7 checks passed
@lanyue-llk
lanyue-llk deleted the refactor/trajectory-replay-shared-executor branch November 4, 2026 01:46
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.

Share Trajectory Replay executor and runner code between tracks

1 participant