A result spec written right after launch can get an mtime below `launched_ns` and be rejected as stale
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start by tracing launched_ns through start_session, the artifact freshness checks in devcontract, and SignalWatcher.wait_for in adapters/generic.py and probe.py; compare the artifact checks with hook-event replay filters. Review the launch paths and existing session snapshot logic, then inspect tests/test_stories_e2e.py and the regression cases listed in the issue. Done means post-launch artifacts qualify under a distinct freshness rule while pre-launch terminal specs and hook events remain rejected.
由索引模型根据 Issue 内容生成。
描述
Summary
launched_ns is taken from time.time_ns() at session launch, and the result-artifact freshness checks compare a file's st_mtime_ns against it (mtime >= launched_ns). On the hosts measured below, a file written after time.time_ns() was read can still get an mtime below that reading, by up to about 20 ms. A session that writes its result spec within that window can have the spec rejected as stale-mtime or no-artifact.
With the scripted fake CLI in tests/test_stories_e2e.py, the observed sequence was:
- resultless Stop;
- the fake's window dies after its
sleep 30, and the session is recordedcrashed; - a retry that needs a rollback;
- with auto-rollback off,
rollback-manual-requiredandrun-paused.
bmad-loop run then exits 0 (RunPaused is caught), with the story's spec on disk saying done and no story commit. A real CLI hitting the same rejection could instead stall, time out, or later produce an artifact that qualifies; that was not observed.
Environment
- WSL2, Ubuntu 24.04, kernel 5.15.167.4-microsoft-standard-WSL2 (
CONFIG_HZ=100,CONFIG_NO_HZ_IDLE=y), ext4 root filesystem, a native clone (not/mnt/c). - tmux 3.4, distro Python 3.12.3.
- bmad-loop
mainat a4375bba.
Repro
python -m pytest -n 2 -p no:cacheprovider tests/test_stories_e2e.py in that clone: 4 of 4 file runs failed (2, 3, 2 and 7 failures). Ten different tests were hit, among them test_e2e_two_story_happy_path and test_e2e_sweep_intent_gap_patch_restore. Alone, each passes.
Clock check:
import os, tempfile, time
p = os.path.join(tempfile.mkdtemp(), "f")
neg = worst = 0
for _ in range(5000):
t = time.time_ns()
with open(p, "w") as f:
f.write("x")
m = os.stat(p).st_mtime_ns
if m < t:
neg += 1
worst = max(worst, t - m)
print(f"{neg} of 5000 below time_ns(); worst {worst / 1e6:.1f} ms")
Measured:
- WSL2 (ext4): 4998 of 5000, worst 19.9 ms.
- Native Windows 11 (NTFS, Python 3.13.2, where
time.time_ns()usesGetSystemTimePreciseAsFileTime): 3088 of 5000, worst 3.6 ms.
Native Linux was not measured.
Evidence
- Every failing test's task dir has
resultless-stops.jsonl, with verdictstale-mtime(.../stories/2-slug.md predates session launch) orno-artifact(no result artifact newer than session launch directly under: .../implementation-artifacts). Passing tests have none. - In one failing run, the fake CLI stamped its SessionStart event with
date +%s%N=...148.300279456before writing the spec, yet the spec'sst_mtimeis...148.289336126, 11 ms earlier. - Two-story run journal:
- story 1
story-done; - story 2
session-end crashed (resultless_verdict: stale-mtime), thendev-decision retry,rollback-manual-requiredandrun-paused.
HEAD holds only story 1's commit, and the paused run's tmux session stays alive.
- story 1
- A/B: with the floor lowered to the filesystem's own clock (
log_file.touch(); launched_ns = min(launched_ns, log_file.stat().st_mtime_ns)instart_session), the same file passed 72/72 in 3 of 3 runs, in about 60 s instead of 117–301 s. That one-line change also moves the hook-event floor, so it is a confirmation, not a proposed fix.
Likely cause
The floor mixes two clock sources. On Linux, inode timestamps are normally taken from the kernel's coarse clock, which advances per tick (10 ms at HZ=100). time.time_ns() reads the precise clock. A write less than about a tick after the launch reading can therefore be stamped earlier than it. Why the measured lag (19.9 ms) exceeds one 10 ms tick was not established.
Some Linux filesystems can use fine-grained timestamps (multigrain), so how much this applies depends on the kernel and filesystem. The Windows measurement shows the same symptom; the mechanism there was not investigated.
The fake CLI writes its spec within a few ms of launch, which is why the E2E suite hits this. Real CLIs normally take longer, so in practice the exposure is a very fast session, or a host with coarse timestamps.
Floor consumers
Artifact-freshness checks, which all compare mtime against handle.launched_ns:
devcontract.find_result_artifact,is_result_artifact,find_frontmatter_candidates,is_frontmatter_candidate;- the nested-spec diagnostics (
_nested_spec_hint,find_nested_result_hints, and its unreadable-file path); _DevSynthesisMixin._written_this_session, inherited byGenericDevAdapterandOpencodeDevAdapter.
The opencode HTTP adapter builds its own handle with its own launch stamp.
Hook-event replay filters, SignalWatcher.wait_for(since_ns=...) in adapters/generic.py and probe.py, compare against hook-event wall-clock nanosecond stamps (time.time_ns() in the production hooks, date +%s%N in the E2E fake). They are correct as they are and must keep launched_ns.
Fix direction (open for discussion)
Keep launched_ns for hook-event filtering, and give the artifact checks a separate floor. Options, each with a tradeoff:
- Filesystem-clock floor. Sample an mtime floor from the filesystem immediately before launch, ideally by touching a marker beside the artifact dir, not the session log, since artifact dirs can be rebased into a worktree or configured outside the project. Take the floor as
min(launched_ns, sampled_mtime)and thread it through both launch paths.- Assumes the marker and the artifacts share a filesystem and its clock. Network filesystems that take server timestamps, and backward wall-clock steps, break that.
- Fixed slack (subtract a tick or a few ms). Simpler, but it guesses the granularity.
Both widen admission. Because the checks accept mtime >= floor, an unchanged spec written in the same tick before launch would qualify. The stories path has a launch-snapshot gate against an unchanged done spec, but only for review sessions; a dev leg has no snapshot and relies on the mtime floor alone. Comparing against an attempt-relative content snapshot of the artifacts at launch, like the review gate's digest, would avoid the clock question at the cost of a larger change. It detects changed bytes, not who wrote them, and misses an identical rewrite; an (mtime, size) snapshot would not help, since a same-size rewrite within one tick leaves both unchanged.
Regression tests, none needing timing luck:
- stub
time.time_nsahead of the filesystem clock, and assert a spec written after launch qualifies; - assert an unchanged pre-launch terminal spec with an equal timestamp is still rejected where a snapshot exists;
- assert hook-event replay still rejects pre-launch events.
- 主要语言
- Python
- 星标
- 196
- 派生
- 78
- 平均合并
- 9 小时 24 分钟
- 30 天内合并 PR
- 44
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
bmad-code-org/bmad-loop 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
bmad-code-org/bmad-loop#1063 ·
维护者通常 1 天内回复
-
psmux: task window name starting with '-' creates no window; session reads as crashed可能已有人在做 @RECOHA 于 8 天前认领。 未关闭
难度 1/5 1-3 小时 新手友好度 82/100
bmad-code-org/bmad-loop#1061 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 77/100
bmad-code-org/bmad-loop#1057 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 69/100
bmad-code-org/bmad-loop#973 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
bmad-code-org/bmad-loop#965 ·
维护者通常 1 天内回复
查看 bmad-code-org/bmad-loop 的全部 Issue
相似的 Issue
-
accepted
难度 2/5 1-3 小时 新手友好度 67/100
future-agi/future-agi#5274 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
GenericMappingTools/pygmt#5014 · 1 条评论 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 66/100
w3c/feedvalidator#204 ·
-
[BUG][Low–Medium] founder_numbers.py silently reads a SAFE discount or pool target given as a fraction (0.2) as 0.2%可能已有人在做 @sumitkhond111-del 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 72/100
bmad-code-org/BMAD-METHOD#3358 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 86/100
open-mmlab/mmcv#3352 ·