fix(ltm): evaluate BasicRange.create() datetime defaults at call time - #143
Open
manuel-goepfi wants to merge 1 commit into
Open
fix(ltm): evaluate BasicRange.create() datetime defaults at call time#143manuel-goepfi wants to merge 1 commit into
manuel-goepfi wants to merge 1 commit into
Conversation
Both `from_` and `to` parameters used direct `datetime.datetime.now()` expressions as default values. Python evaluates default expressions once, at function-definition time, so every call without an explicit argument received a timestamp frozen to module-import time. `chat_enable_ltm()` calls `BasicRange.create()` with no arguments to attach a temporal range to a chat. With both defaults frozen at import, every chat got the same fixed window from process startup, regardless of when the user actually enabled LTM. Long-lived clients therefore retrieved progressively staler context. Fix: default both args to `None`, resolve to `now() - 15min` and `now()` respectively inside the body so each call gets a live window.
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()directly in the default-argument expression for bothfrom_andto. Python evaluates default expressions once, at function-definition time, so every call without explicit arguments received a timestamp frozen to module-import time.chat_enable_ltm()callsBasicRange.create()with no arguments to attach a temporal range to a chat. With both defaults frozen at import, every chat received the same fixed window relative to process startup, regardless of when the user actually enabled LTM. Long-lived clients therefore retrieved progressively staler context.This is the classic Python mutable-default-argument anti-pattern.
Fix
Default both parameters to
Noneand resolve tonow() - 15minandnow()respectively inside the body, so each call produces a live window.Test plan
A companion PR is open against
pieces-app/cli-agentfor the immediate vendored fix.