Skip to content

fix(livecodebench): support sys.stdout.buffer in output capture - #581

Open
mantuoluozk wants to merge 1 commit into
AISBench:masterfrom
mantuoluozk:fix/livecodebench-stdout-buffer
Open

mantuoluozk wants to merge 1 commit into
AISBench:masterfrom
mantuoluozk:fix/livecodebench-stdout-buffer

Conversation

@mantuoluozk

Copy link
Copy Markdown

Fixes #579.

问题与修复

LiveCodeBench 执行模型生成的 Python 程序时,会用普通 StringIO 替换 sys.stdout。如果程序使用 sys.stdout.buffer.write(...),就会抛出 AttributeError,被判为运行错误。

本 PR 使用由同一个 BytesIO 支撑的 TextIOWrapper 捕获输出。文本写入和二进制写入共享底层流,因此可以保持写入顺序,并正确处理分多次写入的 UTF-8 字符。程序关闭 sys.stdout 后,判题器仍可读取已捕获的输出。

本次只修改 stdout;sys.stdin.buffer 已由 #570 修复。相关的开放 PR 见 #518。

验证

  • 在 AISBench Docker 环境(Python 3.10)运行 LiveCodeBench 单测:132 项通过。
  • 新增回归测试,覆盖二进制输出、文本与二进制混写顺序、UTF-8 分段写入、关闭 stdout,以及 call_method 调用路径。
  • 本地进行精度测试顺利通过。
  • git diff --check 通过。

@github-actions github-actions Bot added the no_review PR 未包含任何检视意见,合入前必须包含检视意见 label Sep 29, 2026
@github-actions

Copy link
Copy Markdown

🚫 PR 合入质量检查未通过,PR 已被禁止合入。

未通过项:no_review

  • 无检视意见:请至少邀请一位 reviewer 提交检视意见(Approve / Request changes / Comment 均可)。

请按上述提示整改后,重新推送(push)或评论本 PR 即可触发再次检查。

from enum import Enum
# for capturing the stdout
from io import BytesIO, StringIO, TextIOWrapper
from io import BytesIO, TextIOWrapper

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

【review】 livecodebench是AISBench集成的第三方测试基准,AISBench没有权利随意更改livecodebench的evaluate的逻辑,同时修改评价逻辑会影响历史所有结果的复现,影响面过大,如果认为livecodebench的评价逻辑有问题请往上游社区提issue和PR https://github.com/livecodebench/livecodebench

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

【review】如果https://github.com/livecodebench/livecodebench 上游社区有相同的issue,欢迎在AISBench仓库做同步修改

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的理解,上游livecodebench上次更新已经是去年了,issue和pr应该也不会有人处理,应该是不会修改了

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no_review PR 未包含任何检视意见,合入前必须包含检视意见

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[疑问] [LiveCodeBench v6] 判题器不支持 sys.stdout.buffer,可能将正确程序判为运行错误

2 participants