chat-recall 0.7.37 → 0.7.39

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/watch.js CHANGED
@@ -10180,15 +10180,18 @@ var init_opencode = __esm({
10180
10180
  FROM part p JOIN (SELECT id, data FROM message WHERE session_id = ?) m ON p.message_id = m.id
10181
10181
  WHERE p.session_id = ?
10182
10182
  ORDER BY p.time_created ASC, p.id ASC
10183
- `).all(realId, realId);
10184
- const lines = [JSON.stringify({ kind: "session", row: session })];
10185
- for (const r of rows)
10186
- lines.push(JSON.stringify({ kind: "part", row: r }));
10183
+ `);
10184
+ const chunks = [Buffer.from(`${JSON.stringify({ kind: "session", row: session })}
10185
+ `, "utf-8")];
10186
+ for (const r of rows.iterate(realId, realId)) {
10187
+ chunks.push(Buffer.from(`${JSON.stringify({ kind: "part", row: r })}
10188
+ `, "utf-8"));
10189
+ }
10187
10190
  const mtime = session.time_updated || session.time_created || Date.now();
10188
10191
  return {
10189
10192
  tool: "opencode",
10190
10193
  mtime: Number(mtime),
10191
- files: [{ name: `${realId}.dump.jsonl`, bytes: Buffer.from(lines.join("\n") + "\n", "utf-8") }]
10194
+ files: [{ name: `${realId}.dump.jsonl`, bytes: Buffer.concat(chunks) }]
10192
10195
  };
10193
10196
  } catch {
10194
10197
  return null;
@@ -15136,6 +15139,36 @@ var init_secret_precision = __esm({
15136
15139
  }
15137
15140
  });
15138
15141
 
15142
+ // src/walk-budget.ts
15143
+ function walkSessionLimit(env = process.env) {
15144
+ const raw = env.CHAT_RECALL_SYNC_WALK_MAX;
15145
+ if (raw === void 0 || raw.trim() === "") return DEFAULT_WALK_MAX_SESSIONS;
15146
+ const n = Number(raw);
15147
+ if (!Number.isFinite(n) || !Number.isInteger(n) || n <= 0) return DEFAULT_WALK_MAX_SESSIONS;
15148
+ return n;
15149
+ }
15150
+ function orderRefsForWalk(refs, isAcked) {
15151
+ const fresh = [];
15152
+ const acked = [];
15153
+ for (const ref of refs) (isAcked(ref.prefixedId) ? acked : fresh).push(ref);
15154
+ return [...fresh, ...acked];
15155
+ }
15156
+ function shouldWalkFull(opts) {
15157
+ const { lastSuccessAt, now } = opts;
15158
+ const interval = opts.fullIntervalMs ?? FULL_WALK_INTERVAL_MS;
15159
+ if (typeof lastSuccessAt !== "number" || !Number.isFinite(lastSuccessAt) || lastSuccessAt <= 0) return true;
15160
+ if (lastSuccessAt > now) return true;
15161
+ return now - lastSuccessAt >= interval;
15162
+ }
15163
+ var DEFAULT_WALK_MAX_SESSIONS, FULL_WALK_INTERVAL_MS;
15164
+ var init_walk_budget = __esm({
15165
+ "src/walk-budget.ts"() {
15166
+ "use strict";
15167
+ DEFAULT_WALK_MAX_SESSIONS = 2e3;
15168
+ FULL_WALK_INTERVAL_MS = 6 * 60 * 6e4;
15169
+ }
15170
+ });
15171
+
15139
15172
  // ../engine/dist/transcript/types.js
15140
15173
  var TRANSCRIPT_VERSION;
