fix(turn-driver): pin UTF-8 on the Codex session evidence I/O #6709
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.52) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #6709"
general
weight: 0.35
JasonBuildAI
Goal And Delivered Outcome
Path.open()with no codec, and two durable attempt records were written throughos.fdopen()with no codec while their own reader re-reads them as UTF-8 bytes (json.loads(path.read_bytes())). On any host whose default encoding is not UTF-8, the read raises before the native identity is observed, and the Turn then fails closed withCodex did not confirm the expected session identity— a state the class contract deliberately does not repair with a fresh conversation. The shipped UTF-8 file gate could not see either site, because it inspectsread_text()/write_text()/ builtinopen()only.cp936,observe()on an ordinary UTF-8 event stream containing non-ASCII model text raisesUnicodeDecodeError: 'gbk' codec can't decode byte 0x90 ...before the change and returns the observed identity after it (regression_parityandunitrows below).CodexAgentSession.observe()has no caller underloopx/. The production callers arebenchmark/runtime/worker.py:510,benchmark/runtime/checkpoint_wake.py:214, andbenchmark/runtime/checkpoint_session_refresh.py:80— the only production caller ofprepare_checkpoint_refresh. The ordinary Turn path streams events over a pipe (codex_cli.py) and never performs this file read, so the capability this repairs today is the benchmark wake / checkpoint-refresh harness on a non-UTF-8 host. It is worth repairing here because the failing class is shared control-plane code on the host class this repository ships for (windows-powershell,cp936), the failure is post-spend and non-retryable under the class contract, and the gate rule closes the API-class hole for every future caller.Fixes #6708, basemain(110893bca, rebased).Author Declaration
Implemented against
tests/test_loopx_text_io_utf8.py(revision110893bca); the class contract documented inloopx/control_plane/turn_driver/codex_agent_session.py(CodexAgentSessiondocstring: "A native ID must be observed even on timeout; neither missing history nor a failed resume permits a fresh fork").| Criterion (spec clause) | Disposition | Symbol / path | Test or command |
| --- | --- | --- | --- |
| Shipped text file I/O pins UTF-8 explicitly (
tests/test_loopx_text_io_utf8.py) | implemented |tests/test_loopx_text_io_utf8.py(_text_io_calls_without_utf8_encoding) | the extended gate reports no Codex site; its self-check coversos.fdopenmissing/binary/keyword/positional codec shapes || The observed Codex event stream is decoded as the UTF-8 JSONL the CLI writes (
CodexAgentSession.observe) | implemented |loopx/control_plane/turn_driver/codex_agent_session.py|pytest tests/control_plane/test_codex_session_utf8_evidence.py|| A durable attempt record is written with the codec its own reader assumes (
prepare_checkpoint_refresh,_fork_native_checkpoint) | implemented |loopx/control_plane/turn_driver/codex_agent_session.py,loopx/hosts/codex_checkpoint.py| protected by the gate rule: reverting both pins leaves this suite green and makestests/test_loopx_text_io_utf8.pyreportcodex_agent_session.py:173andcodex_checkpoint.py:415. The write is latent rather than reproduced —json.dumpescapes non-ASCII by default, so the record bytes are ASCII even undercp936. |packages/scope the file gate does not scan, and thePath.open()receiver-shape gap the gate cannot decide statically (named under Coverage and gaps).Scope And Continuation
Path.open()receiver-shape gap is documented in the test suite rather than deferred to a new task; the widepackages/inventory is a separate, larger piece of work and is not claimed here.Validation
e1da32c1cb9409ece520e5b8d8265a10338dace9| Check kind | Result | Public-safe evidence / limitation |
| --- | --- | --- |
|
regression_parity|passed| Baseline (same source, fix reverted):UnicodeDecodeError: 'gbk' codec can't decode byte 0x90 in position 50: illegal multibyte sequence, raised fromcodex_agent_session.observeatloopx/control_plane/turn_driver/codex_agent_session.py:96. Head:pytest tests/control_plane/test_codex_session_utf8_evidence.py→ 2 passed. The non-UTF-8 default codec is the reproduced condition; the downstreamRuntimeError: Codex did not confirm the expected session identityis quoted from the class contract incodex_agent_session.py, not independently reproduced on this host. ||
unit|passed|pytest tests/control_plane/test_codex_session_utf8_evidence.py -q→ 2 passed. Both cases drive the shipped owners in a child interpreter with-X utf8=0,LC_ALL=C,PYTHONCOERCECLOCALE=0; the child asserts its own default codec is not UTF-8 and then decodes the exact bytes it writes, so the case cannot pass vacuously. On a host whose codec accepts those bytes (latin-1,cp1251) the child reports it and the case skips with the resolved codec named instead of claiming coverage; the probe was checked againstcp936,ascii,cp1252,cp1250,cp1257,latin-1,cp1251andutf-8. ||
integration|passed|pytest tests/control_plane/test_codex_checkpoint_context_refresh.py tests/test_loopx_turn_driver.py tests/control_plane/test_codex_session_utf8_evidence.py -q→ 126 passed, 2 failed. Both failures reproduce with the diff reverted:test_redirected_original_output_cannot_recover_an_identityneeds symlink privilege on this host, andtest_default_agent_session_reuses_planning_across_completed_todosreads the fake Codex executable as text (Path.read_text()on a binary) before any changed code runs. ||
static|passed|ruff checkon the four changed paths →All checks passed!; the gate's own self-check case (test_guard_reports_missing_and_non_utf8_codecs) passes with the newos.fdopenshapes. ||
integration|passed|pytest tests/test_loopx_text_io_utf8.py -q->2 passedat this head. The 12 pre-existing trajectory-assessment offenders this PR disclosed atcd148933bwere fixed by #6691 (560fc66b9, merged before this head) and the rebased base110893bcacarries them, so the gate is green here with nothing deselected; stripping the pins from the two shipped files in a scratch copy still makes it reportcodex_agent_session.py:173andcodex_checkpoint.py:415.pytest tests/control_plane/test_codex_checkpoint_context_refresh.py tests/test_loopx_turn_driver.py tests/control_plane/test_codex_session_utf8_evidence.py -q->126 passed, 2 failed; both failures reproduce with the diff reverted:test_redirected_original_output_cannot_recover_an_identityneeds symlink privilege on this host, andtest_default_agent_session_reuses_planning_across_completed_todosreads the fake Codex executable as text (Path.read_text()on a binary) before any changed code runs. ||
unit|passed| Review-follow-up heade1da32c1c(rebased onmain110893bca): the same two cases on Linux Python 3.12 (python:3.12-slim, repository mounted at/src) ->2 passed; with onlypath.open(encoding="utf-8")reverted in a scratch copy ->2 failedwithUnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 36from the observe read. The earlier headsa786ed7cband400d7a1cbfailed both cases on that host before importingloopx(Unable to decode the command from the command line), because-ctext is decoded with the ASCII filesystem encoding; the child program now travels on stdin (CPython decodes stdin source as UTF-8) and the fixture's workspace is the filesystem-safetmp_path, while the non-ASCII payload stays in the CLI's UTF-8 event bytes. Windowscp936, focused suite + gate:4 passed. |os.fdopenwrite pins (latent, as above, and guarded only by the gate rule), thepackages/tree the file gate does not scan, andPath.open()receivers whose type cannot be decided statically — the gate still cannot reject that API shape, which is why the regression suite exists next to it. Same-class sites outside this PR's scope, left for their existing owners:trajectory_assessment.py:190/191(fixed by #6691,560fc66b9),benchmark/runtime/worker.py:487and:524(outside the gate'sloopx/scan root), and the test-sidetests/test_loopx_turn_driver.py:1032.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 origin/main --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 and review.