Skip to content

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

Open
manuel-goepfi wants to merge 1 commit intopieces-app:mainfrom
manuel-goepfi:fix/ltm-chat-range-frozen-default
Open

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

Conversation

@manuel-goepfi
Copy link
Copy Markdown

Summary

BasicRange.create() evaluated datetime.datetime.now() as a default argument, so the to parameter was frozen at module-import time. chat_enable_ltm() calls BasicRange.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

  1. Launch pieces tui.
  2. Wait 15+ minutes.
  3. Open a fresh chat, enable LTM, ask about activity captured in the last few minutes.
  4. Pre-fix: no recent context returned (the chat's range to is pinned at TUI startup).
  5. Post-fix: recent context retrieved correctly.

Fix

Default to to None, resolve to now() inside the body. This mirrors the existing pattern already used for from_ in this same function.

Test plan

  • Unit syntax / py_compile of the patched file
  • Local install on macOS 26.4.1 (Pieces OS 12.3.11, CLI 1.20.1) — newest range to value now advances with each call instead of staying pinned at TUI launch time
  • Reviewer confirms the equivalent change is applied (or backported) in pieces-os-client-sdk-for-python — separate PR pending

The vendored copy here at src/pieces/_vendor/pieces_os_client/wrapper/basic_identifier/range.py is currently slightly improved over the upstream SDK (only to is frozen, vs both args in the SDK), so this PR fixes only that one default.

`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.
@mark-at-pieces
Copy link
Copy Markdown
Member

  • might consider a basic unit test, but looking solid

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.

2 participants