15141
15174
  var init_types = __esm({
@@ -27785,7 +27818,7 @@ var init_http = __esm({
27785
27818
  CLI_VERSION = JSON.parse(readFileSync37(new URL("../package.json", import.meta.url), "utf-8")).version || CLI_VERSION;
27786
27819
  } catch {
27787
27820
  try {
27788
- if (true) CLI_VERSION = "0.7.37";
27821
+ if (true) CLI_VERSION = "0.7.39";
27789
27822
  } catch {
27790
27823
  }
27791
27824
  }
@@ -28279,7 +28312,7 @@ var init_telemetry = __esm({
28279
28312
  init_sync_client();
28280
28313
  cliVersion = () => {
28281
28314
  try {
28282
- return true ? "0.7.37" : "dev";
28315
+ return true ? "0.7.39" : "dev";
28283
28316
  } catch {
28284
28317
  return "dev";
28285
28318
  }
@@ -28976,11 +29009,15 @@ function isStandingFailure(err) {
28976
29009
  const c = taggedClass(err);
28977
29010
  return c !== null && STANDING_FAILURE.has(c);
28978
29011
  }
29012
+ function countsForBreaker(cls) {
29013
+ return cls !== "rate_limited" && cls !== "payload_too_large";
29014
+ }
28979
29015
  function classifyError(msg, err) {
28980
29016
  const tagged = taggedClass(err);
28981
29017
  if (tagged) return tagged;
28982
29018
  const m = msg.toLowerCase();
28983
29019
  if (m.includes("429")) return "rate_limited";
29020
+ if (m.includes("body_too_large") || m.includes("payload too large") || m.includes("entity too large")) return "payload_too_large";
28984
29021
  if (m.includes("402")) return "payment_required";
28985
29022
  if (m.includes("401") || m.includes("403") || m.includes("token")) return "auth";
28986
29023
  if (m.includes("timed out") || m.includes("etimedout") || m.includes("aborted due to timeout")) return "timeout";
@@ -29215,6 +29252,12 @@ async function syncSessions(opts = {}) {
29215
29252
  const msg = e instanceof Error ? e.message : String(e);
29216
29253
  errors.push(`${cred.serverUrl}: ${msg}`);
29217
29254
  perTarget[cred.serverUrl] = { ok: false, error: msg, accepted: acceptedUploads.get(cred.serverUrl) ?? 0 };
29255
+ const cls = classifyError(msg, e);
29256
+ if (!countsForBreaker(cls)) {
29257
+ console.error(`[sync] ${cred.serverUrl}: ${cls === "rate_limited" ? "asked to slow down" : "refused one oversized body"}; the target stays out of cooldown and the next walk retries`);
29258
+ record({ kind: "target_throttled", failures: 0, retryInMs: 0, errorClass: cls, local: isLocalHost(cred.serverUrl) ? 1 : 0 });
29259
+ continue;
29260
+ }
29218
29261
  const next = noteTargetFailure(cred.serverUrl, msg);
29219
29262
  const notice = breakerNotice(cred.serverUrl, next);
29220
29263
  if (notice) console.error(`[sync] ${notice}`);
@@ -29227,7 +29270,7 @@ async function syncSessions(opts = {}) {
29227
29270
  kind: next.tripped ? "breaker_trip" : "target_failure",
29228
29271
  failures: next.failures,
29229
29272
  retryInMs: next.retryInMs,
29230
- errorClass: classifyError(msg, e),
29273
+ errorClass: cls,
29231
29274
  local: isLocalHost(cred.serverUrl) ? 1 : 0
29232
29275
  });
29233
29276
  }
@@ -29252,6 +29295,11 @@ async function syncSessions(opts = {}) {
29252
29295
  rssPeakMb: Math.round(process.memoryUsage().rss / 1048576)
29253
29296
  });
29254
29297
  }
29298
+ if (agg) {
29299
+ for (const t of targets) {
29300
+ if (!errors.some((e) => e.startsWith(`${t.serverUrl}:`))) noteWalkSuccess(t.serverUrl);
29301
+ }
29302
+ }
29255
29303
  void flush().catch(() => {
29256
29304
  });
29257
29305
  if (!agg) throw new Error(`sync failed for all targets:
@@ -29260,6 +29308,32 @@ async function syncSessions(opts = {}) {
29260
29308
  ${errors.join("\n ")}`);
29261
29309
  return { ...agg, perTarget };
29262
29310
  }
29311
+ function walkStatePath() {
29312
+ return join47(getDataDir(), "walk-state.json");
29313
+ }
29314
+ function readWalkState() {
29315
+ try {
29316
+ const raw = JSON.parse(readFileSync41(walkStatePath(), "utf-8"));
29317
+ return raw && typeof raw === "object" ? raw : {};
29318
+ } catch {
29319
+ return {};
29320
+ }
29321
+ }
29322
+ function noteWalkSuccess(serverUrl) {
29323
+ try {
29324
+ const state2 = readWalkState();
29325
+ state2[serverUrl.replace(/\/+$/, "")] = Date.now();
29326
+ mkdirSync11(getDataDir(), { recursive: true });
29327
+ writeFileSync10(walkStatePath(), JSON.stringify(state2));
29328
+ } catch {
29329
+ }
29330
+ }
29331
+ function lastSuccessfulWalkAt(serverUrl) {
29332
+ const state2 = readWalkState();
29333
+ const key2 = serverUrl?.replace(/\/+$/, "");
29334
+ const stamps = key2 ? [state2[key2]] : Object.values(state2);
29335
+ return stamps.reduce((max, v) => Math.max(max, typeof v === "number" ? v : 0), 0);
29336
+ }
29263
29337
  async function postFieldBatch(base3, token, rows) {
29264
29338
  const headers = { "content-type": "application/json" };
29265
29339
  if (token) headers.authorization = `Bearer ${token}`;
@@ -29762,7 +29836,9 @@ async function syncToTargetInScope(cred, opts = {}) {
29762
29836
  }
29763
29837
  };
29764
29838
  let scanMs = 0, scanned = 0;
29765
- const slice = refs.slice(0, opts.limit ?? refs.length);
29839
+ const walkMax = opts.limit ?? walkSessionLimit();
29840
+ const ordered = walkMax > 0 ? orderRefsForWalk(refs, (id) => Boolean(ledger?.get(id))) : refs;
29841
+ const slice = walkMax > 0 ? ordered.slice(0, walkMax) : ordered;
29766
29842
  const trace = process.env.CHAT_RECALL_SYNC_TRACE === "1" ? (msg) => {
29767
29843
  const m = process.memoryUsage();
29768
29844
  console.error(`[sync-trace] ${msg} \xB7 heap=${(m.heapUsed / 1048576).toFixed(0)}MB rss=${(m.rss / 1048576).toFixed(0)}MB`);
@@ -30156,6 +30232,10 @@ async function syncToTargetInScope(cred, opts = {}) {
30156
30232
  scanMs: Math.round(scanMs)
30157
30233
  };
30158
30234
  }
30235
+ function exportByteLength(exp) {
30236
+ if (!exp) return 0;
30237
+ return exp.files.reduce((n, f) => n + f.bytes.length, 0);
30238
+ }
30159
30239
  async function scanTranscriptFindingsChunked(ref, tenantRules) {
30160
30240
  const backend = getBackendForId(ref.prefixedId);
30161
30241
  const findings = [];
@@ -30226,7 +30306,20 @@ async function buildConversationSync(ref, mtime, opts = {}) {
30226
30306
  const backend = getBackendForId(ref.prefixedId) ?? getBackend("claude");
30227
30307
  const exp = backend.exportRawSession(ref.prefixedId);
30228
30308
  let built;
30229
- if (exp) {
30309
+ const exportBytes = exportByteLength(exp);
30310
+ const overCeiling = exportBytes > FULL_BUILD_MAX_BYTES;
30311
+ if (exp && overCeiling) {
30312
+ console.error(`[sync] ${ref.prefixedId} export is ${(exportBytes / 1048576).toFixed(0)}MB (over the ${(FULL_BUILD_MAX_BYTES / 1048576).toFixed(0)}MB ceiling) \u2014 parsing it in place, no container copy, no shadow merge, no raw archive`);
30313
+ record({
30314
+ kind: "oversized_session",
30315
+ mb: Math.round(exportBytes / 1048576),
30316
+ tool: ref.toolId,
30317
+ dedupeKey: stableMark(ref.prefixedId)
30318
+ });
30319
+ includeRaw = false;
30320
+ includeMeta = false;
30321
+ }
30322
+ if (exp && !overCeiling) {
30230
30323
  try {
30231
30324
  built = buildRawContainer(exp);
30232
30325
  srcHash = containerSrcHash(built);
@@ -30250,7 +30343,7 @@ async function buildConversationSync(ref, mtime, opts = {}) {
30250
30343
  includeMeta = false;
30251
30344
  }
30252
30345
  }
30253
- const shadow = updateShadow(ref.rawId, exp, built);
30346
+ const shadow = overCeiling ? { container: null, status: "skipped", recovered: 0 } : updateShadow(ref.rawId, exp, built);
30254
30347
  if (shadow.container) {
30255
30348
  fullestContainer = shadow.container;
30256
30349
  if (shadow.status === "rewrite-merged" && shadow.recovered > 0) {
@@ -30617,6 +30710,7 @@ var init_sync_client = __esm({
30617
30710
  init_secret_precision();
30618
30711
  init_settings();
30619
30712
  init_paths();
30713
+ init_walk_budget();
30620
30714
  init_tool_backend();
30621
30715
  init_transcript();
30622
30716
  init_claude();
@@ -30650,7 +30744,7 @@ var init_sync_client = __esm({
30650
30744
  ownVersion = JSON.parse(readFileSync41(join47(dir, "../package.json"), "utf-8")).version || ownVersion;
30651
30745
  } catch {
30652
30746
  try {
30653
- if (true) ownVersion = "0.7.37";
30747
+ if (true) ownVersion = "0.7.39";
30654
30748
  } catch {
30655
30749
  }
30656
30750
  }
@@ -32456,7 +32550,7 @@ var init_intent_drain = __esm({
32456
32550
  ownVersion2 = JSON.parse(readFileSync45(join53(dir, "../package.json"), "utf-8")).version || ownVersion2;
32457
32551
  } catch {
32458
32552
  try {
32459
- if (true) ownVersion2 = "0.7.37";
32553
+ if (true) ownVersion2 = "0.7.39";
32460
32554
  } catch {
32461
32555
  }
32462
32556
  }
@@ -34160,6 +34254,7 @@ var init_collector = __esm({
34160
34254
  var service_installer_exports = {};
34161
34255
  __export(service_installer_exports, {
34162
34256
  ServiceInstallError: () => ServiceInstallError,
34257
+ WATCH_HEAP_MB: () => WATCH_HEAP_MB,
34163
34258
  installService: () => installService,
34164
34259
  isServiceRunning: () => isServiceRunning,
34165
34260
  platformName: () => platformName,
@@ -34270,9 +34365,8 @@ function renderSystemdUnit(watchJs, node, logFile) {
34270
34365
  // Bounded heap: the daemon does bursty batch work (transcript parse,
34271
34366
  // base64 payloads); V8's default old-space on a big-RAM box is ~4GB and
34272
34367
  // GC only gets aggressive near the ceiling — observed as a multi-GB RSS
34273
- // sawtooth. 1536MB keeps GC honest (768 OOMed on the largest subagent-fanout session) with plenty of headroom for the
34274
- // largest transcripts.
34275
- `ExecStart=${node} --max-old-space-size=1536 ${watchJs}`,
34368
+ // sawtooth. The ceiling below is measured, not guessed: see WATCH_HEAP_MB.
34369
+ `ExecStart=${node} --max-old-space-size=${WATCH_HEAP_MB} ${watchJs}`,
34276
34370
  // ALWAYS: the collector never ends its own work, so any exit systemd did
34277
34371
  // not ask for is a fault. Under on-failure a clean exit left it dead: on
34278
34372
  // 2026-09-16 the unit went "inactive (dead) … status=0/SUCCESS" and stayed
@@ -34345,7 +34439,7 @@ function renderLaunchdPlist(watchJs, node, logFile, label = "com.chat-recall.wat
34345
34439
  '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
34346
34440
  '<plist version="1.0"><dict>',
34347
34441
  ` <key>Label</key><string>${label}</string>`,
34348
- ` <key>ProgramArguments</key><array><string>${node}</string><string>--max-old-space-size=1536</string><string>${watchJs}</string></array>`,
34442
+ ` <key>ProgramArguments</key><array><string>${node}</string><string>--max-old-space-size=${WATCH_HEAP_MB}</string><string>${watchJs}</string></array>`,
34349
34443
  " <key>RunAtLoad</key><true/>",
34350
34444
  " <key>KeepAlive</key><true/>",
34351
34445
  ` <key>StandardOutPath</key><string>${logFile}</string>`,
@@ -34356,7 +34450,7 @@ function renderLaunchdPlist(watchJs, node, logFile, label = "com.chat-recall.wat
34356
34450
  }
34357
34451
  function installWindowsTask(watchJs, node, logFile) {
34358
34452
  const taskName = "chat-recall-watch";
34359
- const tr = `cmd /c \\"\\"${node}\\" --max-old-space-size=1536 \\"${watchJs}\\" >> \\"${logFile}\\" 2>&1\\"`;
34453
+ const tr = `cmd /c \\"\\"${node}\\" --max-old-space-size=${WATCH_HEAP_MB} \\"${watchJs}\\" >> \\"${logFile}\\" 2>&1\\"`;
34360
34454
  try {
34361
34455
  execSync5(`schtasks /create /tn "${taskName}" /tr "${tr}" /sc onlogon /rl LIMITED /f`, { stdio: "inherit" });
34362
34456
  try {
@@ -34369,7 +34463,7 @@ function installWindowsTask(watchJs, node, logFile) {
34369
34463
  return { definitionPath: null, logFile };
34370
34464
  }
34371
34465
  function renderWindowsTaskCommand(watchJs, node, taskName = "chat-recall-watch", logFile) {
34372
- const tr = logFile ? `cmd /c \\"\\"${node}\\" --max-old-space-size=1536 \\"${watchJs}\\" >> \\"${logFile}\\" 2>&1\\"` : `\\"${node}\\" --max-old-space-size=1536 \\"${watchJs}\\"`;
34466
+ const tr = logFile ? `cmd /c \\"\\"${node}\\" --max-old-space-size=${WATCH_HEAP_MB} \\"${watchJs}\\" >> \\"${logFile}\\" 2>&1\\"` : `\\"${node}\\" --max-old-space-size=${WATCH_HEAP_MB} \\"${watchJs}\\"`;
34373
34467
  return `schtasks /create /tn "${taskName}" /tr "${tr}" /sc onlogon /rl LIMITED /f`;
34374
34468
  }
34375
34469
  function uninstallService() {
@@ -34420,10 +34514,11 @@ function platformName() {
34420
34514
  if (process.platform === "win32") return "Scheduled Task";
34421
34515
  return process.platform;
34422
34516
  }
34423
- var ServiceInstallError;
34517
+ var WATCH_HEAP_MB, ServiceInstallError;
34424
34518
  var init_service_installer = __esm({
34425
34519
  "src/service-installer.ts"() {
34426
34520
  "use strict";
34521
+ WATCH_HEAP_MB = 640;
34427
34522
  ServiceInstallError = class extends Error {
34428
34523
  hint;
34429
34524
  constructor(message, hint) {
@@ -34448,7 +34543,9 @@ async function shipToServer(trigger) {
34448
34543
  if (syncInFlight) return;
34449
34544
  syncInFlight = true;
34450
34545
  try {
34451
- const result = await syncIncremental({ scope: trigger === "file-change" ? "changed" : "full" });
34546
+ const recentSuccess = !shouldWalkFull({ lastSuccessAt: lastSuccessfulWalkAt(), now: Date.now() });
34547
+ const scope = trigger === "file-change" || trigger === "startup" && recentSuccess ? "changed" : "full";
34548
+ const result = await syncIncremental({ scope });
34452
34549
  if (isSyncSkip(result)) {
34453
34550
  if (result.skipped === "no-credentials") {
34454
34551
  daemonLog.warn(`Sync skipped (${trigger}): not logged in \u2014 run \`chat-recall login\` to ship sessions to a server.`);
@@ -34792,6 +34889,7 @@ var init_indexer = __esm({
34792
34889
  init_collector_health();
34793
34890
  init_settings();
34794
34891
  init_sync_client();
34892
+ init_walk_budget();
34795
34893
  init_http();
34796
34894
  init_intent_drain();
34797
34895
  init_sync_client();
@@ -34805,7 +34903,7 @@ var init_indexer = __esm({
34805
34903
  init_collector_migrate();
34806
34904
  init_sync_ledger();
34807
34905
  init_collector_health();
34808
- CLI_VERSION3 = true ? "0.7.37" : "0.0.0";
34906
+ CLI_VERSION3 = true ? "0.7.39" : "0.0.0";
34809
34907
  DEBOUNCE_MS = 5e3;
34810
34908
  PLANS_DIR = claudeBackend.plansDir();
34811
34909
  TASKS_DIR = claudeBackend.tasksDir();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chat-recall",
3
- "version": "0.7.37",
3
+ "version": "0.7.39",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/munhq/chat-recall.git"