Telos UpdateTelos.ts: two writes to the same file within one second share a backup filename, so the pre-change backup is overwritten
Version
LifeOS v7.40.4 (skills/Telos/Tools/UpdateTelos.ts is identical on main as of 2026-10-20)
What is broken
What happens
getLocalTimestamp() formats the backup name as YYYYMMDD-HHMMSS, which has only one-second resolution. copyFileSync(targetFile, backupPath) then runs without checking whether backupPath already exists. When two calls write the same TELOS file within the same second, both resolve to the same backup name. The second call's backup (which already contains the first edit) overwrites the first call's backup (which held the true pre-change state).
This happens in normal use, not only in tests. --section takes one section per call, so a single logical change that touches two sections of one file needs two back-to-back calls. Adding a strategy is one example: its body goes under "Active Strategies" and its row goes into the mapping table.
Observed output: both calls print the same ✅ Backup created: STRATEGIES-<same timestamp>.md. Only one backup remains, and it already contains the first edit. Both updates.md entries point to that one file.
Expected
Each call keeps its own pre-change backup. At minimum, the backup taken before the first edit of a burst should survive.
Possible fixes (any one)
- Add milliseconds to the backup timestamp, or a counter suffix when
backupPathalready exists - Skip the copy when a backup with that name already exists, so the earliest pre-change snapshot of the burst is kept
- Accept several
--section/content pairs in one call, so one logical change takes one backup
Where (file:line)
skills/Telos/Tools/UpdateTelos.ts
Repro on a clean tree
SB=$(mktemp -d); mkdir -p $SB/.claude/LIFEOS/USER/TELOS
printf '# Strategies\n\n## Active Strategies\n\n### S0: existing\n\n---\n\n## Strategy → Challenge/Goal Mapping\n\n| Strategy | Addresses | Status |\n|---|---|---|\n| S0 | C0 | Active |\n\n---\n' \
> $SB/.claude/LIFEOS/USER/TELOS/STRATEGIES.md
HOME=$SB bun skills/Telos/Tools/UpdateTelos.ts STRATEGIES.md "### S9: test" "add strategy" --section "Active Strategies"
HOME=$SB bun skills/Telos/Tools/UpdateTelos.ts STRATEGIES.md "| S9 | C1 | Active |" "add mapping row" --section "Strategy → Challenge/Goal Mapping"
ls $SB/.claude/LIFEOS/USER/TELOS/Backups # one file, not two
grep -c S9 $SB/.claude/LIFEOS/USER/TELOS/Backups/*.md # 1, but the pre-change file had 0
Negative control
The backup's whole job is to hold the state from before a change, and in this case that state is silently lost. Users who keep TELOS under git can still recover it. Users without git cannot, and the "Backup created" message suggests they are covered.
Suggested fix
No response
Before submitting
- [x] I searched open and closed issues for this defect.
- [x] The repro runs against a clean tree of the version above, not against my modified install.
- [x] I removed personal data from the pasted output — real names, absolute home paths, tokens, my own content.
[!NOTE] 🤖 Kai (AI assistant) responding on behalf of Daniel Miessler
Thanks, this is fixed: takeBackup adds a -N suffix when two backups land in the same second (UpdateTelos.ts).