From cdfb869e8ab63568c614cbe0998d7e3a96eaaf17 Mon Sep 17 00:00:00 2001 From: Manuel Goepfert Date: Tue, 28 Apr 2026 17:53:24 +0200 Subject: [PATCH] fix(ltm): evaluate BasicRange.create() datetime defaults at call time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `BasicRange.create()` used `datetime.datetime.now()` as the default value of the `to` parameter. Python evaluates default expressions once, at function-definition time, so every call without an explicit `to` received a timestamp frozen to module-import time — i.e. the moment the CLI/TUI process started. `chat_enable_ltm()` calls `BasicRange.create()` with no arguments every time LTM is turned on for a chat, so the chat's temporal range was capped at process-start. Long-running TUI sessions therefore retrieved progressively staler context the longer they stayed open, while the unaffected workstream view kept rendering current data. Fix: default `to` to `None`, resolve to `now()` inside the body so each call gets a live window. Mirrors the existing pattern already used for `from_`. Repro: launch `pieces tui`, wait > 15 min, ask `pieces ask … --ltm` about activity captured in the last few minutes — pre-fix returns no recent context because the chat's range `to` is pinned at TUI startup. --- .../pieces_os_client/wrapper/basic_identifier/range.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pieces/_vendor/pieces_os_client/wrapper/basic_identifier/range.py b/src/pieces/_vendor/pieces_os_client/wrapper/basic_identifier/range.py index cd234256..c7b6897f 100644 --- a/src/pieces/_vendor/pieces_os_client/wrapper/basic_identifier/range.py +++ b/src/pieces/_vendor/pieces_os_client/wrapper/basic_identifier/range.py @@ -66,7 +66,7 @@ def disassociate_chat(self, chat: "BasicChat"): @staticmethod def create( from_: Optional[datetime.datetime] = None, - to: Optional[datetime.datetime] = datetime.datetime.now(), + to: Optional[datetime.datetime] = None, ) -> "BasicRange": """ Creates a new range based on a Range. @@ -82,6 +82,8 @@ def create( from pieces._vendor.pieces_os_client.models.grouped_timestamp import GroupedTimestamp if not from_: from_ = datetime.datetime.now() - datetime.timedelta(minutes=15) + if not to: + to = datetime.datetime.now() r = RangeSnapshot.pieces_client.ranges_api.ranges_create_new_range( SeededRange(