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
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,7 @@ DEBUG=false
# LOG_LEVEL=INFO
# SENIOR_DEVELOPER_REPO_DELAY_MS=1000
# PORT=8080

# Review waits for every check (required or not) of the head SHA; stuck checks stop blocking after this many minutes since the head commit
CHECKS_WAIT_ENABLED=true
CHECKS_WAIT_MAX_MINUTES=45
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ Everything is read from environment variables (see `.env.example` and
| `AGENT_CONTRACT_REFRESH`, `REPO_STANDARDS_MAX_PRS` | Runtime refresh of skills + global AGENTS.md (on in the image); standardization PRs per run |
| `TELEGRAM_BOT_TOKEN`, `TELEGRAM_CHAT_ID` | Notifications |
| `CONFLICT_OPENCODE_ENABLED`, `PIPELINE_FIX_ENABLED` | Opt-in opencode conflict / CI fixing |
| `CHECKS_WAIT_ENABLED`, `CHECKS_WAIT_MAX_MINUTES` | PR Assistant waits for all checks of the head SHA to finish before reviewing; no checks (or billing-blocked Actions) never wait, stuck ones stop blocking after the timeout |
| `REVIEW_WAIVE_AFTER_MINUTES`, `REVIEW_WAIVE_MAX_LINES`, `REVIEW_WAIVE_MAX_PER_RUN` | When a model outage may let a PR merge without model review |
| `MERGE_LOCAL_CHECKS_ENABLED`, `PR_ASSISTANT_RESOLVE_CONFLICTS`, `GITHUB_BOT_LOGIN` | Substitute CI for billing/no-CI PRs, inline conflicts, bot identity |
| `AUTOMATION_MODE`, `SIMULATION_MODE` | `observe` vs `autonomous`; dry-run all writes |
Expand Down
6 changes: 6 additions & 0 deletions ts/src/agents/pr_assistant/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { attemptPipelineFix } from "./pipeline-fix-flow.ts";
import { enabled as flagEnabled } from "./review-flags.ts";
import { botAuthActive, botLogin } from "../../github/bot-auth.ts";
import { reviewerLogins } from "./bot-identity.ts";
import { mustWaitForChecks } from "./checks-wait.ts";
import { clearManualConflictLabel, handleConflict, type Resolver } from "./conflict-flow.ts";
import { hasLabel, KEEP_DRAFT_LABEL } from "../core/pr-options.ts";
import { resolveConflictsAutonomously } from "./conflict-resolver.ts";
Expand Down Expand Up @@ -125,6 +126,11 @@ export class PRAssistantAgent extends BaseAgent {
const [status, comments] = await Promise.all([checkPipelineStatus(this.githubClient, pr), this.githubClient.getIssueComments(repo, pr.number)]);
const cmds = ownerCommands(comments, this.targetOwner);
if (cmds.hold) { this.recordSkip(results, pr.number, pr.title, repo, "owner_hold"); return; }
// Owner `/review` or `/merge` skips the wait; otherwise no model work while any check of this head is still running.
if (cmds.reviewAt === null && cmds.mergeAt === null && status.state === "pending" && mustWaitForChecks(status, await headCommitAt(this.githubClient, pr))) {
this.log(`PR #${pr.number}: waiting for ${status.pending_checks.length} pending check(s)`);
this.recordSkip(results, pr.number, pr.title, repo, "checks_pending"); return;
}
// Builder PRs: reviewed like any other, but never marked ready nor merged by the bot (not even on `/merge`).
if (hasLabel(pr, KEEP_DRAFT_LABEL)) {
if (!this.simulationMode) await this.reviews.runOpencodeReview(pr, comments, { force: this.reviewForced(cmds, comments) });
Expand Down
13 changes: 13 additions & 0 deletions ts/src/agents/pr_assistant/checks-wait.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Review starts only after every check of the head SHA finished (required or not). Absent checks never wait (no CI,
* billing-blocked Actions); jobs stuck pending past CHECKS_WAIT_MAX_MINUTES since the head commit stop blocking.
*/
const int = (v: string | undefined, d: number) => { const n = parseInt(v ?? "", 10); return Number.isNaN(n) ? d : Math.max(0, n); };
export const checksWaitEnabled = (v = process.env.CHECKS_WAIT_ENABLED) => !["0", "false", "no", "off"].includes((v ?? "").trim().toLowerCase());
export const checksWaitMaxMinutes = () => int(process.env.CHECKS_WAIT_MAX_MINUTES, 45);

/** True while the PR must keep waiting. `headAt` = head commit time (ms); unknown time waits (next run re-checks). */
export function mustWaitForChecks(status: Record<string, any>, headAt: number | null, now = Date.now()): boolean {
if (!checksWaitEnabled() || status.state !== "pending" || !(status.pending_checks?.length)) return false;
return headAt === null || now - headAt < checksWaitMaxMinutes() * 60_000;
}
2 changes: 1 addition & 1 deletion ts/src/notifications/telegram-format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { TelegramNotifier } from "./telegram.ts";
export const esc = TelegramNotifier.escapeHtml;
export const SEP = "──────────────────────";
const REASON_LABELS: Record<string, string> = {
pr_too_young: "PR recente (aguardando idade mínima)", "auto-merge-skip": "label auto-merge-skip", untrusted_author: "autor não confiável",
pr_too_young: "PR recente (aguardando idade mínima)", checks_pending: "checks ainda rodando (aguardando)", "auto-merge-skip": "label auto-merge-skip", untrusted_author: "autor não confiável",
has_conflicts: "conflito de merge", mergeable_unknown: "GitHub ainda calculando mergeabilidade", pipeline_failure: "pipeline falhou",
pipeline_fix_attempted: "correção de pipeline enviada", pipeline_pending: "pipeline em andamento", pipeline_queued: "pipeline na fila",
review_blocked: "revisão encontrou problema crítico", review_pending: "revisão ainda não executada (tenta na próxima rodada)",
Expand Down
15 changes: 15 additions & 0 deletions ts/tests/checks-wait.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { expect, test } from "bun:test";
import { mustWaitForChecks } from "../src/agents/pr_assistant/checks-wait.ts";

const now = Date.parse("2026-01-01T12:00:00Z"), min = (n: number) => now - n * 60_000;
const pending = { state: "pending", pending_checks: ["lint", "e2e"] };

test("waits while any check is pending on a fresh head", () => expect(mustWaitForChecks(pending, min(5), now)).toBe(true));
test("stops waiting once stuck checks pass the timeout (billing/queue never finishing)", () => expect(mustWaitForChecks(pending, min(46), now)).toBe(false));
test("no checks at all never waits (no CI)", () => expect(mustWaitForChecks({ state: "success", pending_checks: [], no_ci: true }, min(1), now)).toBe(false));
test("finished checks do not wait", () => expect(mustWaitForChecks({ state: "success", pending_checks: [] }, min(1), now)).toBe(false));
test("unknown head time keeps waiting until next run", () => expect(mustWaitForChecks(pending, null, now)).toBe(true));
test("can be disabled", () => {
process.env.CHECKS_WAIT_ENABLED = "false";
try { expect(mustWaitForChecks(pending, min(1), now)).toBe(false); } finally { delete process.env.CHECKS_WAIT_ENABLED; }
});
Loading