fix(mates): delta-based DM digests to prevent content loss past 6k chars#282
fix(mates): delta-based DM digests to prevent content loss past 6k chars#282leiyangyou wants to merge 1 commit intochadbyte:mainfrom
Conversation
19f179e to
4116b46
Compare
|
This is heading in a great direction. Delta-based digests feel like the right next step for session memory. Looking forward to it. I've been watching your PRs and it's clear you use Mates a lot. I'm curious, walk me through what a typical session with a Mate looks like for you? |
|
Thanks! Honestly my usage is pretty varied — I jump between a few different projects, and the thing I appreciate most is how fluidly I can switch between different projects and sessions. It's a much better flow than juggling CLI tabs. In the downtime between projects I'll circle back to Clay to add features or fixes I've been wanting. I also access Clay remotely through mobile sometimes, which has been surprisingly useful. Mates is probably the most interesting feature to me right now. I'm still exploring what's possible with it — the delta digest thing wasn't really a bug I hit, more something Claude Code spotted when I was poking around to understand what mates can do, and it seemed worth digging into. |
|
Also worth mentioning — I do intend at some point to invite some of my colleagues into Clay. The collaboration angle is a big plus. Things like working within the same project together, or opening things up for non-tech folks to do data analysis on a project I'm maintaining through Claude Code. That's a really compelling use case. |
b9f4590 to
94a85f8
Compare
Only collect new turns since the last successful digest instead of re-reading from index 0. Checkpoint persisted in session history so the index survives restarts. Prior memory summary injected into digest prompt for context on small deltas.
94a85f8 to
2d45be8
Compare
|
Thanks for the thorough writeup and the implementation. Answers to your open questions: 1. Delta vs full-conversation: The full-conversation approach wasn't intentional design, just the initial implementation. Delta is the right direction. No concerns here. 2. Debounce: Current concurrency-based approach is fine. With the delta change, skipped turns get picked up by the next delta via the index, so there's no content loss. Time-based debounce would add timer complexity without a clear benefit. 3. Checkpoint in session history: This is the right place. Keeping it in history means it naturally stays in sync with trim/rewind operations, and you've already handled the trim reset in Looks good overall. Ready to take it out of draft when the test plan is checked off. |
Problem
The current DM digest system collects the full conversation from index 0 on every turn, capped at 6000 chars. Once a DM session exceeds ~5 turns:
_dmDigestPending) can skip turns entirelylastResponseTextfallback only leaks ~200 chars per digestThis hasn't been a problem yet because all existing digests are from
@mentions(which use a separate code path with fixed 2k per question/response), but it would affect any long-running DM session with a mate.Proposed approach: delta-based collection
Instead of re-reading the full conversation each time, only collect new turns since the last successful digest. This means:
Key design decisions (want your input on these):
Delta vs full-conversation: Each digest now covers a small slice rather than the full conversation. This changes the nature of what gets stored in
session-digests.jsonl— fragments vs self-contained summaries. BM25 search quality may be affected since individual entries have less context.Prior summary injection: To give Haiku context for small deltas like "User: sounds good / Mate: proceeding", we inject the existing
memory-summary.mdinto the digest worker prompt. This lets Haiku produce properly contextualized digests but increases prompt size.Checkpoint persistence: We write
digest_checkpointentries intosession.historyso the index survives server restarts. These are filtered fromreplayHistoryso they don't leak to the UI.onDone(err)convention: The checkpoint only advances on success (err === null). On Haiku failures or parse errors, the index stays put so the turns can be retried.Changes
lib/project.js: Delta collection with per-session index, prior summary injection, parse failure guard, history trim guard,onDone(err)for digest worker callbackslib/sessions.js: Filterdigest_checkpointfromreplayHistoryOpen questions
Test plan
session-digests.jsonldigest_checkpointentries don't appear in chat UI