@sjawhar/pi-envoy 15.1.0 → 15.1.1

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 (3) hide show
  1. package/README.md +7 -2
  2. package/dist/envoy.js +37 -18
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -313,7 +313,12 @@ reviews these calls:
313
313
  Every other Dispatch command is outside the gate, and its text posts unreviewed: among them
314
314
  `dispatch issue-update --reason`, `dispatch resolve-ask --reason` and `dispatch suggest`.
315
315
 
316
- The gate reads the arguments from the command's own `--dry-run`. An upload that reads its name
316
+ The gate reads the arguments from the command's own `--dry-run`. The dry run sends nothing and
317
+ contacts no Dispatch server, so a slow one most likely means a busy machine. The reads, the dry
318
+ run and the `cd`'s `pwd -P` probe, take at most half the call's deadline: the first run of each
319
+ is cut at 20 s, or sooner when that half ends sooner, and a run cut there is run once more with
320
+ what is left of that half (25 s at the 90 s default), when at least 2 s of it is left. The
321
+ review keeps the other half. An upload that reads its name
317
322
  from a file (`--name-file`) is decided from the name the dry run prints. `--path-file` is refused:
318
323
  its content names a file the gate does not read before Dispatch opens it. An upload whose name or
319
324
  path holds an expansion (`"$NAME"`) is outside the form the gate reads. The gate reads each file
@@ -558,7 +563,7 @@ why. The note reaches a headless session too:
558
563
  | Outcome | What happened |
559
564
  | --- | --- |
560
565
  | `timeout` | the review did not answer within its deadline |
561
- | `error` | the review failed: a model error, a handler exception, or a dry run that failed |
566
+ | `error` | the review failed: a model error, a handler exception, or a dry run that failed; a dry run that timed out twice, or once with no time left to run it again, gets a note that the machine was busy and that the agent should read back what the write posted |
562
567
  | `no-verdict` | the model answered with no verdict the gate could read |
563
568
  | `halted` | three calls in a row reached no verdict, and the gate is paused for the session |
564
569
  | `skipped` | the session's main model is on another provider than the gate's |
package/dist/envoy.js CHANGED
@@ -38160,7 +38160,7 @@ var import_nats2 = __toESM(require_mod4(), 1);
38160
38160
 
38161
38161
  // package.json
38162
38162
  var name = "@sjawhar/pi-envoy";
