Skip to content

feat(webfetch): add reproducible Codex CLI modes - #310

Open
Maisiqi wants to merge 10 commits into
mainfrom
codex/webfetch-codex-cli
Open

Maisiqi wants to merge 10 commits into
mainfrom
codex/webfetch-codex-cli

Conversation

@Maisiqi

@Maisiqi Maisiqi commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Add two Codex CLI Web Fetch methods to the shared runner. Both score the native web tool output with the existing Web Fetch scorer and retain the raw CLI and session evidence. The comparison measures one open of the supplied URL versus continuation within the opened page.

flowchart LR
    Dataset["Web Fetch task"] --> Session["Codex CLI conversation"]
    Session --> Single["One native open"]
    Session --> Same["Native open and same-page ranges"]
    Single --> Evidence["Tool output and raw evidence"]
    Same --> Evidence
    Evidence --> Scorer["Shared Web Fetch scorer"]
    Scorer --> Report["Offline rescore and HTML report"]
Loading

Reproduce

Set CODEX_API_KEY in the repository .env using an API project with Luna and live web access. Install the version declared for the selected method in the provider config. Use the Web Fetch guide to export content-scopes-530 with its reference assets. Choose a fresh output directory for each invocation.

dataset=/path/to/export/dataset.json
method=codex-single
out="$HOME/webstone-$method"

uv run --frozen webstone run \
  --dataset "$dataset" --provider-config configs/providers.example.json \
  --providers "$method" --runs 1 --timeout 300 --max-failure-retries 0 \
  --content-scope full --score-scope full --no-report --output "$out"

uv run --frozen webstone rescore "$out" \
  --dataset "$dataset" --content-scope full --score-scope full --no-report

uv run --frozen webstone report "$out" --language zh

Repeat with method=codex-same-page and its configured CLI version. Each invocation starts a fresh conversation and resumes it for later tasks. Both modes use Luna, medium reasoning, live web, high context and long tool returns.

Verification

  • 149 focused tests passed, including the capability-catalog tests that failed on the original head. Ruff lint and formatting checks passed.
  • Both methods ran a synthetic case through the shared run, offline rescore and HTML report commands.
  • Replayed 530 saved attempts per mode. The updated continuation rule found two additional same-page acquisition violations caused by reopening the original URL. Historical results and scorer code are unchanged.
  • The historical pilot used signed-in Codex. The current runner binds API-key authentication and CLI version in the result metadata. Live acquisition with the new credential setup remains unverified.

Historical report correction

  • Rebuilt the 530-task comparison locally. The report lists the recorded CLI versions, run dates, 300-second budgets, and zero caller retries.
  • Verified 1,060 launches and 1,401 native long-return calls. The timing table uses the measured population of 530 single-open calls and 529 same-page calls.
  • The shared scorer receives the title explicitly returned for the requested page by the initial native open. The numbered body and task rules retain their original bytes. Offline replay covered all 140 title-bearing candidates and changed three same-page verdicts. The score moves from 81/530 to 84/530. Single open remains 52/530. The revision added zero provider calls.
  • The report shows failures by stage and outcomes by deliverable. Paired controls cover an owned title and a foreign title. The local build passed the source and rendering checks against the saved evidence.

@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 · dcba368

This review found 2 issue(s), including 2 blocking issue(s).

@Maisiqi Maisiqi 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.

Conditional pass on f0161fe7. I reviewed the full diff from 997a228e, followed both modes through the shared runner, scorer and report, and checked both OCR threads against the original implementation.

  • P2, fixed. The open parser matched object-key patterns inside quoted URL strings. The valid URL in the OCR thread failed on the original head and passes with string-aware tokenization.
  • P2, fixed. The timeout finding reproduced before a complete thread event. The adapter now preserves exact stdout, session and stderr bytes for incomplete records and returns a failed attempt. A real subprocess timeout and both regression cases passed.
  • P1, fixed. Both registered profiles lacked capability and source records. This omitted their evidence links and failed two existing CI tests. Both modes now share a complete catalog entry and those tests pass.
  • P2, fixed. The old same-page validator admitted reopening the original URL, and usage could be attributed to the following case after a missing counter. Replaying 1,060 historical attempts found two additional same-page acquisition violations. The change preserves historical evidence and the scorer.
  • P2, fixed. The original run inherited local account state and did not enforce the documented CLI version. The adapter uses the repository credential, isolates the CLI runtime, and checks and records the selected version. The PR body now documents the workflow and includes a diagram. The PR timeline contains no linked issue to close.

149 focused tests and both synthetic run, rescore and report paths passed. Live acquisition with the repository API key is still unverified.

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

✅ Re-review complete · f0161fe

No findings in this incremental review.

