Skip to content

store: rebuild ReadConversation around thread completion - #363

Open
anish749 wants to merge 2 commits into
mainfrom
worktree-read-thread-completion
Open

store: rebuild ReadConversation around thread completion#363
anish749 wants to merge 2 commits into
mainfrom
worktree-read-thread-completion

Conversation

@anish749

@anish749 anish749 commented May 3, 2026

Copy link
Copy Markdown
Owner

Problem

ReadConversation had asymmetric filter logic: --since post-filtered by ts at the caller, while --date had no post-filter and interleaveThreads dumped every unmatched thread file at the end. Result: --date X for a day with no date file leaked unrelated thread data, and matched-thread replies on different days were treated inconsistently between modes.

Solution

Rebuild around one model. Both --date and --since are time windows. Pipeline is filter → thread-complete → dedupe → sort → interleave.

  • A thread is the unit of context: any thread with ≥ 1 in-window member is kept whole, regardless of which member fell in window. Symmetric — parent-in-window pulls replies, reply-in-window pulls parent.
  • Parents that live in both the date file and the thread file are deduped by ID. Thread atoms sort by parent ts (earliest reply ts for orphans); replies inside an atom sort by ts. Interleave is the last step.
  • File discovery: date files are filtered by filename window via read.GlobFiles (filename is a directory-layout contract — type-safe). Thread files are listed whole and filtered at parse time using typed time.Time comparisons; pre-filtering by content patterns would couple to MsgLine.Ts's JSON serialization, which is fragile.
  • The window/discovery code lives in internal/store/window.go — store layer owns it, calling internal/read for the rg primitives.
  • --last=25 default for pigeon read lives in commands.RunRead (the UX layer). Store has no opinions; with no filter, it returns the full conversation. Hub callers (which pass Since explicitly) are unaffected.

Tests

  • New: Date_NoFile_NoThreadActivity, Date_ParentInWindow_PullsLaterReplies, Date_ReplyInWindow_PullsOlderParent, Date_ThreadAtomSortedByParentTs, DedupsParentBetweenDateAndThreadFiles, NoFilter_ReturnsEverything.
  • Updated: ThreadReply_OldParentInDateFile now asserts the old parent rides along — direct consequence of the new thread-completion model.
  • Live-verified on real data: a day with no date file but thread files now returns empty (was 110 lines of leaked orphans); a day with a thread reply pulls the older parent + sibling replies into one atom.

Supersedes #358.

@anish749
anish749 force-pushed the worktree-read-thread-completion branch from c20589c to 48607b5 Compare May 28, 2026 21:43
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