38163
- var version2 = "15.1.0";
38163
+ var version2 = "15.1.1";
38164
38164
  var package_default = {
38165
38165
  name,
38166
38166
  version: version2,
@@ -41327,7 +41327,9 @@ var INDIRECT_FLAGS = ["--name-file", "--path-file"];
41327
41327
  var NO_SEND_FLAGS = ["--dry-run", "--help"];
41328
41328
  var REBUTTAL_KEY = "advisor_rebuttal";
41329
41329
  var REBUTTAL_FLAG = "--advisor-rebuttal";
41330
- var DRY_RUN_TIMEOUT_MS = 1e4;
41330
+ var DRY_RUN_TIMEOUT_MS = 20000;
41331
+ var READ_SHARE = 0.5;
41332
+ var MIN_RETRY_MS = 2000;
41331
41333
  var GATE_TIMEOUT_MS = 90000;
41332
41334
  var CEILING_MARGIN_MS = 5000;
41333
41335
  var ABORT_GRACE_MS = 2000;
@@ -42415,6 +42417,9 @@ var renderUnreviewed = (outcome, reason) => {
42415
42417
  ${opening}${why}. The call ran unreviewed.
42416
42418
  </advisor-gate>`;
42417
42419
  };
42420
+ var renderSlowDryRun = (reason) => `<advisor-gate advisor="AskGate" outcome="error">
42421
+ AskGate did not review this Dispatch write: ${agentFacing(reason)}. A dry run only checks the arguments on this machine and contacts no Dispatch server, so the likely cause is a busy machine, not Dispatch. The call ran unreviewed: read back what it posted, and correct it if it is wrong.
42422
+ </advisor-gate>`;
42418
42423
  function resendFlags(flag) {
42419
42424
  if (flag === "--path" || flag === "--path-file")
42420
42425
  return { stdin: "--content-file", regular: "`--path` or `--content-file`" };
@@ -42697,14 +42702,12 @@ ${notice}
42697
42702
  rebuttals.delete(rebuttals.keys().next().value);
42698
42703
  return { input: { ...input, content } };
42699
42704
  };
42700
- const pass = (outcome, fields = {}, effect = "none") => {
42701
- const note = renderUnreviewed(outcome, fields.reason);
42702
- return {
42703
- fields: { decision: "allow", outcome, ...fields },
42704
- ...note === undefined ? {} : { result: { additionalContext: note } },
42705
- effect
42706
- };
42707
- };
42705
+ const pass = (outcome, fields = {}, effect = "none", note = renderUnreviewed(outcome, fields.reason)) => ({
42706
+ fields: { decision: "allow", outcome, ...fields },
42707
+ ...note === undefined ? {} : { result: { additionalContext: note } },
42708
+ effect
42709
+ });
42710
+ const callDeadlineMs = () => Math.min(timeoutMs, deps.handlerCeilingMs() - CEILING_MARGIN_MS);
42708
42711
  const givenUp = (mode, cause, fields = {}) => mode === "block" ? {
42709
42712
  fields: { decision: "revise", outcome: cause, ...fields },
42710
42713
  result: { block: true, reason: NO_VERDICT_REFUSAL[cause] },
@@ -42862,7 +42865,7 @@ ${user}
42862
42865
  const { role, model } = resolved;
42863
42866
  if (ctx.model?.provider !== model.provider)
42864
42867
  return pass("skipped", { reason: `primary on ${ctx.model?.provider ?? "no model"}` });
42865
- const deadlineMs = Math.min(timeoutMs, deps.handlerCeilingMs() - CEILING_MARGIN_MS);
42868
+ const deadlineMs = callDeadlineMs();
42866
42869
  stop.arm(Math.max(0, deadlineMs - (deps.now() - started)));
42867
42870
  const chain = [
42868
42871
  model,
@@ -42965,7 +42968,7 @@ ${user}
42965
42968
  return { kind: "error", reason: messageOf(error) };
42966
42969
  }
42967
42970
  };
42968
- const readArgs = async (scoped, input, ctx, stop) => {
42971
+ const readArgs = async (scoped, input, ctx, stop, readsEnd) => {
42969
42972
  const raw = typeof input.cwd === "string" && input.cwd !== "" ? input.cwd.replace(/^~(?=$|\/)/, deps.home) : undefined;
42970
42973
  const cwd = raw === undefined || /^\/+$/.test(raw) ? ctx.cwd : path4.resolve(ctx.cwd, raw);
42971
42974
  const { CDPATH: _cdpath, ...env } = deps.env;
@@ -42974,23 +42977,37 @@ ${user}
42974
42977
  throw new Error("the gate's deadline fired while its dry run was still reading");
42975
42978
  return stop.cause;
42976
42979
  };
42977
- const runScript = async (script) => {
42980
+ const runScript = async (script, limitMs) => {
42978
42981
  const run = await deps.dryRun(script, {
42979
42982
  cwd,
42980
42983
  env,
42981
- timeoutMs: DRY_RUN_TIMEOUT_MS,
42984
+ timeoutMs: limitMs,
42982
42985
  signal: stop.signal
42983
42986
  });
42984
42987
  const cause = abandoned();
42985
42988
  return cause === undefined ? { run } : { cause };
42986
42989
  };
42987
42990
  const stdoutOf = async (script, what) => {
42988
- const ran = await runScript(script);
42991
+ const firstMs = Math.max(0, Math.min(DRY_RUN_TIMEOUT_MS, readsEnd - deps.now()));
42992
+ let ran = await runScript(script, firstMs);
42989
42993
  if ("cause" in ran)
42990
42994
  return ran;
42995
+ let retryMs;
42996
+ if (ran.run.timedOut) {
42997
+ const leftMs = readsEnd - deps.now();
42998
+ if (leftMs >= MIN_RETRY_MS) {
42999
+ retryMs = leftMs;
43000
+ ran = await runScript(script, retryMs);
43001
+ if ("cause" in ran)
43002
+ return ran;
43003
+ }
43004
+ }
42991
43005
  const { run } = ran;
42992
43006
  if (run.timedOut)
42993
- return { failure: `${what} did not finish within ${DRY_RUN_TIMEOUT_MS} ms` };
43007
+ return {
43008
+ failure: `${what} did not finish within ${firstMs} ms, ${retryMs === undefined ? "and the call's deadline left no time to run it again" : `nor within ${retryMs} ms when run again`}`,
43009
+ slow: true
43010
+ };
42994
43011
  if (run.exitCode !== 0) {
42995
43012
  const printed = clipBytes((run.stdout || run.stderr).trim(), GATE_PRINTED_MAX_BYTES);
42996
43013
  return { failure: `${what} exited ${run.exitCode ?? "on a signal"}: ${printed}` };
@@ -43207,7 +43224,9 @@ ${user}
43207
43224
  else {
43208
43225
  const stop = openStop(event.toolCallId);
43209
43226
  try {
43210
- const run = await readArgs(scoped, event.input, ctx, stop);
43227
+ const deadlineMs = callDeadlineMs();
43228
+ const readsEnd = started + Math.floor(deadlineMs * READ_SHARE);
43229
+ const run = await readArgs(scoped, event.input, ctx, stop, readsEnd);
43211
43230
  if ("unscoped" in run)
43212
43231
  return revised === undefined ? undefined : { input: revised };
43213
43232
  if ("cause" in run)
@@ -43222,7 +43241,7 @@ ${user}
43222
43241
  else
43223
43242
  decision = unreadableCall(run.unreadable, checks);
43224
43243
  } else if ("failure" in run)
43225
- decision = pass("error", { reason: run.failure });
43244
+ decision = pass("error", { reason: run.failure, deadlineMs }, "none", run.slow ? renderSlowDryRun(run.failure) : undefined);
43226
43245
  else {
43227
43246
  dryRun = { args: run.args, files: run.files };
43228
43247
  const { key, label } = breakerKey(scoped.tool, run.review);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjawhar/pi-envoy",
3
- "version": "15.1.0",
3
+ "version": "15.1.1",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "omp": {