Repository navigation
fix(planning): read the batch-planning CLI as UTF-8 - #9400
Conversation
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh
动机 / Motivation
使用非 UTF-8 主机环境开始批量规划的 benchmark 操作者会遇到这个问题。 准备中文任务时,主干会按宿主编码读错 UTF-8 JSON,任务创建前中止。该提交修好了写入回执的解码,规划入口仍在读取初始状态时中止。 预期是中文规划能生成可继续执行的 Todo。新提交的写入回执保留了中文,实际规划入口在模拟 GBK 时仍失败。 沿用现有规划入口、Goal/Todo 存储和回执格式。
改动思路 / Approach
读包和写入回执都来自同一个 UTF-8 CLI。给同一条规划链上的两个读取点明确编码即可。 apply_initial_plan 先从 todo plan 取得 Goal、输入摘要与版本,然后才调用 CLI 提交要求和 Todo。该提交把后段回执固定为 UTF-8。补齐前段读取即可延续同一条规划路线,无须新增命令、状态或跨版本协议。沿用现有规划入口、Goal/Todo 存储和回执格式。
具体改动 / Changes
关键代码讲解
- CliPlanningBatchBackend._call 现在用 UTF-8 读写入回执。在 head 模拟父进程 GBK,真实子进程写出固定 UTF-8 回执后,中文标题完整;返回码 1 时 PlanningBatchCommandError 保留错误码和中文详情。 当前提交
- task_plan_packet 在同一个外部 CLI 上运行 todo plan,继续依赖父进程默认 codec。规划 worker 在提示模型前已使用这条路径,提交申请时又用它读当前 Goal。 当前提交
- apply_initial_plan 必须从读包建立当前 scope 和版本,后面才会执行 refine 与 add。读包抛错时两步都走不到。 当前提交
按问题验收,RUNTIME-UTF8-GUARD 已实现,RECEIPT-ERROR-PARITY 在合法回执探针中通过,LOCALIZED-PLANNING 尚未满足。 #9399
对主干的风险 / Risks
[P2] 前置规划包仍按宿主编码读取。 同一合成任务含“中文目标”。真实子进程发送合法 UTF-8。模拟父进程 GBK 时,base 和 head 的 apply_initial_plan 都在读取 todo plan 结果时抛出 UnicodeDecodeError,隔离 SQLite 回读仍为零条 Todo。 在 task_plan_packet 读取文本的 subprocess.run 也固定 UTF-8,并用真实中文规划和 SQLite 回读做回归测试。
- PASS · 静态 guard 在基线 e5d5945 为 1 failed / 3 passed,失败定位到这次修改的回执解码点。4362c2a 全部 5 项通过,git diff --check 通过。
- PASS · 父进程使用 UTF-8 时,真实入口返回 ready,SQLite 回读到一条中文 Todo。 同一探针只为 todo plan 加 UTF-8 后,保持父进程 GBK,真实入口也返回 ready 并回读一条中文 Todo。
- FAIL · 保持同一真实 CLI 并模拟父进程 GBK,两个提交均在前段解码失败,零条 Todo。
- UNVERIFIED · 在 macOS 模拟父进程 GBK,实际执行源 CLI 和隔离 SQLite。原生 Windows 和远端 CI 未核验。
我的整体评价 / Verdict
运行时检查已经恢复。要让操作者在原环境里继续中文规划,仍需修复共用的 todo plan 读取点,按同一任务验收到可执行 Todo。当前持久结构与回执足以承载修复。检查的是 CLI 编码和测试,无图形界面改动。 在 macOS 模拟父进程 GBK,实际执行源 CLI 和隔离 SQLite。原生 Windows 和远端 CI 未核验。
English verdict: REQUEST_CHANGES at 4362c2a. The exact head fixes receipt decoding, but the real planning entry still fails on a UTF-8 packet with a GBK parent codec.
4362c2a to
e318405
Compare
|
Re-reviewed at e318405 (rebased onto e5d5945; main has since advanced to 2167578 with no overlap in the changed files). The gap was real. Added Evidence:
LOCALIZED-PLANNING should now be satisfied. PR body/title updated. Note that the diff now touches |
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · reasoning_effort=xhigh
动机 / Motivation
受影响的是在非 UTF-8 主机上用 benchmark runner 开始中文任务规划的操作者。旧版按主机编码读取 UTF-8 规划包,中文输入在创建任何 Todo 前中止。当前提交在模拟 GBK 的父进程下返回 ready,File 和 SQLite 都读回了一条完整的中文 Todo。本次只改读取编码,Windows 原生主机与实际 benchmark 运行未验。 issue-9399
改动思路 / Approach
这次改动的范围是原 batch-planning 流程中两个现有 CLI 读取点。写入回执和前置规划包来自同一个 UTF-8 子进程,两个调用各指定编码即可。保留原来的批次编排、权限检查、回执和写入顺序。全局切换主机编码会改变无关调用,两个消费点的局部修复更直接。
具体改动 / Changes
task_plan_packet在读取todo plan之前不再依赖 Python 父进程的默认编码。这个包确立 Goal、输入摘要和当前 provider 版本,之后才允许提交规划。上一轮缺的 LOCALIZED-PLANNING 项现在通过,前置读取和提交后的读回都使用真实 CLI。 当前提交CliPlanningBatchBackend._call固定写入回执的 UTF-8 读取。非零退出仍命中原PlanningBatchCommandError,中文详情和结构化错误码完整。非法 JSON 仍返回原错误。RUNTIME-UTF8-GUARD 和 RECEIPT-ERROR-PARITY 也有独立对照。 当前提交- 两个测试文件分别覆盖回执消费和规划流程。完整四文件差异 +61/-0,生产变化仅两行编码参数,其他为测试。现有产品
todo plan-batch仍走进程内后端。 测试
对主干的风险 / Risks
- PASS · 两端各运行 10 项隔离对照。模拟 GBK 时,精确基线的两个 provider 均在写入前出错,随后独立读回零条 Todo。新头均进入 ready,读回完整中文。UTF-8 对照在两端通过,非法 JSON 拒绝不变。
- PASS · 当前头两套定向测试共 31 项通过。基线为 27 项通过、1 项 UTF-8 守卫失败。Ruff、diff 和 6 项直接加 17 项所选 premerge 检查均过。该 gate 仍保留 benchmark_sensitive 人工复核,合入须由维护者处理。
- UNVERIFIED · 未查询远端 CI,也未运行物理 Windows。GBK 通过 Python 父进程默认编码模拟,File 和 SQLite 使用真实隔离实例。
我的整体评价 / Verdict
两个生产读取点明确了现有 UTF-8 传输约定。精确基线与新头的原生对照证明,原先中止的中文任务现在可创建并读回待办,错误分流也完整保留。当前改动足以解决 #9399,维护者的 benchmark 合入复核仍适用。
English verdict: APPROVE at e318405. Both CLI reads now use UTF-8. The same localized plan reaches ready and reads back on real File and SQLite under a simulated GBK parent. The benchmark maintainer hold still applies.
CliPlanningBatchBackend._call and task_plan_packet both run the wrapped LoopX CLI with text=True but no explicit codec. On a cp936 host the UTF-8 JSON receipt/packet is decoded as gbk: the reader thread raises UnicodeDecodeError, stdout stays None and json.loads surfaces a raw TypeError. apply_initial_plan reads the todo plan packet before refine and add, so the localized planning stage aborts with zero Todos. Pin UTF-8 on both text-mode reads and cover the initial planning entry with a real Chinese task, real CLI and File/SQLite readback under a simulated GBK parent locale. Signed-off-by: JasonBuildAI <jasonbuildai@gmail.com>
e318405 to
64cbc7f
Compare
Signed-off-by: huangruiteng <huangrt01@163.com>
huangruiteng
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · GPT-5 · OpenAI · self_reported
动机 / Motivation
在 cp936/GBK 等非 UTF-8 主机上运行 benchmark planning 的操作者会遇到这个问题:候选规划和写回回执都是 UTF-8 JSON,但两条子进程读取仍按宿主 locale 解码,中文目标在创建 Todo 前就以 UnicodeDecodeError 或原始 TypeError 中止。
修复前,同一个中文任务在 GBK 父进程下读取 todo plan 或写回 receipt 时得到 stdout=None 并失败;修复后,这两个已知 UTF-8 调用显式指定 encoding="utf-8",初始规划返回 ready,File 与 SQLite 都能回读完整中文 Todo 和 outcome。
可观察结果是模拟 GBK 父进程下 apply_initial_plan 成功,回读的 Todo 文本为 [P0] 统计中文结果。,outcome objective 为原始中文目标;原有非零回执、错误码、错误详情和非法 JSON 处理保持不变。
本 PR 不改变规划协议、Todo 持久格式、provider revision、benchmark 阶段编排或其它子进程调用;物理 Windows 和完整 benchmark stage 环境仍由对应 CI/宿主验收,而不是由这次局部编码修复冒充完成。
改动思路 / Approach
两个读取点都调用已经约定输出 UTF-8 JSON 的 LoopX CLI,因此在现有 subprocess.run(text=True) 上明确编码即可;没有引入新的 transport、解码 helper、持久字段或第二套 planning authority。
当前 PR 只覆盖组成一次 initial planning journey 的前置 todo plan 包和写回 receipt;Goal/Todo 校验、批量提案、错误映射与 File/SQLite 存储继续由原 owner 处理。
调用链分为两段:task_plan_packet 先执行 loopx todo plan,得到 Goal、输入摘要与 provider revision;随后 CliPlanningBatchBackend._call 执行 refine 和 todo add,并解析写回 receipt。两段都已知子进程输出 UTF-8,因此显式 codec 消除了 locale 依赖。apply_initial_plan 仍然从同一个初始包建立当前 scope,不改变任何匹配或写入顺序。
flowchart LR
A[GBK parent process] --> B[todo plan subprocess]
B --> C{encoding=utf-8}
C --> D[Initial packet]
D --> E[Refine/add subprocess]
E --> F{encoding=utf-8}
F --> G[Typed receipt]
G --> H[File or SQLite Todo readback]
上图是当前 head 源码的示意,不是执行收据。最强的反对意见是其它 locale 或未来 CLI 可能不输出 UTF-8,但现有产品 CLI 与 runner 已把 JSON 传输固定为 UTF-8;若要改变这条合同,应在 transport owner 统一修改,而不是让两个调用点重新依赖机器 locale。
具体改动 / Changes
按 #9399 的 revision 2026-11-24T13:51:17Z 核对。runtime-utf8-guard 要求所有 shipped runtime text-mode subprocess 明确 UTF-8;planning-receipt 要求写回 receipt 在 cp936 host 保持中文;localized-planning 要求完整 initial plan 可达 ready 并回读中文;error-parity 要求退出码和错误详情不变。
关键代码讲解
task_plan_packet在现有subprocess.run上增加encoding="utf-8",让前置todo plan包不再由宿主 locale 解码。 精确实现CliPlanningBatchBackend._call对写回 receipt 使用同一 UTF-8 合同,保留原 capture、timeout、JSON 解析和错误分支。 精确实现apply_initial_plan仍通过task_plan_packet建立 scope,再调用现有apply_planning_batch;修复没有改变 proposal digest、Todo 写入或 readback 逻辑。 精确实现
变更共 4 个文件、+61/-0,生产代码仅两行 encoding 关键字,其余为 UTF-8 guard 与 File/SQLite 真实规划回归。没有新增依赖或持久状态。
对主干的风险 / Risks
最强回归风险是把一个实际输出非 UTF-8 的 CLI 误当成 UTF-8 后产生解码失败。触发范围被限制在两个已经由 LoopX 自身发出的 JSON CLI;其它 subprocess 调用没有变化。若未来替换 CLI 合同,应从共享 transport owner 调整 codec,并保持 receipt schema 与错误映射。
本轮运行 combined runtime guard 与完整 benchmark planning-batch suite,31 项通过。独立探针在模拟 GBK 下确认未固定编码的基线抛 UnicodeDecodeError: 'gbk' codec can't decode byte 0xad,而当前 _call 返回 {"ok": true, "title": "中文目标"}。File/SQLite 的真实初始规划、中文 Todo/outcome 回读、非零退出错误详情与非法 JSON 路径均通过。Ruff、4 文件 scoped public-boundary scan 和 standard premerge 的 6 direct checks、9 catalog canaries、8 risk profiles 全部无 failure。
语义与 CI 对齐
Standard premerge 的唯一人工状态是 benchmark_sensitive 维护者复核 hold;本次 exact-head review 已复核变更仅涉及编码读取,未触碰 benchmark 计分、任务语义、runner 选择或权限边界,并且用户本轮明确授权自合并。远端 CI 尚未完成,保持 UNVERIFIED,合并 readiness 单独判断。编码合同复用现有 shipped-runtime UTF-8 guard,没有新增公共 vocabulary。
我的整体评价 / Verdict
长程效果得到改善:非 UTF-8 主机不再在中文任务进入规划前后随机中止,同一个 proposal 能完成写入并形成后续可继续的 Todo。用户旅程保持原命令和无界面交互,只把此前失败的成功路径修复;错误详情和退出码保持原样,视觉检查不适用。
两处一行修复与问题完全匹配,且真实 File/SQLite 证据覆盖了从前置包到 write receipt 的完整链路。没有发现重复的解码框架、额外状态或应该拆分的范围。剩余风险是物理 Windows、真实 benchmark stage 和远端 CI 未在本机完成,但这些不阻断当前 exact-head 的源码语义判断。
English verdict: APPROVE at efea9be. Pin UTF-8 on both known LoopX JSON subprocess reads, preserve typed receipt/error behavior, and allow localized initial planning to complete and read back on File and SQLite.
Goal And Delivered Outcome
On a non-UTF-8 host, the batch-planning entry reads both of its wrapped-CLI JSON payloads with the host locale codec.
CliPlanningBatchBackend._calldecoded the write receipt withlocale.getpreferredencoding(False);task_plan_packetdecoded the initialtodo planpacket the same way.apply_initial_planreads that packet for the Goal, input digest and provider revision before it can refine or add anything, so on a cp936 Windows host a Chinese task aborts with aUnicodeDecodeErrorin the pipe reader, a rawTypeErrorfromjson.loads, and zero Todos. This PR pins UTF-8 on both text-mode reads and proves the full initial planning journey with a real CLI and File/SQLite readback.loopx/control_plane/goals/planning_batch.py:709(CliPlanningBatchBackend._call) andbenchmark/runtime/planning.py:61(task_plan_packet) passtext=Truewithoutencoding; the shipped-runtime guardtests/test_runtime_subprocess_utf8.pyreports theloopxnode, while the wrapped LoopX CLI emits UTF-8 JSON withensure_ascii=False.task_plan_packetkeyword makes the new test fail in both providers atbenchmark/runtime/planning.py:65(TypeError: the JSON object must be str, bytes or bytearray, not NoneType) after the reader thread reportsUnicodeDecodeError: 'gbk' codec can't decode byte 0xad; restoring it makes the Chinese task reachstatus: readywith the Chinese Todo and outcome read back from the isolated File/SQLite authority.Fixes #9399; intended base isloopx-project/loopxmainate5d5945f6, and the branch is rebased onto that head.Author Declaration
Implemented against
tests/test_runtime_subprocess_utf8.py. Its docstring states thatsubprocess.run(..., text=True)withoutencoding=decodes the child withlocale.getpreferredencoding(False)whilegh,gitand the wrapped LoopX CLI all emit UTF-8. No public RFC governs these internal calls.loopxpins UTF-8CliPlanningBatchBackend._calltests/test_runtime_subprocess_utf8.py::test_shipped_runtime_pins_utf8_for_every_text_mode_subprocess_callCliPlanningBatchBackend._calltests/test_runtime_subprocess_utf8.py::test_planning_batch_cli_backend_survives_gbk_host_localetask_plan_packet→apply_initial_plantests/control_plane/test_benchmark_planning_batch.py::test_planning_batch_packet_survives_gbk_parent_locale(File and SQLite)CliPlanningBatchBackend._callgit diff e5d5945f6..HEADruff checkon the changed files,git diff --check, the repository public-boundary scan, andloopx canary premergeat the exact head. The fullpytestsuite was left to CI.Scope And Continuation
encodingkeywords; no successor is needed.Validation
efea9be70311c6cca16c86cc05258139395f3b81main(c82e96141a039d1ab83c0693e8aa274e550d51ff); the combined runtime UTF-8 guard and full benchmark planning-batch suite passed 31 tests. Standard premerge completed 6 direct checks, 9 catalog canaries and 8 risk-profile smokes with 0 failures; its sole manual hold is the declared benchmark-sensitive maintainer-review boundary.regression_paritypassedtask_plan_packetkeyword reverted, the new test fails both providers (2 failed): readerUnicodeDecodeError: 'gbk' codec can't decode byte 0xad, thenTypeErroratbenchmark/runtime/planning.py:65. At head, the guard file plus the new test are7 passed. The counterfactual is the exact removed keyword.unitpasseduv run --extra test python -m pytest tests/test_runtime_subprocess_utf8.py tests/control_plane/test_benchmark_planning_batch.py::test_planning_batch_packet_survives_gbk_parent_locale -q->7 passed.unitpassedtests/control_plane/test_benchmark_planning_batch.pyon this Windows host:10 passed, 16 failedat head vs8 passed, 16 failedat basee5d5945f6with an identical failed set. The failures are this host'sdistlibfixture generation (SameFileError) and empty fixture stdout; they reproduce unchanged without this diff and the affected fixtures execute on CI's Linux runners.staticpassedpython -m ruff check benchmark/runtime/planning.py loopx/control_plane/goals/planning_batch.py tests/control_plane/test_benchmark_planning_batch.py tests/test_runtime_subprocess_utf8.py-> all checks passed;git diff --check e5d5945f6..HEAD-> clean.integrationpasseduv run --extra test loopx canary premerge --from-git-diff --git-diff-base e5d5945f6-> tier standard, changed_files 4, surfaces control_plane/benchmark_sensitive/python, 17 selected checks, failures 0. Statusmanual_review_requiredonly becausebenchmark_sensitiveis an explicit maintainer hold.manualpassedloopx check --scan-path ...on the four changed files -> public boundary scan clean, 4 files. It also reports an unrelated localdemo-goalregistry warning.real_entrypointpassedtask_plan_packetandapply_initial_planthrough the real wrapped CLI and an isolated File/SQLite authority with a Chinese task, reading back one Chinese Todo and the Chinese outcome. The standalonebenchmark.runtime.planning_batchargparse wrapper is not spawned; a live benchmark stage still needs its full environment.unitnot_runpytest; the required Python Tests shard owns it.loopx, and the new test exercises the actual pipe reader andjson.loadspath under the same_text_encodingvalue used whenencodingis omitted, for both File and SQLite authority. Untested locally: the full six-shard CI matrix and a real cp936 host whose Python runs in locale mode (this host runs Python in UTF-8 mode, so the locale path is simulated with the standard-library hook the existing guard tests use).Frontend / Visual Evidence
Type of Change
LoopX Area
Technical Direction
Shared-authority RFC fixture impact
Boundary Checklist
.loopx/,.codex/goals/, and liveACTIVE_GOAL_STATE.md).python3 scripts/check_rfc_bilingual.py --base e5d5945f6 --head HEADpasses, or no paired RFC changed.none.Signed-off-bytrailer (git commit -s).AI disclosure: this change was drafted with AI assistance at my request, under my direction. No human line-by-line review of this diff has taken place.