mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-27 01:19:25 +08:00
fix(panel): ignore empty .db-wal mtime churn and throttle remote SSH trajectory rescan
This commit is contained in:
@@ -122,7 +122,9 @@ function readConversationMtime(files = []) {
|
|||||||
const fullPath = /[\\/]|^[a-zA-Z]:/.test(nameOrPath)
|
const fullPath = /[\\/]|^[a-zA-Z]:/.test(nameOrPath)
|
||||||
? nameOrPath
|
? nameOrPath
|
||||||
: join(CONVERSATIONS_DIR, nameOrPath);
|
: join(CONVERSATIONS_DIR, nameOrPath);
|
||||||
mtimeMs = Math.max(mtimeMs, Number(statSync(fullPath)?.mtimeMs || 0));
|
const st = statSync(fullPath);
|
||||||
|
if (/\.db-wal$/i.test(fullPath) && Number(st?.size || 0) <= 0) continue;
|
||||||
|
mtimeMs = Math.max(mtimeMs, Number(st?.mtimeMs || 0));
|
||||||
} catch {
|
} catch {
|
||||||
// 轨迹文件可能在目录枚举后被宿主删除。
|
// 轨迹文件可能在目录枚举后被宿主删除。
|
||||||
}
|
}
|
||||||
@@ -352,6 +354,12 @@ function attachStepAccountOwners(steps, prev, currentAccountName, entryAccountNa
|
|||||||
const MAX_SUBAGENT_RECONCILE_DEPTH = 4;
|
const MAX_SUBAGENT_RECONCILE_DEPTH = 4;
|
||||||
const FAILED_RPC_COOLDOWN_MS = 60_000;
|
const FAILED_RPC_COOLDOWN_MS = 60_000;
|
||||||
const ACTIVE_FAILED_RPC_COOLDOWN_MS = 15_000;
|
const ACTIVE_FAILED_RPC_COOLDOWN_MS = 15_000;
|
||||||
|
const REMOTE_FAILED_RPC_COOLDOWN_MS = 15 * 60_000;
|
||||||
|
const REMOTE_ACTIVE_FAILED_RPC_COOLDOWN_MS = 30_000;
|
||||||
|
const NOT_FOUND_RPC_COOLDOWN_MS = 30 * 60_000;
|
||||||
|
const REMOTE_TRAJECTORY_RPC_TIMEOUT_MS = 25_000;
|
||||||
|
const REMOTE_BACKGROUND_FETCH_LIMIT = 2;
|
||||||
|
const REMOTE_CONSECUTIVE_TIMEOUT_BREAKER = 2;
|
||||||
const TRANSCRIPT_TAIL_MAX_BYTES = 96 * 1024;
|
const TRANSCRIPT_TAIL_MAX_BYTES = 96 * 1024;
|
||||||
const MAX_TRANSCRIPT_MEMO_ENTRIES = 64;
|
const MAX_TRANSCRIPT_MEMO_ENTRIES = 64;
|
||||||
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
||||||
@@ -1407,7 +1415,8 @@ export async function enumerateAndSyncConversations({
|
|||||||
const persistCacheIfNeeded = cacheStore.persistTrajectoryCacheIfNeeded;
|
const persistCacheIfNeeded = cacheStore.persistTrajectoryCacheIfNeeded;
|
||||||
const activeCooldownMap = isRemote ? endpoint.failedFetchCooldownMap : failedFetchCooldownMap;
|
const activeCooldownMap = isRemote ? endpoint.failedFetchCooldownMap : failedFetchCooldownMap;
|
||||||
const activeLiveActivityMemo = isRemote ? endpoint.liveActivityMemo : liveActivityMemo;
|
const activeLiveActivityMemo = isRemote ? endpoint.liveActivityMemo : liveActivityMemo;
|
||||||
const maxConcurrentRpc = isRemote ? 2 : MAX_CONCURRENT_RPC;
|
const maxConcurrentRpc = isRemote ? 1 : MAX_CONCURRENT_RPC;
|
||||||
|
let remoteConsecutiveTimeouts = 0;
|
||||||
|
|
||||||
const nowSweepMs = Date.now();
|
const nowSweepMs = Date.now();
|
||||||
if (forceRefresh) {
|
if (forceRefresh) {
|
||||||
@@ -1791,6 +1800,9 @@ export async function enumerateAndSyncConversations({
|
|||||||
attemptedFetchIds.add(c.cascadeId.toLowerCase());
|
attemptedFetchIds.add(c.cascadeId.toLowerCase());
|
||||||
}
|
}
|
||||||
for (let i = 0; i < targetConvs.length; i += maxConcurrentRpc) {
|
for (let i = 0; i < targetConvs.length; i += maxConcurrentRpc) {
|
||||||
|
if (isRemote && remoteConsecutiveTimeouts >= REMOTE_CONSECUTIVE_TIMEOUT_BREAKER) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
const batch = targetConvs.slice(i, i + maxConcurrentRpc);
|
const batch = targetConvs.slice(i, i + maxConcurrentRpc);
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
batch.map(async (conv) => {
|
batch.map(async (conv) => {
|
||||||
@@ -1825,10 +1837,13 @@ export async function enumerateAndSyncConversations({
|
|||||||
trajRes = await callLsRpc(
|
trajRes = await callLsRpc(
|
||||||
'GetCascadeTrajectory',
|
'GetCascadeTrajectory',
|
||||||
{ cascadeId: conv.cascadeId },
|
{ cascadeId: conv.cascadeId },
|
||||||
5000,
|
isRemote ? REMOTE_TRAJECTORY_RPC_TIMEOUT_MS : 5000,
|
||||||
endpoint
|
endpoint
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (isRemote) {
|
||||||
|
remoteConsecutiveTimeouts = 0;
|
||||||
|
}
|
||||||
if (!Array.isArray(trajRes?.trajectory?.steps)) {
|
if (!Array.isArray(trajRes?.trajectory?.steps)) {
|
||||||
throw new Error('Trajectory steps unavailable');
|
throw new Error('Trajectory steps unavailable');
|
||||||
}
|
}
|
||||||
@@ -2144,10 +2159,23 @@ export async function enumerateAndSyncConversations({
|
|||||||
) {
|
) {
|
||||||
console.error(`Failed loading trajectory ${conv.cascadeId}: ${err.message}`);
|
console.error(`Failed loading trajectory ${conv.cascadeId}: ${err.message}`);
|
||||||
}
|
}
|
||||||
|
const errText = String(err?.message || '');
|
||||||
|
const isNotFoundErr = /(?:\(404\)|\bnot_found\b)/i.test(errText);
|
||||||
|
const isTimeoutErr = /(?:timed out|timeout|aborted)/i.test(errText);
|
||||||
|
if (isRemote && isTimeoutErr) {
|
||||||
|
remoteConsecutiveTimeouts += 1;
|
||||||
|
}
|
||||||
if (!(isRunning && (hasTailStepInfo || offlineRecovered))) {
|
if (!(isRunning && (hasTailStepInfo || offlineRecovered))) {
|
||||||
const cooldownMs =
|
const cooldownMs = isNotFoundErr
|
||||||
isRunning || isReq ? ACTIVE_FAILED_RPC_COOLDOWN_MS : FAILED_RPC_COOLDOWN_MS;
|
? NOT_FOUND_RPC_COOLDOWN_MS
|
||||||
activeCooldownMap.set(cooldownKey, { failedAt: nowPollMs, cooldownMs });
|
: isRemote
|
||||||
|
? isRunning || isReq
|
||||||
|
? REMOTE_ACTIVE_FAILED_RPC_COOLDOWN_MS
|
||||||
|
: REMOTE_FAILED_RPC_COOLDOWN_MS
|
||||||
|
: isRunning || isReq
|
||||||
|
? ACTIVE_FAILED_RPC_COOLDOWN_MS
|
||||||
|
: FAILED_RPC_COOLDOWN_MS;
|
||||||
|
activeCooldownMap.set(cooldownKey, { failedAt: Date.now(), cooldownMs });
|
||||||
}
|
}
|
||||||
const tailStepsOnErr =
|
const tailStepsOnErr =
|
||||||
partialTailSteps.length > 0
|
partialTailSteps.length > 0
|
||||||
@@ -2320,7 +2348,28 @@ export async function enumerateAndSyncConversations({
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
await fetchTrajectoryBatch(toFetch);
|
let fetchQueue = toFetch;
|
||||||
|
if (isRemote && toFetch.length > REMOTE_BACKGROUND_FETCH_LIMIT) {
|
||||||
|
const priorityConvs = [];
|
||||||
|
const backgroundConvs = [];
|
||||||
|
for (const conv of toFetch) {
|
||||||
|
const lowerCid = conv.cascadeId.toLowerCase();
|
||||||
|
const isPriority =
|
||||||
|
conv.status === 'CASCADE_RUN_STATUS_RUNNING' ||
|
||||||
|
lowerCid === reqLower ||
|
||||||
|
lowerCid === contextTelemetryCascadeId ||
|
||||||
|
lowerCid === selectedRootId ||
|
||||||
|
Boolean(conv.rootConversationId && conv.rootConversationId.toLowerCase() === selectedRootId);
|
||||||
|
if (isPriority) {
|
||||||
|
priorityConvs.push(conv);
|
||||||
|
} else if (backgroundConvs.length < REMOTE_BACKGROUND_FETCH_LIMIT) {
|
||||||
|
backgroundConvs.push(conv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fetchQueue = [...priorityConvs, ...backgroundConvs];
|
||||||
|
}
|
||||||
|
|
||||||
|
await fetchTrajectoryBatch(fetchQueue);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 阶段 2:根据父会话的 `subagentRefs` 将子代理归属关系、角色名称与启动顺序回填至子代理会话,
|
* 阶段 2:根据父会话的 `subagentRefs` 将子代理归属关系、角色名称与启动顺序回填至子代理会话,
|
||||||
|
|||||||
@@ -88,8 +88,9 @@ export function computeSqliteWalSig(dbPath) {
|
|||||||
}
|
}
|
||||||
const dbMtimeMs = Number(dbStat.mtimeMs || 0);
|
const dbMtimeMs = Number(dbStat.mtimeMs || 0);
|
||||||
const dbSize = Number(dbStat.size || 0);
|
const dbSize = Number(dbStat.size || 0);
|
||||||
const walMtimeMs = Number(walStat?.mtimeMs || 0);
|
|
||||||
const walSize = Number(walStat?.size || 0);
|
const walSize = Number(walStat?.size || 0);
|
||||||
|
// 0 字节的空 .db-wal 不含未 checkpoint 事务帧,忽略其 mtime 避免只读打开或宿主 LRU 驱逐触发死循环重扫
|
||||||
|
const walMtimeMs = walSize > 0 ? Number(walStat?.mtimeMs || 0) : 0;
|
||||||
return {
|
return {
|
||||||
exists: true,
|
exists: true,
|
||||||
mtimeMs: Math.max(dbMtimeMs, walMtimeMs),
|
mtimeMs: Math.max(dbMtimeMs, walMtimeMs),
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ import assert from 'node:assert/strict';
|
|||||||
import http from 'node:http';
|
import http from 'node:http';
|
||||||
import { execFile } from 'node:child_process';
|
import { execFile } from 'node:child_process';
|
||||||
import { promisify } from 'node:util';
|
import { promisify } from 'node:util';
|
||||||
import { mkdtempSync, mkdirSync, rmSync } from 'node:fs';
|
import { mkdtempSync, mkdirSync, rmSync, truncateSync, utimesSync, writeFileSync } from 'node:fs';
|
||||||
import { tmpdir } from 'node:os';
|
import { tmpdir } from 'node:os';
|
||||||
import { join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
import { readLocalSqliteTrajectory } from '../backend/cli-sqlite-reader.mjs';
|
import { computeSqliteWalSig, readLocalSqliteTrajectory } from '../backend/cli-sqlite-reader.mjs';
|
||||||
import { backendHarness } from './backend-harness.mjs';
|
import { backendHarness } from './backend-harness.mjs';
|
||||||
import { i18nStore } from '../src/i18n/index.js';
|
import { i18nStore } from '../src/i18n/index.js';
|
||||||
import {
|
import {
|
||||||
@@ -786,3 +786,43 @@ test('SQLite trajectory reader scans backwards past trailing plannerConfig-only
|
|||||||
'must decode tokenBreakdown on gen_metadata[0] even with 3 trailing plannerConfig-only records'
|
'must decode tokenBreakdown on gen_metadata[0] even with 3 trailing plannerConfig-only records'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('computeSqliteWalSig ignores zero-byte .db-wal mtime churn while detecting non-empty WAL writes', (t) => {
|
||||||
|
const tempRoot = mkdtempSync(join(tmpdir(), 'agy-sqlite-empty-wal-'));
|
||||||
|
t.after(() => rmSync(tempRoot, { recursive: true, force: true, maxRetries: 3, retryDelay: 50 }));
|
||||||
|
|
||||||
|
const dbPath = join(tempRoot, 'aaaaaaaa-bbbb-4ccc-8ddd-111111111111.db');
|
||||||
|
const walPath = `${dbPath}-wal`;
|
||||||
|
writeFileSync(dbPath, Buffer.from('sqlite-main-placeholder'));
|
||||||
|
const baseSec = 1_795_000_000;
|
||||||
|
utimesSync(dbPath, baseSec, baseSec);
|
||||||
|
|
||||||
|
const sigNoWal = computeSqliteWalSig(dbPath);
|
||||||
|
assert.equal(sigNoWal.exists, true);
|
||||||
|
assert.ok(sigNoWal.sig.endsWith('|0:0'), `expected |0:0 suffix, got ${sigNoWal.sig}`);
|
||||||
|
|
||||||
|
// Creating and touching a 0-byte .db-wal (e.g. SQLite WAL open/close or host LRU eviction)
|
||||||
|
// must NOT change sig or mtimeMs.
|
||||||
|
writeFileSync(walPath, Buffer.alloc(0));
|
||||||
|
utimesSync(walPath, baseSec + 120, baseSec + 120);
|
||||||
|
const sigEmptyWal1 = computeSqliteWalSig(dbPath);
|
||||||
|
assert.deepEqual(sigEmptyWal1, sigNoWal);
|
||||||
|
|
||||||
|
utimesSync(walPath, baseSec + 360, baseSec + 360);
|
||||||
|
const sigEmptyWal2 = computeSqliteWalSig(dbPath);
|
||||||
|
assert.deepEqual(sigEmptyWal2, sigNoWal);
|
||||||
|
|
||||||
|
// Real uncheckpointed WAL write (size > 0) MUST change sig and advance mtimeMs.
|
||||||
|
writeFileSync(walPath, Buffer.alloc(4096, 1));
|
||||||
|
utimesSync(walPath, baseSec + 500, baseSec + 500);
|
||||||
|
const sigNonEmptyWal = computeSqliteWalSig(dbPath);
|
||||||
|
assert.notEqual(sigNonEmptyWal.sig, sigNoWal.sig);
|
||||||
|
assert.ok(sigNonEmptyWal.mtimeMs > sigNoWal.mtimeMs);
|
||||||
|
assert.ok(sigNonEmptyWal.sig.endsWith(':4096'));
|
||||||
|
|
||||||
|
// Truncating the WAL back to 0 bytes converges back to the canonical |0:0 signature.
|
||||||
|
truncateSync(walPath, 0);
|
||||||
|
utimesSync(walPath, baseSec + 900, baseSec + 900);
|
||||||
|
const sigTruncatedWal = computeSqliteWalSig(dbPath);
|
||||||
|
assert.deepEqual(sigTruncatedWal, sigNoWal);
|
||||||
|
});
|
||||||
|
|||||||
@@ -2265,4 +2265,156 @@ test('Local Swarm ground truth (members.json killed=false & live transcript.json
|
|||||||
assert.equal(byCid2.get(wakingCid)?.swarmState, 'working');
|
assert.equal(byCid2.get(wakingCid)?.swarmState, 'working');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('remote endpoint caps background history fetches per poll, prioritizes active/selected sessions, records completion-time cooldowns, and trips timeout breaker', async () => {
|
||||||
|
let now = Date.UTC(2026, 10, 22, 12, 0, 0);
|
||||||
|
const h = backendHarness({ clock: () => now });
|
||||||
|
const ep = h.registerRemoteEndpoint({
|
||||||
|
origin: 'https://127.0.0.1:41999',
|
||||||
|
hostLabel: 'slow-ssh-host',
|
||||||
|
stableHostKey: 'slow-ssh-host',
|
||||||
|
});
|
||||||
|
|
||||||
|
const isoAt = (sec) => new Date(Date.UTC(2026, 10, 22, 11, 0, sec)).toISOString();
|
||||||
|
const makeStep = (sec) => ({
|
||||||
|
type: 'CORTEX_STEP_TYPE_PLANNER_RESPONSE',
|
||||||
|
status: 'CORTEX_STEP_STATUS_DONE',
|
||||||
|
metadata: {
|
||||||
|
createdAt: isoAt(sec),
|
||||||
|
completedAt: isoAt(sec + 2),
|
||||||
|
generatorModel: 'gemini-4-carbon-high',
|
||||||
|
modelUsage: {
|
||||||
|
model: 'gemini-4-carbon-high',
|
||||||
|
inputTokens: '100',
|
||||||
|
outputTokens: '50',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const selectedCid = '11111111-1111-4111-8111-000000000001';
|
||||||
|
const runningCid = '11111111-1111-4111-8111-000000000002';
|
||||||
|
const hist1 = '11111111-1111-4111-8111-000000000003';
|
||||||
|
const hist2 = '11111111-1111-4111-8111-000000000004';
|
||||||
|
const hist3 = '11111111-1111-4111-8111-000000000005';
|
||||||
|
const hist4 = '11111111-1111-4111-8111-000000000006';
|
||||||
|
|
||||||
|
const fetchedPerPoll = [];
|
||||||
|
let currentPollFetches = [];
|
||||||
|
h.setRemoteWindowRpcInvoker(async (_ep, method, body) => {
|
||||||
|
if (method === 'GetUserStatus') return { userStatus: { email: 'remote@example.com' } };
|
||||||
|
if (method === 'RetrieveUserQuotaSummary') return { response: { groups: [] } };
|
||||||
|
if (method === 'GetAllCascadeTrajectories') {
|
||||||
|
return {
|
||||||
|
trajectorySummaries: {
|
||||||
|
[selectedCid]: { stepCount: 1, createdTime: isoAt(10), lastModifiedTime: isoAt(10), status: 'CASCADE_RUN_STATUS_IDLE' },
|
||||||
|
[runningCid]: { stepCount: 1, createdTime: isoAt(20), lastModifiedTime: isoAt(20), status: 'CASCADE_RUN_STATUS_RUNNING' },
|
||||||
|
[hist1]: { stepCount: 1, createdTime: isoAt(60), lastModifiedTime: isoAt(60), status: 'CASCADE_RUN_STATUS_IDLE' },
|
||||||
|
[hist2]: { stepCount: 1, createdTime: isoAt(50), lastModifiedTime: isoAt(50), status: 'CASCADE_RUN_STATUS_IDLE' },
|
||||||
|
[hist3]: { stepCount: 1, createdTime: isoAt(40), lastModifiedTime: isoAt(40), status: 'CASCADE_RUN_STATUS_IDLE' },
|
||||||
|
[hist4]: { stepCount: 1, createdTime: isoAt(30), lastModifiedTime: isoAt(30), status: 'CASCADE_RUN_STATUS_IDLE' },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (method === 'GetCascadeTrajectory') {
|
||||||
|
currentPollFetches.push(body?.cascadeId);
|
||||||
|
return { trajectory: { steps: [makeStep(1)] } };
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
});
|
||||||
|
|
||||||
|
// Poll 1: Must fetch selectedCid + runningCid + at most 2 background history items (hist1, hist2)
|
||||||
|
currentPollFetches = [];
|
||||||
|
await h.executeTelemetryAction({ conversationId: selectedCid, range: 'today' }, { endpointId: ep.id });
|
||||||
|
fetchedPerPoll.push([...currentPollFetches]);
|
||||||
|
assert.ok(fetchedPerPoll[0].includes(selectedCid));
|
||||||
|
assert.ok(fetchedPerPoll[0].includes(runningCid));
|
||||||
|
assert.ok(fetchedPerPoll[0].includes(hist1));
|
||||||
|
assert.ok(fetchedPerPoll[0].includes(hist2));
|
||||||
|
assert.equal(fetchedPerPoll[0].includes(hist3), false, 'hist3 must be deferred to a later poll');
|
||||||
|
assert.equal(fetchedPerPoll[0].includes(hist4), false, 'hist4 must be deferred to a later poll');
|
||||||
|
|
||||||
|
// Poll 2: Backfills remaining hist3, hist4 (plus runningCid because it is RUNNING)
|
||||||
|
currentPollFetches = [];
|
||||||
|
now += 5_000;
|
||||||
|
await h.executeTelemetryAction({ conversationId: selectedCid, range: 'today' }, { endpointId: ep.id });
|
||||||
|
assert.ok(currentPollFetches.includes(hist3));
|
||||||
|
assert.ok(currentPollFetches.includes(hist4));
|
||||||
|
assert.equal(currentPollFetches.includes(hist1), false, 'cached hist1 must not be re-fetched');
|
||||||
|
|
||||||
|
// Part 2: Consecutive timeout breaker + completion-time cooldown + 404 long cooldown
|
||||||
|
const ep2 = h.registerRemoteEndpoint({
|
||||||
|
origin: 'https://127.0.0.1:42000',
|
||||||
|
hostLabel: 'timeout-ssh-host',
|
||||||
|
stableHostKey: 'timeout-ssh-host',
|
||||||
|
});
|
||||||
|
const t1 = '22222222-2222-4222-8222-000000000001';
|
||||||
|
const t2 = '22222222-2222-4222-8222-000000000002';
|
||||||
|
const t3 = '22222222-2222-4222-8222-000000000003';
|
||||||
|
const missingCid = '22222222-2222-4222-8222-000000000004';
|
||||||
|
const calls2 = [];
|
||||||
|
|
||||||
|
h.setRemoteWindowRpcInvoker(async (_ep, method, body) => {
|
||||||
|
if (method === 'GetUserStatus') return { userStatus: { email: 'remote@example.com' } };
|
||||||
|
if (method === 'RetrieveUserQuotaSummary') return { response: { groups: [] } };
|
||||||
|
if (method === 'GetAllCascadeTrajectories') {
|
||||||
|
return {
|
||||||
|
trajectorySummaries: {
|
||||||
|
[t1]: { stepCount: 1, createdTime: isoAt(90), lastModifiedTime: isoAt(90), status: 'CASCADE_RUN_STATUS_IDLE' },
|
||||||
|
[t2]: { stepCount: 1, createdTime: isoAt(80), lastModifiedTime: isoAt(80), status: 'CASCADE_RUN_STATUS_IDLE' },
|
||||||
|
[t3]: { stepCount: 1, createdTime: isoAt(70), lastModifiedTime: isoAt(70), status: 'CASCADE_RUN_STATUS_IDLE' },
|
||||||
|
[missingCid]: { stepCount: 1, createdTime: isoAt(60), lastModifiedTime: isoAt(60), status: 'CASCADE_RUN_STATUS_IDLE' },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (method === 'GetCascadeTrajectory') {
|
||||||
|
const cid = body?.cascadeId;
|
||||||
|
calls2.push(cid);
|
||||||
|
if (cid === missingCid) {
|
||||||
|
throw new Error('RPC GetCascadeTrajectory failed (404): not_found');
|
||||||
|
}
|
||||||
|
// Simulate slow remote RPC advancing the clock by 70s (> old 60s cooldown) before timing out
|
||||||
|
now += 70_000;
|
||||||
|
throw new Error('signal timed out');
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
});
|
||||||
|
|
||||||
|
// Poll A: t1 (selected, isReq=true -> 30s cooldown) and t2 (background -> 15m cooldown) both time out
|
||||||
|
// after advancing clock by 70s each -> trips 2-consecutive-timeout breaker, so t3 is NOT attempted.
|
||||||
|
await h.executeTelemetryAction({ conversationId: t1, range: 'today' }, { endpointId: ep2.id });
|
||||||
|
assert.deepEqual(calls2, [t1, t2]);
|
||||||
|
|
||||||
|
// Poll B (+15s after Poll A finished): if failedAt had wrongly used nowPollMs (140s earlier),
|
||||||
|
// BOTH t1 and t2 would already be expired; with completion-time Date.now(), t2 stays in 15m cooldown
|
||||||
|
// (and t1 is still within 30s of its completion if only 15s elapsed since t2 finished? t1 finished 85s ago -> expired,
|
||||||
|
// while t2 finished 15s ago -> still in 15m cooldown). Verify t2 stays suppressed and t3 + missingCid run.
|
||||||
|
calls2.length = 0;
|
||||||
|
now += 15_000;
|
||||||
|
await h.executeTelemetryAction({ conversationId: t3, range: 'today' }, { endpointId: ep2.id });
|
||||||
|
assert.equal(calls2.includes(t2), false, 't2 must stay in 15m remote timeout cooldown');
|
||||||
|
assert.ok(calls2.includes(t3), 'selected t3 must be attempted');
|
||||||
|
assert.ok(calls2.includes(missingCid) || calls2.includes(t1), 'remaining non-cooled entries proceed until breaker');
|
||||||
|
|
||||||
|
// Ensure missingCid hits 404 once if deferred by breaker above
|
||||||
|
if (!calls2.includes(missingCid)) {
|
||||||
|
calls2.length = 0;
|
||||||
|
now += 5_000;
|
||||||
|
await h.executeTelemetryAction({ conversationId: missingCid, range: 'today' }, { endpointId: ep2.id });
|
||||||
|
assert.ok(calls2.includes(missingCid));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Poll C (+10 min later): t2 STILL in 15m timeout cooldown, missingCid STILL in 30m 404 cooldown
|
||||||
|
calls2.length = 0;
|
||||||
|
now += 10 * 60_000;
|
||||||
|
await h.executeTelemetryAction({ conversationId: missingCid, range: 'today' }, { endpointId: ep2.id });
|
||||||
|
assert.equal(calls2.includes(t2), false, 't2 must remain in 15m remote timeout cooldown');
|
||||||
|
assert.equal(calls2.includes(missingCid), false, '404 missingCid must remain in 30m cooldown');
|
||||||
|
|
||||||
|
// Poll D (+10 more min -> 20m since 404): missingCid STILL in 30m 404 cooldown
|
||||||
|
calls2.length = 0;
|
||||||
|
now += 10 * 60_000;
|
||||||
|
await h.executeTelemetryAction({ conversationId: missingCid, range: 'today' }, { endpointId: ep2.id });
|
||||||
|
assert.equal(calls2.includes(missingCid), false, '404 missingCid must stay in 30m cooldown after 20m');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user