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/cli.js +283 -94
- package/dist/cli.js.map +1 -1
- package/dist/kit-store.d.ts +4 -3
- package/dist/kit-store.d.ts.map +1 -1
- package/dist/kit-store.js +4 -4
- package/dist/kit-store.js.map +1 -1
- package/dist/mcp-relay.js +1 -1
- package/dist/mcp.js +111 -20
- package/dist/message-hook.js +1 -1
- package/dist/scan-worker.js +8 -5
- package/dist/service-installer.d.ts +13 -0
- package/dist/service-installer.d.ts.map +1 -1
- package/dist/service-installer.js +19 -7
- package/dist/service-installer.js.map +1 -1
- package/dist/sync-client.d.ts +33 -3
- package/dist/sync-client.d.ts.map +1 -1
- package/dist/sync-client.js +117 -7
- package/dist/sync-client.js.map +1 -1
- package/dist/walk-budget.d.ts +52 -0
- package/dist/walk-budget.d.ts.map +1 -0
- package/dist/walk-budget.js +68 -0
- package/dist/walk-budget.js.map +1 -0
- package/dist/watch.js +120 -22
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-client.d.ts","sourceRoot":"","sources":["../src/sync-client.ts"],"names":[],"mappings":"AAmCA,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,0CAA0C,CAAC;AAQzF,OAAO,EAAoF,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,4CAA4C,CAAC;
|
|
1
|
+
{"version":3,"file":"sync-client.d.ts","sourceRoot":"","sources":["../src/sync-client.ts"],"names":[],"mappings":"AAmCA,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,0CAA0C,CAAC;AAQzF,OAAO,EAAoF,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,4CAA4C,CAAC;AAYrL,OAAO,EAA+B,KAAK,UAAU,EAAE,MAAM,0CAA0C,CAAC;AA2ExG,yDAAyD;AACzD,wBAAgB,YAAY,CAAC,UAAU,EAAE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internal-prompts.
|
|
|
46
46
|
import { dropFuzzyFindings } from '@chat-recall/engine/core/secret-precision.js';
|
|
47
47
|
import { loadSettings, saveSettings, isProjectSyncable } from '@chat-recall/engine/core/settings.js';
|
|
48
48
|
import { getDataDir } from '@chat-recall/engine/core/paths.js';
|
|
49
|
+
import { walkSessionLimit, orderRefsForWalk } from './walk-budget.js';
|
|
49
50
|
import { listAvailableBackends } from '@chat-recall/engine/core/tool-backend.js';
|
|
50
51
|
import { parseTranscript, trimTranscriptForSync, TRANSCRIPT_VERSION, gzipContainer, redactContainer, buildRawContainer, containerSrcHash, parseTranscriptFromContainer, updateShadow, shadowUncompressedBytes } from '@chat-recall/engine/transcript/index.js';
|
|
51
52
|
import { parseClaudeTranscriptText } from '@chat-recall/engine/transcript/claude.js';
|
|
@@ -155,6 +156,19 @@ export function isStandingFailure(err) {
|
|
|
155
156
|
* A tag from the throw site always wins. The message tests remain for errors
|
|
156
157
|
* thrown by fetch itself, and by code that predates the tag.
|
|
157
158
|
*/
|
|
159
|
+
/**
|
|
160
|
+
* Does a failed walk count against the target's circuit breaker?
|
|
161
|
+
*
|
|
162
|
+
* A server that answers 429 (busy, Retry-After) or 413 (this body is above the
|
|
163
|
+
* limit) is not broken. The in-walk retry already honoured Retry-After, and the
|
|
164
|
+
* body limit is a fact about one session. Counting either would open the
|
|
165
|
+
* breaker for 1–15 minutes and silence a healthy collector exactly while the
|
|
166
|
+
* server recovers (issue #16: the collector sat in cooldown on 502s and on
|
|
167
|
+
* rate limits while the pods were restarting).
|
|
168
|
+
*/
|
|
169
|
+
export function countsForBreaker(cls) {
|
|
170
|
+
return cls !== 'rate_limited' && cls !== 'payload_too_large';
|
|
171
|
+
}
|
|
158
172
|
export function classifyError(msg, err) {
|
|
159
173
|
const tagged = taggedClass(err);
|
|
160
174
|
if (tagged)
|
|
@@ -162,6 +176,11 @@ export function classifyError(msg, err) {
|
|
|
162
176
|
const m = msg.toLowerCase();
|
|
163
177
|
if (m.includes('429'))
|
|
164
178
|
return 'rate_limited';
|
|
179
|
+
// The server refused the SIZE of one body (413 with code body_too_large, or a
|
|
180
|
+
// parser limit). It is a fact about that session, not a broken target: the
|
|
181
|
+
// walk must keep its cooldown out of it (see countsForBreaker).
|
|
182
|
+
if (m.includes('body_too_large') || m.includes('payload too large') || m.includes('entity too large'))
|
|
183
|
+
return 'payload_too_large';
|
|
165
184
|
if (m.includes('402'))
|
|
166
185
|
return 'payment_required';
|
|
167
186
|
if (m.includes('401') || m.includes('403') || m.includes('token'))
|
|
@@ -593,7 +612,16 @@ export async function syncSessions(opts = {}) {
|
|
|
593
612
|
// delivered thousands of rows and then failed reads as "never synced".
|
|
594
613
|
perTarget[cred.serverUrl] = { ok: false, error: msg, accepted: acceptedUploads.get(cred.serverUrl) ?? 0 };
|
|
595
614
|
// Report the NEXT attempt in the same breath as the failure, so the log
|
|
596
|
-
// says what will happen rather than leaving the user to infer it.
|
|
615
|
+
// says what will happen rather than leaving the user to infer it. A 429
|
|
616
|
+
// or a 413 is the server asking for a pause, or a fact about ONE session:
|
|
617
|
+
// it is reported, but it does not count against the cooldown, because a
|
|
618
|
+
// collector in cooldown cannot use the moment the server recovers.
|
|
619
|
+
const cls = classifyError(msg, e);
|
|
620
|
+
if (!countsForBreaker(cls)) {
|
|
621
|
+
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`);
|
|
622
|
+
record({ kind: 'target_throttled', failures: 0, retryInMs: 0, errorClass: cls, local: isLocalHost(cred.serverUrl) ? 1 : 0 });
|
|
623
|
+
continue;
|
|
624
|
+
}
|
|
597
625
|
const next = noteTargetFailure(cred.serverUrl, msg);
|
|
598
626
|
const notice = breakerNotice(cred.serverUrl, next);
|
|
599
627
|
if (notice)
|
|
@@ -609,7 +637,7 @@ export async function syncSessions(opts = {}) {
|
|
|
609
637
|
kind: next.tripped ? 'breaker_trip' : 'target_failure',
|
|
610
638
|
failures: next.failures,
|
|
611
639
|
retryInMs: next.retryInMs,
|
|
612
|
-
errorClass:
|
|
640
|
+
errorClass: cls,
|
|
613
641
|
local: isLocalHost(cred.serverUrl) ? 1 : 0,
|
|
614
642
|
});
|
|
615
643
|
}
|
|
@@ -645,6 +673,14 @@ export async function syncSessions(opts = {}) {
|
|
|
645
673
|
rssPeakMb: Math.round(process.memoryUsage().rss / 1048576),
|
|
646
674
|
});
|
|
647
675
|
}
|
|
676
|
+
// A successful target gets a timestamp, so the next daemon start can walk
|
|
677
|
+
// 'changed' instead of listing all 12,224 sessions again (issue #16).
|
|
678
|
+
if (agg) {
|
|
679
|
+
for (const t of targets) {
|
|
680
|
+
if (!errors.some((e) => e.startsWith(`${t.serverUrl}:`)))
|
|
681
|
+
noteWalkSuccess(t.serverUrl);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
648
684
|
// After the walk: the connection is warm and the numbers are final. Never
|
|
649
685
|
// awaited into the caller's error path — telemetry must not fail a sync.
|
|
650
686
|
void flush().catch(() => { });
|
|
@@ -656,6 +692,36 @@ export async function syncSessions(opts = {}) {
|
|
|
656
692
|
// to infer one target's fate from the sum of all of them.
|
|
657
693
|
return { ...agg, perTarget };
|
|
658
694
|
}
|
|
695
|
+
/** File that holds the last successful walk per target (see noteWalkSuccess). */
|
|
696
|
+
function walkStatePath() { return join(getDataDir(), 'walk-state.json'); }
|
|
697
|
+
function readWalkState() {
|
|
698
|
+
try {
|
|
699
|
+
const raw = JSON.parse(readFileSync(walkStatePath(), 'utf-8'));
|
|
700
|
+
return raw && typeof raw === 'object' ? raw : {};
|
|
701
|
+
}
|
|
702
|
+
catch {
|
|
703
|
+
return {};
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
function noteWalkSuccess(serverUrl) {
|
|
707
|
+
try {
|
|
708
|
+
const state = readWalkState();
|
|
709
|
+
state[serverUrl.replace(/\/+$/, '')] = Date.now();
|
|
710
|
+
mkdirSync(getDataDir(), { recursive: true });
|
|
711
|
+
writeFileSync(walkStatePath(), JSON.stringify(state));
|
|
712
|
+
}
|
|
713
|
+
catch { /* the stamp only tunes the NEXT walk, so it must never fail a sync */ }
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* When did a walk last succeed (0 = never on this machine)?
|
|
717
|
+
* The daemon uses this to decide 'changed' or 'full' after a restart.
|
|
718
|
+
*/
|
|
719
|
+
export function lastSuccessfulWalkAt(serverUrl) {
|
|
720
|
+
const state = readWalkState();
|
|
721
|
+
const key = serverUrl?.replace(/\/+$/, '');
|
|
722
|
+
const stamps = key ? [state[key]] : Object.values(state);
|
|
723
|
+
return stamps.reduce((max, v) => Math.max(max, typeof v === 'number' ? v : 0), 0);
|
|
724
|
+
}
|
|
659
725
|
/** POST one derived-field batch, retrying the ingest gate's 429 (honoring
|
|
660
726
|
* Retry-After) and transient 5xx. */
|
|
661
727
|
async function postFieldBatch(base, token, rows) {
|
|
@@ -1640,7 +1706,13 @@ async function syncToTargetInScope(cred, opts = {}) {
|
|
|
1640
1706
|
}
|
|
1641
1707
|
};
|
|
1642
1708
|
let scanMs = 0, scanned = 0; // secret-scan metrics
|
|
1643
|
-
|
|
1709
|
+
// ONE walk is bounded (issue #16). Sessions the ledger has not acknowledged
|
|
1710
|
+
// go first, so a large corpus moves forward in bounded steps instead of one
|
|
1711
|
+
// unbounded pass that a restart repeats from the first session. An explicit
|
|
1712
|
+
// `opts.limit` from the caller still wins.
|
|
1713
|
+
const walkMax = opts.limit ?? walkSessionLimit();
|
|
1714
|
+
const ordered = walkMax > 0 ? orderRefsForWalk(refs, (id) => Boolean(ledger?.get(id))) : refs;
|
|
1715
|
+
const slice = walkMax > 0 ? ordered.slice(0, walkMax) : ordered;
|
|
1644
1716
|
// CHAT_RECALL_SYNC_TRACE=1: phase + progress markers with heap usage, to
|
|
1645
1717
|
// stderr. This is how the 2026-07-03 walk OOM was localized — keep it.
|
|
1646
1718
|
const trace = process.env.CHAT_RECALL_SYNC_TRACE === '1'
|
|
@@ -2299,10 +2371,22 @@ async function syncToTargetInScope(cred, opts = {}) {
|
|
|
2299
2371
|
* a resting RSS near 400 MB. At about 18 bytes per container byte, 24 MB
|
|
2300
2372
|
* stays under the limit. */
|
|
2301
2373
|
export const FULL_BUILD_MAX_BYTES = Math.max(8, parseInt(process.env.CHAT_RECALL_FULL_BUILD_MAX_MB || '24', 10)) * 1024 * 1024;
|
|
2374
|
+
/** Bytes of transcript an export actually carries.
|
|
2375
|
+
*
|
|
2376
|
+
* The ceiling above is measured on what we HAVE, and what we have first is the
|
|
2377
|
+
* export. Checking the export is what makes the guard reach every backend:
|
|
2378
|
+
* sessionBuildBytes() reads fileSize(), which is 0 for a backend whose sessions
|
|
2379
|
+
* live in SQLite and have no file at all, so the full build ran and a 353 MB
|
|
2380
|
+
* session OOMed the walk. A build costs many times the bytes it is given, so
|
|
2381
|
+
* the decision has to be made before the build, not after it. */
|
|
2382
|
+
export function exportByteLength(exp) {
|
|
2383
|
+
if (!exp)
|
|
2384
|
+
return 0;
|
|
2385
|
+
return exp.files.reduce((n, f) => n + f.bytes.length, 0);
|
|
2386
|
+
}
|
|
2302
2387
|
/** Transcript bytes beyond which the derived computations (diff, outcome,
|
|
2303
2388
|
* commits, markers) are skipped. They run in the scan worker and read the
|
|
2304
|
-
* whole transcript; a 353 MB session with 100 MB JSON lines OOMed the walk. */
|
|
2305
|
-
export const DERIVED_MAX_BYTES = Math.max(8, parseInt(process.env.CHAT_RECALL_DERIVED_MAX_MB || '64', 10)) * 1024 * 1024;
|
|
2389
|
+
* whole transcript; a 353 MB session with 100 MB JSON lines OOMed the walk. */ export const DERIVED_MAX_BYTES = Math.max(8, parseInt(process.env.CHAT_RECALL_DERIVED_MAX_MB || '64', 10)) * 1024 * 1024;
|
|
2306
2390
|
/** Bytes of transcript one chunk of a chunked sync carries: the head of an
|
|
2307
2391
|
* oversized FULL sync, and each append. */
|
|
2308
2392
|
export const SYNC_CHUNK_BYTES = 8 * 1024 * 1024;
|
|
@@ -2445,7 +2529,31 @@ export async function buildConversationSync(ref, mtime, opts = {}) {
|
|
|
2445
2529
|
// updateShadow used to build a second identical copy from the same
|
|
2446
2530
|
// export — a wasted copy of every byte on a 47 MB transcript.
|
|
2447
2531
|
let built;
|
|
2448
|
-
|
|
2532
|
+
// THE BUILD COSTS MANY TIMES WHAT IT IS GIVEN, SO ASK BEFORE THE BUILD.
|
|
2533
|
+
//
|
|
2534
|
+
// Measured on this machine with the service's own heap cap: a 124 MB
|
|
2535
|
+
// transcript reached 263 MB after the read, 511 MB after
|
|
2536
|
+
// buildRawContainer, 555 MB after the gzip — and heapUsed never passed
|
|
2537
|
+
// 25 MB, because the container's strings and the buffers are off-heap.
|
|
2538
|
+
// The ceiling check after the build therefore cannot protect the build.
|
|
2539
|
+
// An export over the ceiling gets no container copy and no shadow merge;
|
|
2540
|
+
// the live parse below reads it once instead.
|
|
2541
|
+
const exportBytes = exportByteLength(exp);
|
|
2542
|
+
const overCeiling = exportBytes > FULL_BUILD_MAX_BYTES;
|
|
2543
|
+
if (exp && overCeiling) {
|
|
2544
|
+
console.error(`[sync] ${ref.prefixedId} export is ${(exportBytes / 1048576).toFixed(0)}MB `
|
|
2545
|
+
+ `(over the ${(FULL_BUILD_MAX_BYTES / 1048576).toFixed(0)}MB ceiling) — parsing it in place, `
|
|
2546
|
+
+ 'no container copy, no shadow merge, no raw archive');
|
|
2547
|
+
record({
|
|
2548
|
+
kind: 'oversized_session',
|
|
2549
|
+
mb: Math.round(exportBytes / 1048576),
|
|
2550
|
+
tool: ref.toolId,
|
|
2551
|
+
dedupeKey: stableMark(ref.prefixedId),
|
|
2552
|
+
});
|
|
2553
|
+
includeRaw = false;
|
|
2554
|
+
includeMeta = false;
|
|
2555
|
+
}
|
|
2556
|
+
if (exp && !overCeiling) {
|
|
2449
2557
|
try {
|
|
2450
2558
|
built = buildRawContainer(exp);
|
|
2451
2559
|
srcHash = containerSrcHash(built);
|
|
@@ -2496,7 +2604,9 @@ export async function buildConversationSync(ref, mtime, opts = {}) {
|
|
|
2496
2604
|
includeMeta = false;
|
|
2497
2605
|
}
|
|
2498
2606
|
}
|
|
2499
|
-
const shadow =
|
|
2607
|
+
const shadow = overCeiling
|
|
2608
|
+
? { container: null, status: 'skipped', recovered: 0 }
|
|
2609
|
+
: updateShadow(ref.rawId, exp, built);
|
|
2500
2610
|
if (shadow.container) {
|
|
2501
2611
|
fullestContainer = shadow.container;
|
|
2502
2612
|
if (shadow.status === 'rewrite-merged' && shadow.recovered > 0) {
|