nox-mem 3.11.0 → 3.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/session-distill.js +38 -15
- package/package.json +1 -1
package/dist/session-distill.js
CHANGED
|
@@ -133,6 +133,31 @@ export function listUnprocessedSessions(db, agentIds, lookbackDays) {
|
|
|
133
133
|
sessions.sort((a, b) => a.mtimeMs - b.mtimeMs || a.sessionKey.localeCompare(b.sessionKey));
|
|
134
134
|
return sessions;
|
|
135
135
|
}
|
|
136
|
+
/** A session with fewer messages than this holds only init events: nothing to distill. */
|
|
137
|
+
export const MIN_SESSION_MESSAGES = 3;
|
|
138
|
+
/**
|
|
139
|
+
* Walks `pending` in order and splits it into the sessions to distill now (at most `max`, each
|
|
140
|
+
* with its messages already read) and the short ones, which are logged as done without counting
|
|
141
|
+
* against `max`. Reading stops once `max` sessions are taken; `left` is how many were not read.
|
|
142
|
+
*
|
|
143
|
+
* The budget used to be cut before the short sessions were set aside, so they spent it. Measured
|
|
144
|
+
* on one deployment (nightly run, 1-day lookback, max 50): 43 to 48 of the 50 sessions taken each
|
|
145
|
+
* night since 2026-11-10 were short, 2 to 7 were distilled, and the ~35 left over aged out of the
|
|
146
|
+
* lookback before the next run.
|
|
147
|
+
*/
|
|
148
|
+
export function partitionPending(pending, max, read) {
|
|
149
|
+
const take = [];
|
|
150
|
+
const short = [];
|
|
151
|
+
let i = 0;
|
|
152
|
+
for (; i < pending.length && take.length < max; i++) {
|
|
153
|
+
const messages = read(pending[i]);
|
|
154
|
+
if (messages.length < MIN_SESSION_MESSAGES)
|
|
155
|
+
short.push({ session: pending[i], count: messages.length });
|
|
156
|
+
else
|
|
157
|
+
take.push({ session: pending[i], messages });
|
|
158
|
+
}
|
|
159
|
+
return { take, short, left: pending.length - i };
|
|
160
|
+
}
|
|
136
161
|
// ─── Message extraction ───────────────────────────────────────────────────────
|
|
137
162
|
export function extractMessages(sessionFile) {
|
|
138
163
|
const messages = [];
|
|
@@ -288,30 +313,28 @@ export async function distillSessions(options = {}) {
|
|
|
288
313
|
blockOutcomes: {},
|
|
289
314
|
};
|
|
290
315
|
const pending = listUnprocessedSessions(db, agentIds, lookbackDays);
|
|
291
|
-
const sessions = pending
|
|
292
|
-
|
|
316
|
+
const { take: sessions, short, left } = partitionPending(pending, maxSessionsPerRun, (s) => extractMessages(s.sessionFile));
|
|
317
|
+
// Short sessions (just init events) are logged as done and do not count against the budget.
|
|
318
|
+
for (const { session, count } of short) {
|
|
319
|
+
stats.skippedSessions++;
|
|
320
|
+
if (!dryRun) {
|
|
321
|
+
db.prepare("INSERT OR IGNORE INTO session_distill_log (session_key, agent, chunks_extracted, message_count) VALUES (?, ?, 0, ?)").run(session.sessionKey, session.agentId, count);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (left > 0) {
|
|
293
325
|
// A full list on every run is the backlog signal: say how much is left, in the log a
|
|
294
326
|
// scheduled job keeps, instead of leaving it to be found by a census.
|
|
295
|
-
console.log(`[DISTILL] Backlog: ${pending.length} unprocessed in the lookback, taking the ${sessions.length} oldest; ${
|
|
327
|
+
console.log(`[DISTILL] Backlog: ${pending.length} unprocessed in the lookback; ${short.length} short logged, taking the ${sessions.length} oldest; ${left} left for the next run`);
|
|
296
328
|
}
|
|
297
329
|
if (sessions.length === 0) {
|
|
298
|
-
console.log("[DISTILL] No unprocessed sessions found");
|
|
330
|
+
console.log(short.length ? `[DISTILL] ${short.length} short sessions logged, none to distill` : "[DISTILL] No unprocessed sessions found");
|
|
299
331
|
recordOutcomes(dryRun, agentIds, lookbackDays, pending.length, stats);
|
|
300
332
|
return stats;
|
|
301
333
|
}
|
|
302
|
-
console.log(`[DISTILL] Processing ${sessions.length} sessions (lookback: ${lookbackDays}d)`);
|
|
334
|
+
console.log(`[DISTILL] Processing ${sessions.length} sessions (lookback: ${lookbackDays}d; ${short.length} short logged)`);
|
|
303
335
|
// Group messages into blocks of ~2000 chars for the LLM
|
|
304
336
|
const BLOCK_SIZE = 2000;
|
|
305
|
-
for (const { agentId,
|
|
306
|
-
const messages = extractMessages(sessionFile);
|
|
307
|
-
if (messages.length < 3) {
|
|
308
|
-
// Skip tiny sessions (just session init events)
|
|
309
|
-
stats.skippedSessions++;
|
|
310
|
-
if (!dryRun) {
|
|
311
|
-
db.prepare("INSERT OR IGNORE INTO session_distill_log (session_key, agent, chunks_extracted, message_count) VALUES (?, ?, 0, ?)").run(sessionKey, agentId, messages.length);
|
|
312
|
-
}
|
|
313
|
-
continue;
|
|
314
|
-
}
|
|
337
|
+
for (const { session: { agentId, sessionKey }, messages } of sessions) {
|
|
315
338
|
stats.messagesRead += messages.length;
|
|
316
339
|
// Build conversation text, apply noise filter
|
|
317
340
|
const conversationLines = messages
|