plugin: the agent-output readers crash on a JSON line that is not an object

未关闭
#182 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@rahul05ranjan 已经在做这个了。

开始于 2026年11月9日。

  • #183 来自 @rahul05ranjan —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
python
领域
tooling

调研方向

Read plugin/probe.py (run_session and inspect_session), plugin/sidecall.py (codex_call and copilot_call), and plugin/toolcheck.py (_init_tools); the report names each affected reader and the failure case. Check the regression tests mentioned in the linked pull request, then confirm malformed or non-object JSON lines are skipped while valid events still work. Pull request #183 is already open.

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

描述

What happens

Five readers of agent CLI output parse each line with json.loads and then call .get on the result, without the isinstance(ev, dict) check — the same gap #150 closed for the trace readers (and #181 for the cursor pair):

  • plugin/probe.py run_session — Copilot -p --output-format json stdout: ev.get("type")
  • plugin/probe.py inspect_session — Copilot's own events.jsonl: json.loads(line).get("data") (this one also has no except ValueError, so a partially-written or corrupt line containing "hook.end" crashes before .get is even reached)
  • plugin/sidecall.py codex_call — codex exec --json stdout: ev.get("item")
  • plugin/sidecall.py copilot_call — Copilot -p stdout: ev.get("type")
  • plugin/toolcheck.py _init_tools — claude -p --output-format stream-json stdout: ev.get("type")

A line that is valid JSON but not an object (null, 42, "text", [1, 2]) — or, for inspect_session, any line with the "hook.end" prefilter that does not parse — raises and kills the whole probe / side call / tool check, instead of skipping the one line.

These are external-process streams, same exposure as the transcripts #150 hardened: anything the CLI or a tool it spawns writes to inherited stdout lands line-shaped in these loops.

Repro

>>> # sidecall.codex_call with a stubbed runner whose stdout is:
"null\n{\"type\":\"item.completed\",\"item\":{\"type\":\"agent_message\",\"text\":\"hi\"}}\n"
AttributeError: 'NoneType' object has no attribute 'get'

Fix

The same one-line isinstance(ev, dict) guard after json.loads in the four loops, plus the ValueError catch in inspect_session. I have it with regression tests ready and will open the PR.

主要语言
Python
星标
5.6k
派生
344
平均合并
14 小时 41 分钟
30 天内合并 PR
54

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

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

microsoft/TokenEconomizer 的其他 Issue

查看 microsoft/TokenEconomizer 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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