glimmervoid 0.49.1-next.556 → 0.49.1-next.558
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/{main-CMr5f42v.js → main-DgtVpNch.js} +610 -492
- package/dist/client/assets/{benchmark-panel-BYlJ--dm.js → benchmark-panel-DvqHK9nP.js} +1 -1
- package/dist/client/assets/benchmark-panel-DvqHK9nP.js.br +0 -0
- package/dist/client/assets/{boards-view-OHgyNDUo.js → boards-view-CDxxTYRW.js} +1 -1
- package/dist/client/assets/boards-view-CDxxTYRW.js.br +0 -0
- package/dist/client/assets/{community-panel-Gr-EnAGO.js → community-panel-og5uIpku.js} +1 -1
- package/dist/client/assets/community-panel-og5uIpku.js.br +0 -0
- package/dist/client/assets/{dialogs-BlFjIxEh.js → dialogs-BOdhkTua.js} +1 -1
- package/dist/client/assets/dialogs-BOdhkTua.js.br +0 -0
- package/dist/client/assets/{doc-editor-ui-BS50QK1Z.js → doc-editor-ui-BCKNAQ7A.js} +1 -1
- package/dist/client/assets/doc-editor-ui-BCKNAQ7A.js.br +0 -0
- package/dist/client/assets/{feature-hint-DG1cn7RR.js → feature-hint-1Lnivebk.js} +1 -1
- package/dist/client/assets/feature-hint-1Lnivebk.js.br +0 -0
- package/dist/client/assets/{first-run-checklist-Dpi5KJp4.js → first-run-checklist-DvWDg4SI.js} +1 -1
- package/dist/client/assets/first-run-checklist-DvWDg4SI.js.br +0 -0
- package/dist/client/assets/{hooks-panel-CNA-co2J.js → hooks-panel-DHVXE_P5.js} +1 -1
- package/dist/client/assets/hooks-panel-DHVXE_P5.js.br +0 -0
- package/dist/client/assets/{index-C6pDSgFH.js → index-D5amIIkt.js} +5 -5
- package/dist/client/assets/index-D5amIIkt.js.br +0 -0
- package/dist/client/assets/{issues-panel-B--zPFcE.js → issues-panel-Bwkz_csv.js} +1 -1
- package/dist/client/assets/issues-panel-Bwkz_csv.js.br +0 -0
- package/dist/client/assets/{my-prs-panel-BFuBQ1Uu.js → my-prs-panel-CHiS-Jck.js} +1 -1
- package/dist/client/assets/my-prs-panel-CHiS-Jck.js.br +0 -0
- package/dist/client/assets/{nyan-cat-CIkroLyQ.js → nyan-cat-D1svhFDj.js} +1 -1
- package/dist/client/assets/nyan-cat-D1svhFDj.js.br +0 -0
- package/dist/client/assets/{phone-shell-CU4FhhH_.js → phone-shell-C7zdM163.js} +1 -1
- package/dist/client/assets/phone-shell-C7zdM163.js.br +0 -0
- package/dist/client/assets/{plan-face-CC42933Z.js → plan-face-DM6Bjzg8.js} +1 -1
- package/dist/client/assets/plan-face-DM6Bjzg8.js.br +0 -0
- package/dist/client/assets/{plan-render-DLWlfCxO.js → plan-render-C3WYR0MJ.js} +1 -1
- package/dist/client/assets/plan-render-C3WYR0MJ.js.br +0 -0
- package/dist/client/assets/{pr-queue-columns-C2EwDiuy.js → pr-queue-columns-awCq2u1n.js} +1 -1
- package/dist/client/assets/pr-queue-columns-awCq2u1n.js.br +0 -0
- package/dist/client/assets/{radar-panel-B_p-DGJL.js → radar-panel-Dw4Wlj4y.js} +1 -1
- package/dist/client/assets/radar-panel-Dw4Wlj4y.js.br +0 -0
- package/dist/client/assets/{repo-roots-adder-BSsO4_he.js → repo-roots-adder-aaX58BR2.js} +1 -1
- package/dist/client/assets/repo-roots-adder-aaX58BR2.js.br +0 -0
- package/dist/client/assets/{resume-dialog-ChRUEJVP.js → resume-dialog-CdLkdFsT.js} +1 -1
- package/dist/client/assets/resume-dialog-CdLkdFsT.js.br +0 -0
- package/dist/client/assets/{review-queue-panel-ChgaCJI8.js → review-queue-panel-BLmn71Fy.js} +1 -1
- package/dist/client/assets/review-queue-panel-BLmn71Fy.js.br +0 -0
- package/dist/client/assets/{settings-panel-DkABFXRK.js → settings-panel-j8rERO0K.js} +2 -2
- package/dist/client/assets/settings-panel-j8rERO0K.js.br +0 -0
- package/dist/client/assets/{shown-face-C1okw_q6.js → shown-face-DgRi7d73.js} +1 -1
- package/dist/client/assets/shown-face-DgRi7d73.js.br +0 -0
- package/dist/client/assets/{team-review-queue-row-D152iO6w.js → team-review-queue-row-D8E4TF2O.js} +1 -1
- package/dist/client/assets/team-review-queue-row-D8E4TF2O.js.br +0 -0
- package/dist/client/assets/{trace-panel-BWTqE8i_.js → trace-panel-CS7H0EoY.js} +1 -1
- package/dist/client/assets/trace-panel-CS7H0EoY.js.br +0 -0
- package/dist/client/assets/{usage-panel-DjQputIe.js → usage-panel-Dx0m32aD.js} +1 -1
- package/dist/client/assets/usage-panel-Dx0m32aD.js.br +0 -0
- package/dist/client/assets/{your-day-tip-IcwJnIjR.js → your-day-tip-DqNwVgUW.js} +1 -1
- package/dist/client/assets/your-day-tip-DqNwVgUW.js.br +0 -0
- package/dist/client/index.html +1 -1
- package/dist/client/index.html.br +0 -0
- package/dist/server/index.js +1 -1
- package/package.json +1 -1
- package/dist/client/assets/benchmark-panel-BYlJ--dm.js.br +0 -0
- package/dist/client/assets/boards-view-OHgyNDUo.js.br +0 -0
- package/dist/client/assets/community-panel-Gr-EnAGO.js.br +0 -0
- package/dist/client/assets/dialogs-BlFjIxEh.js.br +0 -0
- package/dist/client/assets/doc-editor-ui-BS50QK1Z.js.br +0 -0
- package/dist/client/assets/feature-hint-DG1cn7RR.js.br +0 -0
- package/dist/client/assets/first-run-checklist-Dpi5KJp4.js.br +0 -0
- package/dist/client/assets/hooks-panel-CNA-co2J.js.br +0 -0
- package/dist/client/assets/index-C6pDSgFH.js.br +0 -0
- package/dist/client/assets/issues-panel-B--zPFcE.js.br +0 -0
- package/dist/client/assets/my-prs-panel-BFuBQ1Uu.js.br +0 -0
- package/dist/client/assets/nyan-cat-CIkroLyQ.js.br +0 -0
- package/dist/client/assets/phone-shell-CU4FhhH_.js.br +0 -0
- package/dist/client/assets/plan-face-CC42933Z.js.br +0 -0
- package/dist/client/assets/plan-render-DLWlfCxO.js.br +0 -0
- package/dist/client/assets/pr-queue-columns-C2EwDiuy.js.br +0 -0
- package/dist/client/assets/radar-panel-B_p-DGJL.js.br +0 -0
- package/dist/client/assets/repo-roots-adder-BSsO4_he.js.br +0 -0
- package/dist/client/assets/resume-dialog-ChRUEJVP.js.br +0 -0
- package/dist/client/assets/review-queue-panel-ChgaCJI8.js.br +0 -0
- package/dist/client/assets/settings-panel-DkABFXRK.js.br +0 -0
- package/dist/client/assets/shown-face-C1okw_q6.js.br +0 -0
- package/dist/client/assets/team-review-queue-row-D152iO6w.js.br +0 -0
- package/dist/client/assets/trace-panel-BWTqE8i_.js.br +0 -0
- package/dist/client/assets/usage-panel-DjQputIe.js.br +0 -0
- package/dist/client/assets/your-day-tip-IcwJnIjR.js.br +0 -0
|
@@ -30962,7 +30962,7 @@ async function writeUntrustedPayload(laneCwd, payload, maxCharsPerItem) {
|
|
|
30962
30962
|
return payloadPath;
|
|
30963
30963
|
}
|
|
30964
30964
|
//#endregion
|
|
30965
|
-
//#region server/radar/radar-
|
|
30965
|
+
//#region server/radar/radar-posture.ts
|
|
30966
30966
|
var RADAR_SHELL_AND_WEB_DENY = Object.freeze([
|
|
30967
30967
|
"Bash",
|
|
30968
30968
|
"NotebookEdit",
|
|
@@ -31021,51 +31021,14 @@ function radarClaudeArgs(posture, laneArgs) {
|
|
|
31021
31021
|
...readRules.length > 0 ? ["--allowedTools", ...readRules] : []
|
|
31022
31022
|
];
|
|
31023
31023
|
}
|
|
31024
|
-
|
|
31025
|
-
|
|
31026
|
-
var FORCE_TICK_DEBOUNCE_MS = 3e3;
|
|
31027
|
-
var HANDOFF_STEP_LABELS = Object.freeze({
|
|
31028
|
-
"commit-fix": "committing the fix",
|
|
31029
|
-
"read-diff": "reading the branch diff",
|
|
31030
|
-
"count-commits": "counting the branch commits"
|
|
31031
|
-
});
|
|
31032
|
-
async function readNewTranscriptLines(tail, transcriptPath) {
|
|
31033
|
-
const opened = await openContainedFile(path.resolve(transcriptPath), claudeProjectsDir(process.env, os.homedir()));
|
|
31034
|
-
if (!opened.ok) return [];
|
|
31035
|
-
const { handle, realPath, stat } = opened.file;
|
|
31036
|
-
try {
|
|
31037
|
-
if (tail.realPath !== realPath) Object.assign(tail, {
|
|
31038
|
-
realPath,
|
|
31039
|
-
offset: 0
|
|
31040
|
-
});
|
|
31041
|
-
const plan = planContiguousRead(tail, stat);
|
|
31042
|
-
if (plan.action === "skip") return [];
|
|
31043
|
-
const chunk = Buffer.alloc(plan.end - plan.start);
|
|
31044
|
-
const { bytesRead } = await handle.read(chunk, 0, chunk.length, plan.start);
|
|
31045
|
-
const readBytes = chunk.subarray(0, bytesRead);
|
|
31046
|
-
const wholeLineBytes = completeLineBytes(readBytes);
|
|
31047
|
-
const isOneOversizedLine = wholeLineBytes === 0 && bytesRead >= 1048576;
|
|
31048
|
-
tail.offset = plan.start + (isOneOversizedLine ? bytesRead : wholeLineBytes);
|
|
31049
|
-
return readBytes.subarray(0, wholeLineBytes).toString("utf8").split("\n");
|
|
31050
|
-
} finally {
|
|
31051
|
-
await handle.close().catch(() => {});
|
|
31052
|
-
}
|
|
31053
|
-
}
|
|
31024
|
+
//#endregion
|
|
31025
|
+
//#region server/radar/radar-prompts.ts
|
|
31054
31026
|
function safeIssueId(issueId) {
|
|
31055
31027
|
return String(issueId).replace(/[^\w.-]+/g, "-").replace(/\.{2,}/g, "-");
|
|
31056
31028
|
}
|
|
31057
|
-
function reportPathFor(issueId) {
|
|
31058
|
-
return path.join(REPORT_DIR, `${safeIssueId(issueId)}.html`);
|
|
31059
|
-
}
|
|
31060
31029
|
function promptIssueUrl(host, projectId, issueId) {
|
|
31061
31030
|
return `${String(host || "").replace(/\/+$/, "")}/project/${safeIssueId(projectId)}/error_tracking/${safeIssueId(issueId)}`;
|
|
31062
31031
|
}
|
|
31063
|
-
function createResultFileFor(kind, projectId, issueId) {
|
|
31064
|
-
return createJobResultFile(`glimmervoid-posthog-${kind}${safeIssueId(projectId)}-${safeIssueId(issueId)}`);
|
|
31065
|
-
}
|
|
31066
|
-
function newFixDiscriminator() {
|
|
31067
|
-
return `${Date.now().toString(36)}${crypto.randomBytes(2).toString("hex")}`;
|
|
31068
|
-
}
|
|
31069
31032
|
function untrustedIssueLines(eventsFetched) {
|
|
31070
31033
|
return [
|
|
31071
31034
|
UNTRUSTED_PREAMBLE,
|
|
@@ -31142,40 +31105,25 @@ function buildFixPrompt({ issueId, projectId, host, resultPath, repoPath, branch
|
|
|
31142
31105
|
"preamble, no emoji, no em or en dashes."
|
|
31143
31106
|
].join("\n");
|
|
31144
31107
|
}
|
|
31145
|
-
|
|
31146
|
-
|
|
31147
|
-
const names = (await fs.promises.readdir(dir)).filter((n) => n.endsWith(".html") || n.endsWith(".md"));
|
|
31148
|
-
if (names.length <= retain) return;
|
|
31149
|
-
const ordered = (await Promise.all(names.map(async (name) => {
|
|
31150
|
-
const full = path.join(dir, name);
|
|
31151
|
-
try {
|
|
31152
|
-
return {
|
|
31153
|
-
full,
|
|
31154
|
-
mtimeMs: (await fs.promises.stat(full)).mtimeMs
|
|
31155
|
-
};
|
|
31156
|
-
} catch {
|
|
31157
|
-
return null;
|
|
31158
|
-
}
|
|
31159
|
-
}))).filter((entry) => entry !== null).sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
31160
|
-
for (const victim of ordered.slice(retain)) await fs.promises.rm(victim.full, { force: true }).catch(() => {});
|
|
31161
|
-
} catch {}
|
|
31162
|
-
}
|
|
31163
|
-
var INVESTIGATION_VERDICTS = /* @__PURE__ */ new Set([
|
|
31164
|
-
"ROOT_CAUSE",
|
|
31165
|
-
"NEEDS_HUMAN",
|
|
31166
|
-
"TRANSIENT",
|
|
31167
|
-
"ERROR"
|
|
31168
|
-
]);
|
|
31169
|
-
var FIX_RESULT_VERDICTS = new Set(FIX_VERDICTS);
|
|
31170
|
-
function readInvestigationResult(resultPath) {
|
|
31171
|
-
return readResultFile(resultPath, INVESTIGATION_VERDICTS);
|
|
31108
|
+
function fallbackPrTitle(issueId) {
|
|
31109
|
+
return `fix: PostHog issue ${issueId}`;
|
|
31172
31110
|
}
|
|
31173
|
-
function
|
|
31174
|
-
return
|
|
31175
|
-
|
|
31176
|
-
|
|
31177
|
-
|
|
31111
|
+
function fallbackPrBody({ issueUrl, summary }) {
|
|
31112
|
+
return [
|
|
31113
|
+
"Automated fix from the Glimmervoid Radar lane. Reviewed by nobody yet.",
|
|
31114
|
+
"",
|
|
31115
|
+
`Issue: ${issueUrl}`,
|
|
31116
|
+
"Not run: the fix lane has no shell, so neither the fix nor any test it added was executed.",
|
|
31117
|
+
`Agent summary: ${summaryLineFromReportText(summary) || "(none written)"}`
|
|
31118
|
+
].join("\n");
|
|
31178
31119
|
}
|
|
31120
|
+
//#endregion
|
|
31121
|
+
//#region server/radar/radar-fix-handoff.ts
|
|
31122
|
+
var HANDOFF_STEP_LABELS = Object.freeze({
|
|
31123
|
+
"commit-fix": "committing the fix",
|
|
31124
|
+
"read-diff": "reading the branch diff",
|
|
31125
|
+
"count-commits": "counting the branch commits"
|
|
31126
|
+
});
|
|
31179
31127
|
var FIX_HANDOFF_TIMEOUT_MS = 12e4;
|
|
31180
31128
|
async function runCli(cmd, args, cwd, execFileFn) {
|
|
31181
31129
|
const options = {
|
|
@@ -31205,11 +31153,6 @@ function handoffFailure(step, detail, branch) {
|
|
|
31205
31153
|
failedStep: step
|
|
31206
31154
|
};
|
|
31207
31155
|
}
|
|
31208
|
-
function resultErrorReason(outcome) {
|
|
31209
|
-
if (outcome.verdict !== "ERROR") return void 0;
|
|
31210
|
-
if (outcome.ok !== false) return "agent-reported";
|
|
31211
|
-
return outcome.kind === "missing" ? "no-result" : "invalid-result";
|
|
31212
|
-
}
|
|
31213
31156
|
async function checkFixBranch({ run = runCli, workspace }) {
|
|
31214
31157
|
const branch = workspace.branch;
|
|
31215
31158
|
const baseRef = workspace.baseSha || workspace.base;
|
|
@@ -31287,17 +31230,80 @@ async function commitFixWork({ run = runCli, workspace, message, emptyHooksDir }
|
|
|
31287
31230
|
if (!committed.ok) return handoffFailure("commit-fix", committed.err, branch);
|
|
31288
31231
|
return null;
|
|
31289
31232
|
}
|
|
31290
|
-
|
|
31291
|
-
|
|
31233
|
+
//#endregion
|
|
31234
|
+
//#region server/radar/radar-wiring.ts
|
|
31235
|
+
var REPORT_DIR = DEFAULT_POSTHOG_REPORT_DIR;
|
|
31236
|
+
var REPORT_RETAIN_FILES = 20;
|
|
31237
|
+
var FORCE_TICK_DEBOUNCE_MS = 3e3;
|
|
31238
|
+
async function readNewTranscriptLines(tail, transcriptPath) {
|
|
31239
|
+
const opened = await openContainedFile(path.resolve(transcriptPath), claudeProjectsDir(process.env, os.homedir()));
|
|
31240
|
+
if (!opened.ok) return [];
|
|
31241
|
+
const { handle, realPath, stat } = opened.file;
|
|
31242
|
+
try {
|
|
31243
|
+
if (tail.realPath !== realPath) Object.assign(tail, {
|
|
31244
|
+
realPath,
|
|
31245
|
+
offset: 0
|
|
31246
|
+
});
|
|
31247
|
+
const plan = planContiguousRead(tail, stat);
|
|
31248
|
+
if (plan.action === "skip") return [];
|
|
31249
|
+
const chunk = Buffer.alloc(plan.end - plan.start);
|
|
31250
|
+
const { bytesRead } = await handle.read(chunk, 0, chunk.length, plan.start);
|
|
31251
|
+
const readBytes = chunk.subarray(0, bytesRead);
|
|
31252
|
+
const wholeLineBytes = completeLineBytes(readBytes);
|
|
31253
|
+
const isOneOversizedLine = wholeLineBytes === 0 && bytesRead >= 1048576;
|
|
31254
|
+
tail.offset = plan.start + (isOneOversizedLine ? bytesRead : wholeLineBytes);
|
|
31255
|
+
return readBytes.subarray(0, wholeLineBytes).toString("utf8").split("\n");
|
|
31256
|
+
} finally {
|
|
31257
|
+
await handle.close().catch(() => {});
|
|
31258
|
+
}
|
|
31292
31259
|
}
|
|
31293
|
-
function
|
|
31294
|
-
return
|
|
31295
|
-
|
|
31296
|
-
|
|
31297
|
-
|
|
31298
|
-
|
|
31299
|
-
|
|
31300
|
-
|
|
31260
|
+
function reportPathFor(issueId) {
|
|
31261
|
+
return path.join(REPORT_DIR, `${safeIssueId(issueId)}.html`);
|
|
31262
|
+
}
|
|
31263
|
+
function createResultFileFor(kind, projectId, issueId) {
|
|
31264
|
+
return createJobResultFile(`glimmervoid-posthog-${kind}${safeIssueId(projectId)}-${safeIssueId(issueId)}`);
|
|
31265
|
+
}
|
|
31266
|
+
function newFixDiscriminator() {
|
|
31267
|
+
return `${Date.now().toString(36)}${crypto.randomBytes(2).toString("hex")}`;
|
|
31268
|
+
}
|
|
31269
|
+
async function sweepReports(dir = REPORT_DIR, retain = REPORT_RETAIN_FILES) {
|
|
31270
|
+
try {
|
|
31271
|
+
const names = (await fs.promises.readdir(dir)).filter((n) => n.endsWith(".html") || n.endsWith(".md"));
|
|
31272
|
+
if (names.length <= retain) return;
|
|
31273
|
+
const ordered = (await Promise.all(names.map(async (name) => {
|
|
31274
|
+
const full = path.join(dir, name);
|
|
31275
|
+
try {
|
|
31276
|
+
return {
|
|
31277
|
+
full,
|
|
31278
|
+
mtimeMs: (await fs.promises.stat(full)).mtimeMs
|
|
31279
|
+
};
|
|
31280
|
+
} catch {
|
|
31281
|
+
return null;
|
|
31282
|
+
}
|
|
31283
|
+
}))).filter((entry) => entry !== null).sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
31284
|
+
for (const victim of ordered.slice(retain)) await fs.promises.rm(victim.full, { force: true }).catch(() => {});
|
|
31285
|
+
} catch {}
|
|
31286
|
+
}
|
|
31287
|
+
var INVESTIGATION_VERDICTS = /* @__PURE__ */ new Set([
|
|
31288
|
+
"ROOT_CAUSE",
|
|
31289
|
+
"NEEDS_HUMAN",
|
|
31290
|
+
"TRANSIENT",
|
|
31291
|
+
"ERROR"
|
|
31292
|
+
]);
|
|
31293
|
+
var FIX_RESULT_VERDICTS = new Set(FIX_VERDICTS);
|
|
31294
|
+
function readInvestigationResult(resultPath) {
|
|
31295
|
+
return readResultFile(resultPath, INVESTIGATION_VERDICTS);
|
|
31296
|
+
}
|
|
31297
|
+
function readFixResult(resultPath) {
|
|
31298
|
+
return readResultFile(resultPath, FIX_RESULT_VERDICTS, (obj) => ({
|
|
31299
|
+
prTitle: normalizePrTitle(obj.prTitle),
|
|
31300
|
+
prBody: normalizePrBody(obj.prBody)
|
|
31301
|
+
}));
|
|
31302
|
+
}
|
|
31303
|
+
function resultErrorReason(outcome) {
|
|
31304
|
+
if (outcome.verdict !== "ERROR") return void 0;
|
|
31305
|
+
if (outcome.ok !== false) return "agent-reported";
|
|
31306
|
+
return outcome.kind === "missing" ? "no-result" : "invalid-result";
|
|
31301
31307
|
}
|
|
31302
31308
|
function radarShouldStart(cfg) {
|
|
31303
31309
|
const p = cfg.posthog;
|
|
@@ -34767,7 +34773,7 @@ async function reapTeamReviewProcesses({ ownedDirectories, reviewRoots, scope, l
|
|
|
34767
34773
|
}
|
|
34768
34774
|
}
|
|
34769
34775
|
//#endregion
|
|
34770
|
-
//#region server/github/team-review-poller.ts
|
|
34776
|
+
//#region server/github/team-review-poller/team-review-poller-context.ts
|
|
34771
34777
|
var TEAM_REVIEW_RATE_LIMIT_RESOURCES = [
|
|
34772
34778
|
"search",
|
|
34773
34779
|
"graphql",
|
|
@@ -34782,56 +34788,14 @@ var REQUEUEABLE_STATUSES = /* @__PURE__ */ new Set([
|
|
|
34782
34788
|
"discarded",
|
|
34783
34789
|
"posted"
|
|
34784
34790
|
]);
|
|
34785
|
-
|
|
34786
|
-
|
|
34787
|
-
|
|
34788
|
-
const
|
|
34789
|
-
const skipIdleAfterMs = deps.skipIdleAfterMs ?? 12096e5;
|
|
34790
|
-
let state = {};
|
|
34791
|
-
let self = null;
|
|
34792
|
-
let teamProfile = null;
|
|
34793
|
-
const progressByKey = /* @__PURE__ */ new Map();
|
|
34794
|
-
const reviewCancellersByKey = /* @__PURE__ */ new Map();
|
|
34795
|
-
const notMineWhileReviewingKeys = /* @__PURE__ */ new Set();
|
|
34796
|
-
let waitingForSlot = [];
|
|
34791
|
+
//#endregion
|
|
34792
|
+
//#region server/github/team-review-poller/team-review-status-reporter.ts
|
|
34793
|
+
function createTeamReviewStatusReporter(context) {
|
|
34794
|
+
const { onTickComplete, now, setTimeoutFn, clearTimeoutFn, runtime, progressByKey, loop } = context;
|
|
34797
34795
|
let lastEmitAt = Number.NEGATIVE_INFINITY;
|
|
34798
34796
|
let pendingProgressEmit = null;
|
|
34799
|
-
let hasSlotFreedSinceSlotCount = false;
|
|
34800
|
-
let pollingError = null;
|
|
34801
|
-
const watches = /* @__PURE__ */ new Map();
|
|
34802
|
-
let hasLoadedState = false;
|
|
34803
|
-
let lastRebuildQueueSignature = null;
|
|
34804
|
-
let tickRateLimitWaitMs = null;
|
|
34805
|
-
let teamCandidateKeys = /* @__PURE__ */ new Set();
|
|
34806
|
-
const loop = createTickLoop({
|
|
34807
|
-
tag: TEAM_REVIEW_LANE_ID,
|
|
34808
|
-
intervalMs: (deps.intervalMinutes ?? 15) * 6e4,
|
|
34809
|
-
tick: async () => {
|
|
34810
|
-
try {
|
|
34811
|
-
return await runTick();
|
|
34812
|
-
} catch (error) {
|
|
34813
|
-
pollingError = errorMessage(error);
|
|
34814
|
-
log.warn(`[${TEAM_REVIEW_LANE_ID}] poll failed: ${pollingError}`);
|
|
34815
|
-
return rateLimitedOutcome();
|
|
34816
|
-
}
|
|
34817
|
-
},
|
|
34818
|
-
quickRetries: true,
|
|
34819
|
-
now,
|
|
34820
|
-
setTimeoutFn,
|
|
34821
|
-
clearTimeoutFn,
|
|
34822
|
-
onScheduleChange: emitStatus,
|
|
34823
|
-
rateLimitWaitMs: () => store.rateLimitWaitMs(now(), TEAM_REVIEW_RATE_LIMIT_RESOURCES),
|
|
34824
|
-
writeState: () => writeState(state),
|
|
34825
|
-
setIntervalFn,
|
|
34826
|
-
clearIntervalFn,
|
|
34827
|
-
clock: storeReadingLaneClock(deps.clock),
|
|
34828
|
-
firstTickDelayMs: deps.firstTickDelayMs,
|
|
34829
|
-
backoffMaxMs: GITHUB_RATE_LIMIT_WINDOW_MS,
|
|
34830
|
-
log
|
|
34831
|
-
});
|
|
34832
|
-
const persist = () => loop.persist();
|
|
34833
34797
|
function inFlightKeys() {
|
|
34834
|
-
return Object.keys(state).filter((key) => state[key]?.inFlight);
|
|
34798
|
+
return Object.keys(runtime.state).filter((key) => runtime.state[key]?.inFlight);
|
|
34835
34799
|
}
|
|
34836
34800
|
function inFlightReviews() {
|
|
34837
34801
|
return inFlightKeys().flatMap((key) => {
|
|
@@ -34851,12 +34815,12 @@ function createTeamReviewPoller(deps) {
|
|
|
34851
34815
|
...teamReviewStatus({
|
|
34852
34816
|
ts: now(),
|
|
34853
34817
|
configured: true,
|
|
34854
|
-
team: teamProfile,
|
|
34855
|
-
drafts: draftsNewestFirst(state),
|
|
34818
|
+
team: runtime.teamProfile,
|
|
34819
|
+
drafts: draftsNewestFirst(runtime.state),
|
|
34856
34820
|
inFlight: inFlightReviews(),
|
|
34857
|
-
queued: waitingForSlot.filter((candidate) => !state[candidate.key]?.inFlight)
|
|
34821
|
+
queued: runtime.waitingForSlot.filter((candidate) => !runtime.state[candidate.key]?.inFlight)
|
|
34858
34822
|
}),
|
|
34859
|
-
error: pollingError,
|
|
34823
|
+
error: runtime.pollingError,
|
|
34860
34824
|
...loop.scheduleStatus()
|
|
34861
34825
|
});
|
|
34862
34826
|
}
|
|
@@ -34881,88 +34845,218 @@ function createTeamReviewPoller(deps) {
|
|
|
34881
34845
|
emitStatus();
|
|
34882
34846
|
}, waitMs);
|
|
34883
34847
|
}
|
|
34884
|
-
|
|
34885
|
-
|
|
34886
|
-
|
|
34887
|
-
|
|
34888
|
-
|
|
34889
|
-
|
|
34890
|
-
|
|
34891
|
-
|
|
34892
|
-
|
|
34893
|
-
|
|
34894
|
-
|
|
34895
|
-
|
|
34896
|
-
|
|
34897
|
-
|
|
34898
|
-
|
|
34899
|
-
|
|
34900
|
-
tier: args.tier,
|
|
34901
|
-
reasons: args.reasons,
|
|
34902
|
-
reviewedHead: args.detail.headRefOid,
|
|
34903
|
-
error: firstLine$1(errorMessage(error)) || "review crashed"
|
|
34848
|
+
return {
|
|
34849
|
+
inFlightKeys,
|
|
34850
|
+
cancelPendingProgressEmit,
|
|
34851
|
+
emitStatus,
|
|
34852
|
+
progressReporter
|
|
34853
|
+
};
|
|
34854
|
+
}
|
|
34855
|
+
//#endregion
|
|
34856
|
+
//#region server/github/team-review-poller/team-review-candidate-search.ts
|
|
34857
|
+
function createTeamReviewCandidateSearch(context) {
|
|
34858
|
+
const { org, teams, store, discardResumable, now, skipIdleAfterMs, runtime, watches, loop } = context;
|
|
34859
|
+
function closedEntryKeys() {
|
|
34860
|
+
const prs = store.getSnapshot().prs;
|
|
34861
|
+
return new Set(Object.keys(runtime.state).filter((key) => {
|
|
34862
|
+
const pr = prs[key.toLowerCase()];
|
|
34863
|
+
return !runtime.state[key]?.inFlight && pr !== void 0 && pr.state !== "OPEN";
|
|
34904
34864
|
}));
|
|
34905
|
-
|
|
34906
|
-
|
|
34907
|
-
|
|
34908
|
-
|
|
34909
|
-
|
|
34910
|
-
|
|
34911
|
-
|
|
34912
|
-
|
|
34913
|
-
|
|
34914
|
-
|
|
34915
|
-
|
|
34916
|
-
|
|
34917
|
-
|
|
34918
|
-
|
|
34865
|
+
}
|
|
34866
|
+
function watchDeparted(candidateKeys) {
|
|
34867
|
+
const departedKeys = Object.keys(runtime.state).filter((key) => !candidateKeys.has(key) && !runtime.state[key]?.inFlight);
|
|
34868
|
+
store.setWatchedKeys("team-review-departed", departedKeys.map((key) => key.toLowerCase()));
|
|
34869
|
+
}
|
|
34870
|
+
async function pruneDeparted(candidateKeys, isComplete) {
|
|
34871
|
+
let isDirty = false;
|
|
34872
|
+
watchDeparted(candidateKeys);
|
|
34873
|
+
const closedKeys = closedEntryKeys();
|
|
34874
|
+
for (const [key, entry] of Object.entries(runtime.state)) {
|
|
34875
|
+
const isClosed = closedKeys.has(key);
|
|
34876
|
+
if (candidateKeys.has(key) || !isComplete && !isClosed) continue;
|
|
34877
|
+
if (entry.resumable) {
|
|
34878
|
+
await discardResumable(entry.resumable);
|
|
34879
|
+
entry.resumable = null;
|
|
34880
|
+
isDirty = true;
|
|
34881
|
+
}
|
|
34882
|
+
if (!shouldPruneEntry$1(entry, false, now(), isClosed)) continue;
|
|
34883
|
+
delete runtime.state[key];
|
|
34884
|
+
isDirty = true;
|
|
34919
34885
|
}
|
|
34920
|
-
|
|
34921
|
-
|
|
34922
|
-
|
|
34923
|
-
|
|
34924
|
-
|
|
34925
|
-
|
|
34886
|
+
return isDirty;
|
|
34887
|
+
}
|
|
34888
|
+
async function collectCandidates() {
|
|
34889
|
+
const firstTeam = teams[0];
|
|
34890
|
+
if (!firstTeam) {
|
|
34891
|
+
unregisterWatches();
|
|
34892
|
+
return null;
|
|
34926
34893
|
}
|
|
34927
|
-
|
|
34928
|
-
|
|
34929
|
-
|
|
34930
|
-
|
|
34931
|
-
|
|
34932
|
-
|
|
34894
|
+
if (runtime.teamProfile === null) {
|
|
34895
|
+
const profileRead = await store.requestTeamProfile(firstTeam.org, firstTeam.slug, "no-wait");
|
|
34896
|
+
if (profileRead.isRateLimited) {
|
|
34897
|
+
runtime.tickRateLimitWaitMs = profileRead.waitMs;
|
|
34898
|
+
return null;
|
|
34899
|
+
}
|
|
34900
|
+
runtime.teamProfile = profileRead.value;
|
|
34901
|
+
}
|
|
34902
|
+
if (runtime.self === null) {
|
|
34903
|
+
const viewerRead = await store.requestViewer("no-wait");
|
|
34904
|
+
if (viewerRead.isRateLimited) {
|
|
34905
|
+
runtime.tickRateLimitWaitMs = viewerRead.waitMs;
|
|
34906
|
+
return null;
|
|
34907
|
+
}
|
|
34908
|
+
runtime.self = viewerRead.value;
|
|
34909
|
+
}
|
|
34910
|
+
const viewer = runtime.self;
|
|
34911
|
+
if (viewer === null) return null;
|
|
34912
|
+
const memberLists = [];
|
|
34913
|
+
for (const team of teams) {
|
|
34914
|
+
const membersRead = await store.requestTeamMembers(team.org, team.slug, "no-wait");
|
|
34915
|
+
if (membersRead.isRateLimited) {
|
|
34916
|
+
runtime.tickRateLimitWaitMs = membersRead.waitMs;
|
|
34917
|
+
return null;
|
|
34918
|
+
}
|
|
34919
|
+
memberLists.push(membersRead.value);
|
|
34920
|
+
}
|
|
34921
|
+
const isMembershipComplete = memberLists.every((members) => members !== null);
|
|
34922
|
+
const fetchedMemberLists = memberLists.map((members) => members ?? []);
|
|
34923
|
+
if (fetchedMemberLists.every((members) => members.length === 0)) {
|
|
34924
|
+
if (isMembershipComplete) unregisterWatches();
|
|
34925
|
+
return null;
|
|
34926
|
+
}
|
|
34927
|
+
if (loop.isStopped()) return null;
|
|
34928
|
+
registerWatches(orgSearchPlans(org, teams, fetchedMemberLists, viewer));
|
|
34929
|
+
const collected = candidatesFromSnapshot(viewer);
|
|
34930
|
+
runtime.teamCandidateKeys = collected.teamCandidateKeys;
|
|
34931
|
+
return {
|
|
34932
|
+
candidates: collected.candidates,
|
|
34933
|
+
isComplete: isMembershipComplete && collected.isComplete
|
|
34933
34934
|
};
|
|
34934
|
-
entry.reviewedHead = draft.reviewedHead;
|
|
34935
|
-
entry.updatedAt = now();
|
|
34936
|
-
entry.reviewedAt = entry.updatedAt;
|
|
34937
|
-
entry.draft.reviewedAt = entry.reviewedAt;
|
|
34938
|
-
await persist();
|
|
34939
|
-
emitStatus();
|
|
34940
|
-
if (draft.status === "ready") telemetry?.capture("team_review_drafted", { inline_comment_count: draft.comments.length });
|
|
34941
|
-
if (waitingForSlot.length > 0 && !loop.isStopped()) loop.tick();
|
|
34942
34935
|
}
|
|
34943
|
-
|
|
34944
|
-
|
|
34945
|
-
|
|
34946
|
-
|
|
34947
|
-
|
|
34948
|
-
|
|
34949
|
-
|
|
34950
|
-
|
|
34951
|
-
|
|
34952
|
-
|
|
34936
|
+
function registerWatches(searchPlans) {
|
|
34937
|
+
const nextWatches = /* @__PURE__ */ new Map();
|
|
34938
|
+
for (const plan of searchPlans) {
|
|
34939
|
+
nextWatches.set(`team-review-direct:${plan.org.toLowerCase()}`, {
|
|
34940
|
+
qualifiers: `is:open draft:false org:${plan.org} user-review-requested:@me`,
|
|
34941
|
+
source: "direct"
|
|
34942
|
+
});
|
|
34943
|
+
for (let index = 0; index < plan.authors.length; index += 5) {
|
|
34944
|
+
const authors = plan.authors.slice(index, index + 5).map((author) => `author:${author}`).join(" ");
|
|
34945
|
+
nextWatches.set(`team-review-authored:${plan.org.toLowerCase()}:${index / 5}`, {
|
|
34946
|
+
qualifiers: `is:open draft:false org:${plan.org} ${authors}`,
|
|
34947
|
+
source: "authored"
|
|
34948
|
+
});
|
|
34949
|
+
}
|
|
34950
|
+
}
|
|
34951
|
+
for (const team of teams) nextWatches.set(`team-review-team:${team.org.toLowerCase()}/${team.slug.toLowerCase()}`, {
|
|
34952
|
+
qualifiers: `is:open draft:false org:${team.org} team-review-requested:${team.org}/${team.slug}`,
|
|
34953
|
+
source: "team"
|
|
34954
|
+
});
|
|
34955
|
+
for (const name of watches.keys()) if (!nextWatches.has(name)) store.unregisterWatch(name);
|
|
34956
|
+
for (const [name, watch] of nextWatches) if (watches.get(name)?.qualifiers !== watch.qualifiers) store.registerWatch({
|
|
34957
|
+
name,
|
|
34958
|
+
qualifiers: watch.qualifiers,
|
|
34959
|
+
needsDetail: true
|
|
34960
|
+
});
|
|
34961
|
+
watches.clear();
|
|
34962
|
+
for (const [name, watch] of nextWatches) watches.set(name, watch);
|
|
34963
|
+
}
|
|
34964
|
+
function askedForKeys() {
|
|
34965
|
+
return Object.keys(runtime.state).filter((key) => runtime.state[key]?.requestedAt !== void 0);
|
|
34966
|
+
}
|
|
34967
|
+
function isTeamCandidate(key) {
|
|
34968
|
+
return runtime.teamCandidateKeys.has(key.toLowerCase());
|
|
34969
|
+
}
|
|
34970
|
+
function askedForSlotsInUse() {
|
|
34971
|
+
return askedForKeys().filter((key) => runtime.state[key]?.draft?.status !== "posted" && !isTeamCandidate(key)).length;
|
|
34972
|
+
}
|
|
34973
|
+
function watchAskedFor() {
|
|
34974
|
+
store.setWatchedKeys(ASKED_FOR_WATCH_OWNER, askedForKeys());
|
|
34975
|
+
}
|
|
34976
|
+
function candidatesFromSnapshot(viewer) {
|
|
34977
|
+
const snapshot = store.getSnapshot();
|
|
34978
|
+
let isAskedForComplete = true;
|
|
34979
|
+
const askedFor = askedForKeys().flatMap((key) => {
|
|
34980
|
+
const pr = snapshot.prs[key.toLowerCase()];
|
|
34981
|
+
if (pr) return [pr];
|
|
34982
|
+
const requestedAt = runtime.state[key]?.requestedAt ?? 0;
|
|
34983
|
+
if (now() - requestedAt < 36e5) isAskedForComplete = false;
|
|
34984
|
+
return [];
|
|
34985
|
+
});
|
|
34986
|
+
const prsBySource = {
|
|
34987
|
+
direct: [],
|
|
34988
|
+
team: [],
|
|
34989
|
+
authored: []
|
|
34990
|
+
};
|
|
34991
|
+
let isComplete = true;
|
|
34992
|
+
for (const [name, { source }] of watches) {
|
|
34993
|
+
const watch = snapshot.watches[name];
|
|
34994
|
+
if (!watch?.isLoaded || !watch.isComplete) isComplete = false;
|
|
34995
|
+
for (const key of watch?.keys ?? []) {
|
|
34996
|
+
const pr = snapshot.prs[key];
|
|
34997
|
+
if (!pr) {
|
|
34998
|
+
isComplete = false;
|
|
34999
|
+
continue;
|
|
35000
|
+
}
|
|
35001
|
+
prsBySource[source].push(pr);
|
|
35002
|
+
}
|
|
35003
|
+
}
|
|
35004
|
+
return {
|
|
35005
|
+
...selectCandidates(prsBySource.direct, prsBySource.team, prsBySource.authored, {
|
|
35006
|
+
self: viewer,
|
|
35007
|
+
nowMs: now(),
|
|
35008
|
+
skipIdleAfterMs,
|
|
35009
|
+
askedFor
|
|
35010
|
+
}),
|
|
35011
|
+
isComplete: isComplete && isAskedForComplete
|
|
35012
|
+
};
|
|
35013
|
+
}
|
|
35014
|
+
function unregisterWatches() {
|
|
35015
|
+
for (const name of watches.keys()) store.unregisterWatch(name);
|
|
35016
|
+
watches.clear();
|
|
35017
|
+
store.setWatchedKeys("team-review-departed", []);
|
|
35018
|
+
store.setWatchedKeys(ASKED_FOR_WATCH_OWNER, []);
|
|
35019
|
+
}
|
|
35020
|
+
return {
|
|
35021
|
+
closedEntryKeys,
|
|
35022
|
+
pruneDeparted,
|
|
35023
|
+
collectCandidates,
|
|
35024
|
+
isTeamCandidate,
|
|
35025
|
+
askedForSlotsInUse,
|
|
35026
|
+
watchAskedFor,
|
|
35027
|
+
candidatesFromSnapshot,
|
|
35028
|
+
unregisterWatches
|
|
35029
|
+
};
|
|
35030
|
+
}
|
|
35031
|
+
//#endregion
|
|
35032
|
+
//#region server/github/team-review-poller/team-review-head-planning.ts
|
|
35033
|
+
function createTeamReviewHeadPlanning(context) {
|
|
35034
|
+
const { store, now, reReviewAfterMs, runtime } = context;
|
|
35035
|
+
function entryFor(key) {
|
|
35036
|
+
const existing = runtime.state[key];
|
|
35037
|
+
if (existing) return existing;
|
|
35038
|
+
const created = {
|
|
35039
|
+
draft: null,
|
|
35040
|
+
reviewedHead: null,
|
|
35041
|
+
inFlight: false,
|
|
35042
|
+
reviewAttempts: 0,
|
|
35043
|
+
updatedAt: now()
|
|
35044
|
+
};
|
|
35045
|
+
runtime.state[key] = created;
|
|
35046
|
+
return created;
|
|
34953
35047
|
}
|
|
34954
35048
|
function headsToReview(candidates) {
|
|
34955
35049
|
const queue = [];
|
|
34956
35050
|
let isDirty = false;
|
|
34957
35051
|
const prs = store.getSnapshot().prs;
|
|
34958
35052
|
for (const candidate of candidates) {
|
|
34959
|
-
let entry = state[candidate.key];
|
|
35053
|
+
let entry = runtime.state[candidate.key];
|
|
34960
35054
|
if (entry?.inFlight) continue;
|
|
34961
35055
|
const pr = prs[comparablePrKey(candidate)];
|
|
34962
35056
|
if (!pr) continue;
|
|
34963
35057
|
const snapshot = reviewSnapshotFromGithubPr(pr);
|
|
34964
35058
|
const head = snapshot.head;
|
|
34965
|
-
const githubReviews = githubReviewsFrom(snapshot.reviews, self ?? "");
|
|
35059
|
+
const githubReviews = githubReviewsFrom(snapshot.reviews, runtime.self ?? "");
|
|
34966
35060
|
const reviewDecision = snapshot.reviewDecision ?? null;
|
|
34967
35061
|
candidate.reviewDecision = reviewDecision;
|
|
34968
35062
|
candidate.isDraft = snapshot.isDraft;
|
|
@@ -35033,23 +35127,33 @@ function createTeamReviewPoller(deps) {
|
|
|
35033
35127
|
isDirty
|
|
35034
35128
|
};
|
|
35035
35129
|
}
|
|
35130
|
+
return {
|
|
35131
|
+
entryFor,
|
|
35132
|
+
headsToReview
|
|
35133
|
+
};
|
|
35134
|
+
}
|
|
35135
|
+
//#endregion
|
|
35136
|
+
//#region server/github/team-review-poller/team-review-answered-threads.ts
|
|
35137
|
+
function createTeamReviewAnsweredThreads(context, statusReporter) {
|
|
35138
|
+
const { deps, github, store, now, runtime, loop, persist } = context;
|
|
35139
|
+
const { emitStatus } = statusReporter;
|
|
35036
35140
|
async function handleAnsweredThreads(candidates) {
|
|
35037
35141
|
if (!github.resolveReviewThread) return false;
|
|
35038
35142
|
const eligible = candidates.filter(({ key }) => {
|
|
35039
|
-
const entry = state[key];
|
|
35143
|
+
const entry = runtime.state[key];
|
|
35040
35144
|
return entry?.githubReviews?.some((review) => review.isViewer) || entry?.draft?.status === "posted";
|
|
35041
35145
|
});
|
|
35042
35146
|
if (eligible.length === 0) return false;
|
|
35043
35147
|
const fetchedRead = await store.requestTeamReviewThreads(eligible, "no-wait");
|
|
35044
35148
|
if (fetchedRead.isRateLimited) {
|
|
35045
|
-
tickRateLimitWaitMs = fetchedRead.waitMs;
|
|
35149
|
+
runtime.tickRateLimitWaitMs = fetchedRead.waitMs;
|
|
35046
35150
|
return false;
|
|
35047
35151
|
}
|
|
35048
35152
|
const fetched = fetchedRead.value;
|
|
35049
35153
|
let isDirty = false;
|
|
35050
35154
|
for (const candidate of eligible) {
|
|
35051
35155
|
if (loop.isStopped()) break;
|
|
35052
|
-
const entry = state[candidate.key];
|
|
35156
|
+
const entry = runtime.state[candidate.key];
|
|
35053
35157
|
const nodes = fetched.get(candidate.key);
|
|
35054
35158
|
const head = entry?.liveHead;
|
|
35055
35159
|
if (!entry || !nodes || !head) continue;
|
|
@@ -35092,7 +35196,7 @@ function createTeamReviewPoller(deps) {
|
|
|
35092
35196
|
}
|
|
35093
35197
|
};
|
|
35094
35198
|
if (comparisonRead.isRateLimited) {
|
|
35095
|
-
tickRateLimitWaitMs = comparisonRead.waitMs;
|
|
35199
|
+
runtime.tickRateLimitWaitMs = comparisonRead.waitMs;
|
|
35096
35200
|
return isDirty;
|
|
35097
35201
|
}
|
|
35098
35202
|
const comparisonOutcome = comparisonRead.value;
|
|
@@ -35120,7 +35224,7 @@ function createTeamReviewPoller(deps) {
|
|
|
35120
35224
|
}
|
|
35121
35225
|
emitStatus();
|
|
35122
35226
|
const judgement = parseThreadJudgeResult(await deps.judgeThread(buildThreadJudgeRequest(node, head, evidence.patch)).catch(() => null));
|
|
35123
|
-
if (judgement && state[candidate.key] === entry && entry.liveHead === head && entry.threads?.includes(thread)) {
|
|
35227
|
+
if (judgement && runtime.state[candidate.key] === entry && entry.liveHead === head && entry.threads?.includes(thread)) {
|
|
35124
35228
|
thread.judgement = {
|
|
35125
35229
|
...judgement,
|
|
35126
35230
|
head,
|
|
@@ -35156,37 +35260,74 @@ function createTeamReviewPoller(deps) {
|
|
|
35156
35260
|
}
|
|
35157
35261
|
return false;
|
|
35158
35262
|
}
|
|
35159
|
-
|
|
35160
|
-
|
|
35161
|
-
|
|
35162
|
-
|
|
35163
|
-
|
|
35263
|
+
return { handleAnsweredThreads };
|
|
35264
|
+
}
|
|
35265
|
+
//#endregion
|
|
35266
|
+
//#region server/github/team-review-poller/team-review-runs.ts
|
|
35267
|
+
function createTeamReviewRuns(context, statusReporter, headPlanning, candidateSearch) {
|
|
35268
|
+
const { store, spawnReview, discardResumable, log, telemetry, now, maxConcurrentReviews, runtime, progressByKey, reviewCancellersByKey, notMineWhileReviewingKeys, loop, persist } = context;
|
|
35269
|
+
const { emitStatus, inFlightKeys, progressReporter } = statusReporter;
|
|
35270
|
+
const { entryFor } = headPlanning;
|
|
35271
|
+
const { watchAskedFor } = candidateSearch;
|
|
35272
|
+
async function runReview(args) {
|
|
35273
|
+
const outcome = await spawnReview(args).catch((error) => errorDraft({
|
|
35274
|
+
candidate: args.candidate,
|
|
35275
|
+
tier: args.tier,
|
|
35276
|
+
reasons: args.reasons,
|
|
35277
|
+
reviewedHead: args.detail.headRefOid,
|
|
35278
|
+
error: firstLine$1(errorMessage(error)) || "review crashed"
|
|
35164
35279
|
}));
|
|
35165
|
-
|
|
35166
|
-
|
|
35167
|
-
|
|
35168
|
-
|
|
35169
|
-
|
|
35170
|
-
|
|
35171
|
-
|
|
35172
|
-
|
|
35173
|
-
const closedKeys = closedEntryKeys();
|
|
35174
|
-
for (const [key, entry] of Object.entries(state)) {
|
|
35175
|
-
const isClosed = closedKeys.has(key);
|
|
35176
|
-
if (candidateKeys.has(key) || !isComplete && !isClosed) continue;
|
|
35177
|
-
if (entry.resumable) {
|
|
35178
|
-
await discardResumable(entry.resumable);
|
|
35179
|
-
entry.resumable = null;
|
|
35180
|
-
isDirty = true;
|
|
35181
|
-
}
|
|
35182
|
-
if (!shouldPruneEntry$1(entry, false, now(), isClosed)) continue;
|
|
35183
|
-
delete state[key];
|
|
35184
|
-
isDirty = true;
|
|
35280
|
+
const entry = entryFor(args.candidate.key);
|
|
35281
|
+
entry.inFlight = false;
|
|
35282
|
+
runtime.hasSlotFreedSinceSlotCount = true;
|
|
35283
|
+
progressByKey.delete(args.candidate.key);
|
|
35284
|
+
reviewCancellersByKey.delete(args.candidate.key);
|
|
35285
|
+
if (notMineWhileReviewingKeys.delete(args.candidate.key)) {
|
|
35286
|
+
await settleNotMineReview(entry, args, outcome);
|
|
35287
|
+
return;
|
|
35185
35288
|
}
|
|
35186
|
-
|
|
35289
|
+
if ("kind" in outcome) {
|
|
35290
|
+
if (outcome.resumable) entry.resumable = outcome.resumable;
|
|
35291
|
+
await persist();
|
|
35292
|
+
emitStatus();
|
|
35293
|
+
return;
|
|
35294
|
+
}
|
|
35295
|
+
const draft = outcome;
|
|
35296
|
+
const wasRequeuedAtReviewedHead = entry.requeuedHead === draft.reviewedHead;
|
|
35297
|
+
entry.resumable = null;
|
|
35298
|
+
if (draft.status !== "error") {
|
|
35299
|
+
delete entry.requeuedHead;
|
|
35300
|
+
delete entry.discardedReviewHead;
|
|
35301
|
+
}
|
|
35302
|
+
entry.reviewAttempts = reviewAttemptsAfter(entry, draft.reviewedHead);
|
|
35303
|
+
entry.draft = {
|
|
35304
|
+
...draft,
|
|
35305
|
+
...args.candidate.prCreatedAt ? { prCreatedAt: args.candidate.prCreatedAt } : {},
|
|
35306
|
+
...args.priorReview ? { priorReviewedHead: args.priorReview.head } : {},
|
|
35307
|
+
...wasRequeuedAtReviewedHead ? { requeuedHead: draft.reviewedHead } : {}
|
|
35308
|
+
};
|
|
35309
|
+
entry.reviewedHead = draft.reviewedHead;
|
|
35310
|
+
entry.updatedAt = now();
|
|
35311
|
+
entry.reviewedAt = entry.updatedAt;
|
|
35312
|
+
entry.draft.reviewedAt = entry.reviewedAt;
|
|
35313
|
+
await persist();
|
|
35314
|
+
emitStatus();
|
|
35315
|
+
if (draft.status === "ready") telemetry?.capture("team_review_drafted", { inline_comment_count: draft.comments.length });
|
|
35316
|
+
if (runtime.waitingForSlot.length > 0 && !loop.isStopped()) loop.tick();
|
|
35317
|
+
}
|
|
35318
|
+
async function settleNotMineReview(entry, args, outcome) {
|
|
35319
|
+
if ("kind" in outcome && outcome.resumable) await discardResumable(outcome.resumable);
|
|
35320
|
+
entry.resumable = null;
|
|
35321
|
+
entry.draft = !("kind" in outcome) && outcome.status !== "error" ? {
|
|
35322
|
+
...outcome,
|
|
35323
|
+
status: "discarded"
|
|
35324
|
+
} : notMineDraft(args.candidate, args.detail.headRefOid);
|
|
35325
|
+
entry.reviewedHead = entry.draft.reviewedHead;
|
|
35326
|
+
await settleNotMine(args.candidate.key, entry);
|
|
35327
|
+
if (runtime.waitingForSlot.length > 0 && !loop.isStopped()) loop.tick();
|
|
35187
35328
|
}
|
|
35188
35329
|
function leaveSlotQueue(key) {
|
|
35189
|
-
waitingForSlot = waitingForSlot.filter((queued) => queued.key !== key);
|
|
35330
|
+
runtime.waitingForSlot = runtime.waitingForSlot.filter((queued) => queued.key !== key);
|
|
35190
35331
|
}
|
|
35191
35332
|
async function readCandidateDetail(candidate) {
|
|
35192
35333
|
const snapshotHead = store.getSnapshot().prs[comparablePrKey(candidate)]?.headRefOid;
|
|
@@ -35202,19 +35343,19 @@ function createTeamReviewPoller(deps) {
|
|
|
35202
35343
|
return store.requestPrView(candidate.repo, candidate.number, headRead.value, "no-wait");
|
|
35203
35344
|
}
|
|
35204
35345
|
async function startReviews(queue) {
|
|
35205
|
-
hasSlotFreedSinceSlotCount = false;
|
|
35346
|
+
runtime.hasSlotFreedSinceSlotCount = false;
|
|
35206
35347
|
let freeSlots = maxConcurrentReviews - inFlightKeys().length;
|
|
35207
35348
|
let isDirty = false;
|
|
35208
|
-
waitingForSlot = queue.filter((queued) => state[queued.key]?.draft?.status !== "discarded");
|
|
35349
|
+
runtime.waitingForSlot = queue.filter((queued) => runtime.state[queued.key]?.draft?.status !== "discarded");
|
|
35209
35350
|
for (const candidate of queue) {
|
|
35210
35351
|
if (loop.isStopped()) {
|
|
35211
|
-
waitingForSlot = [];
|
|
35352
|
+
runtime.waitingForSlot = [];
|
|
35212
35353
|
break;
|
|
35213
35354
|
}
|
|
35214
35355
|
if (freeSlots <= 0) break;
|
|
35215
35356
|
const detailRead = await readCandidateDetail(candidate);
|
|
35216
35357
|
if (detailRead.isRateLimited) {
|
|
35217
|
-
tickRateLimitWaitMs = detailRead.waitMs;
|
|
35358
|
+
runtime.tickRateLimitWaitMs = detailRead.waitMs;
|
|
35218
35359
|
break;
|
|
35219
35360
|
}
|
|
35220
35361
|
const detail = detailRead.value;
|
|
@@ -35270,223 +35411,36 @@ function createTeamReviewPoller(deps) {
|
|
|
35270
35411
|
}
|
|
35271
35412
|
return isDirty;
|
|
35272
35413
|
}
|
|
35273
|
-
async function
|
|
35274
|
-
|
|
35275
|
-
|
|
35276
|
-
|
|
35277
|
-
|
|
35278
|
-
|
|
35279
|
-
|
|
35280
|
-
|
|
35281
|
-
|
|
35282
|
-
|
|
35283
|
-
return null;
|
|
35284
|
-
}
|
|
35285
|
-
teamProfile = profileRead.value;
|
|
35286
|
-
}
|
|
35287
|
-
if (self === null) {
|
|
35288
|
-
const viewerRead = await store.requestViewer("no-wait");
|
|
35289
|
-
if (viewerRead.isRateLimited) {
|
|
35290
|
-
tickRateLimitWaitMs = viewerRead.waitMs;
|
|
35291
|
-
return null;
|
|
35292
|
-
}
|
|
35293
|
-
self = viewerRead.value;
|
|
35294
|
-
}
|
|
35295
|
-
const viewer = self;
|
|
35296
|
-
if (viewer === null) return null;
|
|
35297
|
-
const memberLists = [];
|
|
35298
|
-
for (const team of teams) {
|
|
35299
|
-
const membersRead = await store.requestTeamMembers(team.org, team.slug, "no-wait");
|
|
35300
|
-
if (membersRead.isRateLimited) {
|
|
35301
|
-
tickRateLimitWaitMs = membersRead.waitMs;
|
|
35302
|
-
return null;
|
|
35303
|
-
}
|
|
35304
|
-
memberLists.push(membersRead.value);
|
|
35305
|
-
}
|
|
35306
|
-
const isMembershipComplete = memberLists.every((members) => members !== null);
|
|
35307
|
-
const fetchedMemberLists = memberLists.map((members) => members ?? []);
|
|
35308
|
-
if (fetchedMemberLists.every((members) => members.length === 0)) {
|
|
35309
|
-
if (isMembershipComplete) unregisterWatches();
|
|
35310
|
-
return null;
|
|
35311
|
-
}
|
|
35312
|
-
if (loop.isStopped()) return null;
|
|
35313
|
-
registerWatches(orgSearchPlans(org, teams, fetchedMemberLists, viewer));
|
|
35314
|
-
const collected = candidatesFromSnapshot(viewer);
|
|
35315
|
-
teamCandidateKeys = collected.teamCandidateKeys;
|
|
35316
|
-
return {
|
|
35317
|
-
candidates: collected.candidates,
|
|
35318
|
-
isComplete: isMembershipComplete && collected.isComplete
|
|
35319
|
-
};
|
|
35320
|
-
}
|
|
35321
|
-
function registerWatches(searchPlans) {
|
|
35322
|
-
const nextWatches = /* @__PURE__ */ new Map();
|
|
35323
|
-
for (const plan of searchPlans) {
|
|
35324
|
-
nextWatches.set(`team-review-direct:${plan.org.toLowerCase()}`, {
|
|
35325
|
-
qualifiers: `is:open draft:false org:${plan.org} user-review-requested:@me`,
|
|
35326
|
-
source: "direct"
|
|
35327
|
-
});
|
|
35328
|
-
for (let index = 0; index < plan.authors.length; index += 5) {
|
|
35329
|
-
const authors = plan.authors.slice(index, index + 5).map((author) => `author:${author}`).join(" ");
|
|
35330
|
-
nextWatches.set(`team-review-authored:${plan.org.toLowerCase()}:${index / 5}`, {
|
|
35331
|
-
qualifiers: `is:open draft:false org:${plan.org} ${authors}`,
|
|
35332
|
-
source: "authored"
|
|
35333
|
-
});
|
|
35334
|
-
}
|
|
35335
|
-
}
|
|
35336
|
-
for (const team of teams) nextWatches.set(`team-review-team:${team.org.toLowerCase()}/${team.slug.toLowerCase()}`, {
|
|
35337
|
-
qualifiers: `is:open draft:false org:${team.org} team-review-requested:${team.org}/${team.slug}`,
|
|
35338
|
-
source: "team"
|
|
35339
|
-
});
|
|
35340
|
-
for (const name of watches.keys()) if (!nextWatches.has(name)) store.unregisterWatch(name);
|
|
35341
|
-
for (const [name, watch] of nextWatches) if (watches.get(name)?.qualifiers !== watch.qualifiers) store.registerWatch({
|
|
35342
|
-
name,
|
|
35343
|
-
qualifiers: watch.qualifiers,
|
|
35344
|
-
needsDetail: true
|
|
35345
|
-
});
|
|
35346
|
-
watches.clear();
|
|
35347
|
-
for (const [name, watch] of nextWatches) watches.set(name, watch);
|
|
35348
|
-
}
|
|
35349
|
-
function askedForKeys() {
|
|
35350
|
-
return Object.keys(state).filter((key) => state[key]?.requestedAt !== void 0);
|
|
35351
|
-
}
|
|
35352
|
-
function isTeamCandidate(key) {
|
|
35353
|
-
return teamCandidateKeys.has(key.toLowerCase());
|
|
35354
|
-
}
|
|
35355
|
-
function askedForSlotsInUse() {
|
|
35356
|
-
return askedForKeys().filter((key) => state[key]?.draft?.status !== "posted" && !isTeamCandidate(key)).length;
|
|
35357
|
-
}
|
|
35358
|
-
function watchAskedFor() {
|
|
35359
|
-
store.setWatchedKeys(ASKED_FOR_WATCH_OWNER, askedForKeys());
|
|
35360
|
-
}
|
|
35361
|
-
function candidatesFromSnapshot(viewer) {
|
|
35362
|
-
const snapshot = store.getSnapshot();
|
|
35363
|
-
let isAskedForComplete = true;
|
|
35364
|
-
const askedFor = askedForKeys().flatMap((key) => {
|
|
35365
|
-
const pr = snapshot.prs[key.toLowerCase()];
|
|
35366
|
-
if (pr) return [pr];
|
|
35367
|
-
const requestedAt = state[key]?.requestedAt ?? 0;
|
|
35368
|
-
if (now() - requestedAt < 36e5) isAskedForComplete = false;
|
|
35369
|
-
return [];
|
|
35370
|
-
});
|
|
35371
|
-
const prsBySource = {
|
|
35372
|
-
direct: [],
|
|
35373
|
-
team: [],
|
|
35374
|
-
authored: []
|
|
35375
|
-
};
|
|
35376
|
-
let isComplete = true;
|
|
35377
|
-
for (const [name, { source }] of watches) {
|
|
35378
|
-
const watch = snapshot.watches[name];
|
|
35379
|
-
if (!watch?.isLoaded || !watch.isComplete) isComplete = false;
|
|
35380
|
-
for (const key of watch?.keys ?? []) {
|
|
35381
|
-
const pr = snapshot.prs[key];
|
|
35382
|
-
if (!pr) {
|
|
35383
|
-
isComplete = false;
|
|
35384
|
-
continue;
|
|
35385
|
-
}
|
|
35386
|
-
prsBySource[source].push(pr);
|
|
35387
|
-
}
|
|
35414
|
+
async function settleNotMine(key, entry) {
|
|
35415
|
+
delete entry.requeuedHead;
|
|
35416
|
+
delete entry.requestedAt;
|
|
35417
|
+
watchAskedFor();
|
|
35418
|
+
entry.updatedAt = now();
|
|
35419
|
+
runtime.waitingForSlot = runtime.waitingForSlot.filter((queued) => queued.key !== key);
|
|
35420
|
+
const abandonedResumable = entry.resumable;
|
|
35421
|
+
if (abandonedResumable) {
|
|
35422
|
+
entry.resumable = null;
|
|
35423
|
+
await discardResumable(abandonedResumable);
|
|
35388
35424
|
}
|
|
35389
|
-
|
|
35390
|
-
...selectCandidates(prsBySource.direct, prsBySource.team, prsBySource.authored, {
|
|
35391
|
-
self: viewer,
|
|
35392
|
-
nowMs: now(),
|
|
35393
|
-
skipIdleAfterMs,
|
|
35394
|
-
askedFor
|
|
35395
|
-
}),
|
|
35396
|
-
isComplete: isComplete && isAskedForComplete
|
|
35397
|
-
};
|
|
35398
|
-
}
|
|
35399
|
-
function rebuild() {
|
|
35400
|
-
if (!hasLoadedState || loop.isStopped() || self === null) return;
|
|
35401
|
-
const collected = candidatesFromSnapshot(self);
|
|
35402
|
-
teamCandidateKeys = collected.teamCandidateKeys;
|
|
35403
|
-
const { candidates } = collected;
|
|
35404
|
-
const planned = headsToReview(candidates);
|
|
35405
|
-
if (planned.isDirty) loop.track(persist());
|
|
35425
|
+
await persist();
|
|
35406
35426
|
emitStatus();
|
|
35407
|
-
|
|
35408
|
-
loop.tickSoon();
|
|
35409
|
-
return;
|
|
35410
|
-
}
|
|
35411
|
-
if (planned.queue.length === 0 || !canStartReview()) return;
|
|
35412
|
-
const queueSignature = queuedHeadsSignature(planned.queue);
|
|
35413
|
-
if (queueSignature === lastRebuildQueueSignature) return;
|
|
35414
|
-
lastRebuildQueueSignature = queueSignature;
|
|
35415
|
-
loop.tickSoon();
|
|
35416
|
-
}
|
|
35417
|
-
function canStartReview() {
|
|
35418
|
-
return inFlightKeys().length < maxConcurrentReviews;
|
|
35419
|
-
}
|
|
35420
|
-
function queuedHeadsSignature(queue) {
|
|
35421
|
-
const prs = store.getSnapshot().prs;
|
|
35422
|
-
return JSON.stringify(queue.map((candidate) => [candidate.key, prs[comparablePrKey(candidate)]?.headRefOid ?? null]));
|
|
35423
|
-
}
|
|
35424
|
-
async function rateLimitedOutcome() {
|
|
35425
|
-
const rateLimitWaitMs = await store.rateLimitWaitMs(now(), TEAM_REVIEW_RATE_LIMIT_RESOURCES) ?? secondaryRateLimitWaitMs(pollingError);
|
|
35426
|
-
return rateLimitWaitMs === null ? {
|
|
35427
|
-
failed: true,
|
|
35428
|
-
error: pollingError ?? void 0
|
|
35429
|
-
} : {
|
|
35430
|
-
failed: true,
|
|
35431
|
-
retryAfterMs: rateLimitWaitMs,
|
|
35432
|
-
error: pollingError ?? void 0
|
|
35433
|
-
};
|
|
35434
|
-
}
|
|
35435
|
-
async function runTick() {
|
|
35436
|
-
pollingError = null;
|
|
35437
|
-
tickRateLimitWaitMs = null;
|
|
35438
|
-
const collected = await collectCandidates().catch((error) => {
|
|
35439
|
-
pollingError = errorMessage(error);
|
|
35440
|
-
log.warn(`[${TEAM_REVIEW_LANE_ID}] candidate search failed: ${pollingError}`);
|
|
35441
|
-
return null;
|
|
35442
|
-
});
|
|
35443
|
-
if (tickRateLimitWaitMs !== null) {
|
|
35444
|
-
pollingError = "GitHub rate limit asks to wait.";
|
|
35445
|
-
return {
|
|
35446
|
-
failed: true,
|
|
35447
|
-
retryAfterMs: tickRateLimitWaitMs,
|
|
35448
|
-
error: pollingError
|
|
35449
|
-
};
|
|
35450
|
-
}
|
|
35451
|
-
if (collected === null) {
|
|
35452
|
-
pollingError ??= "Could not look up your GitHub account or team members.";
|
|
35453
|
-
return rateLimitedOutcome();
|
|
35454
|
-
}
|
|
35455
|
-
const storeError = store.getSnapshot().freshness.error;
|
|
35456
|
-
if (storeError) {
|
|
35457
|
-
pollingError = storeError;
|
|
35458
|
-
return rateLimitedOutcome();
|
|
35459
|
-
}
|
|
35460
|
-
const { candidates, isComplete } = collected;
|
|
35461
|
-
const rateLimitWaitMs = isComplete ? null : await store.rateLimitWaitMs(now(), TEAM_REVIEW_RATE_LIMIT_RESOURCES);
|
|
35462
|
-
if (rateLimitWaitMs !== null) {
|
|
35463
|
-
pollingError = "GitHub rate limit asks to wait.";
|
|
35464
|
-
return {
|
|
35465
|
-
failed: true,
|
|
35466
|
-
retryAfterMs: rateLimitWaitMs,
|
|
35467
|
-
error: pollingError
|
|
35468
|
-
};
|
|
35469
|
-
}
|
|
35470
|
-
const isPruned = await pruneDeparted(new Set(candidates.map((candidate) => candidate.key)), isComplete);
|
|
35471
|
-
if (isPruned) watchAskedFor();
|
|
35472
|
-
const planned = headsToReview(candidates);
|
|
35473
|
-
const isStarted = await startReviews(planned.queue);
|
|
35474
|
-
const areThreadsChanged = tickRateLimitWaitMs === null ? await handleAnsweredThreads(candidates) : false;
|
|
35475
|
-
if (isPruned || planned.isDirty || areThreadsChanged || isStarted) await persist();
|
|
35476
|
-
if (tickRateLimitWaitMs !== null) {
|
|
35477
|
-
pollingError = "GitHub rate limit asks to wait.";
|
|
35478
|
-
return {
|
|
35479
|
-
failed: true,
|
|
35480
|
-
retryAfterMs: tickRateLimitWaitMs,
|
|
35481
|
-
error: pollingError
|
|
35482
|
-
};
|
|
35483
|
-
}
|
|
35484
|
-
if (hasSlotFreedSinceSlotCount && waitingForSlot.length > 0 && !loop.isStopped()) setTimeoutFn(() => {
|
|
35485
|
-
loop.tick();
|
|
35486
|
-
}, 0);
|
|
35427
|
+
return { ok: true };
|
|
35487
35428
|
}
|
|
35429
|
+
return {
|
|
35430
|
+
startReviews,
|
|
35431
|
+
settleNotMine
|
|
35432
|
+
};
|
|
35433
|
+
}
|
|
35434
|
+
//#endregion
|
|
35435
|
+
//#region server/github/team-review-poller/team-review-operator-actions.ts
|
|
35436
|
+
function createTeamReviewOperatorActions(context, statusReporter, headPlanning, candidateSearch, reviewRuns) {
|
|
35437
|
+
const { store, now, runtime, reviewCancellersByKey, notMineWhileReviewingKeys, loop, persist } = context;
|
|
35438
|
+
const { emitStatus } = statusReporter;
|
|
35439
|
+
const { entryFor } = headPlanning;
|
|
35440
|
+
const { isTeamCandidate, askedForSlotsInUse, watchAskedFor } = candidateSearch;
|
|
35441
|
+
const { settleNotMine } = reviewRuns;
|
|
35488
35442
|
function getDraft(key) {
|
|
35489
|
-
const entry = state[key];
|
|
35443
|
+
const entry = runtime.state[key];
|
|
35490
35444
|
if (!entry?.draft) return null;
|
|
35491
35445
|
return {
|
|
35492
35446
|
...entry.draft,
|
|
@@ -35496,7 +35450,7 @@ function createTeamReviewPoller(deps) {
|
|
|
35496
35450
|
};
|
|
35497
35451
|
}
|
|
35498
35452
|
async function updateDraft(key, expected, patch) {
|
|
35499
|
-
const entry = state[key];
|
|
35453
|
+
const entry = runtime.state[key];
|
|
35500
35454
|
if (!entry?.draft) return null;
|
|
35501
35455
|
if (entry.draft.reviewedHead !== expected.reviewedHead || entry.draft.status !== expected.status) return null;
|
|
35502
35456
|
const postedAt = patch.status === "posted" ? { postedAt: now() } : {};
|
|
@@ -35516,7 +35470,7 @@ function createTeamReviewPoller(deps) {
|
|
|
35516
35470
|
return parsed.data;
|
|
35517
35471
|
}
|
|
35518
35472
|
async function updateThread(key, threadId, patch) {
|
|
35519
|
-
const entry = state[key];
|
|
35473
|
+
const entry = runtime.state[key];
|
|
35520
35474
|
const thread = entry?.threads?.find((thread) => thread.id === threadId);
|
|
35521
35475
|
if (!entry || !thread) return false;
|
|
35522
35476
|
Object.assign(thread, patch);
|
|
@@ -35527,7 +35481,7 @@ function createTeamReviewPoller(deps) {
|
|
|
35527
35481
|
return true;
|
|
35528
35482
|
}
|
|
35529
35483
|
async function requeue(key, head) {
|
|
35530
|
-
const entry = state[key];
|
|
35484
|
+
const entry = runtime.state[key];
|
|
35531
35485
|
if (!entry?.draft || entry.inFlight || entry.draft.reviewedHead !== head) return false;
|
|
35532
35486
|
if (!REQUEUEABLE_STATUSES.has(entry.draft.status)) return false;
|
|
35533
35487
|
entry.reviewAttempts = 0;
|
|
@@ -35554,7 +35508,7 @@ function createTeamReviewPoller(deps) {
|
|
|
35554
35508
|
return { ok: true };
|
|
35555
35509
|
}
|
|
35556
35510
|
async function markNotMine(key) {
|
|
35557
|
-
const entry = state[key];
|
|
35511
|
+
const entry = runtime.state[key];
|
|
35558
35512
|
if (entry?.inFlight) return cancelReviewAsNotMine(key);
|
|
35559
35513
|
if (entry?.draft?.status === "posted") return {
|
|
35560
35514
|
ok: false,
|
|
@@ -35567,7 +35521,7 @@ function createTeamReviewPoller(deps) {
|
|
|
35567
35521
|
};
|
|
35568
35522
|
return settleNotMine(key, entry);
|
|
35569
35523
|
}
|
|
35570
|
-
const candidate = waitingForSlot.find((queued) => queued.key === key) ?? entry?.draft ?? void 0;
|
|
35524
|
+
const candidate = runtime.waitingForSlot.find((queued) => queued.key === key) ?? entry?.draft ?? void 0;
|
|
35571
35525
|
if (!candidate) return {
|
|
35572
35526
|
ok: false,
|
|
35573
35527
|
error: "That pull request is no longer in the review queue"
|
|
@@ -35586,27 +35540,12 @@ function createTeamReviewPoller(deps) {
|
|
|
35586
35540
|
ok: false,
|
|
35587
35541
|
error: "Could not read the pull request head from GitHub"
|
|
35588
35542
|
};
|
|
35589
|
-
if (state[key]?.inFlight) return cancelReviewAsNotMine(key);
|
|
35543
|
+
if (runtime.state[key]?.inFlight) return cancelReviewAsNotMine(key);
|
|
35590
35544
|
const notMineEntry = entryFor(key);
|
|
35591
35545
|
notMineEntry.draft = notMineDraft(candidate, head);
|
|
35592
35546
|
notMineEntry.reviewedHead = head;
|
|
35593
35547
|
return settleNotMine(key, notMineEntry);
|
|
35594
35548
|
}
|
|
35595
|
-
async function settleNotMine(key, entry) {
|
|
35596
|
-
delete entry.requeuedHead;
|
|
35597
|
-
delete entry.requestedAt;
|
|
35598
|
-
watchAskedFor();
|
|
35599
|
-
entry.updatedAt = now();
|
|
35600
|
-
waitingForSlot = waitingForSlot.filter((queued) => queued.key !== key);
|
|
35601
|
-
const abandonedResumable = entry.resumable;
|
|
35602
|
-
if (abandonedResumable) {
|
|
35603
|
-
entry.resumable = null;
|
|
35604
|
-
await discardResumable(abandonedResumable);
|
|
35605
|
-
}
|
|
35606
|
-
await persist();
|
|
35607
|
-
emitStatus();
|
|
35608
|
-
return { ok: true };
|
|
35609
|
-
}
|
|
35610
35549
|
async function markAskedFor(key, entry) {
|
|
35611
35550
|
if (!isTeamCandidate(key)) entry.requestedAt ??= now();
|
|
35612
35551
|
entry.updatedAt = now();
|
|
@@ -35646,13 +35585,13 @@ function createTeamReviewPoller(deps) {
|
|
|
35646
35585
|
};
|
|
35647
35586
|
}
|
|
35648
35587
|
async function requestReview(reference) {
|
|
35649
|
-
if (loop.isStopped() || !hasLoadedState) return {
|
|
35588
|
+
if (loop.isStopped() || !runtime.hasLoadedState) return {
|
|
35650
35589
|
ok: false,
|
|
35651
35590
|
error: "Team review is not running"
|
|
35652
35591
|
};
|
|
35653
|
-
const findKnownKey = () => Object.keys(state).find((key) => key.toLowerCase() === comparablePrKey(reference));
|
|
35592
|
+
const findKnownKey = () => Object.keys(runtime.state).find((key) => key.toLowerCase() === comparablePrKey(reference));
|
|
35654
35593
|
const knownKey = findKnownKey();
|
|
35655
|
-
const knownEntry = knownKey === void 0 ? void 0 : state[knownKey];
|
|
35594
|
+
const knownEntry = knownKey === void 0 ? void 0 : runtime.state[knownKey];
|
|
35656
35595
|
if (knownKey !== void 0 && knownEntry) return requestKnownReview(knownKey, knownEntry);
|
|
35657
35596
|
if (!isTeamCandidate(comparablePrKey(reference)) && askedForSlotsInUse() >= 20) return {
|
|
35658
35597
|
ok: false,
|
|
@@ -35678,13 +35617,13 @@ function createTeamReviewPoller(deps) {
|
|
|
35678
35617
|
ok: false,
|
|
35679
35618
|
error: `could not read ${label} from GitHub`
|
|
35680
35619
|
};
|
|
35681
|
-
const refusal = askedForRefusal(detail, self);
|
|
35620
|
+
const refusal = askedForRefusal(detail, runtime.self);
|
|
35682
35621
|
if (refusal) return {
|
|
35683
35622
|
ok: false,
|
|
35684
35623
|
error: `${label} cannot be reviewed: ${refusal}`
|
|
35685
35624
|
};
|
|
35686
35625
|
const raceKey = findKnownKey();
|
|
35687
|
-
const raceEntry = raceKey === void 0 ? void 0 : state[raceKey];
|
|
35626
|
+
const raceEntry = raceKey === void 0 ? void 0 : runtime.state[raceKey];
|
|
35688
35627
|
if (raceKey !== void 0 && raceEntry) return requestKnownReview(raceKey, raceEntry);
|
|
35689
35628
|
const key = pullRequestKeyFromReference(detail.url) ?? label;
|
|
35690
35629
|
const entry = entryFor(key);
|
|
@@ -35697,29 +35636,208 @@ function createTeamReviewPoller(deps) {
|
|
|
35697
35636
|
status: "queued"
|
|
35698
35637
|
};
|
|
35699
35638
|
}
|
|
35639
|
+
return {
|
|
35640
|
+
getDraft,
|
|
35641
|
+
updateDraft,
|
|
35642
|
+
updateThread,
|
|
35643
|
+
requeue,
|
|
35644
|
+
requestReview,
|
|
35645
|
+
markNotMine
|
|
35646
|
+
};
|
|
35647
|
+
}
|
|
35648
|
+
//#endregion
|
|
35649
|
+
//#region server/github/team-review-poller.ts
|
|
35650
|
+
function createTeamReviewPoller(deps) {
|
|
35651
|
+
const { org, teams, github, store, spawnReview, discardResumable = async () => {}, readState = async () => ({}), writeState = async () => {}, beforeStart = async () => {}, setIntervalFn = DEFAULT_TIMER_FNS.setIntervalFn, clearIntervalFn = DEFAULT_TIMER_FNS.clearIntervalFn, setTimeoutFn = DEFAULT_TIMER_FNS.setTimeoutFn, clearTimeoutFn = DEFAULT_TIMER_FNS.clearTimeoutFn, log = console, telemetry = null, onTickComplete = () => {}, now = () => Date.now() } = deps;
|
|
35652
|
+
const maxConcurrentReviews = deps.maxConcurrentReviews ?? 2;
|
|
35653
|
+
const reReviewAfterMs = deps.reReviewAfterMs ?? 864e5;
|
|
35654
|
+
const skipIdleAfterMs = deps.skipIdleAfterMs ?? 12096e5;
|
|
35655
|
+
const runtime = {
|
|
35656
|
+
state: {},
|
|
35657
|
+
self: null,
|
|
35658
|
+
teamProfile: null,
|
|
35659
|
+
waitingForSlot: [],
|
|
35660
|
+
pollingError: null,
|
|
35661
|
+
tickRateLimitWaitMs: null,
|
|
35662
|
+
teamCandidateKeys: /* @__PURE__ */ new Set(),
|
|
35663
|
+
hasLoadedState: false,
|
|
35664
|
+
hasSlotFreedSinceSlotCount: false
|
|
35665
|
+
};
|
|
35666
|
+
const progressByKey = /* @__PURE__ */ new Map();
|
|
35667
|
+
const reviewCancellersByKey = /* @__PURE__ */ new Map();
|
|
35668
|
+
const notMineWhileReviewingKeys = /* @__PURE__ */ new Set();
|
|
35669
|
+
const watches = /* @__PURE__ */ new Map();
|
|
35670
|
+
let lastRebuildQueueSignature = null;
|
|
35671
|
+
const loop = createTickLoop({
|
|
35672
|
+
tag: TEAM_REVIEW_LANE_ID,
|
|
35673
|
+
intervalMs: (deps.intervalMinutes ?? 15) * 6e4,
|
|
35674
|
+
tick: async () => {
|
|
35675
|
+
try {
|
|
35676
|
+
return await runTick();
|
|
35677
|
+
} catch (error) {
|
|
35678
|
+
runtime.pollingError = errorMessage(error);
|
|
35679
|
+
log.warn(`[${TEAM_REVIEW_LANE_ID}] poll failed: ${runtime.pollingError}`);
|
|
35680
|
+
return rateLimitedOutcome();
|
|
35681
|
+
}
|
|
35682
|
+
},
|
|
35683
|
+
quickRetries: true,
|
|
35684
|
+
now,
|
|
35685
|
+
setTimeoutFn,
|
|
35686
|
+
clearTimeoutFn,
|
|
35687
|
+
onScheduleChange: () => {
|
|
35688
|
+
emitStatus();
|
|
35689
|
+
},
|
|
35690
|
+
rateLimitWaitMs: () => store.rateLimitWaitMs(now(), TEAM_REVIEW_RATE_LIMIT_RESOURCES),
|
|
35691
|
+
writeState: () => writeState(runtime.state),
|
|
35692
|
+
setIntervalFn,
|
|
35693
|
+
clearIntervalFn,
|
|
35694
|
+
clock: storeReadingLaneClock(deps.clock),
|
|
35695
|
+
firstTickDelayMs: deps.firstTickDelayMs,
|
|
35696
|
+
backoffMaxMs: GITHUB_RATE_LIMIT_WINDOW_MS,
|
|
35697
|
+
log
|
|
35698
|
+
});
|
|
35699
|
+
const persist = () => loop.persist();
|
|
35700
|
+
const context = {
|
|
35701
|
+
deps,
|
|
35702
|
+
org,
|
|
35703
|
+
teams,
|
|
35704
|
+
github,
|
|
35705
|
+
store,
|
|
35706
|
+
spawnReview,
|
|
35707
|
+
discardResumable,
|
|
35708
|
+
log,
|
|
35709
|
+
telemetry,
|
|
35710
|
+
onTickComplete,
|
|
35711
|
+
now,
|
|
35712
|
+
setTimeoutFn,
|
|
35713
|
+
clearTimeoutFn,
|
|
35714
|
+
maxConcurrentReviews,
|
|
35715
|
+
reReviewAfterMs,
|
|
35716
|
+
skipIdleAfterMs,
|
|
35717
|
+
runtime,
|
|
35718
|
+
progressByKey,
|
|
35719
|
+
reviewCancellersByKey,
|
|
35720
|
+
notMineWhileReviewingKeys,
|
|
35721
|
+
watches,
|
|
35722
|
+
loop,
|
|
35723
|
+
persist
|
|
35724
|
+
};
|
|
35725
|
+
const statusReporter = createTeamReviewStatusReporter(context);
|
|
35726
|
+
const candidateSearch = createTeamReviewCandidateSearch(context);
|
|
35727
|
+
const headPlanning = createTeamReviewHeadPlanning(context);
|
|
35728
|
+
const { handleAnsweredThreads } = createTeamReviewAnsweredThreads(context, statusReporter);
|
|
35729
|
+
const reviewRuns = createTeamReviewRuns(context, statusReporter, headPlanning, candidateSearch);
|
|
35730
|
+
const { getDraft, updateDraft, updateThread, requeue, requestReview, markNotMine } = createTeamReviewOperatorActions(context, statusReporter, headPlanning, candidateSearch, reviewRuns);
|
|
35731
|
+
const { inFlightKeys, cancelPendingProgressEmit, emitStatus } = statusReporter;
|
|
35732
|
+
const { closedEntryKeys, pruneDeparted, collectCandidates, watchAskedFor, candidatesFromSnapshot, unregisterWatches } = candidateSearch;
|
|
35733
|
+
const { headsToReview } = headPlanning;
|
|
35734
|
+
const { startReviews } = reviewRuns;
|
|
35735
|
+
function rebuild() {
|
|
35736
|
+
if (!runtime.hasLoadedState || loop.isStopped() || runtime.self === null) return;
|
|
35737
|
+
const collected = candidatesFromSnapshot(runtime.self);
|
|
35738
|
+
runtime.teamCandidateKeys = collected.teamCandidateKeys;
|
|
35739
|
+
const { candidates } = collected;
|
|
35740
|
+
const planned = headsToReview(candidates);
|
|
35741
|
+
if (planned.isDirty) loop.track(persist());
|
|
35742
|
+
emitStatus();
|
|
35743
|
+
if (closedEntryKeys().size > 0) {
|
|
35744
|
+
loop.tickSoon();
|
|
35745
|
+
return;
|
|
35746
|
+
}
|
|
35747
|
+
if (planned.queue.length === 0 || !canStartReview()) return;
|
|
35748
|
+
const queueSignature = queuedHeadsSignature(planned.queue);
|
|
35749
|
+
if (queueSignature === lastRebuildQueueSignature) return;
|
|
35750
|
+
lastRebuildQueueSignature = queueSignature;
|
|
35751
|
+
loop.tickSoon();
|
|
35752
|
+
}
|
|
35753
|
+
function canStartReview() {
|
|
35754
|
+
return inFlightKeys().length < maxConcurrentReviews;
|
|
35755
|
+
}
|
|
35756
|
+
function queuedHeadsSignature(queue) {
|
|
35757
|
+
const prs = store.getSnapshot().prs;
|
|
35758
|
+
return JSON.stringify(queue.map((candidate) => [candidate.key, prs[comparablePrKey(candidate)]?.headRefOid ?? null]));
|
|
35759
|
+
}
|
|
35760
|
+
async function rateLimitedOutcome() {
|
|
35761
|
+
const rateLimitWaitMs = await store.rateLimitWaitMs(now(), TEAM_REVIEW_RATE_LIMIT_RESOURCES) ?? secondaryRateLimitWaitMs(runtime.pollingError);
|
|
35762
|
+
return rateLimitWaitMs === null ? {
|
|
35763
|
+
failed: true,
|
|
35764
|
+
error: runtime.pollingError ?? void 0
|
|
35765
|
+
} : {
|
|
35766
|
+
failed: true,
|
|
35767
|
+
retryAfterMs: rateLimitWaitMs,
|
|
35768
|
+
error: runtime.pollingError ?? void 0
|
|
35769
|
+
};
|
|
35770
|
+
}
|
|
35771
|
+
async function runTick() {
|
|
35772
|
+
runtime.pollingError = null;
|
|
35773
|
+
runtime.tickRateLimitWaitMs = null;
|
|
35774
|
+
const collected = await collectCandidates().catch((error) => {
|
|
35775
|
+
runtime.pollingError = errorMessage(error);
|
|
35776
|
+
log.warn(`[${TEAM_REVIEW_LANE_ID}] candidate search failed: ${runtime.pollingError}`);
|
|
35777
|
+
return null;
|
|
35778
|
+
});
|
|
35779
|
+
if (runtime.tickRateLimitWaitMs !== null) {
|
|
35780
|
+
runtime.pollingError = "GitHub rate limit asks to wait.";
|
|
35781
|
+
return {
|
|
35782
|
+
failed: true,
|
|
35783
|
+
retryAfterMs: runtime.tickRateLimitWaitMs,
|
|
35784
|
+
error: runtime.pollingError
|
|
35785
|
+
};
|
|
35786
|
+
}
|
|
35787
|
+
if (collected === null) {
|
|
35788
|
+
runtime.pollingError ??= "Could not look up your GitHub account or team members.";
|
|
35789
|
+
return rateLimitedOutcome();
|
|
35790
|
+
}
|
|
35791
|
+
const storeError = store.getSnapshot().freshness.error;
|
|
35792
|
+
if (storeError) {
|
|
35793
|
+
runtime.pollingError = storeError;
|
|
35794
|
+
return rateLimitedOutcome();
|
|
35795
|
+
}
|
|
35796
|
+
const { candidates, isComplete } = collected;
|
|
35797
|
+
const rateLimitWaitMs = isComplete ? null : await store.rateLimitWaitMs(now(), TEAM_REVIEW_RATE_LIMIT_RESOURCES);
|
|
35798
|
+
if (rateLimitWaitMs !== null) {
|
|
35799
|
+
runtime.pollingError = "GitHub rate limit asks to wait.";
|
|
35800
|
+
return {
|
|
35801
|
+
failed: true,
|
|
35802
|
+
retryAfterMs: rateLimitWaitMs,
|
|
35803
|
+
error: runtime.pollingError
|
|
35804
|
+
};
|
|
35805
|
+
}
|
|
35806
|
+
const isPruned = await pruneDeparted(new Set(candidates.map((candidate) => candidate.key)), isComplete);
|
|
35807
|
+
if (isPruned) watchAskedFor();
|
|
35808
|
+
const planned = headsToReview(candidates);
|
|
35809
|
+
const isStarted = await startReviews(planned.queue);
|
|
35810
|
+
const areThreadsChanged = runtime.tickRateLimitWaitMs === null ? await handleAnsweredThreads(candidates) : false;
|
|
35811
|
+
if (isPruned || planned.isDirty || areThreadsChanged || isStarted) await persist();
|
|
35812
|
+
if (runtime.tickRateLimitWaitMs !== null) {
|
|
35813
|
+
runtime.pollingError = "GitHub rate limit asks to wait.";
|
|
35814
|
+
return {
|
|
35815
|
+
failed: true,
|
|
35816
|
+
retryAfterMs: runtime.tickRateLimitWaitMs,
|
|
35817
|
+
error: runtime.pollingError
|
|
35818
|
+
};
|
|
35819
|
+
}
|
|
35820
|
+
if (runtime.hasSlotFreedSinceSlotCount && runtime.waitingForSlot.length > 0 && !loop.isStopped()) setTimeoutFn(() => {
|
|
35821
|
+
loop.tick();
|
|
35822
|
+
}, 0);
|
|
35823
|
+
}
|
|
35700
35824
|
async function start() {
|
|
35701
35825
|
await loop.start(async () => {
|
|
35702
|
-
state = await readState() || {};
|
|
35703
|
-
for (const entry of Object.values(state)) entry.inFlight = false;
|
|
35826
|
+
runtime.state = await readState() || {};
|
|
35827
|
+
for (const entry of Object.values(runtime.state)) entry.inFlight = false;
|
|
35704
35828
|
progressByKey.clear();
|
|
35705
35829
|
emitStatus();
|
|
35706
35830
|
const keepPaths = /* @__PURE__ */ new Set();
|
|
35707
|
-
for (const entry of Object.values(state)) {
|
|
35831
|
+
for (const entry of Object.values(runtime.state)) {
|
|
35708
35832
|
if (!entry.resumable) continue;
|
|
35709
35833
|
keepPaths.add(entry.resumable.workDir);
|
|
35710
35834
|
keepPaths.add(entry.resumable.worktreePath);
|
|
35711
35835
|
}
|
|
35712
35836
|
await beforeStart(keepPaths);
|
|
35713
|
-
hasLoadedState = true;
|
|
35837
|
+
runtime.hasLoadedState = true;
|
|
35714
35838
|
watchAskedFor();
|
|
35715
35839
|
});
|
|
35716
35840
|
}
|
|
35717
|
-
function unregisterWatches() {
|
|
35718
|
-
for (const name of watches.keys()) store.unregisterWatch(name);
|
|
35719
|
-
watches.clear();
|
|
35720
|
-
store.setWatchedKeys("team-review-departed", []);
|
|
35721
|
-
store.setWatchedKeys(ASKED_FOR_WATCH_OWNER, []);
|
|
35722
|
-
}
|
|
35723
35841
|
async function refresh() {
|
|
35724
35842
|
if (loop.isStopped()) return {
|
|
35725
35843
|
ok: false,
|
|
@@ -35733,7 +35851,7 @@ function createTeamReviewPoller(deps) {
|
|
|
35733
35851
|
});
|
|
35734
35852
|
}
|
|
35735
35853
|
async function stop() {
|
|
35736
|
-
hasLoadedState = false;
|
|
35854
|
+
runtime.hasLoadedState = false;
|
|
35737
35855
|
unregisterWatches();
|
|
35738
35856
|
cancelPendingProgressEmit();
|
|
35739
35857
|
await loop.stop();
|
|
@@ -35751,7 +35869,7 @@ function createTeamReviewPoller(deps) {
|
|
|
35751
35869
|
requeue,
|
|
35752
35870
|
requestReview,
|
|
35753
35871
|
markNotMine,
|
|
35754
|
-
_state: () => state
|
|
35872
|
+
_state: () => runtime.state
|
|
35755
35873
|
};
|
|
35756
35874
|
}
|
|
35757
35875
|
//#endregion
|