@lanyue-llk lanyue-llk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review:建议修改后再合并

范围:已阅读 PR 描述、完整 diff、codex.py 全文、测试,并对照 AGENTS.md、CONTRIBUTING.md 和 provider-contract。未 checkout 运行代码。CI 全绿,以下问题均为设计和契约层面,CI 看不到。

P1:影响结果可信度

  1. 两个对比方法使用不同 CLI 版本。 codex-single 为 0.171.0-alpha.13,codex-same-page 为 0.169.1。PR 目的是对比"打开一次"与"页内续读",版本不同引入混杂变量,且固定在 alpha 版本上。建议统一版本;若必须不同,请说明原因及如何排除版本影响。
  2. reported_version 记录的是配置的期望版本,不是实际观察到的版本。 codex.py 写的是 f"codex-cli {self.expected_version}",版本只在 validate() 检查一次,之后二进制被替换证据仍写期望值。建议 validate() 保存实际输出并写入 metadata。authentication="api_key" 同理,现为写死字符串。
  3. live 路径未验证。 适配器依赖 Codex 内部细节:tools.web__run 的 JS 形态、exec 工具名、rollout 路径 sessions/**/*-{thread}.jsonl、模型名 gpt-6-luna,全部只用合成 fixture 测过。合并前请用真实 API 跑至少一次单题 smoke 并贴结果。

P2:设计与根因

  1. 用正则解析模型生成的 JS 源码是脆弱点。 OPEN_CALL/OPEN_TOKENS 把 JS 对象字面量转成 JSON,OCR 指出的 URL 误替换问题是靠再加一层 tokenization 修补,没有消除根因。web_search 事件或 rollout 里是否已有结构化的 open 参数?若有,直接读结构化字段,_open_entries 可整体删除;若没有,可否让 prompt 要求严格 JSON?
  2. same-page 的"同页"判定过宽。 targets 累积所有 results 里的 ref_id,未区分本页引用与外链引用,模型可能续读其他页面仍被判合规。测试 fixture 每次只返回一个 view{i},覆盖不到。请确认 Codex 的 ref 语义,并补"外链 ref 续读判违规"的用例。
  3. parse_returns 把契约校验、迭代、内容投影放在一个函数里,valid_open 是嵌套三元加六个 and。建议抽出 _valid_open(entries, url, first, targets);zip(..., strict=False) 在前面已断言等长,可去掉。
  4. fetch() 约 55 行混了五件事(session 读取、状态机、用量差分、原始证据打包、metadata)。建议把证据和 metadata 拆成 _evidence(...)。
  5. except (ValueError, KeyError, TypeError, AttributeError, OSError) 过宽。 parse_returns 内的编码 bug 会被伪装成 codex_evidence_error 写进评测结果,污染统计。建议只捕获数据解析相关异常。
  6. mode 字符串散落在三处分支(__init__、_prompt、parse_returns),且 config["mode"] 缺失是裸 KeyError。建议用 MODES = {"single": 1, "same-page": None}(最大打开次数)之类的数据驱动。
  7. validate() 有副作用:把 API key 写入 self.env。 若调用方未调用 validate(),key 缺失会得到难懂的 CLI 认证错误。建议 key 在 __init__/_run 读取,validate() 只做检查。
  8. 魔法数字。 cancellation_cleanup_seconds 返回 3,同文件已导入 PROCESS_EXIT_GRACE_SECONDS,应复用。模型名、reasoning、context_size 是否应进入 provider 配置?

P3:仓库规范与格式

  1. CONTRIBUTING 要求 setup/usage 变更同步 Chinese README,本 PR 新增 CODEX_API_KEY 与两个 provider,但文件列表没有 docs/README.zh-CN.md。请确认是否需要。
  2. provider-contract "Add an adapter" 第 3 步为"Assign its output contract in methods.py",本 PR 只改了 report-methods.json。请确认流程或文档是否需要更新。
  3. 在 README 末尾新增 47 行,含两段近似的命令块,PR 正文又重复一遍;同页续读缺 rescore 步骤,与单次模式不一致。建议合并为一个参数化块(method=codex-single|codex-same-page),PR 正文只放链接。
  4. 小格式:PROVIDER_TYPES 中 codex_cli 插在 brightdata_unlocker 之前,破坏字母序;providers.example.json 新增两行为单行,周围是多行;report-methods.json 两个方法的 profile.description 与 interface.params 文案重复。
  5. PR 元信息:标题格式正确,有 Purpose、复现命令和图;但没有关联 issue,缺少"为什么做这个对比"的动机(CONTRIBUTING 要求评测发现挂在 Task/sub-issue 下)。作者在自己的 PR 上发的 "Conditional pass" 不算独立评审,其条件(live 验证)也尚未落实。

