aglio-worker 0.115.0 → 0.115.3

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/agent.js +62 -15
  2. package/package.json +1 -1
package/agent.js CHANGED
@@ -72756,6 +72756,24 @@ async function pullOnce(client, image, platform2) {
72756
72756
  });
72757
72757
  await readPullStream(stream);
72758
72758
  }
72759
+ function abortable(work, signal) {
72760
+ if (!signal) return work;
72761
+ if (signal.aborted) return Promise.reject(new Error("Runner image pull cancelled"));
72762
+ return new Promise((resolve7, reject) => {
72763
+ const onAbort = () => reject(new Error("Runner image pull cancelled"));
72764
+ signal.addEventListener("abort", onAbort, { once: true });
72765
+ work.then(
72766
+ (value) => {
72767
+ signal.removeEventListener("abort", onAbort);
72768
+ resolve7(value);
72769
+ },
72770
+ (error63) => {
72771
+ signal.removeEventListener("abort", onAbort);
72772
+ reject(error63);
72773
+ }
72774
+ );
72775
+ });
72776
+ }
72759
72777
  async function pullDockerImage(client, image, options = {}) {
72760
72778
  if (!isRegistryImage(image)) {
72761
72779
  throw new Error(
@@ -72763,7 +72781,7 @@ async function pullDockerImage(client, image, options = {}) {
72763
72781
  );
72764
72782
  }
72765
72783
  const existing = inFlight.get(image);
72766
- if (existing) return existing;
72784
+ if (existing) return abortable(existing, options.signal);
72767
72785
  const pull = (async () => {
72768
72786
  try {
72769
72787
  await pullOnce(client, image);
@@ -72778,11 +72796,10 @@ async function pullDockerImage(client, image, options = {}) {
72778
72796
  }
72779
72797
  })();
72780
72798
  inFlight.set(image, pull);
72781
- try {
72782
- await pull;
72783
- } finally {
72784
- inFlight.delete(image);
72785
- }
72799
+ void pull.finally(() => {
72800
+ if (inFlight.get(image) === pull) inFlight.delete(image);
72801
+ }).catch(() => void 0);
72802
+ await abortable(pull, options.signal);
72786
72803
  }
72787
72804
  async function ensureDockerImage(input2) {
72788
72805
  try {
@@ -72797,8 +72814,12 @@ async function ensureDockerImage(input2) {
72797
72814
  }
72798
72815
  input2.log?.("runner image missing, pulling", { image: input2.image });
72799
72816
  try {
72800
- await pullDockerImage(input2.client, input2.image, { log: input2.log });
72817
+ await pullDockerImage(input2.client, input2.image, {
72818
+ log: input2.log,
72819
+ signal: input2.signal
72820
+ });
72801
72821
  } catch (error63) {
72822
+ if (input2.signal?.aborted) throw error63;
72802
72823
  const reason = error63 instanceof Error ? error63.message : String(error63);
72803
72824
  throw new Error(
72804
72825
  `Runner image ${input2.image} not found and could not be pulled: ${reason}. Check registry access or docker login, then retry: docker pull ${input2.image}`
@@ -72930,9 +72951,12 @@ var RUNNER_CACHE_ENTRIES = [
72930
72951
  { id: "composer", containerPath: "/root/.cache/composer", description: "Composer package cache" },
72931
72952
  { id: "maven", containerPath: "/root/.m2/repository", description: "Maven local repository" },
72932
72953
  { id: "gradle", containerPath: "/root/.gradle/caches", description: "Gradle dependency cache" },
72933
- // Only the .deb archive, not /var/lib/apt/lists: package lists are locked per
72934
- // directory, and two concurrent jobs sharing that lock would make one fail.
72935
- { id: "apt", containerPath: "/var/cache/apt/archives", description: "apt .deb download cache" }
72954
+ // Browser builds are directory-per-revision, so two jobs running different
72955
+ // Playwright versions on this host never write the same files.
72956
+ { id: "playwright", containerPath: "/root/.cache/ms-playwright", description: "Playwright browser builds" }
72957
+ // apt is not cached: its archive lock file sits inside the directory, so two
72958
+ // concurrent jobs sharing it fail with "Could not get lock", and a killed
72959
+ // job leaves the lock behind for the next one.
72936
72960
  ];
72937
72961
  var RUNNER_CACHE_VOLUME_PREFIX = "aglio-runner-cache-";
72938
72962
  function runnerCacheEnabled(env = process.env) {
@@ -73039,7 +73063,13 @@ function remoteDockerClient(socketPath) {
73039
73063
  }
73040
73064
  async function createDockerJobExecutor(input2) {
73041
73065
  const client = input2.client ?? remoteDockerClient(input2.socketPath ?? "/var/run/docker.sock");
73042
- await ensureDockerImage({ client, image: input2.image, log: input2.log });
73066
+ await ensureDockerImage({
73067
+ client,
73068
+ image: input2.image,
73069
+ signal: input2.signal,
73070
+ log: input2.log
73071
+ });
73072
+ if (input2.signal?.aborted) throw new Error("Job cancelled before the runner container started");
73043
73073
  const { hostPath } = mapDockerWorkspace({
73044
73074
  workspaceRoot: input2.workspaceRoot,
73045
73075
  hostWorkspaceRoot: input2.hostWorkspaceRoot,
@@ -73883,8 +73913,12 @@ async function executeRemoteJob(job, deps) {
73883
73913
  const leaseAbort = new AbortController();
73884
73914
  const leaseTimer = setInterval(
73885
73915
  () => {
73916
+ if (cancelRequested || leaseLost) {
73917
+ clearInterval(leaseTimer);
73918
+ return;
73919
+ }
73886
73920
  void deps.api.heartbeatLease({ jobId: job.id, leaseId: job.lease.id, token: job.lease.token }).then((result) => {
73887
- if (result && result.cancelled) {
73921
+ if (result && result.cancelled && !cancelRequested) {
73888
73922
  cancelRequested = true;
73889
73923
  leaseAbort.abort();
73890
73924
  log("cancel requested", { jobId: job.id });
@@ -73932,7 +73966,7 @@ ${job.instructions.trim()}
73932
73966
  }
73933
73967
  if (deps.createExecutor) {
73934
73968
  try {
73935
- executor = await deps.createExecutor({ job, workspace });
73969
+ executor = await deps.createExecutor({ job, workspace, signal: leaseAbort.signal });
73936
73970
  } catch (error63) {
73937
73971
  write(`[aglio] executor failed: ${errorText(error63)}
73938
73972
  `);
@@ -74006,6 +74040,10 @@ $ ${step.command}
74006
74040
  if (error63 instanceof JobLeaseLostError || leaseLost) {
74007
74041
  throw new JobLeaseLostError(errorText(error63));
74008
74042
  }
74043
+ if (cancelRequested) {
74044
+ await finish(deps, job, "cancelled", "Cancelled from the board").catch(() => void 0);
74045
+ return "cancelled";
74046
+ }
74009
74047
  if (error63 instanceof JobAbortedError || deps.signal?.aborted) throw new JobAbortedError();
74010
74048
  await finish(deps, job, "failed", errorText(error63)).catch(() => void 0);
74011
74049
  return "failed";
@@ -74240,7 +74278,7 @@ function buildDriverCommand(input2) {
74240
74278
  if (input2.tools && input2.tools.length > 0) args.push("--tools", input2.tools.join(","));
74241
74279
  if (input2.systemPromptAppend) args.push("--append-system-prompt", input2.systemPromptAppend);
74242
74280
  if (input2.resume && input2.sessionId) {
74243
- args.push("--session", input2.sessionId);
74281
+ args.push("--fork", input2.sessionId);
74244
74282
  } else if (input2.sessionId) {
74245
74283
  args.push("--session-id", input2.sessionId);
74246
74284
  }
@@ -87859,6 +87897,14 @@ async function runRemoteCardJob(deps) {
87859
87897
  usage: usagePatch
87860
87898
  });
87861
87899
  }
87900
+ if ((isChat || isConsult) && !error63 && !assistantTextSeen && !finalMessage) {
87901
+ return complete({
87902
+ error: stderr.trim().slice(-2e3) || "Agent exited without a reply",
87903
+ sessionId,
87904
+ finalMessage,
87905
+ usage: usagePatch
87906
+ });
87907
+ }
87862
87908
  return complete({ error: null, sessionId, finalMessage, usage: usagePatch });
87863
87909
  }
87864
87910
  }
@@ -101963,11 +102009,12 @@ async function main() {
101963
102009
  signal: controller.signal,
101964
102010
  mcpHost: mcpHost ?? void 0,
101965
102011
  runRoot: (workspace) => mode === "docker" ? "/workspace" : workspace,
101966
- createExecutor: mode === "docker" ? ({ job, workspace }) => createDockerJobExecutor({
102012
+ createExecutor: mode === "docker" ? ({ job, workspace, signal }) => createDockerJobExecutor({
101967
102013
  jobId: job.id,
101968
102014
  workspace,
101969
102015
  workspaceRoot,
101970
102016
  hostWorkspaceRoot,
102017
+ signal,
101971
102018
  image: job.runnerImage ?? resolveRunnerImage({
101972
102019
  requiredLabels: job.requiredLabels,
101973
102020
  images: runnerImages,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aglio-worker",
3
- "version": "0.115.0",
3
+ "version": "0.115.3",
4
4
  "description": "Host machine agent for Aglio: claims jobs over the API and starts aglio-runner containers.",
5
5
  "type": "module",
6
6
  "bin": {