fix(engine): recover orphaned tasks at startup

This commit is contained in:
gsxdsm
2026-04-10 07:19:26 -07:00
parent f7fde6a2d3
commit d293f099df
4 changed files with 43 additions and 0 deletions

View File

@@ -8,11 +8,13 @@ const {
mockSelfHealingStart,
mockSelfHealingStop,
mockSelfHealingCtor,
mockRunStartupRecovery,
mockExecutorCtor,
} = vi.hoisted(() => ({
mockSelfHealingStart: vi.fn(),
mockSelfHealingStop: vi.fn(),
mockSelfHealingCtor: vi.fn(),
mockRunStartupRecovery: vi.fn().mockResolvedValue(undefined),
mockExecutorCtor: vi.fn(),
}));
@@ -92,6 +94,7 @@ vi.mock("../self-healing.js", async () => {
return {
start: mockSelfHealingStart,
stop: mockSelfHealingStop,
runStartupRecovery: mockRunStartupRecovery,
};
}),
};
@@ -184,6 +187,12 @@ describe("InProcessRuntime", () => {
expect(mockSelfHealingStart).toHaveBeenCalled();
}, 30000);
it("runs self-healing startup recovery immediately after orphan resume on startup", async () => {
await runtime.start();
expect(mockRunStartupRecovery).toHaveBeenCalledTimes(1);
}, 30000);
it("creates a stuck task detector and passes it to the executor", async () => {
await runtime.start();

View File

@@ -360,6 +360,12 @@ export class InProcessRuntime
// 9. Resume orphaned in-progress tasks
await this.executor.resumeOrphaned();
// Some "stuck" tasks are already orphaned by the time the runtime boots:
// they no longer have a tracked session/worktree, so the stuck detector
// cannot recover them. Delegate the startup recovery pass to
// SelfHealingManager so the policy lives in one place.
await this.selfHealingManager.runStartupRecovery();
// 10. Start scheduler
this.scheduler.start();