信息完整性

能看清:做什么、怎么复现、测了什么。看不清:要解决的问题与动机;历史 pilot 的数据和代码在哪(PR 提到重放 530 个样本,但输入不在仓库,无法复核);"两个额外违规"具体是哪两个样本;登录账号与 API key 两种认证对结果的影响,以及新旧结果是否可比。

回退与遗漏风险

  • 本 PR 只新增(0 删除),对现有 provider 回退风险低。
  • 网页注入:子进程里模型可被页面内容诱导调用 functions.exec,目前靠 sandbox_mode="read-only" 与 shell_environment_policy.inherit="none" 兜底,但 HOME 被透传,read-only 沙箱仍可读文件,请评估。
  • 证据泄密:原始 stdout/session/stderr 完整存入 metadata,provider-contract 要求凭据不得进入 metadata/日志。请确认 CLI 的 stderr 与 rollout 不会回显 key,并补断言测试。
  • TemporaryDirectory 无显式清理,只靠 GC。

想请作者回答

  1. 两个方法版本为何不同,结论如何排除版本混杂?
  2. Codex 的 web_search 事件或 rollout 是否有结构化的 open 参数,可以不解析 JS?
  3. results 里的 ref_id 能否区分本页引用与外链引用?same-page 约束如何保证?
  4. _project_blocks 里的 【\d+†…】 与 [Button: …] 清洗,是否与现有 native answer projection 重复,能否复用?
  5. 若 rollout 文件在进程退出后才完整落盘,_session_chunk 的读取时机会不会丢记录?
  6. 同一线程 resume 时,上一题上下文会影响下一题的打开行为吗?"每题一次"是否被对话历史污染?
  7. 这两个方法与历史 pilot 结果的可比性边界是什么,报告里是否需要标注?

建议的最小修改顺序

统一版本或说明理由(1)→ 记录真实版本(2)→ 跑一次真实 smoke(3)→ 抽 _valid_open、收窄 except、validate() 去副作用(6/8/10)→ 补外链 ref 测试(5)→ 其余格式与文档项一并处理(P3)。

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

⚠️ Re-review complete · 36c073f

This review found 1 issue(s), including 1 blocking issue(s).

Comment thread src/harness/web_fetch/report.py Resolved
@Maisiqi

Maisiqi commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Reviewed llk’s review and the OCR timing finding against the saved traces and the current adapter. The fixes are in 8a87d4ce.

  • Run configuration (1–3, 10–11). The two historical CLI versions remain recorded as observed. The example now pins a shared CLI version for future pairs. Preflight records the actual version output, pins the resolved executable, and rejects a file change before launch. Credentials are read from the repository and passed only to the invocation; metadata describes the configured auth mode. The three-second caller cleanup window and the process exit grace have different jobs. The compared model and tool settings remain fixed. The repository has no CODEX_API_KEY configured, so the real API path remains unverified. That smoke test is a merge-validation gap and does not require rerunning the historical cohort.
  • Open protocol (4–6, 8–9). The recorded continuation events often omit structured request parameters, so parsing the original request remains necessary. New prompts ask for strict JSON, which the adapter parses without rewriting JS object keys. It verifies that the event lists agree, each action matches the permitted open, and continuation references and returned text belong to the requested page. A mixed-source fixture reproduces and now rejects the previously admitted reference. Configuration errors identify the missing mode. Malformed capture data is handled separately from unexpected parser errors.
  • Lifecycle and logs (7 and follow-up questions). Evidence packaging is separate from request interpretation. The CLI process uses an isolated home, and the exact configured credential is scrubbed from retained diagnostics and score-bearing text. Tests exercise that boundary. Read-only isolation governs file access and the temporary home isolates lookup and account state. The conversation directory is owned by the provider for the life of the run. The runner waits for the CLI to exit before reading the captured session, and the existing partial-record tests cover cancellation. The Codex display markers have no equivalent in the shared native field extraction code.
  • Docs and PR information (12–16). Updated the Chinese setup link, corrected the catalog owner in the provider guide, and consolidated the two reproduction commands and offline rescoring. The provider registry has no global alphabetical order, so it was kept intact. Both profile and parameter descriptions serve existing report views. The PR explains the comparison and distinguishes historical observations from the new API-key execution path. There is no existing linked issue. The prior author comment is an implementation verification note.
  • OCR timing. The home table shows measured calls out of total saved calls when durations are missing. A two-call fixture now shows 1/2 or 0/2, and the latency statistics use measured durations only.

