FunctionManager reload can execute stale bytecode after same-size source edits
维护者通常 1 天内回复
评估
调研方向
Issue 指出了 utils/function_manager.py,并提供了一个复现步骤,展示 reload_functions() 后出现过时结果的情况。阅读加载器并运行所述复现步骤以确认故障;预期结果是,重新加载和新建的管理器会执行当前源代码,同时现有的源代码编码、函数筛选以及重新加载时的移除行为仍能正常通过。
由索引模型根据 Issue 内容生成。
描述
FunctionManager.reload_functions() can continue executing a tool's old source after the file has been edited. The dynamic loader accepts a timestamp-based .pyc when the source has the same integer-second mtime and byte length. Two same-length saves within one second can therefore survive an explicit reload.
Reproduced against main a2ea4a263cebe9a7abd01ee3b5b0bf95698ed328 on Windows with Python 3.12.13:
import os
import tempfile
from pathlib import Path
from utils.function_manager import FunctionManager
with tempfile.TemporaryDirectory() as directory:
tool = Path(directory) / "tool.py"
tool.write_text("def value(): return 1\n", encoding="utf-8")
os.utime(tool, (1700000000, 1700000000))
manager = FunctionManager(directory)
assert manager.call_function("value") == 1
tool.write_text("def value(): return 2\n", encoding="utf-8")
os.utime(tool, (1700000000, 1700000000))
manager.reload_functions()
assert manager.call_function("value") == 2 # fails: still returns 1
The fixed timestamp makes the cache collision deterministic; ordinary same-second edits can have the same effect. Creating a new manager also accepts a stale existing bytecode cache.
A focused fix is to execute compiled current source in the module namespace already prepared by module_from_spec, rather than reading the timestamp-based bytecode cache. Three tests against the real module give 2 failed, 1 passed on main and 3 passed with this change; the control checks source encoding, function filtering, and removing a tool on reload. No model/provider calls are involved.
This concerns source freshness, independently of the dataclass/module-registration issue #681 and closed PR #682. Searches for FunctionManager, reload, and bytecode found no matching report or PR. Prepared with Codex assistance; the reproduction and tests were run locally.
- 主要语言
- Python
- 星标
- 34.6k
- 派生
- 4.3k
- 平均合并
- 9 小时 21 分钟
- 30 天内合并 PR
- 1
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
OpenBMB/ChatDev 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 76/100
维护者通常 1 天内回复
-
CodeReviewModification never shows the programmer the six review regulations, so fixes are made blind to the checklist they are re-reviewed against可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 1/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 85/100
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 35/100
维护者通常 1 天内回复
-
FunctionManager silently drops tool modules containing dataclasses with postponed annotations可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 3/5 1-2 天 新手友好度 72/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 86/100
-
Validate finite output clamping limits in StepPredictor.prepare_clamping_params to prevent silent NaN/Inf propagation可能已有人在做 @muskan-creates352 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 84/100
mllam/neural-lam#848 ·
维护者通常 2 天内回复
-
infra
难度 1/5 1 小时以内 新手友好度 88/100
fab-geocommuns/RNB-coeur#1166 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
deepspeedai/DeepSpeed#8951 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
aws/context-ontology-accelerator#343 ·
维护者通常 1 天内回复