chat-recall 0.7.37 → 0.7.38
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 +75 -6
- package/dist/mcp-relay.js +1 -1
- package/dist/mcp.js +75 -6
- package/dist/message-hook.js +1 -1
- package/dist/sync-client.d.ts +17 -1
- package/dist/sync-client.d.ts.map +1 -1
- package/dist/sync-client.js +75 -3
- 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 +85 -8
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -16056,6 +16056,29 @@ var init_secret_precision = __esm({
|
|
|
16056
16056
|
}
|
|
16057
16057
|
});
|
|
16058
16058
|
|
|
16059
|
+
// src/walk-budget.ts
|
|
16060
|
+
function walkSessionLimit(env = process.env) {
|
|
16061
|
+
const raw = env.CHAT_RECALL_SYNC_WALK_MAX;
|
|
16062
|
+
if (raw === void 0 || raw.trim() === "") return DEFAULT_WALK_MAX_SESSIONS;
|
|
16063
|
+
const n = Number(raw);
|
|
16064
|
+
if (!Number.isFinite(n) || !Number.isInteger(n) || n <= 0) return DEFAULT_WALK_MAX_SESSIONS;
|
|
16065
|
+
return n;
|
|
16066
|
+
}
|
|
16067
|
+
function orderRefsForWalk(refs, isAcked) {
|
|
16068
|
+
const fresh = [];
|
|
16069
|
+
const acked = [];
|
|
16070
|
+
for (const ref of refs) (isAcked(ref.prefixedId) ? acked : fresh).push(ref);
|
|
16071
|
+
return [...fresh, ...acked];
|
|
16072
|
+
}
|
|
16073
|
+
var DEFAULT_WALK_MAX_SESSIONS, FULL_WALK_INTERVAL_MS;
|
|
16074
|
+
var init_walk_budget = __esm({
|
|
16075
|
+
"src/walk-budget.ts"() {
|
|
16076
|
+
"use strict";
|
|
16077
|
+
DEFAULT_WALK_MAX_SESSIONS = 2e3;
|
|
16078
|
+
FULL_WALK_INTERVAL_MS = 6 * 60 * 6e4;
|
|
16079
|
+
}
|
|
16080
|
+
});
|
|
16081
|
+
|
|
16059
16082
|
// ../engine/dist/transcript/types.js
|
|
16060
16083
|
var TRANSCRIPT_VERSION;
|
|
16061
16084
|
var init_types = __esm({
|
|
@@ -28318,7 +28341,7 @@ var init_http = __esm({
|
|
|
28318
28341
|
CLI_VERSION = JSON.parse(readFileSync36(new URL("../package.json", import.meta.url), "utf-8")).version || CLI_VERSION;
|
|
28319
28342
|
} catch {
|
|
28320
28343
|
try {
|
|
28321
|
-
if (true) CLI_VERSION = "0.7.
|
|
28344
|
+
if (true) CLI_VERSION = "0.7.38";
|
|
28322
28345
|
} catch {
|
|
28323
28346
|
}
|
|
28324
28347
|
}
|
|
@@ -28816,7 +28839,7 @@ var init_telemetry = __esm({
|
|
|
28816
28839
|
init_sync_client();
|
|
28817
28840
|
cliVersion2 = () => {
|
|
28818
28841
|
try {
|
|
28819
|
-
return true ? "0.7.
|
|
28842
|
+
return true ? "0.7.38" : "dev";
|
|
28820
28843
|
} catch {
|
|
28821
28844
|
return "dev";
|
|
28822
28845
|
}
|
|
@@ -29664,8 +29687,10 @@ __export(sync_client_exports, {
|
|
|
29664
29687
|
buildConversationTail: () => buildConversationTail,
|
|
29665
29688
|
classedError: () => classedError,
|
|
29666
29689
|
classifyError: () => classifyError,
|
|
29690
|
+
countsForBreaker: () => countsForBreaker,
|
|
29667
29691
|
isStandingFailure: () => isStandingFailure,
|
|
29668
29692
|
isSyncSkip: () => isSyncSkip,
|
|
29693
|
+
lastSuccessfulWalkAt: () => lastSuccessfulWalkAt,
|
|
29669
29694
|
loadAllCredentials: () => loadAllCredentials,
|
|
29670
29695
|
loadCredentials: () => loadCredentials,
|
|
29671
29696
|
reapStaleScanDirs: () => reapStaleScanDirs,
|
|
@@ -29700,11 +29725,15 @@ function isStandingFailure(err) {
|
|
|
29700
29725
|
const c = taggedClass(err);
|
|
29701
29726
|
return c !== null && STANDING_FAILURE.has(c);
|
|
29702
29727
|
}
|
|
29728
|
+
function countsForBreaker(cls) {
|
|
29729
|
+
return cls !== "rate_limited" && cls !== "payload_too_large";
|
|
29730
|
+
}
|
|
29703
29731
|
function classifyError(msg, err) {
|
|
29704
29732
|
const tagged = taggedClass(err);
|
|
29705
29733
|
if (tagged) return tagged;
|
|
29706
29734
|
const m = msg.toLowerCase();
|
|
29707
29735
|
if (m.includes("429")) return "rate_limited";
|
|
29736
|
+
if (m.includes("body_too_large") || m.includes("payload too large") || m.includes("entity too large")) return "payload_too_large";
|
|
29708
29737
|
if (m.includes("402")) return "payment_required";
|
|
29709
29738
|
if (m.includes("401") || m.includes("403") || m.includes("token")) return "auth";
|
|
29710
29739
|
if (m.includes("timed out") || m.includes("etimedout") || m.includes("aborted due to timeout")) return "timeout";
|
|
@@ -29973,6 +30002,12 @@ async function syncSessions(opts = {}) {
|
|
|
29973
30002
|
const msg = e instanceof Error ? e.message : String(e);
|
|
29974
30003
|
errors.push(`${cred.serverUrl}: ${msg}`);
|
|
29975
30004
|
perTarget[cred.serverUrl] = { ok: false, error: msg, accepted: acceptedUploads.get(cred.serverUrl) ?? 0 };
|
|
30005
|
+
const cls = classifyError(msg, e);
|
|
30006
|
+
if (!countsForBreaker(cls)) {
|
|
30007
|
+
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`);
|
|
30008
|
+
record({ kind: "target_throttled", failures: 0, retryInMs: 0, errorClass: cls, local: isLocalHost(cred.serverUrl) ? 1 : 0 });
|
|
30009
|
+
continue;
|
|
30010
|
+
}
|
|
29976
30011
|
const next = noteTargetFailure(cred.serverUrl, msg);
|
|
29977
30012
|
const notice = breakerNotice(cred.serverUrl, next);
|
|
29978
30013
|
if (notice) console.error(`[sync] ${notice}`);
|
|
@@ -29985,7 +30020,7 @@ async function syncSessions(opts = {}) {
|
|
|
29985
30020
|
kind: next.tripped ? "breaker_trip" : "target_failure",
|
|
29986
30021
|
failures: next.failures,
|
|
29987
30022
|
retryInMs: next.retryInMs,
|
|
29988
|
-
errorClass:
|
|
30023
|
+
errorClass: cls,
|
|
29989
30024
|
local: isLocalHost(cred.serverUrl) ? 1 : 0
|
|
29990
30025
|
});
|
|
29991
30026
|
}
|
|
@@ -30010,6 +30045,11 @@ async function syncSessions(opts = {}) {
|
|
|
30010
30045
|
rssPeakMb: Math.round(process.memoryUsage().rss / 1048576)
|
|
30011
30046
|
});
|
|
30012
30047
|
}
|
|
30048
|
+
if (agg) {
|
|
30049
|
+
for (const t of targets) {
|
|
30050
|
+
if (!errors.some((e) => e.startsWith(`${t.serverUrl}:`))) noteWalkSuccess(t.serverUrl);
|
|
30051
|
+
}
|
|
30052
|
+
}
|
|
30013
30053
|
void flush().catch(() => {
|
|
30014
30054
|
});
|
|
30015
30055
|
if (!agg) throw new Error(`sync failed for all targets:
|
|
@@ -30018,6 +30058,32 @@ async function syncSessions(opts = {}) {
|
|
|
30018
30058
|
${errors.join("\n ")}`);
|
|
30019
30059
|
return { ...agg, perTarget };
|
|
30020
30060
|
}
|
|
30061
|
+
function walkStatePath() {
|
|
30062
|
+
return join47(getDataDir(), "walk-state.json");
|
|
30063
|
+
}
|
|
30064
|
+
function readWalkState() {
|
|
30065
|
+
try {
|
|
30066
|
+
const raw = JSON.parse(readFileSync41(walkStatePath(), "utf-8"));
|
|
30067
|
+
return raw && typeof raw === "object" ? raw : {};
|
|
30068
|
+
} catch {
|
|
30069
|
+
return {};
|
|
30070
|
+
}
|
|
30071
|
+
}
|
|
30072
|
+
function noteWalkSuccess(serverUrl) {
|
|
30073
|
+
try {
|
|
30074
|
+
const state2 = readWalkState();
|
|
30075
|
+
state2[serverUrl.replace(/\/+$/, "")] = Date.now();
|
|
30076
|
+
mkdirSync11(getDataDir(), { recursive: true });
|
|
30077
|
+
writeFileSync10(walkStatePath(), JSON.stringify(state2));
|
|
30078
|
+
} catch {
|
|
30079
|
+
}
|
|
30080
|
+
}
|
|
30081
|
+
function lastSuccessfulWalkAt(serverUrl) {
|
|
30082
|
+
const state2 = readWalkState();
|
|
30083
|
+
const key2 = serverUrl?.replace(/\/+$/, "");
|
|
30084
|
+
const stamps = key2 ? [state2[key2]] : Object.values(state2);
|
|
30085
|
+
return stamps.reduce((max, v) => Math.max(max, typeof v === "number" ? v : 0), 0);
|
|
30086
|
+
}
|
|
30021
30087
|
async function postFieldBatch(base4, token, rows) {
|
|
30022
30088
|
const headers = { "content-type": "application/json" };
|
|
30023
30089
|
if (token) headers.authorization = `Bearer ${token}`;
|
|
@@ -30547,7 +30613,9 @@ async function syncToTargetInScope(cred, opts = {}) {
|
|
|
30547
30613
|
}
|
|
30548
30614
|
};
|
|
30549
30615
|
let scanMs = 0, scanned = 0;
|
|
30550
|
-
const
|
|
30616
|
+
const walkMax = opts.limit ?? walkSessionLimit();
|
|
30617
|
+
const ordered = walkMax > 0 ? orderRefsForWalk(refs, (id) => Boolean(ledger?.get(id))) : refs;
|
|
30618
|
+
const slice = walkMax > 0 ? ordered.slice(0, walkMax) : ordered;
|
|
30551
30619
|
const trace = process.env.CHAT_RECALL_SYNC_TRACE === "1" ? (msg) => {
|
|
30552
30620
|
const m = process.memoryUsage();
|
|
30553
30621
|
console.error(`[sync-trace] ${msg} \xB7 heap=${(m.heapUsed / 1048576).toFixed(0)}MB rss=${(m.rss / 1048576).toFixed(0)}MB`);
|
|
@@ -31402,6 +31470,7 @@ var init_sync_client = __esm({
|
|
|
31402
31470
|
init_secret_precision();
|
|
31403
31471
|
init_settings();
|
|
31404
31472
|
init_paths();
|
|
31473
|
+
init_walk_budget();
|
|
31405
31474
|
init_tool_backend();
|
|
31406
31475
|
init_transcript();
|
|
31407
31476
|
init_claude2();
|
|
@@ -31435,7 +31504,7 @@ var init_sync_client = __esm({
|
|
|
31435
31504
|
ownVersion = JSON.parse(readFileSync41(join47(dir, "../package.json"), "utf-8")).version || ownVersion;
|
|
31436
31505
|
} catch {
|
|
31437
31506
|
try {
|
|
31438
|
-
if (true) ownVersion = "0.7.
|
|
31507
|
+
if (true) ownVersion = "0.7.38";
|
|
31439
31508
|
} catch {
|
|
31440
31509
|
}
|
|
31441
31510
|
}
|
|
@@ -37459,7 +37528,7 @@ var init_intent_drain = __esm({
|
|
|
37459
37528
|
ownVersion2 = JSON.parse(readFileSync52(join65(dir, "../package.json"), "utf-8")).version || ownVersion2;
|
|
37460
37529
|
} catch {
|
|
37461
37530
|
try {
|
|
37462
|
-
if (true) ownVersion2 = "0.7.
|
|
37531
|
+
if (true) ownVersion2 = "0.7.38";
|
|
37463
37532
|
} catch {
|
|
37464
37533
|
}
|
|
37465
37534
|
}
|
package/dist/mcp-relay.js
CHANGED
|
@@ -377,7 +377,7 @@ function resilientBridge(input, output, first, reconnect, exit, opts = {}) {
|
|
|
377
377
|
}
|
|
378
378
|
|
|
379
379
|
// src/mcp-relay.ts
|
|
380
|
-
var VERSION = true ? "0.7.
|
|
380
|
+
var VERSION = true ? "0.7.38" : "0.0.0";
|
|
381
381
|
var SERVER_URL = new URL("./mcp.js", import.meta.url);
|
|
382
382
|
var SERVER_PATH = fileURLToPath(SERVER_URL);
|
|
383
383
|
var START_TIMEOUT_MS = 15e3;
|
package/dist/mcp.js
CHANGED
|
@@ -17370,6 +17370,29 @@ var init_secret_precision = __esm({
|
|
|
17370
17370
|
}
|
|
17371
17371
|
});
|
|
17372
17372
|
|
|
17373
|
+
// src/walk-budget.ts
|
|
17374
|
+
function walkSessionLimit(env = process.env) {
|
|
17375
|
+
const raw = env.CHAT_RECALL_SYNC_WALK_MAX;
|
|
17376
|
+
if (raw === void 0 || raw.trim() === "") return DEFAULT_WALK_MAX_SESSIONS;
|
|
17377
|
+
const n = Number(raw);
|
|
17378
|
+
if (!Number.isFinite(n) || !Number.isInteger(n) || n <= 0) return DEFAULT_WALK_MAX_SESSIONS;
|
|
17379
|
+
return n;
|
|
17380
|
+
}
|
|
17381
|
+
function orderRefsForWalk(refs, isAcked) {
|
|
17382
|
+
const fresh = [];
|
|
17383
|
+
const acked = [];
|
|
17384
|
+
for (const ref of refs) (isAcked(ref.prefixedId) ? acked : fresh).push(ref);
|
|
17385
|
+
return [...fresh, ...acked];
|
|
17386
|
+
}
|
|
17387
|
+
var DEFAULT_WALK_MAX_SESSIONS, FULL_WALK_INTERVAL_MS;
|
|
17388
|
+
var init_walk_budget = __esm({
|
|
17389
|
+
"src/walk-budget.ts"() {
|
|
17390
|
+
"use strict";
|
|
17391
|
+
DEFAULT_WALK_MAX_SESSIONS = 2e3;
|
|
17392
|
+
FULL_WALK_INTERVAL_MS = 6 * 60 * 6e4;
|
|
17393
|
+
}
|
|
17394
|
+
});
|
|
17395
|
+
|
|
17373
17396
|
// ../engine/dist/core/entity-extractor.js
|
|
17374
17397
|
function looksLikeStrictTool(raw) {
|
|
17375
17398
|
const t = raw.trim().toLowerCase();
|
|
@@ -29285,7 +29308,7 @@ var init_http = __esm({
|
|
|
29285
29308
|
CLI_VERSION = JSON.parse(readFileSync44(new URL("../package.json", import.meta.url), "utf-8")).version || CLI_VERSION;
|
|
29286
29309
|
} catch {
|
|
29287
29310
|
try {
|
|
29288
|
-
if (true) CLI_VERSION = "0.7.
|
|
29311
|
+
if (true) CLI_VERSION = "0.7.38";
|
|
29289
29312
|
} catch {
|
|
29290
29313
|
}
|
|
29291
29314
|
}
|
|
@@ -29783,7 +29806,7 @@ var init_telemetry = __esm({
|
|
|
29783
29806
|
init_sync_client();
|
|
29784
29807
|
cliVersion2 = () => {
|
|
29785
29808
|
try {
|
|
29786
|
-
return true ? "0.7.
|
|
29809
|
+
return true ? "0.7.38" : "dev";
|
|
29787
29810
|
} catch {
|
|
29788
29811
|
return "dev";
|
|
29789
29812
|
}
|
|
@@ -30413,8 +30436,10 @@ __export(sync_client_exports, {
|
|
|
30413
30436
|
buildConversationTail: () => buildConversationTail,
|
|
30414
30437
|
classedError: () => classedError,
|
|
30415
30438
|
classifyError: () => classifyError,
|
|
30439
|
+
countsForBreaker: () => countsForBreaker,
|
|
30416
30440
|
isStandingFailure: () => isStandingFailure,
|
|
30417
30441
|
isSyncSkip: () => isSyncSkip,
|
|
30442
|
+
lastSuccessfulWalkAt: () => lastSuccessfulWalkAt,
|
|
30418
30443
|
loadAllCredentials: () => loadAllCredentials,
|
|
30419
30444
|
loadCredentials: () => loadCredentials,
|
|
30420
30445
|
reapStaleScanDirs: () => reapStaleScanDirs,
|
|
@@ -30449,11 +30474,15 @@ function isStandingFailure(err) {
|
|
|
30449
30474
|
const c = taggedClass(err);
|
|
30450
30475
|
return c !== null && STANDING_FAILURE.has(c);
|
|
30451
30476
|
}
|
|
30477
|
+
function countsForBreaker(cls) {
|
|
30478
|
+
return cls !== "rate_limited" && cls !== "payload_too_large";
|
|
30479
|
+
}
|
|
30452
30480
|
function classifyError(msg, err) {
|
|
30453
30481
|
const tagged = taggedClass(err);
|
|
30454
30482
|
if (tagged) return tagged;
|
|
30455
30483
|
const m = msg.toLowerCase();
|
|
30456
30484
|
if (m.includes("429")) return "rate_limited";
|
|
30485
|
+
if (m.includes("body_too_large") || m.includes("payload too large") || m.includes("entity too large")) return "payload_too_large";
|
|
30457
30486
|
if (m.includes("402")) return "payment_required";
|
|
30458
30487
|
if (m.includes("401") || m.includes("403") || m.includes("token")) return "auth";
|
|
30459
30488
|
if (m.includes("timed out") || m.includes("etimedout") || m.includes("aborted due to timeout")) return "timeout";
|
|
@@ -30722,6 +30751,12 @@ async function syncSessions(opts = {}) {
|
|
|
30722
30751
|
const msg = e instanceof Error ? e.message : String(e);
|
|
30723
30752
|
errors.push(`${cred.serverUrl}: ${msg}`);
|
|
30724
30753
|
perTarget[cred.serverUrl] = { ok: false, error: msg, accepted: acceptedUploads.get(cred.serverUrl) ?? 0 };
|
|
30754
|
+
const cls = classifyError(msg, e);
|
|
30755
|
+
if (!countsForBreaker(cls)) {
|
|
30756
|
+
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`);
|
|
30757
|
+
record({ kind: "target_throttled", failures: 0, retryInMs: 0, errorClass: cls, local: isLocalHost(cred.serverUrl) ? 1 : 0 });
|
|
30758
|
+
continue;
|
|
30759
|
+
}
|
|
30725
30760
|
const next = noteTargetFailure(cred.serverUrl, msg);
|
|
30726
30761
|
const notice = breakerNotice(cred.serverUrl, next);
|
|
30727
30762
|
if (notice) console.error(`[sync] ${notice}`);
|
|
@@ -30734,7 +30769,7 @@ async function syncSessions(opts = {}) {
|
|
|
30734
30769
|
kind: next.tripped ? "breaker_trip" : "target_failure",
|
|
30735
30770
|
failures: next.failures,
|
|
30736
30771
|
retryInMs: next.retryInMs,
|
|
30737
|
-
errorClass:
|
|
30772
|
+
errorClass: cls,
|
|
30738
30773
|
local: isLocalHost(cred.serverUrl) ? 1 : 0
|
|
30739
30774
|
});
|
|
30740
30775
|
}
|
|
@@ -30759,6 +30794,11 @@ async function syncSessions(opts = {}) {
|
|
|
30759
30794
|
rssPeakMb: Math.round(process.memoryUsage().rss / 1048576)
|
|
30760
30795
|
});
|
|
30761
30796
|
}
|
|
30797
|
+
if (agg) {
|
|
30798
|
+
for (const t of targets) {
|
|
30799
|
+
if (!errors.some((e) => e.startsWith(`${t.serverUrl}:`))) noteWalkSuccess(t.serverUrl);
|
|
30800
|
+
}
|
|
30801
|
+
}
|
|
30762
30802
|
void flush().catch(() => {
|
|
30763
30803
|
});
|
|
30764
30804
|
if (!agg) throw new Error(`sync failed for all targets:
|
|
@@ -30767,6 +30807,32 @@ async function syncSessions(opts = {}) {
|
|
|
30767
30807
|
${errors.join("\n ")}`);
|
|
30768
30808
|
return { ...agg, perTarget };
|
|
30769
30809
|
}
|
|
30810
|
+
function walkStatePath() {
|
|
30811
|
+
return join56(getDataDir(), "walk-state.json");
|
|
30812
|
+
}
|
|
30813
|
+
function readWalkState() {
|
|
30814
|
+
try {
|
|
30815
|
+
const raw = JSON.parse(readFileSync47(walkStatePath(), "utf-8"));
|
|
30816
|
+
return raw && typeof raw === "object" ? raw : {};
|
|
30817
|
+
} catch {
|
|
30818
|
+
return {};
|
|
30819
|
+
}
|
|
30820
|
+
}
|
|
30821
|
+
function noteWalkSuccess(serverUrl) {
|
|
30822
|
+
try {
|
|
30823
|
+
const state2 = readWalkState();
|
|
30824
|
+
state2[serverUrl.replace(/\/+$/, "")] = Date.now();
|
|
30825
|
+
mkdirSync14(getDataDir(), { recursive: true });
|
|
30826
|
+
writeFileSync11(walkStatePath(), JSON.stringify(state2));
|
|
30827
|
+
} catch {
|
|
30828
|
+
}
|
|
30829
|
+
}
|
|
30830
|
+
function lastSuccessfulWalkAt(serverUrl) {
|
|
30831
|
+
const state2 = readWalkState();
|
|
30832
|
+
const key2 = serverUrl?.replace(/\/+$/, "");
|
|
30833
|
+
const stamps = key2 ? [state2[key2]] : Object.values(state2);
|
|
30834
|
+
return stamps.reduce((max, v) => Math.max(max, typeof v === "number" ? v : 0), 0);
|
|
30835
|
+
}
|
|
30770
30836
|
async function postFieldBatch(base2, token, rows) {
|
|
30771
30837
|
const headers2 = { "content-type": "application/json" };
|
|
30772
30838
|
if (token) headers2.authorization = `Bearer ${token}`;
|
|
@@ -31296,7 +31362,9 @@ async function syncToTargetInScope(cred, opts = {}) {
|
|
|
31296
31362
|
}
|
|
31297
31363
|
};
|
|
31298
31364
|
let scanMs = 0, scanned = 0;
|
|
31299
|
-
const
|
|
31365
|
+
const walkMax = opts.limit ?? walkSessionLimit();
|
|
31366
|
+
const ordered = walkMax > 0 ? orderRefsForWalk(refs, (id) => Boolean(ledger?.get(id))) : refs;
|
|
31367
|
+
const slice = walkMax > 0 ? ordered.slice(0, walkMax) : ordered;
|
|
31300
31368
|
const trace = process.env.CHAT_RECALL_SYNC_TRACE === "1" ? (msg) => {
|
|
31301
31369
|
const m = process.memoryUsage();
|
|
31302
31370
|
console.error(`[sync-trace] ${msg} \xB7 heap=${(m.heapUsed / 1048576).toFixed(0)}MB rss=${(m.rss / 1048576).toFixed(0)}MB`);
|
|
@@ -32151,6 +32219,7 @@ var init_sync_client = __esm({
|
|
|
32151
32219
|
init_secret_precision();
|
|
32152
32220
|
init_settings();
|
|
32153
32221
|
init_paths();
|
|
32222
|
+
init_walk_budget();
|
|
32154
32223
|
init_tool_backend();
|
|
32155
32224
|
init_transcript();
|
|
32156
32225
|
init_claude2();
|
|
@@ -32184,7 +32253,7 @@ var init_sync_client = __esm({
|
|
|
32184
32253
|
ownVersion = JSON.parse(readFileSync47(join56(dir, "../package.json"), "utf-8")).version || ownVersion;
|
|
32185
32254
|
} catch {
|
|
32186
32255
|
try {
|
|
32187
|
-
if (true) ownVersion = "0.7.
|
|
32256
|
+
if (true) ownVersion = "0.7.38";
|
|
32188
32257
|
} catch {
|
|
32189
32258
|
}
|
|
32190
32259
|
}
|
|
@@ -42355,7 +42424,7 @@ function installCrashGuards() {
|
|
|
42355
42424
|
reportClientEvent2("mcp_crash", { message: err.stack || err.message });
|
|
42356
42425
|
});
|
|
42357
42426
|
}
|
|
42358
|
-
var RELAY_VERSION = true ? "0.7.
|
|
42427
|
+
var RELAY_VERSION = true ? "0.7.38" : "0.0.0";
|
|
42359
42428
|
function daemonIdleSecs() {
|
|
42360
42429
|
const raw = process.env.CHAT_RECALL_DAEMON_IDLE_SECS;
|
|
42361
42430
|
if (raw === void 0) return 900;
|
package/dist/message-hook.js
CHANGED
|
@@ -267,7 +267,7 @@ try {
|
|
|
267
267
|
CLI_VERSION = JSON.parse(readFileSync5(new URL("../package.json", import.meta.url), "utf-8")).version || CLI_VERSION;
|
|
268
268
|
} catch {
|
|
269
269
|
try {
|
|
270
|
-
if (true) CLI_VERSION = "0.7.
|
|
270
|
+
if (true) CLI_VERSION = "0.7.38";
|
|
271
271
|
} catch {
|
|
272
272
|
}
|
|
273
273
|
}
|
package/dist/sync-client.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { type SessionRef } from '@chat-recall/engine/core/tool-backend.js';
|
|
|
5
5
|
export declare function classedError(errorClass: FailureClass, message: string): Error;
|
|
6
6
|
/** True when this error must not be retried. Exported for the tests. */
|
|
7
7
|
export declare function isStandingFailure(err: unknown): boolean;
|
|
8
|
-
export type FailureClass = 'rate_limited' | 'payment_required' | 'auth' | 'timeout' | 'refused' | 'dns' | 'network' | 'insecure_transport' | 'server_error' | 'other';
|
|
8
|
+
export type FailureClass = 'rate_limited' | 'payload_too_large' | 'payment_required' | 'auth' | 'timeout' | 'refused' | 'dns' | 'network' | 'insecure_transport' | 'server_error' | 'other';
|
|
9
9
|
/**
|
|
10
10
|
* Reduce an error message to a bounded CLASS.
|
|
11
11
|
*
|
|
@@ -16,6 +16,17 @@ export type FailureClass = 'rate_limited' | 'payment_required' | 'auth' | 'timeo
|
|
|
16
16
|
* A tag from the throw site always wins. The message tests remain for errors
|
|
17
17
|
* thrown by fetch itself, and by code that predates the tag.
|
|
18
18
|
*/
|
|
19
|
+
/**
|
|
20
|
+
* Does a failed walk count against the target's circuit breaker?
|
|
21
|
+
*
|
|
22
|
+
* A server that answers 429 (busy, Retry-After) or 413 (this body is above the
|
|
23
|
+
* limit) is not broken. The in-walk retry already honoured Retry-After, and the
|
|
24
|
+
* body limit is a fact about one session. Counting either would open the
|
|
25
|
+
* breaker for 1–15 minutes and silence a healthy collector exactly while the
|
|
26
|
+
* server recovers (issue #16: the collector sat in cooldown on 502s and on
|
|
27
|
+
* rate limits while the pods were restarting).
|
|
28
|
+
*/
|
|
29
|
+
export declare function countsForBreaker(cls: FailureClass): boolean;
|
|
19
30
|
export declare function classifyError(msg: string, err?: unknown): FailureClass;
|
|
20
31
|
import { type ArchiveFile } from './raw-archive-parts.js';
|
|
21
32
|
import '@chat-recall/engine/core/backends/index.js';
|
|
@@ -122,6 +133,11 @@ export interface ReconcileResult {
|
|
|
122
133
|
absent: number;
|
|
123
134
|
}>;
|
|
124
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* When did a walk last succeed (0 = never on this machine)?
|
|
138
|
+
* The daemon uses this to decide 'changed' or 'full' after a restart.
|
|
139
|
+
*/
|
|
140
|
+
export declare function lastSuccessfulWalkAt(serverUrl?: string): number;
|
|
125
141
|
/**
|
|
126
142
|
* Manual entrypoint (CLI `reconcile`): reconcile derived fields for ALL targets.
|
|
127
143
|
* Normal `sync` already runs reconciliation each pass; this is the explicit
|
|
@@ -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,YAAY,EAAE,OAAO,EAAE,MAAM,GAAG,KAAK,CAI7E;AAgBD,wEAAwE;AACxE,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAGvD;AAED,MAAM,MAAM,YAAY,GACpB,cAAc,GAAG,mBAAmB,GAAG,kBAAkB,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAC1F,KAAK,GAAG,SAAS,GAAG,oBAAoB,GAAG,cAAc,GAAG,OAAO,CAAC;AAExE;;;;;;;;;GASG;AACH;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAE3D;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,GAAG,YAAY,CAy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IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CAyFlJ;AAED;;;;;;GAMG;AACH;;;;;;;;GAQG;AACH;;;;yCAIyC;AACzC,MAAM,WAAW,QAAQ;IAAG,OAAO,EAAE,gBAAgB,GAAG,QAAQ,GAAG,WAAW,CAAA;CAAE;AAEhF,wBAAgB,UAAU,CAAC,CAAC,EAAE,UAAU,GAAG,QAAQ,GAAG,CAAC,IAAI,QAAQ,CAElE;AAED,wBAAsB,eAAe,CAAC,IAAI,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAO,GAAG,OAAO,CAAC,UAAU,GAAG,QAAQ,CAAC,CA4C/G"}
|
package/dist/sync-client.js
CHANGED
|
@@ -46,6 +46,7 @@ import { isInternalToolPrompt } from '@chat-recall/engine/core/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'
|