The offline historical audit checked 16 of 136 passing results using the saved tool outputs and accepted task scope, including all eight with unavailable identity metadata. The raw open evidence identified the requested page in all 16, and the selected content checks yielded no additional confirmed rejection. The complete same-page capture contains 333 owned continuation targets and two repeated direct opens. Those are webfetch--document-02 (published pass) and dynamic-content--dynamic-043-en-stable-grommet-table (published fail). It contains no observed foreign-page continuation. The repeated open on the PDF is an exception to the historical protocol and should be accounted for before using the historical saved pass total as a strict-mode result. The archived report is a record of the saved judgments. No new provider calls were made.

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

⚠️ Re-review complete · 8a87d4c

This review found 1 issue(s), including 1 blocking issue(s).

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

✅ Re-review complete · aa05c9b

No findings in this incremental review.

@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 · 634c0c1

No reviewable content was selected for this run.

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

⚠️ Re-review complete · a07434d

This review found 1 issue(s), including 1 blocking issue(s).

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

⚠️ Re-review complete · 993f8d6

This review found 1 issue(s), including 1 blocking issue(s).

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

⚠️ Re-review complete · bedee08

This review found 1 issue(s), including 1 blocking issue(s).

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

⚠️ Re-review complete · 697b714

This review found 1 issue(s), including 1 blocking issue(s).

trailing = blob[marker.end() :]
if trailing and canonical.endswith(trailing):
payload = json.loads(json.loads(blob)["content"][0]["text"])
result = payload.get("result")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

bug · medium
Validate that payload is a dictionary before calling .get(). A valid non-object HTTP JSON response (for example, an array containing a long string) can remain valid JSON after middle truncation. In that case this line raises AttributeError, which is not caught here, by parse_returns, or by the Codex caller. This bypasses the intended empty-output failure and prevents diagnostic evidence from being attached. Guard the decoded root type and add a regression test for a parseable, middle-truncated array/string response.

@lanyue-llk

lanyue-llk commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Review @ 697b714(对照最新 main 997a228)

验收要求:PR 提供的 runner 能让其他用户只用仓库代码、配置和自己的 .env,跑完整个评测流程,并生成一份类似 https://yours.lexmount.cn/artifact-site/s/6_Lttwo6wnCH 的报告,不依赖作者会话里的上下文。

实测结论:基本满足

我用一个假的 codex 可执行文件(按 Codex --json 事件流和 CODEX_HOME/sessions rollout 的格式输出)走了一遍 README 里的公开命令:

webstone run --providers codex-single,codex-same-page ... --no-report
webstone rescore ...
webstone report ... --language zh
  • codex-single / codex-same-page 在同一次运行里都完成了调用,原生标题在采集阶段就写进了 page_information.title,不需要事后修订;
  • rescore 和 report 正常完成,生成的报告结构和发布的那份一致:总榜、分榜、耗时、方法版本、环境与复现等页面都有;
  • 160 个相关测试通过(test_codex_fetch_modes、test_local_revision、test_saved_matrix_*)。

codex-lexmount-auto 需要真实的 MCP 工具调用,假二进制覆盖不到,我只看了单测(bridge 只发一次 POST /v1/extract、截断和超大响应的处理)。

P1 文档里没有生成三方法对比报告的命令

README L1828 和 PR 描述的做法是:每个方法单独运行、各用一个输出目录、各出一份报告。这样只能得到三份单方法报告。要把分开的运行合成对比报告,得走 --saved-matrix 加手写 spec,这正是外部用户做不到的那一步。

把三个方法放进同一次 --providers 运行就能直接出对比报告(上面已实测),但 configs/providers.example.json 里 codex-lexmount-auto 锁的是 0.171.0-alpha.13,另外两个锁的是 0.169.1。PATH 上只有一个 codex,所以同一次运行里总有一个方法过不了版本预检。

要求:在 README 里给出生成三方法对比报告的完整命令,包括怎样装两个版本(npm i -g @openai/codex@<version>,或装到两个前缀下),以及在配置里给每个方法设置对应的 executable;或者把三个方法统一到同一个 CLI 版本。

非阻塞说明

  • 普通的 webstone run 产出的报告会标「诊断运行 · 非正式评测」。要发布带排名的正式报告,按 src/harness/web_fetch/README.md:125 应该走 scripts/run_certified_benchmark.py。
  • 完整参考文本需要 lexbench-webfetch export --source <approved-input-directory>。这是仓库层面已有的数据授权限制,不是本 PR 引入的。

@lanyue-llk

Copy link
Copy Markdown
Contributor

这个 PR 开在仓库按 docs/spec.md 重构之前,现在需要 rebase,改动对应到新结构如下(详见 #336):

之前那条审查意见(没有提供三方法对比报告的命令)由 compose 解决了。

This branch has not been deployed

No deployments
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.

2 participants