feat(pi): add opt-in request capture for relay 400 diagnosis - #98
Open
CtriXin wants to merge 1 commit into
Open
Conversation
mmf-launched Pi intermittently gets a 400 from the relay complaining about a raw control byte inside a JSON string literal. Diagnosis established that the relay accepts every properly escaped payload on all three protocols, that Pi's captured traffic escapes control characters correctly, and that the failing byte values are effectively uniform across the whole byte space. That is random body corruption rather than payload content, and synthetic replays do not reproduce it, so the only way to settle where the bad bytes enter is to record what leaves Pi's socket during a real session. MMS_PI_CAPTURE_PROXY routes the launch's providers through a local recording proxy that forwards bytes verbatim and flags raw control bytes. Default-off: with the variable unset, models.json and the launch environment are untouched. Keep-alive and chunked streaming are preserved so the instrument does not change the transport it observes, and every failure path falls back to a normal launch. Refs #97 Agent-Model: claude-fable-5 Agent-Family: anthropic Agent-Session: 2d6d2047-8869-4b65-9345-349181832167 Agent-Step: 0.1.0 Claude-Session: https://claude.ai/code/session_01VA2vRxuCpZsLmXR8sLeUgG
Digger: no new failures
Digger automatic review. Full packet: Actions artifact |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #97
为什么
mmf 启动的 pi 会间歇性收到上游 400(
invalid character '\xNN' in string literal/400 "Invalid JSON")。这一轮先做了诊断,结论是现有的修复方向是错的:tool_calls.arguments/ tool result 上,/v1/messages与/v1/chat/completions都返回 200openai-completions/openai-responses/anthropic-messages三条路径,含真实\x00\x16\x1b的 tool result 全部被正确转义\t、{、§、Û),是随机字节损坏,不是"内容里有控制字符"也就是说
scripts/pi-retry-extension.mjs里的before_provider_request归一化不可能修好这个问题(JSON.stringify本来就会转义),而且它会改写用户内容里字面的\xNN/\a/\e/\v/\0。回退它另开一轮处理,不叠进本 PR。合成压测复现不出来(大 body、走/不走本地代理、undici 连接池并发、中断流后复用连接,全部 0 失败),所以只能在真实 session 上抓现场。
改了什么
MMS_PI_CAPTURE_PROXY开关,把本次启动的 provider baseUrl 指向本地 recording proxy,原样透传字节并标出原始控制字节。判定规则:
raw_control_bytes非空 → pi 侧缺陷;为空但 4xx → relay 或网络路径。边界
models.json,不加任何 envauth_mode语义、bridge 路由、config schema、HOME/XDG 隔离mms_pi_support.py只加 2 行(import + 调用)验证
py_compile覆盖所有改动的 Python 文件tests/test_pi_capture_proxy.py12 passedtests/test_pi_launcher.py+tests/test_pi_retry_extension.py40 passed--quickPASS;完整 gate 390 passed / 1 failedtest_overlay_web_access_session_entries_merges_session_and_web_access_skill,在干净dev上同样失败,既有红灯,与本改动无关过程中修掉两个自身缺陷:转发用
read(65536)会阻塞 SSE(改read1);抓包记录原本在转发结束后才落盘,挂住就没有证据(改成收到响应头即落盘)。残余风险
抓包目录里的原始 body 是明文完整对话(header 不落盘,避免记录 API key)。仅诊断期开启。
https://claude.ai/code/session_01VA2vRxuCpZsLmXR8sLeUgG