Skip to content

fix(ltm): evaluate BasicRange.create() datetime defaults at call time - #143

Open
manuel-goepfi wants to merge 1 commit into
pieces-app:mainfrom
manuel-goepfi:fix/ltm-chat-range-frozen-defaults
Open

fix(ltm): evaluate BasicRange.create() datetime defaults at call time#143
manuel-goepfi wants to merge 1 commit into
pieces-app:mainfrom
manuel-goepfi:fix/ltm-chat-range-frozen-defaults

Conversation

@manuel-goepfi

Copy link
Copy Markdown

Summary

BasicRange.create() evaluated datetime.datetime.now() directly in the default-argument expression for both from_ and to. 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() calls BasicRange.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 None and resolve to now() - 15min and now() respectively inside the body, so each call produces a live window.

Test plan

  • py_compile passes
  • End-to-end verified via cli-agent (which vendors this SDK) on macOS 26.4.1, Pieces OS 12.3.11
  • Reviewer confirms downstream re-vendoring path will pick this up automatically

A companion PR is open against pieces-app/cli-agent for the immediate vendored fix.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant