@mrrlin-dev/mcp 0.4.224 → 0.4.227
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/bin.cjs +159 -47
- package/package.json +1 -1
package/dist/bin.cjs
CHANGED
|
@@ -69839,10 +69839,11 @@ var init_linux_service = __esm({
|
|
|
69839
69839
|
(0, import_node_fs32.unlinkSync)(this.config.socketPath);
|
|
69840
69840
|
} catch {
|
|
69841
69841
|
}
|
|
69842
|
-
|
|
69842
|
+
const server = import_node_net9.default.createServer((socket) => this.connection(socket));
|
|
69843
|
+
this.server = server;
|
|
69843
69844
|
await new Promise((resolve4, reject) => {
|
|
69844
|
-
|
|
69845
|
-
|
|
69845
|
+
server.once("error", reject);
|
|
69846
|
+
server.listen(this.config.socketPath, () => resolve4());
|
|
69846
69847
|
});
|
|
69847
69848
|
(0, import_node_fs32.chmodSync)(this.config.socketPath, 432);
|
|
69848
69849
|
}
|
|
@@ -69993,6 +69994,11 @@ __export(cli_exports, {
|
|
|
69993
69994
|
readDrainServiceEndpoint: () => readDrainServiceEndpoint,
|
|
69994
69995
|
runDrainServiceCli: () => runDrainServiceCli
|
|
69995
69996
|
});
|
|
69997
|
+
function runArgv(argv, options) {
|
|
69998
|
+
const [file2, ...rest] = argv;
|
|
69999
|
+
if (!file2) throw new Error("empty command");
|
|
70000
|
+
(0, import_node_child_process27.execFileSync)(file2, rest, options);
|
|
70001
|
+
}
|
|
69996
70002
|
function flag(args, name) {
|
|
69997
70003
|
const index = args.indexOf(`--${name}`);
|
|
69998
70004
|
return index >= 0 ? args[index + 1] : void 0;
|
|
@@ -70032,7 +70038,7 @@ async function runDrainServiceCli(args, out = process.stdout, version2) {
|
|
|
70032
70038
|
["rm", "-rf", PREFIX]
|
|
70033
70039
|
]) {
|
|
70034
70040
|
try {
|
|
70035
|
-
(
|
|
70041
|
+
runArgv(argv, { stdio: "inherit" });
|
|
70036
70042
|
} catch {
|
|
70037
70043
|
}
|
|
70038
70044
|
}
|
|
@@ -70061,12 +70067,17 @@ function installLinux(args, out, version2) {
|
|
|
70061
70067
|
out.write("drain-service install needs --provider-user <the bridge's user> and --credential <agent credential id>\n");
|
|
70062
70068
|
return 1;
|
|
70063
70069
|
}
|
|
70070
|
+
const bundlePath = process.argv[1];
|
|
70071
|
+
if (!bundlePath) {
|
|
70072
|
+
out.write("drain-service install: cannot locate the running mrrlin-mcp bundle\n");
|
|
70073
|
+
return 1;
|
|
70074
|
+
}
|
|
70064
70075
|
const options = {
|
|
70065
70076
|
serviceUser: flag(args, "service-user") ?? "mrrlin-drain",
|
|
70066
70077
|
providerUser,
|
|
70067
70078
|
nodePath: process.execPath,
|
|
70068
|
-
bundlePath
|
|
70069
|
-
helperSourcePath: (0, import_node_path43.join)(
|
|
70079
|
+
bundlePath,
|
|
70080
|
+
helperSourcePath: (0, import_node_path43.join)(bundlePath, "..", "..", "native", "mrrlin-drain-ns.c"),
|
|
70070
70081
|
version: version2
|
|
70071
70082
|
};
|
|
70072
70083
|
const providerUid = Number((0, import_node_child_process27.execFileSync)("id", ["-u", providerUser]).toString().trim());
|
|
@@ -70074,7 +70085,7 @@ function installLinux(args, out, version2) {
|
|
|
70074
70085
|
const plan = planLinuxInstall(options, { providerUid, providerGid });
|
|
70075
70086
|
for (const argv of plan.commands) {
|
|
70076
70087
|
try {
|
|
70077
|
-
(
|
|
70088
|
+
runArgv(argv, { stdio: "inherit" });
|
|
70078
70089
|
} catch (error51) {
|
|
70079
70090
|
if (argv[0] === "useradd") continue;
|
|
70080
70091
|
if (argv[0] === "cc" && argv[1] === "-static") {
|
|
@@ -89741,7 +89752,7 @@ async function invokeCapability(server, toolName2, payload, executionSignal) {
|
|
|
89741
89752
|
env[key] = expandedValue;
|
|
89742
89753
|
}
|
|
89743
89754
|
const tree = attemptTreeFor(executionSignal);
|
|
89744
|
-
if (tree) {
|
|
89755
|
+
if (tree && executionSignal) {
|
|
89745
89756
|
const transport = new AttemptStdioClientTransport(tree, { command: server.command, args: server.args ?? [], env });
|
|
89746
89757
|
stopStdio = () => void transport.close();
|
|
89747
89758
|
executionSignal.addEventListener("abort", stopStdio, { once: true });
|
|
@@ -94607,6 +94618,15 @@ function stripHumanizeOpener(body) {
|
|
|
94607
94618
|
}
|
|
94608
94619
|
return body;
|
|
94609
94620
|
}
|
|
94621
|
+
async function createInboxItemWithResend(ctx, projectSlug, item) {
|
|
94622
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
94623
|
+
try {
|
|
94624
|
+
return { item: await ctx.client.createInboxItem(projectSlug, item) };
|
|
94625
|
+
} catch {
|
|
94626
|
+
}
|
|
94627
|
+
}
|
|
94628
|
+
return null;
|
|
94629
|
+
}
|
|
94610
94630
|
var DID_NOT_CONVERGE_ERROR = "Consensus blocked: reviewers did not converge within budget.";
|
|
94611
94631
|
async function handleConsensusBlocked(result, ctx, input, resolvedTaskId) {
|
|
94612
94632
|
const operatorClarifications = result.operatorClarifications ?? [];
|
|
@@ -94720,6 +94740,7 @@ async function handleConsensusBlocked(result, ctx, input, resolvedTaskId) {
|
|
|
94720
94740
|
}
|
|
94721
94741
|
const confirmedQuestionIds = /* @__PURE__ */ new Set();
|
|
94722
94742
|
let clarificationDeliveryIncomplete = false;
|
|
94743
|
+
let inboxDeliveryUnconfirmed = false;
|
|
94723
94744
|
const scopeId = taskId ?? planId;
|
|
94724
94745
|
if (toFile.length > 0 && scopeId) {
|
|
94725
94746
|
const clarificationKey = taskId ? result.evaluatedClarificationKey : void 0;
|
|
@@ -94744,14 +94765,12 @@ async function handleConsensusBlocked(result, ctx, input, resolvedTaskId) {
|
|
|
94744
94765
|
};
|
|
94745
94766
|
const uncertain = [];
|
|
94746
94767
|
for (const question of questions) {
|
|
94747
|
-
|
|
94748
|
-
|
|
94749
|
-
item = await ctx.client.createInboxItem(input.projectSlug, question);
|
|
94750
|
-
} catch {
|
|
94768
|
+
const created = await createInboxItemWithResend(ctx, input.projectSlug, question);
|
|
94769
|
+
if (created === null) {
|
|
94751
94770
|
uncertain.push(question);
|
|
94752
94771
|
continue;
|
|
94753
94772
|
}
|
|
94754
|
-
if (matchesQuestion(item, question)) confirmedQuestionIds.add(item.id);
|
|
94773
|
+
if (matchesQuestion(created.item, question)) confirmedQuestionIds.add(created.item.id);
|
|
94755
94774
|
else clarificationDeliveryIncomplete = true;
|
|
94756
94775
|
}
|
|
94757
94776
|
if (uncertain.length > 0) {
|
|
@@ -94764,14 +94783,14 @@ async function handleConsensusBlocked(result, ctx, input, resolvedTaskId) {
|
|
|
94764
94783
|
for (const question of uncertain) {
|
|
94765
94784
|
const item = pending.find((candidate) => matchesQuestion(candidate, question));
|
|
94766
94785
|
if (item) confirmedQuestionIds.add(item.id);
|
|
94767
|
-
else
|
|
94786
|
+
else inboxDeliveryUnconfirmed = true;
|
|
94768
94787
|
}
|
|
94769
94788
|
}
|
|
94770
94789
|
}
|
|
94771
94790
|
const filedQuestionCount = confirmedQuestionIds.size;
|
|
94772
94791
|
const existingQuestionCount = result.pendingReviewQuestionIds?.length ?? 0;
|
|
94773
94792
|
let gateBlockQuestionAvailable;
|
|
94774
|
-
if (!clarificationDeliveryIncomplete && filedQuestionCount === 0 && existingQuestionCount === 0 && diagnostics.length === 0 && taskId && page) {
|
|
94793
|
+
if (!clarificationDeliveryIncomplete && !inboxDeliveryUnconfirmed && filedQuestionCount === 0 && existingQuestionCount === 0 && diagnostics.length === 0 && taskId && page) {
|
|
94775
94794
|
const domain2 = await resolveSpecDomain(ctx.client, input.projectSlug, {
|
|
94776
94795
|
id: page.id,
|
|
94777
94796
|
taskId: page.taskId ?? null
|
|
@@ -94788,25 +94807,35 @@ async function handleConsensusBlocked(result, ctx, input, resolvedTaskId) {
|
|
|
94788
94807
|
const storedOptions = item.questionOptions;
|
|
94789
94808
|
return item.projectSlug === input.projectSlug && item.taskId === taskId && item.id === blockItemId && item.kind === "question" && item.origin === "gate_block" && item.status === "pending" && item.body === body && storedOptions?.length === questionOptions.length && questionOptions.every((option) => storedOptions.some((stored) => stored.answer === option.answer && stored.label === option.label && stored.description === option.description));
|
|
94790
94809
|
};
|
|
94791
|
-
|
|
94792
|
-
|
|
94793
|
-
|
|
94794
|
-
|
|
94795
|
-
|
|
94796
|
-
|
|
94797
|
-
|
|
94798
|
-
|
|
94799
|
-
|
|
94800
|
-
gateBlockQuestionAvailable = matchesPendingQuestion(item);
|
|
94801
|
-
}
|
|
94810
|
+
const created = await createInboxItemWithResend(ctx, input.projectSlug, {
|
|
94811
|
+
id: blockItemId,
|
|
94812
|
+
kind: "question",
|
|
94813
|
+
taskId,
|
|
94814
|
+
body,
|
|
94815
|
+
origin: "gate_block",
|
|
94816
|
+
questionOptions
|
|
94817
|
+
});
|
|
94818
|
+
if (created !== null) {
|
|
94819
|
+
gateBlockQuestionAvailable = matchesPendingQuestion(created.item);
|
|
94820
|
+
} else {
|
|
94802
94821
|
const pending = await ctx.client.listInboxItems(input.projectSlug, {
|
|
94803
94822
|
taskId,
|
|
94804
94823
|
kind: "question",
|
|
94805
94824
|
status: "pending"
|
|
94806
94825
|
}).catch(() => []);
|
|
94807
|
-
|
|
94826
|
+
if (pending.some(matchesPendingQuestion)) gateBlockQuestionAvailable = true;
|
|
94827
|
+
else inboxDeliveryUnconfirmed = true;
|
|
94808
94828
|
}
|
|
94809
94829
|
}
|
|
94830
|
+
if (inboxDeliveryUnconfirmed) {
|
|
94831
|
+
const retryTaskId = taskId ?? resolvedTaskId;
|
|
94832
|
+
return {
|
|
94833
|
+
kind: "retry",
|
|
94834
|
+
failureReason: "consensus_blocked",
|
|
94835
|
+
error: "The Inbox could not confirm the review's questions.",
|
|
94836
|
+
...retryTaskId ? { taskId: retryTaskId } : {}
|
|
94837
|
+
};
|
|
94838
|
+
}
|
|
94810
94839
|
let error51;
|
|
94811
94840
|
if (clarificationDeliveryIncomplete) {
|
|
94812
94841
|
error51 = filedQuestionCount === 0 ? "No open clarification questions could be confirmed in the Inbox." : `Confirmed ${filedQuestionCount} open clarification question${filedQuestionCount === 1 ? "" : "s"} in the Inbox. Some questions could not be confirmed.`;
|
|
@@ -98621,6 +98650,15 @@ async function doPushRunBranch(opts, execGit) {
|
|
|
98621
98650
|
}
|
|
98622
98651
|
return { pushedSha: localSha };
|
|
98623
98652
|
}
|
|
98653
|
+
var FINISHED_RUN_STATUSES = ["done", "failed", "cancelled"];
|
|
98654
|
+
function unfinishedRunWorktrees(runs) {
|
|
98655
|
+
const finished = new Set(FINISHED_RUN_STATUSES);
|
|
98656
|
+
const keep = /* @__PURE__ */ new Set();
|
|
98657
|
+
for (const run4 of runs) {
|
|
98658
|
+
if (run4.worktreeId && !finished.has(run4.status)) keep.add((0, import_node_path24.resolve)(run4.worktreeId));
|
|
98659
|
+
}
|
|
98660
|
+
return keep;
|
|
98661
|
+
}
|
|
98624
98662
|
async function sweepOrphanWorktrees(opts, runGit2 = git2) {
|
|
98625
98663
|
const reaped = [];
|
|
98626
98664
|
const hooksDir = prepareDisabledGitHooksDir(opts.locksDir, `sweep:${opts.slug}`);
|
|
@@ -105481,7 +105519,7 @@ Do NOT derail the current task - if the operator has an in-flight question, answ
|
|
|
105481
105519
|
}
|
|
105482
105520
|
|
|
105483
105521
|
// src/_generated/version.ts
|
|
105484
|
-
var PKG_VERSION = "0.4.
|
|
105522
|
+
var PKG_VERSION = "0.4.227";
|
|
105485
105523
|
|
|
105486
105524
|
// src/bridge-allowed-origins.ts
|
|
105487
105525
|
var DEFAULT_DIRECTOR_BRIDGE_ALLOWED_ORIGINS = [
|
|
@@ -108553,7 +108591,8 @@ async function connect(socketPath, onData, timeoutMs) {
|
|
|
108553
108591
|
for (const listener of onClose) listener();
|
|
108554
108592
|
});
|
|
108555
108593
|
const next = (limitMs) => new Promise((resolve4) => {
|
|
108556
|
-
|
|
108594
|
+
const head = queued.shift();
|
|
108595
|
+
if (head) return resolve4(head);
|
|
108557
108596
|
if (closed) return resolve4({ type: "closed" });
|
|
108558
108597
|
let timer;
|
|
108559
108598
|
const waiter = (message) => {
|
|
@@ -108687,7 +108726,9 @@ function worktreeGitdir(checkout) {
|
|
|
108687
108726
|
const text = (0, import_node_fs34.readFileSync)(dotGit, "utf8").trim();
|
|
108688
108727
|
const match2 = /^gitdir: (.+)$/.exec(text);
|
|
108689
108728
|
if (!match2) throw new Error("not a linked worktree");
|
|
108690
|
-
const
|
|
108729
|
+
const target = match2[1];
|
|
108730
|
+
if (!target) throw new Error("not a linked worktree");
|
|
108731
|
+
const gitdir = (0, import_node_path44.isAbsolute)(target) ? target : (0, import_node_path44.resolve)(checkout, target);
|
|
108691
108732
|
return (0, import_node_fs34.realpathSync)(gitdir);
|
|
108692
108733
|
}
|
|
108693
108734
|
function writeWorktreePin(worktreeRoot, checkout, owner, generation) {
|
|
@@ -111175,6 +111216,48 @@ async function runHasLease(deps, projectSlug, runId, leaseId) {
|
|
|
111175
111216
|
return false;
|
|
111176
111217
|
}
|
|
111177
111218
|
}
|
|
111219
|
+
async function runLeaseState(deps, projectSlug, runId, leaseId) {
|
|
111220
|
+
try {
|
|
111221
|
+
const run4 = await deps.client.getExecutionRun(projectSlug, runId);
|
|
111222
|
+
return run4.status === "running" && run4.leaseId === leaseId ? "held" : "lost";
|
|
111223
|
+
} catch (error51) {
|
|
111224
|
+
if (error51 instanceof MrrlinApiError && error51.status === 404) return "lost";
|
|
111225
|
+
return "error";
|
|
111226
|
+
}
|
|
111227
|
+
}
|
|
111228
|
+
async function confirmLeaseWithRetry(deps, projectSlug, runId, leaseId, signal) {
|
|
111229
|
+
for (; ; ) {
|
|
111230
|
+
const state = await runLeaseState(deps, projectSlug, runId, leaseId);
|
|
111231
|
+
if (state !== "error") return state === "held";
|
|
111232
|
+
if (signal.aborted) return false;
|
|
111233
|
+
await new Promise((resolve4) => {
|
|
111234
|
+
const timer = setTimeout(resolve4, 250);
|
|
111235
|
+
signal.addEventListener("abort", () => {
|
|
111236
|
+
clearTimeout(timer);
|
|
111237
|
+
resolve4();
|
|
111238
|
+
}, { once: true });
|
|
111239
|
+
});
|
|
111240
|
+
if (signal.aborted) return false;
|
|
111241
|
+
}
|
|
111242
|
+
}
|
|
111243
|
+
async function releaseUnconfirmedClaim(deps, projectSlug, runId, leaseId) {
|
|
111244
|
+
const state = await runLeaseState(deps, projectSlug, runId, leaseId);
|
|
111245
|
+
if (state !== "held") {
|
|
111246
|
+
console.warn(JSON.stringify({ event: "execution_preflight_claim_not_released", projectSlug, runId, state }));
|
|
111247
|
+
return;
|
|
111248
|
+
}
|
|
111249
|
+
try {
|
|
111250
|
+
await deps.client.updateExecutionRun(projectSlug, runId, { status: "pending", leaseId: null }, { expectedStatus: "running" });
|
|
111251
|
+
console.warn(JSON.stringify({ event: "execution_preflight_claim_released", projectSlug, runId }));
|
|
111252
|
+
} catch (error51) {
|
|
111253
|
+
console.warn(JSON.stringify({
|
|
111254
|
+
event: "execution_preflight_claim_release_failed",
|
|
111255
|
+
projectSlug,
|
|
111256
|
+
runId,
|
|
111257
|
+
detail: error51 instanceof Error ? error51.message : String(error51)
|
|
111258
|
+
}));
|
|
111259
|
+
}
|
|
111260
|
+
}
|
|
111178
111261
|
var MIXED_CODE_APPROVAL_POLL_MS = 2e3;
|
|
111179
111262
|
var MIXED_CODE_APPROVAL_REQUEST_MS = 3e3;
|
|
111180
111263
|
var ReservedLocalDeliveryFailure = class extends Error {
|
|
@@ -111219,6 +111302,12 @@ async function readApprovedMixedCodeSpec(client, projectSlug, runId, runApproval
|
|
|
111219
111302
|
}
|
|
111220
111303
|
var WorkLeaseUnavailableError = class extends Error {
|
|
111221
111304
|
};
|
|
111305
|
+
var WorkPreflightUnavailableError = class extends WorkLeaseUnavailableError {
|
|
111306
|
+
constructor(reservationAttempted) {
|
|
111307
|
+
super("work preflight could not confirm the lease");
|
|
111308
|
+
this.reservationAttempted = reservationAttempted;
|
|
111309
|
+
}
|
|
111310
|
+
};
|
|
111222
111311
|
async function driveTurn(deps, codex, projectSlug, runId, leaseId, threadId, inputText, overallMs, phase, effort, guard, workPreflight, dispatchBudgetMs) {
|
|
111223
111312
|
let turnError = null;
|
|
111224
111313
|
let interruptFailed = false;
|
|
@@ -111264,16 +111353,16 @@ async function driveTurn(deps, codex, projectSlug, runId, leaseId, threadId, inp
|
|
|
111264
111353
|
const checkDeadline = () => {
|
|
111265
111354
|
preflightSignal.throwIfAborted();
|
|
111266
111355
|
if (Date.now() >= deadlineAt || import_node_perf_hooks.performance.now() >= reservationDeadline || workPreflight.remainingBudgetMs() <= 0) {
|
|
111267
|
-
throw new
|
|
111356
|
+
throw new WorkPreflightUnavailableError(Boolean(workPreflight.begin));
|
|
111268
111357
|
}
|
|
111269
111358
|
};
|
|
111270
111359
|
const eligible = await withTimeout2(
|
|
111271
|
-
workPreflight.begin ? workPreflight.begin(preflightSignal, checkDeadline) :
|
|
111360
|
+
workPreflight.begin ? workPreflight.begin(preflightSignal, checkDeadline) : confirmLeaseWithRetry(deps, projectSlug, runId, leaseId, preflightSignal),
|
|
111272
111361
|
timeoutMs,
|
|
111273
111362
|
"Execution lease preflight timed out"
|
|
111274
111363
|
).catch(() => false).finally(() => preflight.abort());
|
|
111275
111364
|
if (!eligible || workPreflight.begin && import_node_perf_hooks.performance.now() >= reservationDeadline) {
|
|
111276
|
-
throw new
|
|
111365
|
+
throw new WorkPreflightUnavailableError(Boolean(workPreflight.begin));
|
|
111277
111366
|
}
|
|
111278
111367
|
workPreflight.onReserved?.();
|
|
111279
111368
|
overallMs = workPreflight.remainingBudgetMs();
|
|
@@ -111598,7 +111687,7 @@ async function driveRun(deps, projectSlug, runId, shutdown) {
|
|
|
111598
111687
|
shutdown
|
|
111599
111688
|
);
|
|
111600
111689
|
} finally {
|
|
111601
|
-
if (supervision) await closeDrainSupervision(runDeps, supervisor, supervision, projectSlug, runId);
|
|
111690
|
+
if (supervision && supervisor) await closeDrainSupervision(runDeps, supervisor, supervision, projectSlug, runId);
|
|
111602
111691
|
}
|
|
111603
111692
|
}
|
|
111604
111693
|
async function driveLeasedRun(deps, projectSlug, runId, claimed, leaseId, claimStartedMonotonicMs, elapsed, releaseUnstartedClaim, shutdown) {
|
|
@@ -112751,7 +112840,9 @@ ${coldClosureInstruction}` : workInstruction;
|
|
|
112751
112840
|
begin: async (preflightSignal, checkDeadline) => {
|
|
112752
112841
|
checkDeadline();
|
|
112753
112842
|
const supervised = deps.attemptSupervision;
|
|
112754
|
-
|
|
112843
|
+
const beginV3 = deps.client.beginColdWorkV3?.bind(deps.client);
|
|
112844
|
+
const beginV2 = deps.client.beginColdWorkV2?.bind(deps.client);
|
|
112845
|
+
if (supervised ? !beginV3 : !beginV2) return false;
|
|
112755
112846
|
let pin = null;
|
|
112756
112847
|
if (worktreePath) {
|
|
112757
112848
|
const worktreeRoot = deps.worktreeRoot ?? "/tmp/mrrlin-worktrees";
|
|
@@ -112769,21 +112860,13 @@ ${coldClosureInstruction}` : workInstruction;
|
|
|
112769
112860
|
}
|
|
112770
112861
|
checkDeadline();
|
|
112771
112862
|
coldReservation.outcome = "unknown";
|
|
112772
|
-
const applied = supervised ? await
|
|
112863
|
+
const applied = supervised && beginV3 ? await beginV3(projectSlug, runId, {
|
|
112773
112864
|
taskId: task.id,
|
|
112774
112865
|
leaseId,
|
|
112775
112866
|
threadId,
|
|
112776
112867
|
expectedWorktreeId: worktreePath,
|
|
112777
112868
|
supervisionId: supervised.supervisionId
|
|
112778
|
-
}, { signal: preflightSignal }) : await
|
|
112779
|
-
projectSlug,
|
|
112780
|
-
task.id,
|
|
112781
|
-
runId,
|
|
112782
|
-
leaseId,
|
|
112783
|
-
threadId,
|
|
112784
|
-
worktreePath,
|
|
112785
|
-
{ signal: preflightSignal }
|
|
112786
|
-
);
|
|
112869
|
+
}, { signal: preflightSignal }) : !supervised && beginV2 ? await beginV2(projectSlug, task.id, runId, leaseId, threadId, worktreePath, { signal: preflightSignal }) : false;
|
|
112787
112870
|
preflightSignal.throwIfAborted();
|
|
112788
112871
|
if (applied === false) {
|
|
112789
112872
|
coldReservation.outcome = "refused";
|
|
@@ -113270,6 +113353,11 @@ ${coldClosureInstruction}` : workInstruction;
|
|
|
113270
113353
|
});
|
|
113271
113354
|
}
|
|
113272
113355
|
} catch (error51) {
|
|
113356
|
+
if (error51 instanceof WorkPreflightUnavailableError && !error51.reservationAttempted) {
|
|
113357
|
+
skipRunWrites = true;
|
|
113358
|
+
await releaseUnconfirmedClaim(deps, projectSlug, runId, leaseId);
|
|
113359
|
+
return;
|
|
113360
|
+
}
|
|
113273
113361
|
if (error51 instanceof WorkLeaseUnavailableError) {
|
|
113274
113362
|
skipRunWrites = true;
|
|
113275
113363
|
if (coldReservation.outcome === "unknown") {
|
|
@@ -114691,6 +114779,12 @@ async function notifyOperatorHandoff(deps, projectSlug, task, runId, reason) {
|
|
|
114691
114779
|
} catch {
|
|
114692
114780
|
}
|
|
114693
114781
|
}
|
|
114782
|
+
function isHeldStaleRun(run4, staleSeconds, now = Date.now()) {
|
|
114783
|
+
if (run4.status !== "running") return false;
|
|
114784
|
+
const updatedAtMs = run4.updatedAt ? Date.parse(run4.updatedAt) : Number.NaN;
|
|
114785
|
+
if (!Number.isFinite(updatedAtMs) || updatedAtMs >= now - staleSeconds * 1e3) return false;
|
|
114786
|
+
return Boolean(run4.worktreeId) || run4.codeExecution !== false;
|
|
114787
|
+
}
|
|
114694
114788
|
async function runBackstopSweep(deps, drive = (slug, id) => driveRun(deps, slug, id)) {
|
|
114695
114789
|
const projects = await deps.client.listProjects();
|
|
114696
114790
|
for (const project of projects) {
|
|
@@ -114709,7 +114803,16 @@ async function runBackstopSweep(deps, drive = (slug, id) => driveRun(deps, slug,
|
|
|
114709
114803
|
);
|
|
114710
114804
|
continue;
|
|
114711
114805
|
}
|
|
114712
|
-
await deps.client.requeueExecutionRun(slug, run4.id, deps.staleSeconds).catch(() => null);
|
|
114806
|
+
const requeued = await deps.client.requeueExecutionRun(slug, run4.id, deps.staleSeconds).catch(() => null);
|
|
114807
|
+
if (!requeued && isHeldStaleRun(run4, deps.staleSeconds)) {
|
|
114808
|
+
await deps.client.createInboxItem(slug, {
|
|
114809
|
+
id: `II-${run4.id}-held`,
|
|
114810
|
+
kind: "handoff",
|
|
114811
|
+
taskId: run4.taskId,
|
|
114812
|
+
body: `Execution run ${run4.id} has made no progress for over ${Math.round(deps.staleSeconds / 60)} minutes and is held, not restarted automatically, because its worktree may contain work. Inspect the worktree, then restart or stop the run.`
|
|
114813
|
+
}).catch(() => {
|
|
114814
|
+
});
|
|
114815
|
+
}
|
|
114713
114816
|
}
|
|
114714
114817
|
const stoppedRuns = await deps.client.listExecutionRuns(slug, { status: "handoff_requested" }).catch(() => []);
|
|
114715
114818
|
for (const run4 of stoppedRuns) {
|
|
@@ -123740,13 +123843,22 @@ async function runOrphanWorktreeSweep(client, opts) {
|
|
|
123740
123843
|
const slug = project.slug;
|
|
123741
123844
|
const checkout = opts.checkoutRegistry.get(slug);
|
|
123742
123845
|
if (!checkout) continue;
|
|
123846
|
+
let keep;
|
|
123847
|
+
try {
|
|
123848
|
+
const statuses = mrrlinExecutionRunStatusSchema.options.filter(
|
|
123849
|
+
(status) => !FINISHED_RUN_STATUSES.includes(status)
|
|
123850
|
+
);
|
|
123851
|
+
keep = unfinishedRunWorktrees(await client.listExecutionRuns(slug, { statusIn: statuses }));
|
|
123852
|
+
} catch {
|
|
123853
|
+
continue;
|
|
123854
|
+
}
|
|
123743
123855
|
try {
|
|
123744
123856
|
const reaped = await sweepOrphanWorktrees({
|
|
123745
123857
|
checkout: checkout.path,
|
|
123746
123858
|
worktreeRoot: opts.worktreeRoot,
|
|
123747
123859
|
locksDir: opts.locksDir,
|
|
123748
123860
|
slug,
|
|
123749
|
-
isReapable
|
|
123861
|
+
isReapable: (worktreePath) => !keep.has(import_node_path54.default.resolve(worktreePath)) && isReapable(worktreePath)
|
|
123750
123862
|
});
|
|
123751
123863
|
if (reaped.length > 0) {
|
|
123752
123864
|
process.stderr.write(
|