[BUG]: Non-Atomic Gap Log Writes Can Cause Data Loss After an Interrupted Save
维护者通常 1 天内回复
@SYED-IRTEZA-HUSSAIN-RIZVI 已经在做这个了。
开始于 2026年11月9日。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 74/100
调研方向
从 bot.py 中的 _save_gap_log() 和 _load_gap_log() 开始,然后检查项目是否有针对间隔日志持久化的测试。在保存开始后复现写入失败,并验证现有日志仍可读取。当保存失败时保留之前的有效条目,且保存成功时存储更新后的条目,issue 即完成。
由索引模型根据 Issue 内容生成。
描述
Bug Description
The _save_gap_log() function writes directly to gap_log.json using write mode ("w"). Opening the file in this mode truncates its existing contents before the new JSON data has been completely written.
If the process is interrupted, crashes, or encounters a write error during saving, the file may be left with incomplete or invalid JSON. When _load_gap_log() subsequently attempts to read the file, it catches json.JSONDecodeError and returns an empty list.
As a result, previously persisted gap-log entries may become inaccessible after an interrupted or failed save operation.
The save operation should use a safer file-writing strategy, such as writing the updated JSON data to a temporary file in the same directory and replacing the original file with os.replace() only after the temporary write completes successfully. This would help prevent an incomplete write from replacing the existing valid log.
This issue concerns data integrity and potential data loss caused by interrupted, non-atomic file writes. It is separate from the event-loop blocking issue tracked in [#57](https://github.com/AOSSIE-Org/SkillBot/issues/57).
Steps to Reproduce
- Set up SkillBot and ensure that
gap_log.jsonexists and contains valid JSON with multiple entries. - Start the bot and allow
_load_gap_log()to load the existing entries. - Trigger
_save_gap_log()with updated gap-log entries. - Observe that
_save_gap_log()opensgap_log.jsonusing write mode ("w"), which truncates the existing file. - Simulate a write failure after the original file has been truncated and some JSON content has been written. This can be done in a controlled test by mocking the serialization or write operation to raise an exception partway through.
- Inspect
gap_log.jsonand check whether it contains incomplete or invalid JSON. - Invoke
_load_gap_log()again or restart the bot. - Observe that the loader encounters a
json.JSONDecodeErrorand returns an empty list, potentially making the previously stored entries inaccessible.
Logs and Screenshots
No response
Environment Details
- Application: SkillBot Discord Bot
- Repository: AOSSIE-Org/SkillBot
- Operating System: Windows 11
- Python Version: 3.11.3
- Framework: asyncio
- Affected File:
bot.py - Affected Functions:
_save_gap_log()and_load_gap_log() - Affected File:
gap_log.json - Storage Format: JSON
- File Operation: Direct file writing using
open()with"w"mode - Relevant Exception:
json.JSONDecodeError - Affected Component: Persistent gap-log storage and recovery
Impact
Medium - Feature works but has issues
Code of Conduct
- I have joined the Discord server and will post updates there
- I have searched existing issues to avoid duplicates
- 主要语言
- Python
- 星标
- 10
- 派生
- 11
- 平均合并
- 6 分钟
- 30 天内合并 PR
- 4
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
AOSSIE-Org/SkillBot 的其他 Issue
-
[BUG]: Issue-creation intent is missed when the article is omitted (create issue for this)可能已有人在做 @Ankitavasudev 于 8 天前认领。 未关闭bug enhancement
难度 2/5 1-3 小时 新手友好度 82/100
AOSSIE-Org/SkillBot#65 · 2 条评论 ·
维护者通常 1 天内回复
-
[BUG]: os.chdir() Changes the Process-Wide Working Directory During Repository Sync可能已有人在做 @aadityachhipa80-oss 于 2 天前认领。 未关闭bug enhancement
难度 2/5 1-3 小时 新手友好度 75/100
AOSSIE-Org/SkillBot#59 · 3 条评论 ·
维护者通常 1 天内回复
-
[BUG]: wait_for_ollama() Retries Indefinitely When Ollama Is Unavailable可能重新可做 @SYED-IRTEZA-HUSSAIN-RIZVI 于 11 天前认领,目前没有进行中的 PR。 未关闭bug enhancement
难度 2/5 1-3 小时 新手友好度 72/100
AOSSIE-Org/SkillBot#56 · 3 条评论 ·
维护者通常 1 天内回复
-
[BUG]: Backlog Messages Are Re-processed on Discord Reconnection可能重新可做 @SYED-IRTEZA-HUSSAIN-RIZVI 于 11 天前认领,目前没有进行中的 PR。 未关闭bug enhancement
难度 4/5 3-5 天 新手友好度 55/100
AOSSIE-Org/SkillBot#58 · 2 条评论 ·
维护者通常 1 天内回复
-
[BUG]: _log_gap() Performs Blocking File I/O on the Async Event Loop可能已有人在做 @abu-tahir-0 于 13 天前认领。 未关闭bug enhancement
难度 3/5 1-2 天 新手友好度 25/100
AOSSIE-Org/SkillBot#57 · 2 条评论 ·
维护者通常 1 天内回复
查看 AOSSIE-Org/SkillBot 的全部 Issue
相似的 Issue
-
needs-triage
难度 2/5 1-3 小时 新手友好度 78/100
gke-labs/kube-agents#6778 · 1 条评论 ·
维护者通常 1 天内回复
-
Declare the CMS schema library in the optional recipients extra可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭area:python in-progress
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
area/build-framework kind/enhancement priority/low
难度 2/5 1-3 小时 新手友好度 77/100
yugabyte/yugabyte-db#38826 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 73/100
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 72/100
sususweet/midea_auto_cloud#306 ·
维护者通常 9 天内回复