@mrrlin-dev/mcp 0.4.225 → 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.
Files changed (2) hide show
  1. package/dist/bin.cjs +129 -25
  2. package/package.json +1 -1
package/dist/bin.cjs CHANGED
@@ -94618,6 +94618,15 @@ function stripHumanizeOpener(body) {
94618
94618
  }
94619
94619
  return body;
94620
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
+ }
94621
94630
  var DID_NOT_CONVERGE_ERROR = "Consensus blocked: reviewers did not converge within budget.";
94622
94631
  async function handleConsensusBlocked(result, ctx, input, resolvedTaskId) {
94623
94632
  const operatorClarifications = result.operatorClarifications ?? [];
@@ -94731,6 +94740,7 @@ async function handleConsensusBlocked(result, ctx, input, resolvedTaskId) {
94731
94740
  }
94732
94741
  const confirmedQuestionIds = /* @__PURE__ */ new Set();
94733
94742
  let clarificationDeliveryIncomplete = false;
94743
+ let inboxDeliveryUnconfirmed = false;
94734
94744
  const scopeId = taskId ?? planId;
94735
94745
  if (toFile.length > 0 && scopeId) {
94736
94746
  const clarificationKey = taskId ? result.evaluatedClarificationKey : void 0;
@@ -94755,14 +94765,12 @@ async function handleConsensusBlocked(result, ctx, input, resolvedTaskId) {
94755
94765
  };
94756
94766
  const uncertain = [];
94757
94767
  for (const question of questions) {
94758
- let item;
94759
- try {
94760
- item = await ctx.client.createInboxItem(input.projectSlug, question);
94761
- } catch {
94768
+ const created = await createInboxItemWithResend(ctx, input.projectSlug, question);
94769
+ if (created === null) {
94762
94770
  uncertain.push(question);
94763
94771
  continue;
94764
94772
  }
94765
- if (matchesQuestion(item, question)) confirmedQuestionIds.add(item.id);
94773
+ if (matchesQuestion(created.item, question)) confirmedQuestionIds.add(created.item.id);
94766
94774
  else clarificationDeliveryIncomplete = true;
94767
94775
  }
94768
94776
  if (uncertain.length > 0) {
@@ -94775,14 +94783,14 @@ async function handleConsensusBlocked(result, ctx, input, resolvedTaskId) {
94775
94783
  for (const question of uncertain) {
94776
94784
  const item = pending.find((candidate) => matchesQuestion(candidate, question));
94777
94785
  if (item) confirmedQuestionIds.add(item.id);
94778
- else clarificationDeliveryIncomplete = true;
94786
+ else inboxDeliveryUnconfirmed = true;
94779
94787
  }
94780
94788
  }
94781
94789
  }
94782
94790
  const filedQuestionCount = confirmedQuestionIds.size;
94783
94791
  const existingQuestionCount = result.pendingReviewQuestionIds?.length ?? 0;
94784
94792
  let gateBlockQuestionAvailable;
94785
- if (!clarificationDeliveryIncomplete && filedQuestionCount === 0 && existingQuestionCount === 0 && diagnostics.length === 0 && taskId && page) {
94793
+ if (!clarificationDeliveryIncomplete && !inboxDeliveryUnconfirmed && filedQuestionCount === 0 && existingQuestionCount === 0 && diagnostics.length === 0 && taskId && page) {
94786
94794
  const domain2 = await resolveSpecDomain(ctx.client, input.projectSlug, {
94787
94795
  id: page.id,
94788
94796
  taskId: page.taskId ?? null
@@ -94799,25 +94807,35 @@ async function handleConsensusBlocked(result, ctx, input, resolvedTaskId) {
94799
94807
  const storedOptions = item.questionOptions;
94800
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));
94801
94809
  };
94802
- try {
94803
- const item = await ctx.client.createInboxItem(input.projectSlug, {
94804
- id: blockItemId,
94805
- kind: "question",
94806
- taskId,
94807
- body,
94808
- origin: "gate_block",
94809
- questionOptions
94810
- });
94811
- gateBlockQuestionAvailable = matchesPendingQuestion(item);
94812
- } catch {
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 {
94813
94821
  const pending = await ctx.client.listInboxItems(input.projectSlug, {
94814
94822
  taskId,
94815
94823
  kind: "question",
94816
94824
  status: "pending"
94817
94825
  }).catch(() => []);
94818
- gateBlockQuestionAvailable = pending.some(matchesPendingQuestion);
94826
+ if (pending.some(matchesPendingQuestion)) gateBlockQuestionAvailable = true;
94827
+ else inboxDeliveryUnconfirmed = true;
94819
94828
  }
94820
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
+ }
94821
94839
  let error51;
94822
94840
  if (clarificationDeliveryIncomplete) {
94823
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.`;
@@ -98632,6 +98650,15 @@ async function doPushRunBranch(opts, execGit) {
98632
98650
  }
98633
98651
  return { pushedSha: localSha };
98634
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
+ }
98635
98662
  async function sweepOrphanWorktrees(opts, runGit2 = git2) {
98636
98663
  const reaped = [];
98637
98664
  const hooksDir = prepareDisabledGitHooksDir(opts.locksDir, `sweep:${opts.slug}`);
@@ -105492,7 +105519,7 @@ Do NOT derail the current task - if the operator has an in-flight question, answ
105492
105519
  }
105493
105520
 
105494
105521
  // src/_generated/version.ts
105495
- var PKG_VERSION = "0.4.225";
105522
+ var PKG_VERSION = "0.4.227";
105496
105523
 
105497
105524
  // src/bridge-allowed-origins.ts
105498
105525
  var DEFAULT_DIRECTOR_BRIDGE_ALLOWED_ORIGINS = [
@@ -111189,6 +111216,48 @@ async function runHasLease(deps, projectSlug, runId, leaseId) {
111189
111216
  return false;
111190
111217
  }
111191
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
+ }
111192
111261
  var MIXED_CODE_APPROVAL_POLL_MS = 2e3;
111193
111262
  var MIXED_CODE_APPROVAL_REQUEST_MS = 3e3;
111194
111263
  var ReservedLocalDeliveryFailure = class extends Error {
@@ -111233,6 +111302,12 @@ async function readApprovedMixedCodeSpec(client, projectSlug, runId, runApproval
111233
111302
  }
111234
111303
  var WorkLeaseUnavailableError = class extends Error {
111235
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
+ };
111236
111311
  async function driveTurn(deps, codex, projectSlug, runId, leaseId, threadId, inputText, overallMs, phase, effort, guard, workPreflight, dispatchBudgetMs) {
111237
111312
  let turnError = null;
111238
111313
  let interruptFailed = false;
@@ -111278,16 +111353,16 @@ async function driveTurn(deps, codex, projectSlug, runId, leaseId, threadId, inp
111278
111353
  const checkDeadline = () => {
111279
111354
  preflightSignal.throwIfAborted();
111280
111355
  if (Date.now() >= deadlineAt || import_node_perf_hooks.performance.now() >= reservationDeadline || workPreflight.remainingBudgetMs() <= 0) {
111281
- throw new WorkLeaseUnavailableError();
111356
+ throw new WorkPreflightUnavailableError(Boolean(workPreflight.begin));
111282
111357
  }
111283
111358
  };
111284
111359
  const eligible = await withTimeout2(
111285
- workPreflight.begin ? workPreflight.begin(preflightSignal, checkDeadline) : runHasLease(deps, projectSlug, runId, leaseId),
111360
+ workPreflight.begin ? workPreflight.begin(preflightSignal, checkDeadline) : confirmLeaseWithRetry(deps, projectSlug, runId, leaseId, preflightSignal),
111286
111361
  timeoutMs,
111287
111362
  "Execution lease preflight timed out"
111288
111363
  ).catch(() => false).finally(() => preflight.abort());
111289
111364
  if (!eligible || workPreflight.begin && import_node_perf_hooks.performance.now() >= reservationDeadline) {
111290
- throw new WorkLeaseUnavailableError();
111365
+ throw new WorkPreflightUnavailableError(Boolean(workPreflight.begin));
111291
111366
  }
111292
111367
  workPreflight.onReserved?.();
111293
111368
  overallMs = workPreflight.remainingBudgetMs();
@@ -113278,6 +113353,11 @@ ${coldClosureInstruction}` : workInstruction;
113278
113353
  });
113279
113354
  }
113280
113355
  } catch (error51) {
113356
+ if (error51 instanceof WorkPreflightUnavailableError && !error51.reservationAttempted) {
113357
+ skipRunWrites = true;
113358
+ await releaseUnconfirmedClaim(deps, projectSlug, runId, leaseId);
113359
+ return;
113360
+ }
113281
113361
  if (error51 instanceof WorkLeaseUnavailableError) {
113282
113362
  skipRunWrites = true;
113283
113363
  if (coldReservation.outcome === "unknown") {
@@ -114699,6 +114779,12 @@ async function notifyOperatorHandoff(deps, projectSlug, task, runId, reason) {
114699
114779
  } catch {
114700
114780
  }
114701
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
+ }
114702
114788
  async function runBackstopSweep(deps, drive = (slug, id) => driveRun(deps, slug, id)) {
114703
114789
  const projects = await deps.client.listProjects();
114704
114790
  for (const project of projects) {
@@ -114717,7 +114803,16 @@ async function runBackstopSweep(deps, drive = (slug, id) => driveRun(deps, slug,
114717
114803
  );
114718
114804
  continue;
114719
114805
  }
114720
- 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
+ }
114721
114816
  }
114722
114817
  const stoppedRuns = await deps.client.listExecutionRuns(slug, { status: "handoff_requested" }).catch(() => []);
114723
114818
  for (const run4 of stoppedRuns) {
@@ -123748,13 +123843,22 @@ async function runOrphanWorktreeSweep(client, opts) {
123748
123843
  const slug = project.slug;
123749
123844
  const checkout = opts.checkoutRegistry.get(slug);
123750
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
+ }
123751
123855
  try {
123752
123856
  const reaped = await sweepOrphanWorktrees({
123753
123857
  checkout: checkout.path,
123754
123858
  worktreeRoot: opts.worktreeRoot,
123755
123859
  locksDir: opts.locksDir,
123756
123860
  slug,
123757
- isReapable
123861
+ isReapable: (worktreePath) => !keep.has(import_node_path54.default.resolve(worktreePath)) && isReapable(worktreePath)
123758
123862
  });
123759
123863
  if (reaped.length > 0) {
123760
123864
  process.stderr.write(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrrlin-dev/mcp",
3
- "version": "0.4.225",
3
+ "version": "0.4.227",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "mrrlin-mcp": "dist/bin.cjs"