mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 23:44:46 +00:00
Adapts @tynamite's fix from the abandoned #77945 to current main (which moved to replaceFileAtomic after that PR was opened), and adds the docs + changelog updates clawsweeper flagged plus a regression test for the field condition from #80960. When repairSessionFileIfNeeded writes a cleaned transcript, the sibling *.bak-<pid>-<ts> snapshot is deleted after the atomic replace succeeds. It is only retained — and only then reported via backupPath — when the cleanup itself fails. This prevents the unbounded accumulation observed in #80960, where a stuck operations-agent session with a persistently malformed JSONL line caused 2,180 ~1.8 MB backup files to pile up over ~25 hours inside two gateway processes (PIDs 1220 and 2640). Test changes: - Replace requireBackupPath helper with expectNoRetainedBackup that also asserts no .bak-* siblings remain on disk. - Update the four call sites that used to read the retained backup. - Add a regression test that drives repair five times against a file with a recurring malformed tail and asserts zero retained backups. Docs: - docs/reference/transcript-hygiene.md: describe backup as transient, retained only on cleanup failure. Fixes #80960. Supersedes #77945. Co-authored by @tynamite — credit for the original approach. Co-authored-by: tynamite <35367599+tynamite@users.noreply.github.com>