fix: respawn orchestrators when stale metadata is left behind

This commit is contained in:
Harsh 2026-03-06 21:26:15 +05:30
parent 42b3bf3ba6
commit e519628017
2 changed files with 23 additions and 1 deletions

View File

@ -2690,6 +2690,27 @@ describe("spawnOrchestrator", () => {
expect(meta?.["orchestratorSessionReused"]).toBeUndefined();
});
it("respawns the orchestrator when stale metadata exists but the runtime is dead", async () => {
writeMetadata(sessionsDir, "app-orchestrator", {
worktree: join(tmpDir, "my-app"),
branch: "main",
status: "working",
project: "my-app",
role: "orchestrator",
runtimeHandle: JSON.stringify(makeHandle("rt-stale")),
createdAt: new Date().toISOString(),
});
vi.mocked(mockRuntime.isAlive).mockResolvedValueOnce(false);
const sm = createSessionManager({ config, registry: mockRegistry });
await sm.spawnOrchestrator({ projectId: "my-app" });
expect(mockRuntime.create).toHaveBeenCalledTimes(1);
const meta = readMetadataRaw(sessionsDir, "app-orchestrator");
expect(meta?.["runtimeHandle"]).toBe(JSON.stringify(makeHandle("rt-1")));
});
it("uses orchestratorModel when configured", async () => {
const configWithOrchestratorModel: OrchestratorConfig = {
...config,

View File

@ -917,6 +917,7 @@ export function createSessionManager(deps: SessionManagerDeps): SessionManager {
writeFileSync(systemPromptFile, orchestratorConfig.systemPrompt, "utf-8");
}
const existingOrchestratorMetadata = readMetadataRaw(sessionsDir, sessionId);
const existingOrchestrator = await get(sessionId);
if (existingOrchestrator?.runtimeHandle) {
const existingAlive = await plugins.runtime
@ -931,7 +932,7 @@ export function createSessionManager(deps: SessionManagerDeps): SessionManager {
}
}
if (!reserveSessionId(sessionsDir, sessionId)) {
if (!existingOrchestratorMetadata && !reserveSessionId(sessionsDir, sessionId)) {
const raceSession = await get(sessionId);
if (raceSession?.runtimeHandle) {
const raceAlive = await plugins.runtime