fix: skip stale timeout responses (>2min old reject) to prevent phantom REJECT duplicates

This commit is contained in:
2026-03-10 17:23:47 +09:00
parent 186875ad0b
commit 95d4f854f5
3 changed files with 27 additions and 1 deletions

View File

@@ -2100,6 +2100,20 @@ async function processResponseFile(filePath) {
const msg = `[RESPONSE] rid=${resp.request_id} approved=${resp.approved} step_type=${resp.step_type || '(missing)'} keys=[${Object.keys(resp).join(',')}]`;
console.log(`Gravity Bridge: ${msg}`);
logToFile(msg);
// Skip stale timeout responses: if pending is old and this is a reject, it's likely a bot timeout
const ridTimestamp = parseInt((resp.request_id || '').split('_')[0], 10);
if (!isNaN(ridTimestamp)) {
const ageMs = Date.now() - ridTimestamp;
const STALE_THRESHOLD_MS = 120_000; // 2 minutes
if (ageMs > STALE_THRESHOLD_MS && !resp.approved) {
logToFile(`[RESPONSE] SKIPPED stale timeout: rid=${resp.request_id} age=${Math.round(ageMs / 1000)}s (>${STALE_THRESHOLD_MS / 1000}s, reject)`);
try {
fs.unlinkSync(filePath);
}
catch { }
return;
}
}
// Find matching pending request
const pendingDir = path.join(bridgePath, 'pending');
const pendingFile = path.join(pendingDir, `${resp.request_id}.json`);

File diff suppressed because one or more lines are too long

View File

@@ -2055,6 +2055,18 @@ async function processResponseFile(filePath: string) {
console.log(`Gravity Bridge: ${msg}`);
logToFile(msg);
// Skip stale timeout responses: if pending is old and this is a reject, it's likely a bot timeout
const ridTimestamp = parseInt((resp.request_id || '').split('_')[0], 10);
if (!isNaN(ridTimestamp)) {
const ageMs = Date.now() - ridTimestamp;
const STALE_THRESHOLD_MS = 120_000; // 2 minutes
if (ageMs > STALE_THRESHOLD_MS && !resp.approved) {
logToFile(`[RESPONSE] SKIPPED stale timeout: rid=${resp.request_id} age=${Math.round(ageMs / 1000)}s (>${STALE_THRESHOLD_MS / 1000}s, reject)`);
try { fs.unlinkSync(filePath); } catch { }
return;
}
}
// Find matching pending request
const pendingDir = path.join(bridgePath, 'pending');
const pendingFile = path.join(pendingDir, `${resp.request_id}.json`);