fix(ltm): evaluate BasicRange.create() datetime defaults at call time#448
Open
manuel-goepfi wants to merge 1 commit intopieces-app:mainfrom
Open
fix(ltm): evaluate BasicRange.create() datetime defaults at call time#448manuel-goepfi wants to merge 1 commit intopieces-app:mainfrom
manuel-goepfi wants to merge 1 commit intopieces-app:mainfrom
Conversation
`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.
3 tasks
mark-at-pieces
approved these changes
Apr 29, 2026
Member
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BasicRange.create()evaluateddatetime.datetime.now()as a default argument, so thetoparameter was frozen at module-import time.chat_enable_ltm()callsBasicRange.create()with no arguments every time LTM is turned on for a chat, so the resulting temporal range capped at process-start. Long-running CLI/TUI sessions retrieved progressively staler context the longer they stayed open, while the unaffected workstream view kept rendering current data.This is the classic Python mutable-default-argument anti-pattern, applied to
datetime.now().Repro
pieces tui.tois pinned at TUI startup).Fix
Default
totoNone, resolve tonow()inside the body. This mirrors the existing pattern already used forfrom_in this same function.Test plan
tovalue now advances with each call instead of staying pinned at TUI launch timeThe vendored copy here at
src/pieces/_vendor/pieces_os_client/wrapper/basic_identifier/range.pyis currently slightly improved over the upstream SDK (onlytois frozen, vs both args in the SDK), so this PR fixes only that one default.