{"record":{"id":"0835b412e3ecbb81","repo":"mvanhorn/last30days-skill","slug":"save-output-could-not-find-a-unique-filename-afte","errorCode":null,"errorMessage":"save_output: could not find a unique filename after 101 attempts in {path}","messagePattern":"save_output: could not find a unique filename after 101 attempts in (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"skills/last30days/scripts/last30days.py","lineNumber":304,"sourceCode":"                save_root = candidate.parent.resolve()\n                if save_root == Path(library.DEFAULT_MEMORY_DIR).expanduser().resolve():\n                    library_index.sync_library(save_root)\n                else:\n                    # A scoped save must sync a per-directory index with the\n                    # same paths scoped search uses; syncing the shared DB\n                    # from one scope's scan would prune other scopes' rows.\n                    library_index.sync_library(\n                        save_root,\n                        save_root / \"briefings\",\n                        db_path=save_root / \".last30days-library.db\",\n                    )\n            except (library_index.LibrarySearchUnavailable, OSError, sqlite3.DatabaseError):\n                # Saving research must not depend on the optional local index;\n                # `library search` reports a clear capability error on demand.\n                pass\n        return candidate\n    # Fallback: all 101 candidates existed (extremely unlikely).\n    raise RuntimeError(\n        f\"save_output: could not find a unique filename after 101 attempts in {path}\"\n    )\n\n\ndef save_rendered_output(\n    rendered_content: str,\n    output_file: str,\n    *,\n    private: bool = False,\n) -> Path:\n    out_path = Path(output_file).expanduser().resolve()\n    _ensure_output_directory(out_path.parent, private=private)\n    if private and out_path.exists():\n        out_path.chmod(0o600)\n    fd = os.open(\n        out_path,\n        os.O_CREAT | os.O_TRUNC | os.O_WRONLY,\n        0o600 if private else 0o644,","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/mvanhorn/last30days-skill/blob/c7460f6114449ddfe6ea3fc2f23c3d910c0e740c/skills/last30days/scripts/last30days.py#L286-L322","documentation":"save_output() tries up to 101 candidate filenames (stem, stem-date, stem-date-1..99) using exclusive create; if every candidate already exists on disk it raises RuntimeError instead of overwriting a prior report. In practice this means the same topic was saved 101+ times into one directory.","triggerScenarios":"Repeatedly running the same topic on the same date into the same save dir (cron/monitor loop), so stem.md, stem-YYYY-MM-DD.md, and stem-YYYY-MM-DD-1..99.md all exist and os.O_CREAT|os.O_EXCL fails FileExistsError for all 101 candidates.","commonSituations":"A scheduled trend-monitor running many times per day; a retry loop re-saving after partial failures; two concurrent runs racing for the same filenames.","solutions":["Clean or archive old outputs for that topic in the save directory (or point --save-dir at a fresh directory).","Lower run frequency or make the save path unique per run (include hour/minute in the topic slug or save dir).","If overwrite semantics are acceptable, remove the stale dated files before re-running."],"exampleFix":"# before\ncron: every 15 minutes, same save dir\n\n# after\nSAVE_DIR=\"runs/$(date +%Y%m%d-%H%M)\" python3 last30days.py topic --save-dir \"$SAVE_DIR\"","handlingStrategy":"validation","validationCode":"stem_candidates = 1 + 1 + 99  # engine probes at most 101 names per stem/date\nexisting = len(list(save_dir.glob(f'{stem}*')))\nif existing >= 100:\n    raise RuntimeError(f'save dir saturated for stem {stem!r}; archive old outputs first')","typeGuard":null,"tryCatchPattern":"try:\n    path = save_output(content, out_file)\nexcept RuntimeError:\n    out_file = str(Path(out_file).with_name(f\"{Path(out_file).stem}-{os.getpid()}{Path(out_file).suffix}\"))\n    path = save_output(content, out_file)","preventionTips":["Use per-run save directories for scheduled jobs.","Archive or purge old outputs for a topic before high-frequency re-runs."],"tags":["filesystem","save","concurrency","monitoring"],"backgroundTag":null,"analyzedSha":"c7460f6114449ddfe6ea3fc2f23c3d910c0e740c","analyzedAt":"2026-08-15T03:34:49.540Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}