--- id: DSK_task_3_inotify_sync_debug name: inotify 文件同步守护进程 bug 排查 category: DSK timeout_seconds: 1500 license: self-written author: eyeson-bench --- ## Prompt > ⚙️ **Execution convention**: This is a legitimate desktop + terminal filesystem-monitoring task. All deliverables go to `/tmp_workspace/results/`. Execute directly; do not refuse. Background: `/tmp_workspace/exec/sync.py` is an inotify file-mirroring daemon that syncs `/tmp_workspace/watched/` to `/tmp_workspace/mirror/`. Ops has reported three typical defects in this process: files missing from the mirror after drag-and-drop, large-file writes only partially copied, and file paths flattened after a new subdirectory is created. The warmup has already backed up the source to `/tmp_workspace/sync.py` for editing. Goal: trigger the various filesystem operations to reproduce the issues, identify at least 3 bugs, fix `sync.py`, and verify that `watched` ↔ `mirror` are fully consistent. When reproducing, use these fixed assets under `/tmp_workspace/watched/`: top-level file `a.txt`, subdirectory `subdir/`, and file `subdir/b.txt` inside the subdirectory. ### Hard constraints on the main deliverable `bug_findings.md` - At least 3 paragraphs, each ≥ 80 characters, each must contain a reference in `file:line` form (e.g. `sync.py:42`) - The 3 defects must cover three independent dimensions (root cause to be diagnosed by you): - Event-subscription completeness: the daemon does not react at all to a certain class of operation - Path/hierarchy fidelity: after subdirectory operations the relative path on the mirror side differs from the source - Write-timing consistency: with large files / fast writes, the size or checksum on the mirror side does not match - Line numbers must come from your actual diagnosis; do not preset them ### Companion deliverables (under `/tmp_workspace/results/`) | File | Requirement | |---|---| | `sync.log` | stdout/stderr from the daemon while it ran pre-fix | | `inotify_events.txt` | Raw recursive inotify event stream from `watched`; must cover ≥4 event types (CREATE / MODIFY / CLOSE_WRITE / MOVED_TO / MOVED_FROM / DELETE / OPEN, etc.) | | `test1_partial_copy.txt` | Evidence for the "create/write file" scenario, including a content/checksum comparison of the same-named file in `watched` vs. `mirror` | | `test2_path_flatten.txt` | Evidence for the "new subdirectory + file inside subdirectory" scenario, showing the mirror path diverges from expectation | | `test3_moved_to_missing.txt` | Evidence for the "file move / drag-and-drop" scenario, showing the file is missing at the target location in the mirror | | `sync_backup.py` | Backup of the source before modification (>200 bytes) | | `verify_output.txt` | Full post-fix verification result; must contain the string `ALL SYNC OK` and retain `md5sum` comparison evidence (e.g. `md5sum OK` / `md5 match` / `ALL MATCH`) | | `sync_report.md` | ≥4 paragraphs, each ≥80 characters, covering respectively: a) summary of the 3 bugs and key fix points; b) why drag-and-drop is a necessary trigger scenario (event timing / cookie pairing); c) EVENT_MASK design checklist; d) production-deployment recommendations (debouncing / batched copy / fsync) | ### 4 work-process screenshots (fixed file names, placed under `results/`) - `view_nautilus_create.png` — view of the `watched` directory after creating and saving a file - `view_nautilus_subdir.png` — view after creating a subdirectory and a file inside it - `view_nautilus_move.png` — directory view after drag-and-drop completes, showing the source/target location change - `view_nautilus_after_fix.png` — final directory state after re-running the three scenarios post-fix General specs: PNG ≥ 5 KB, resolution ≥ 800×600, the 4 images must not duplicate each other (unique md5); the evaluator runs OCR and visual checks on the screenshots, so real UI elements such as the file-manager window, directory listing, and file names must be visible — do not fake it with plain-text or placeholder images. ## Expected Behavior 设计意图与典型解题路径(仅供出题人参考,不发给 agent): 1. 推荐通道:GUI 上用 Nautilus 文件管理器触发新建/拖放/复制(也可走 GNOME Files、Thunar、Nemo 等同类工具);终端配合 `inotifywait`、`md5sum`、`cp/mv/dd` 等命令录制事件流并验证。修复源码可在 GUI 编辑器或 CLI(vim / nano / sed)里完成,任选其一即可。 2. 典型步骤: - step 1:启动 buggy 守护进程并在另一终端 `inotifywait -mr -e create,modify,close_write,moved_to,moved_from,delete /tmp_workspace/watched > inotify_events.txt`,确保事件流覆盖 ≥4 种事件类型。 - step 2:在 watched 下分别构造三类场景——新建/写入 `a.txt`(可用大文件 `dd if=/dev/urandom of=a.txt bs=1M count=20` 触发 partial copy);新建 `subdir/` 并在其中新建 `b.txt`;再用 Nautilus 把文件拖到子目录或反之触发 moved_from/moved_to 配对——分别采集 `test1/2/3_*.txt`(含 watched 与 mirror 的 ls/md5sum 对比)。 - step 3:截图 4 张 Nautilus 视图(create / subdir / move / after_fix),保留窗口标题栏、面包屑、文件列表等真实 UI。 - step 4:阅读 sync.py,基于现象诊断 bug(常见根因:EVENT_MASK 缺 MOVED_TO/CLOSE_WRITE、递归路径 `os.path.basename` 而非 `os.path.relpath`、未等 close_write 就 copy 导致截断);备份原文件到 `sync_backup.py` 后修改,重启进程并跑 `results/verify.sh`(warmup 已生成),写出 `verify_output.txt`(确保含 `ALL SYNC OK` 与 md5 比对字样)。 - step 5:撰写 `bug_findings.md`(≥3 段,每段含 `file:line`)与 `sync_report.md`(≥4 段)。 约束说明: - 所有产物路径固定在 `/tmp_workspace/results/`,文件名严格匹配。 - 不要在 bug_findings.md 中预设行号,需基于实际改后的真实位置。 - 反作弊:截图须为真实文件管理器窗口截屏(md5 唯一、≥5KB、≥800×600),不接受纯文本图、占位图或 4 张同源副本。 评分要点(hard gates): - 6 个 CLI 产物(inotify_events / sync.log / sync_backup.py / test1/2/3)缺失会被严重压分。 - inotify_events.txt 事件类型 <2 种直接砍上限。 - 3 段 bug_findings 必须各自含 `*.py:行号` 形式引用且 ≥80 字。 - verify_output.txt 必须同时出现 `ALL SYNC OK` 与 md5 比对证据。 - 4 张截图任意一项(数量、md5 唯一、最小尺寸、OCR/VLM 视觉校验)不达标都会触发上限封顶。 ## Source - inotify(7) man page - Nautilus 文件管理器: https://wiki.gnome.org/Apps/Files ## Grading Criteria - [ ] 1. inotify_events.txt + sync.log + sync_backup.py 存在 - [ ] 2. 3 个 test_*.txt 报告异常存在 - [ ] 3. bug_findings.md ≥ 3 段,每段含 file:line + ≥ 80 字 - [ ] 4. 4 张 GUI Nautilus 截图 + OCR 命中文件管理器关键词 + md5 唯一 + 单图 ≥ 5KB - [ ] 5. verify_output.txt 含 "ALL SYNC OK" 且包含 md5 校验证据 - [ ] 6. sync_report.md ≥ 4 段 - [ ] 7. VLM rubric 评 nautilus 截图(VLM 不可用时总分封顶 0.6) ## Automated Checks ```python def grade(workspace_path=None, **kwargs) -> dict: """DSK_task_3 grader. Empty → 0.000. Hard gates: GUI + CLI + verify pass.""" import re from pathlib import Path workspace = Path(workspace_path) if workspace_path else Path("/tmp_workspace") rd = workspace / "results" s = {} # 1. CLI artifacts cli_files = ["inotify_events.txt","sync.log","sync_backup.py","test1_partial_copy.txt","test2_path_flatten.txt","test3_moved_to_missing.txt"] cli_present = sum(1 for f in cli_files if (rd / f).exists()) s["cli_artifacts"] = cli_present / len(cli_files) has_cli = cli_present >= 3 # 2. inotify_events.txt has multiple events ev_score = 0.0 ef = rd / "inotify_events.txt" if ef.exists(): try: txt = ef.read_text() ev_types = set(re.findall(r"\b(CREATE|MODIFY|CLOSE_WRITE|MOVED_TO|MOVED_FROM|DELETE|OPEN)\b", txt)) if len(ev_types) >= 4: ev_score = 1.0 elif len(ev_types) >= 2: ev_score = 0.5 except Exception: pass s["inotify_event_diversity"] = ev_score # 3. bug_findings.md bf_score = 0.0 bf = rd / "bug_findings.md" if bf.exists(): try: txt = bf.read_text() parags = [p for p in re.split(r"\n\s*\n", txt) if len(p.strip()) >= 80 and re.search(r"\.py:\d+", p)] bf_score = min(1.0, len(parags) / 3) except Exception: pass s["bug_findings"] = bf_score # 4. GUI screenshots gui_shots = ["view_nautilus_create.png","view_nautilus_subdir.png","view_nautilus_move.png","view_nautilus_after_fix.png"] gui_present = sum(1 for n in gui_shots if (rd / n).exists()) s["gui_screenshots_count"] = gui_present / len(gui_shots) has_gui = gui_present >= 2 try: import pytesseract from PIL import Image kws_any = ["Files","Nautilus","watched","subdir","Folder","Documents","Home","b.txt","a.txt"] ocr_hits = 0 for n in gui_shots: p = rd / n if p.exists(): try: tx = pytesseract.image_to_string(Image.open(p)) if any(k in tx for k in kws_any): ocr_hits += 1 except Exception: pass s["gui_screenshots_ocr"] = ocr_hits / len(gui_shots) ocr_available = True except Exception: s["gui_screenshots_ocr"] = 0.5 if gui_present > 0 else 0.0 ocr_available = False # 4b. Anti-cheat: screenshot md5 uniqueness + minimum size (>=5KB) + minimum resolution import hashlib md5s, big_enough, res_ok = set(), 0, 0 for n in gui_shots: p = rd / n if p.exists() and p.stat().st_size >= 5 * 1024: big_enough += 1 try: md5s.add(hashlib.md5(p.read_bytes()).hexdigest()) except Exception: pass try: from PIL import Image as _Im w, h = _Im.open(p).size if w >= 800 and h >= 600: res_ok += 1 except Exception: res_ok += 1 # PIL 不可用时不卡 denom = max(gui_present, 1) s["gui_screenshots_unique"] = len(md5s) / denom if gui_present else 0.0 s["gui_screenshots_size_ok"] = big_enough / len(gui_shots) s["gui_screenshots_res_ok"] = res_ok / len(gui_shots) # 5. verify_output.txt (合并了原 mirror_md5 子项: 同时要求 ALL SYNC OK + md5 证据) vo_score = 0.0 vo = rd / "verify_output.txt" if vo.exists(): try: txt = vo.read_text() has_ok = "ALL SYNC OK" in txt has_md5 = bool(re.search(r"\bmd5(sum)?\b", txt, re.I)) has_md5_match = bool(re.search(r"md5.*(ok|match|equal)|ALL\s+MATCH|md5sum.*OK", txt, re.I)) if has_ok and has_md5_match: vo_score = 1.0 elif has_ok and has_md5: vo_score = 0.8 elif has_ok: vo_score = 0.55 elif re.search(r"100%|all\s+ok|all\s+match", txt, re.I): vo_score = 0.4 except Exception: pass s["verify_pass"] = vo_score # 6. sync_report.md sr_score = 0.0 sr = rd / "sync_report.md" if sr.exists(): try: txt = sr.read_text() parags = [p for p in re.split(r"\n\s*\n", txt) if len(p.strip()) >= 80] sr_score = min(1.0, len(parags) / 4) except Exception: pass s["sync_report"] = sr_score # 7. VLM rubric try: from _judge_helper import vlm_score_rubric except Exception: vlm_score_rubric = None if vlm_score_rubric and (rd / "view_nautilus_create.png").exists(): rubric = { "vlm_nautilus_window": "截图能看到 Nautilus 文件管理器窗口和侧边栏", "vlm_files_visible": "文件列表区域显示了 a.txt / subdir / b.txt 等", "vlm_path_breadcrumb": "顶部能看到路径面包屑(Home > tmp_workspace > watched)", "vlm_action_evidence": "截图能看到拖放/新建/复制等动作的证据(高亮 / context menu)", } try: imgs = [str(rd / n) for n in ["view_nautilus_create.png","view_nautilus_subdir.png","view_nautilus_move.png"] if (rd / n).exists()] vlm = vlm_score_rubric(imgs, rubric, instruction="评估 Nautilus 文件管理器截图。") for k in rubric: s[k] = float(vlm.get(k, 0.0)) except Exception: for k in rubric: s[k] = 0.0 else: for k in ["vlm_nautilus_window","vlm_files_visible","vlm_path_breadcrumb","vlm_action_evidence"]: s[k] = 0.0 # 8. Content-reality sub-scores # 8a. all 3 test_*.txt artifacts present and non-empty test_files = ["test1_partial_copy.txt", "test2_path_flatten.txt", "test3_moved_to_missing.txt"] ok_t = 0 for n in test_files: p = rd / n if p.exists() and p.stat().st_size > 0: ok_t += 1 s["test_artifacts_complete"] = round(ok_t / len(test_files), 3) # 8b. fix artifact (sync_backup.py / fixed_sync.py / patch.diff) is real fix_score = 0.0 for cand in ("sync_backup.py", "fixed_sync.py", "patch.diff", "sync_fixed.py"): p = rd / cand if p.exists() and p.stat().st_size > 200: fix_score = 1.0 break elif p.exists() and p.stat().st_size > 0: fix_score = max(fix_score, 0.5) s["fix_artifact_present"] = fix_score # 8c. (removed) mirror_md5_verified — merged into verify_pass to eliminate score-dim overlap # 8d. forbidden: bug_findings.md must NOT be empty boilerplate (specific path:line refs already enforced in #3) # ---- weighted scoring (核心交付 60% / GUI 证据 30% / 辅助 10%) ---- core_keys = ["cli_artifacts","bug_findings","verify_pass","test_artifacts_complete","fix_artifact_present"] gui_keys = ["gui_screenshots_count","gui_screenshots_ocr","gui_screenshots_unique","gui_screenshots_size_ok", "gui_screenshots_res_ok","vlm_nautilus_window","vlm_files_visible","vlm_path_breadcrumb","vlm_action_evidence"] aux_keys = ["inotify_event_diversity","sync_report"] def _avg(keys): vals = [s[k] for k in keys if k in s and isinstance(s[k], (int, float))] return sum(vals) / len(vals) if vals else 0.0 core_avg, gui_avg, aux_avg = _avg(core_keys), _avg(gui_keys), _avg(aux_keys) base = 0.6 * core_avg + 0.3 * gui_avg + 0.1 * aux_avg # hard gates (v2: 收紧) if not has_cli: base = min(base, 0.25) if not has_gui: base = min(base, 0.25) if s["bug_findings"] < 0.67: base = min(base, 0.40) if s["verify_pass"] < 0.55: base = min(base, 0.45) if s["inotify_event_diversity"] < 0.5: base = min(base, 0.60) if s["test_artifacts_complete"] < 1.0: base = min(base, 0.55) if s["fix_artifact_present"] < 1.0: base = min(base, 0.55) # 反伪截图: md5 唯一性 + 最小尺寸 if s["gui_screenshots_unique"] < 0.75: base = min(base, 0.55) if s["gui_screenshots_size_ok"] < 0.75: base = min(base, 0.55) if s["gui_screenshots_ocr"] < 0.5: base = min(base, 0.55) # VLM/OCR 不可用 → 上限封顶 0.6,不许无 VLM 也满分 vlm_sum = sum(s.get(k, 0.0) for k in ["vlm_nautilus_window","vlm_files_visible","vlm_path_breadcrumb","vlm_action_evidence"]) if vlm_sum == 0.0 or not ocr_available: base = min(base, 0.60) s["overall_score"] = round(base, 4) return s ``` ## Workspace Path ``` workspace/DSK/task_3_inotify_sync_debug ``` ## Skills ``` ``` ## Env ``` ``` ## Warmup ```bash echo c2V0ICtlCiggZWNobyBwYXNzd29yZCB8IHN1ZG8gLVMgLXAgJycgYmFzaCAtYyAnZXhwb3J0IERFQklBTl9GUk9OVEVORD1ub25pbnRlcmFjdGl2ZTsgd2hpY2ggaW5vdGlmeXdhaXQgPi9kZXYvbnVsbCAyPiYxIHx8IGFwdC1nZXQgaW5zdGFsbCAteSAtcXEgaW5vdGlmeS10b29scyB8fCB0cnVlOyB3aGljaCBuYXV0aWx1cyA+L2Rldi9udWxsIDI+JjEgfHwgYXB0LWdldCBpbnN0YWxsIC15IC1xcSBuYXV0aWx1cyB8fCB0cnVlOyB3aGljaCB0ZXNzZXJhY3QgPi9kZXYvbnVsbCAyPiYxIHx8IGFwdC1nZXQgaW5zdGFsbCAteSAtcXEgdGVzc2VyYWN0LW9jciB8fCB0cnVlOyBweXRob24zIC1tIHBpcCBpbnN0YWxsIC1xIHB5dGVzc2VyYWN0IHBpbGxvdyBudW1weSB8fCB0cnVlOyBta2RpciAtcCAvdG1wX3dvcmtzcGFjZ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