codex exec --json emits duplicate id keys for web-search items

未关闭 适合新手
#60,992 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
84/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
json, python, rust

调研方向

从 codex-rs/exec/src/exec_events.rs 开始,issue 在这里指向外层项和扁平化的网页搜索负载定义。追踪这些字段的序列化方式,然后按 issue 的要求添加一个拒绝重复键的原始 JSON 序列化测试。完成的标准是每个发出的网页搜索项都有一个明确无歧义的 id,并且测试确认重复键会被拒绝。

由索引模型根据 Issue 内容生成。

描述

bug CLI exec

What issue are you seeing?

codex exec --json emits two different id properties in each web-search item. Parsers that keep the first property identify the item as item_1; parsers that keep the last identify it as ws-1. A duplicate-rejecting parser cannot consume the event.

This is separate from #60990, which concerns an omitted TypeScript field.

Reproduction

Run from the repository root with the Python SDK dependencies and codex on PATH. The Responses API is a local mock; no external web request is made.

import json, os, shutil, subprocess, sys, tempfile
from pathlib import Path

sys.path[:0] = [str(Path("sdk/python/src").resolve()),
                str(Path("sdk/python/tests").resolve())]
from app_server_harness import (
    AppServerHarness, ev_assistant_message, ev_completed,
    ev_response_created, sse,
)

def reject_duplicates(pairs):
    result = {}
    for key, value in pairs:
        if key in result:
            raise ValueError(f"duplicate key: {key}")
        result[key] = value
    return result

with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as tmp:
    with AppServerHarness(Path(tmp)) as harness:
        added = {"type": "response.output_item.added", "item": {
            "type": "web_search_call", "id": "ws-1", "status": "in_progress"}}
        done = {"type": "response.output_item.done", "item": {
            "type": "web_search_call", "id": "ws-1", "status": "completed",
            "action": {"type": "search", "query": "example"}}}
        harness.responses.enqueue_sse(sse([
            ev_response_created("r1"), added, done,
            ev_assistant_message("m1", "Finished."), ev_completed("r1"),
        ]))
        env = dict(os.environ, CODEX_HOME=str(harness.codex_home),
                   CODEX_APP_SERVER_DISABLE_MANAGED_CONFIG="1")
        proc = subprocess.run([
            shutil.which("codex"), "exec", "--json", "--skip-git-repo-check",
            "-c", 'web_search="cached"', "-c", "features.plugins=false",
            "-c", "features.plugin_discovery_prefetch=false", "Example",
        ], cwd=harness.workspace, env=env, capture_output=True, text=True,
           check=True, timeout=15)
        for line in proc.stdout.splitlines():
            event = json.loads(line)
            if event.get("item", {}).get("type") == "web_search":
                print(line)
                try:
                    json.loads(line, object_pairs_hook=reject_duplicates)
                except ValueError as error:
                    print(error)

Observed for the started item (the completed item has the same duplication):

{"type":"item.started","item":{"id":"item_1","type":"web_search","id":"ws-1","query":"","action":{"type":"other"}}}
duplicate key: id

Python's default decoder retains ws-1; a first-wins decoder retains item_1. A separate structurally equivalent Serde deserialization test returned duplicate field id.

Expected behavior

Emit one unambiguous id per item. The outer item flattens a web-search payload that also has an id. Remove the duplicate or give the raw search identifier a distinct field name if both IDs are needed. Add a raw-JSON serialization test that rejects duplicate keys.

Tested with Codex CLI 0.167.0-alpha.4.1, Python 3.14.0, and Windows; source checked at 6bfdc75f0d9e6fae313234f694839866d7c63c39.

主要语言
Rust
星标
135k
派生
21.4k
平均合并
1 分钟
30 天内合并 PR
995

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

openai/codex 的其他 Issue

查看 openai/codex 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。