fix: recover interrupted controller cycles

This commit is contained in:
冰朔 2026-08-05 11:18:54 +08:00
commit 05aeab4817
3 changed files with 49 additions and 3 deletions

View file

@ -28,6 +28,9 @@ function digestFile(file) {
function sourceFingerprint() {
const sources = [
runtimePath,
path.join(moduleDir, "controller-engine.mjs"),
path.join(moduleDir, "model-client.mjs"),
path.join(moduleDir, "server.mjs"),
path.join(
repositoryRoot,
"tcs-core/zhuyuan-brain/runtime/brain-runtime-contract.json",
@ -111,7 +114,14 @@ export class ControllerEngine {
initialize() {
fs.mkdirSync(this.exchangeDir, { recursive: true });
const stateFile = path.join(this.stateDir, "state.json");
let stateFile = path.join(this.stateDir, "state.json");
if (fs.existsSync(stateFile)) {
const existing = this.status();
if (existing.status === "PERCEIVING" && existing.active_cycle_id) {
this.stateDir = `${this.stateDir}-technical-recovery-${Date.now()}`;
stateFile = path.join(this.stateDir, "state.json");
}
}
if (!fs.existsSync(stateFile)) {
runRuntime("enter", [
"--state-dir",