fix: use raius pi id for persistence

This commit is contained in:
Cristina Poncela Cubeiro
2026-06-18 15:16:03 +02:00
parent 9bfafc8c02
commit a6d88ddc3a
7 changed files with 119 additions and 45 deletions
+20 -1
View File
@@ -12,7 +12,7 @@ import {
} from "@earendil-works/pi-coding-agent";
import { radiusPresence } from "./radius.ts";
import { handleRpcCommand } from "./rpc-bridge.ts";
import { getInstance, loadInstances, removeInstance, upsertInstance } from "./storage.ts";
import { getInstance, loadInstances, removeInstance, saveInstances, upsertInstance } from "./storage.ts";
import type { InstanceRecord } from "./types.ts";
interface LiveInstance {
@@ -56,6 +56,19 @@ async function createRuntime(cwd: string): Promise<AgentSessionRuntime> {
export class OrchestratorSupervisor {
private readonly liveInstances = new Map<string, LiveInstance>();
async recoverAfterRestart(): Promise<void> {
const recoveredAt = new Date().toISOString();
const instances = loadInstances().map((instance) => ({
...instance,
status: instance.status === "online" || instance.status === "starting" ? "stopped" : instance.status,
lastSeenAt: recoveredAt,
}));
for (const instance of instances) {
await radiusPresence.disconnectPi(instance);
}
saveInstances(instances);
}
listInstances(): InstanceRecord[] {
return loadInstances().map(cloneInstance);
}
@@ -110,6 +123,12 @@ export class OrchestratorSupervisor {
return handleRpcCommand(live.runtime, command);
}
async shutdown(): Promise<void> {
for (const instanceId of [...this.liveInstances.keys()]) {
await this.stopInstance(instanceId);
}
}
}
export const supervisor = new OrchestratorSupervisor();