Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/orchestrator/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ export class OrchestratorCore {
const terminalStates = toNormalizedStateSet(
this.config.tracker.terminalStates,
);
const refreshedIds = new Set(refreshed.map((snapshot) => snapshot.id));

for (const snapshot of refreshed) {
const runningEntry = this.state.running[snapshot.id];
Expand Down Expand Up @@ -492,6 +493,21 @@ export class OrchestratorCore {
);
}

for (const runningId of runningIds) {
if (refreshedIds.has(runningId)) {
continue;
}

const runningEntry = this.state.running[runningId];
if (runningEntry === undefined) {
continue;
}

stopRequests.push(
await this.requestStop(runningEntry, false, "inactive_state"),
);
}

return {
stopRequests,
reconciliationFetchFailed: false,
Expand Down
19 changes: 19 additions & 0 deletions tests/orchestrator/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,25 @@ describe("orchestrator core", () => {
]);
});

it("requests stop when reconciliation no longer returns a running issue", async () => {
const tracker = createTracker({
statesById: [],
});
const orchestrator = createOrchestrator({ tracker });

await orchestrator.pollTick();
const result = await orchestrator.pollTick();

expect(result.stopRequests).toEqual([
{
issueId: "1",
issueIdentifier: "ISSUE-1",
cleanupWorkspace: false,
reason: "inactive_state",
},
]);
});

it("treats reconciliation with no running issues as a no-op", async () => {
const tracker = createTracker({
candidates: [],
Expand Down