Skip to content

memory2: time windowing on Stream#2315

Merged
leshy merged 2 commits into
mainfrom
feat/ivan/stream-time-windowing
Jun 1, 2026
Merged

memory2: time windowing on Stream#2315
leshy merged 2 commits into
mainfrom
feat/ivan/stream-time-windowing

Conversation

@leshy
Copy link
Copy Markdown
Member

@leshy leshy commented Jun 1, 2026

Adds time-based windowing to Stream - shared base both #2306 (stream alignment) and #2314 (go2dds) need

  • from_time(s) / to_time(s) - relative to the first observation
  • from_timestamp(ts) / to_timestamp(ts) - absolute epoch seconds

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Jun 1, 2026

Greptile Summary

Adds four time-windowing methods to Stream (from_time, to_time, from_timestamp, to_timestamp) that let callers slice a stream by relative duration (anchored to the first observation) or by absolute epoch timestamp. Both None-passthrough and empty-stream edge cases are handled.

  • from_time(s) / to_time(s) eagerly resolve the current stream's first observation at build time, then delegate to the existing after() / before() filters for the computed cutoff.
  • from_timestamp(ts) / to_timestamp(ts) are thin wrappers around after() / before() with no eager evaluation.
  • Nine new tests cover relative, absolute, chained, None-bound, and empty-stream scenarios.

Confidence Score: 5/5

Safe to merge — the new methods are additive, delegate entirely to the established after()/before() filter primitives, and do not touch any existing code paths.

All four methods are thin, well-tested wrappers. The empty-stream guard (catching LookupError from first()) is handled correctly for static and pre-filtered streams. Test coverage is thorough, including chained relative+absolute combinations and boundary conditions.

No files require special attention.

Important Files Changed

Filename Overview
dimos/memory2/stream.py Adds four time-windowing methods with correct empty-stream guard and consistent delegation to existing after()/before() filters; no regressions to existing API.
dimos/memory2/test_stream.py Comprehensive test class covers relative, absolute, chained, None-bound, and empty-stream cases; all assertions are arithmetically correct against the fixture data.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    FT["from_time(s)"] --> FT1{"s is None?"}
    FT1 -->|yes| FT2["return self"]
    FT1 -->|no| FT3["self.first()"]
    FT3 -->|LookupError| FT4["return self (empty)"]
    FT3 -->|"t0"| FT5["self.after(t0 + s)"]
    FT5 --> AF["AfterFilter appended to query"]

    TT["to_time(s)"] --> TT1{"s is None?"}
    TT1 -->|yes| TT2["return self"]
    TT1 -->|no| TT3["self.first()"]
    TT3 -->|LookupError| TT4["return self (empty)"]
    TT3 -->|"t0"| TT5["self.before(t0 + s)"]
    TT5 --> BF["BeforeFilter appended to query"]

    FTS["from_timestamp(ts)"] --> FTS1{"ts is None?"}
    FTS1 -->|yes| FTS2["return self"]
    FTS1 -->|no| FTS3["self.after(ts)"]
    FTS3 --> AF

    TTS["to_timestamp(ts)"] --> TTS1{"ts is None?"}
    TTS1 -->|yes| TTS2["return self"]
    TTS1 -->|no| TTS3["self.before(ts)"]
    TTS3 --> BF
Loading

Reviews (3): Last reviewed commit: "memory2: from_time/to_time yield empty o..." | Re-trigger Greptile

Comment thread dimos/memory2/stream.py Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

leshy added 2 commits June 1, 2026 14:39
Add from_time/to_time (relative to the first observation) and
from_timestamp/to_timestamp (absolute epoch seconds) for windowing a
stream by time. A trailing to_time is a duration measured from the
current start, so from_time(2).to_time(30) reads as "skip 2s, take the
following 30s"; frames mix freely (from_timestamp(ts).to_time(30)).

Shared base for the stream-alignment (#2306) and go2dds (#2314)
branches, which both need this windowing API.
from_time/to_time resolve their anchor via first(), which raised
LookupError when the stream was already empty (e.g.
from_timestamp(future_ts).to_time(30) — the mixed pattern the PR
advertises). Guard the eager first() so an empty slice returns an empty
window, matching the lazy from_timestamp/to_timestamp. Adds a regression
test.
@leshy leshy force-pushed the feat/ivan/stream-time-windowing branch from a8bed40 to 6ab8f0a Compare June 1, 2026 06:42
@leshy leshy enabled auto-merge (squash) June 1, 2026 08:59
@leshy leshy merged commit 9ebd600 into main Jun 1, 2026
21 checks passed
@leshy leshy deleted the feat/ivan/stream-time-windowing branch June 1, 2026 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants