Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

FunctionManager reload can execute stale bytecode after same-size source edits

未关闭 适合新手
#688 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@jadelike-wine 已经在做这个了。

开始于 2026年10月18日。

  • #689 来自 @jadelike-wine —— 未关闭

评估

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

调研方向

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 模板
  • 没有贡献指南

从这里开始

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

OpenBMB/ChatDev 的其他 Issue

查看 OpenBMB/ChatDev 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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