From ce84998374ce241fd22e3c5f5d2709d9dce1e5cc Mon Sep 17 00:00:00 2001 From: Codex Date: Tue, 10 Mar 2026 16:37:16 +0800 Subject: [PATCH] fix: avoid loop deadlock when bridge is disabled --- index.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/index.js b/index.js index 15362e4..903916b 100644 --- a/index.js +++ b/index.js @@ -23,6 +23,37 @@ function readJsonSafe(p) { } } +function rejectPendingRun(statePath) { + try { + const { getRepoRoot } = require('./src/gep/paths'); + const { execSync } = require('child_process'); + const repoRoot = getRepoRoot(); + + execSync('git checkout -- .', { cwd: repoRoot, encoding: 'utf8', timeout: 30000 }); + execSync('git clean -fd', { cwd: repoRoot, encoding: 'utf8', timeout: 30000 }); + } catch (e) { + console.warn('[Loop] Pending run rollback failed: ' + (e.message || e)); + } + + try { + const state = readJsonSafe(statePath); + if (state && state.last_run && state.last_run.run_id) { + state.last_solidify = { + run_id: state.last_run.run_id, + rejected: true, + reason: 'loop_bridge_disabled_autoreject', + timestamp: new Date().toISOString(), + }; + fs.writeFileSync(statePath, JSON.stringify(state, null, 2) + '\n', 'utf8'); + return true; + } + } catch (e) { + console.warn('[Loop] Failed to clear pending run state: ' + (e.message || e)); + } + + return false; +} + function isPendingSolidify(state) { const lastRun = state && state.last_run ? state.last_run : null; const lastSolid = state && state.last_solidify ? state.last_solidify : null; @@ -136,6 +167,16 @@ async function main() { try { await evolve.run(); ok = true; + + if (String(process.env.EVOLVE_BRIDGE || '').toLowerCase() === 'false') { + const stAfterRun = readJsonSafe(solidifyStatePath); + if (isPendingSolidify(stAfterRun)) { + const cleared = rejectPendingRun(solidifyStatePath); + if (cleared) { + console.warn('[Loop] Auto-rejected pending run because bridge is disabled in loop mode.'); + } + } + } } catch (error) { const msg = error && error.message ? String(error.message) : String(error); console.error(`Evolution cycle failed: ${msg}`);