From d722935020e32aad65fc59959fd08a456dc757c1 Mon Sep 17 00:00:00 2001 From: Dylan De Faoite Date: Wed, 29 Apr 2026 21:31:39 +0100 Subject: [PATCH] fix(state): ensure files are sorted by timestamp --- rewind/state.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rewind/state.py b/rewind/state.py index f5891a2..35a1012 100644 --- a/rewind/state.py +++ b/rewind/state.py @@ -37,7 +37,7 @@ def write_state(state: dict) -> None: def add_file_to_state(file_path: str) -> None: state = load_state() - files = state.get("files", []) + files = sorted(state.get("files", []), key=lambda f: f["timestamp"]) # Idempotency guard existing_paths = {f["path"] for f in files} @@ -46,7 +46,7 @@ def add_file_to_state(file_path: str) -> None: files.append({ "path": file_path, - "timestamp": datetime.datetime.now().timestamp(), + "timestamp": datetime.datetime.now().timestamp() }) state["files"] = files