fix: poll follower closeout after refresh

This commit is contained in:
Codex
2026-07-03 19:58:22 +00:00
parent 20a61b47e1
commit b3c039c8ca
2 changed files with 28 additions and 2 deletions
+27 -1
View File
@@ -875,7 +875,7 @@ async function decideAndMaybeTrigger(
else if (flush !== null) automaticCloseoutAccelerated = true;
}
if (automaticCloseoutAccelerated && observedSha !== null) {
const reread = await readAdapterStatus(registry, follower, { ...options, timeoutSeconds: follower.budgets.statusSeconds });
const reread = await readAdapterStatusAfterCloseoutAcceleration(registry, follower, observedSha, options);
if (!reread.ok) {
warnings.push(`post-closeout status re-read failed: ${redactText(tailText(reread.message, 300))}`);
} else if (reread.observedSha === observedSha) {
@@ -955,6 +955,32 @@ function shouldRefreshAutomaticCloseout(
return !argoReady || !runtimeAligned || live.targetSha !== observedSha;
}
async function readAdapterStatusAfterCloseoutAcceleration(
registry: BranchFollowerRegistry,
follower: FollowerSpec,
observedSha: string,
options: ParsedOptions,
): Promise<AdapterSummary> {
const timeoutSeconds = follower.budgets.statusSeconds;
const startedAt = Date.now();
const deadline = startedAt + Math.max(1, timeoutSeconds) * 1000;
let latest = await readAdapterStatus(registry, follower, { ...options, timeoutSeconds: Math.min(timeoutSeconds, remainingSeconds(startedAt, timeoutSeconds)) });
while (
latest.ok
&& latest.observedSha === observedSha
&& latest.aligned !== true
&& Date.now() < deadline
) {
const remaining = Math.max(0, deadline - Date.now());
const pollSeconds = Math.min(registry.controller.budgets.nativePollIntervalSeconds, Math.ceil(remaining / 1000));
if (pollSeconds <= 0) break;
runCommand(["sleep", String(pollSeconds)], repoRoot, { timeoutMs: (pollSeconds + 1) * 1000 });
if (Date.now() >= deadline) break;
latest = await readAdapterStatus(registry, follower, { ...options, timeoutSeconds: remainingSeconds(startedAt, timeoutSeconds) });
}
return latest;
}
function shouldFlushAutomaticCloseout(
follower: FollowerSpec,
observedSha: string | null,