fix: prioritize branch follower closeout scheduling

This commit is contained in:
Codex
2026-07-04 09:05:22 +00:00
parent c1b61c72fa
commit e06df03544
2 changed files with 39 additions and 1 deletions
+30
View File
@@ -0,0 +1,30 @@
// SPEC: PJ2026-01060703 CI/CD branch follower controller scheduling.
// Responsibility: keep automatic closeout observations ahead of unrelated followers.
import type { FollowerSpec, FollowerState, ParsedOptions } from "./cicd-types";
const CLOSEOUT_PHASES = new Set(["Triggering", "ClosingOut"]);
export function orderFollowersForControllerCloseout(
followers: FollowerSpec[],
stateByFollower: Record<string, Record<string, unknown>>,
): FollowerSpec[] {
return followers
.map((follower, index) => ({ follower, index, priority: followerPriority(stateByFollower[follower.id]) }))
.sort((left, right) => left.priority - right.priority || left.index - right.index)
.map((item) => item.follower);
}
export function shouldYieldAfterAutomaticTrigger(options: ParsedOptions, state: FollowerState): boolean {
if (!options.inCluster || !options.confirm || options.wait || options.dryRun) return false;
return state.phase === "Triggering" && state.inFlightJob !== null;
}
function followerPriority(state: Record<string, unknown> | undefined): number {
if (state === undefined) return 2;
const phase = typeof state.phase === "string" ? state.phase : null;
if (phase !== null && CLOSEOUT_PHASES.has(phase)) return 0;
if (typeof state.inFlightJob === "string" && state.inFlightJob.trim() !== "") return 0;
if (phase === "PendingTrigger" || phase === "Superseded") return 1;
return 2;
}