diff --git a/packages/runner/src/conflict-step.ts b/packages/runner/src/conflict-step.ts index d1c06df8..6065514a 100644 --- a/packages/runner/src/conflict-step.ts +++ b/packages/runner/src/conflict-step.ts @@ -16,6 +16,7 @@ import { getSetting, giteaForBot, isProjectPaused, + isWaitingForCapacity, listSessions, logEvent, platformDelay, @@ -44,6 +45,7 @@ export interface ConflictStep { /** Head of the result and of the main branch when the agent was last asked. */ headSha: string; baseSha: string | null; + /** When the agent was asked; while the story waits for a place among the agents — the last minute of that wait (PEP-297). */ at: number; attempts: number; /** A new head of the result first seen (Gitea re-checks mergeability in the background after a push). */ @@ -148,6 +150,12 @@ export async function conflictStep(db: Db, ref: TaskRef, pull: GiteaPull, o: { n if (!step) return (await ask(db, ref, pull, 1, now, log, o.force)) ? "requested" : "held"; if (step.escalated) return "escalated"; if (pull.head.sha === step.headSha) { + // PEP-297: the story waits for a place among the agents (the repository limit, the subscriptions) — + // its agent has not started, so it is not silent. The agent's time counts from the moment it gets the place. + if (await isWaitingForCapacity(db, ref.task.id)) { + if (now - step.at >= 60_000) await setSetting(db, stepKey(ref.task.id), { ...step, at: now } satisfies ConflictStep); + return "waiting"; + } // The agent has not pushed yet. if ((await working(db, ref.task.id)) || now - step.at < CONFLICT_WAIT_MIN * 60_000) return "waiting"; return escalate(db, ref, pull, step, m("агент не обновил изменения"), now, log); diff --git a/packages/testkit/test/conflict-step.test.ts b/packages/testkit/test/conflict-step.test.ts index 61d69efa..eca1028b 100644 --- a/packages/testkit/test/conflict-step.test.ts +++ b/packages/testkit/test/conflict-step.test.ts @@ -151,6 +151,29 @@ describe("Конфликт с основной веткой — отдельны assert.equal(await t.requests(), 1); }); + test("PEP-297: задача ждёт места среди агентов — это не молчание агента", async () => { + const t = await conflicted(); + const T = Date.now(); + await minute(T); + assert.equal(await t.requests(), 1); + // No room (the repository limit): the rebase waits in the queue for an agent. + await core.waitForCapacity(db, t.ref.task.id, "rebase", new Date(T)); + await minute(T + 91 * MIN); + await minute(T + 200 * MIN); + assert.equal(await core.getPlatformDelay(db, t.scope, "conflict"), null, "the agent has not even started"); + assert.equal((await toAdmin(t.tp.taskKey)).length, 0, "nobody is told «агент не обновил изменения»"); + assert.equal((await t.step())?.escalated, undefined); + // It gets the place and stays silent: 90 minutes from that moment, not from the request. + await core.clearCapacityWait(db, t.ref.task.id); + await minute(T + 201 * MIN); + await minute(T + 285 * MIN); + assert.equal(await core.getPlatformDelay(db, t.scope, "conflict"), null, "still the agent's time"); + await minute(T + 292 * MIN); + assert.equal((await core.getPlatformDelay(db, t.scope, "conflict"))?.exhausted, true); + assert.match((await toAdmin(t.tp.taskKey))[0]!, /агент не обновил изменения/); + assert.equal(await t.requests(), 1); + }); + test("Scenario: Агент разрешил конфликт — шаг снят", async () => { const t = await conflicted(); const T = Date.now();