@elpapi42/pi-fleet 0.1.0-beta.5 → 0.1.0-beta.8

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.
@@ -2,24 +2,24 @@
2
2
  "schemaVersion": 3,
3
3
  "package": {
4
4
  "name": "@elpapi42/pi-fleet",
5
- "version": "0.1.0-beta.5"
5
+ "version": "0.1.0-beta.8"
6
6
  },
7
7
  "managedPi": "@earendil-works/pi-coding-agent@0.80.10",
8
8
  "files": [
9
9
  {
10
10
  "path": "dist/cli-meta.json",
11
11
  "bytes": 21248,
12
- "sha256": "e4ed20fc94195e21b0da78bb789d54a74913fe9db6ea7b8041a201873447f957"
12
+ "sha256": "5847ef7406dd0e1186b7c1395cf6afa8f30cd8a43bdcb36caeb780edee9969d7"
13
13
  },
14
14
  {
15
15
  "path": "dist/cli.mjs",
16
- "bytes": 150369,
17
- "sha256": "4ed384c54fa9b6bc4c9b80fcde2e9c0106ef902a0518baeb71565566fe0501dc"
16
+ "bytes": 150476,
17
+ "sha256": "0553362dc5d95b35035ef98aa6dffffaa0bcf1d3dba8e9e1d64629befb7fedb0"
18
18
  },
19
19
  {
20
20
  "path": "dist/cli.mjs.map",
21
- "bytes": 270001,
22
- "sha256": "449c833189699a96d06ece97e9e3ba06cce92c0483dc3f1dce2f7dd1e1fdf5ab"
21
+ "bytes": 270235,
22
+ "sha256": "b1a0e49b475f8a10b88dcd94ee3c5e53fdc3c959026c48685e8d1639d3104c5c"
23
23
  },
24
24
  {
25
25
  "path": "dist/installer-meta.json",
@@ -39,17 +39,17 @@
39
39
  {
40
40
  "path": "dist/runtime-meta.json",
41
41
  "bytes": 241246,
42
- "sha256": "2ab87b9b582fa0d7469f038bbddb014fe2f05dfe53bdc99154f4d01dbd683ebc"
42
+ "sha256": "c032364ccea9b67eb133199beabc76f81a3cc8b74e074f8c3e6861166f4e6266"
43
43
  },
44
44
  {
45
45
  "path": "dist/runtime.mjs",
46
- "bytes": 320605,
47
- "sha256": "2628c307f631e1ac30ff580252252c20fc517e716c875f5332f9140d72159d2b"
46
+ "bytes": 322583,
47
+ "sha256": "de25fd4f02af9a886f350626da70ac872e211b011e5583a32972e8a937023f20"
48
48
  },
49
49
  {
50
50
  "path": "dist/runtime.mjs.map",
51
- "bytes": 700561,
52
- "sha256": "c6f300c13c6c3b985e73c30ec4fc32926cdcaf444d9e234954e9623d2862a3ce"
51
+ "bytes": 703760,
52
+ "sha256": "ab625292928298bad35333d62178a40a9a91ca4d3309cf39957a610239d42297"
53
53
  },
54
54
  {
55
55
  "path": "dist/sqlite-worker-meta.json",
@@ -79,7 +79,7 @@
79
79
  {
80
80
  "path": "package.json",
81
81
  "bytes": 2375,
82
- "sha256": "103d0802e5d1df06d193a9f7d0da60303ae0c24ca23c915b0947140af1c7d29c"
82
+ "sha256": "a1cbfc1347c7d28ecf289fb3f4e77e7bd6b5b477d397b6cf7b1890be0c69f1fd"
83
83
  }
84
84
  ],
85
85
  "dependencies": [
@@ -6272,7 +6272,7 @@
6272
6272
  "format": "esm"
6273
6273
  },
6274
6274
  "src/runtime/fleet-service.ts": {
6275
- "bytes": 34926,
6275
+ "bytes": 36962,
6276
6276
  "imports": [
6277
6277
  {
6278
6278
  "path": "node:crypto",
@@ -6385,7 +6385,7 @@
6385
6385
  "imports": [],
6386
6386
  "exports": [],
6387
6387
  "inputs": {},
6388
- "bytes": 700561
6388
+ "bytes": 703760
6389
6389
  },
6390
6390
  "dist/runtime.mjs": {
6391
6391
  "imports": [
@@ -6950,7 +6950,7 @@
6950
6950
  "bytesInOutput": 108
6951
6951
  },
6952
6952
  "src/runtime/fleet-service.ts": {
6953
- "bytesInOutput": 29982
6953
+ "bytesInOutput": 31960
6954
6954
  },
6955
6955
  "src/pi/session-selector.ts": {
6956
6956
  "bytesInOutput": 2113
@@ -6968,7 +6968,7 @@
6968
6968
  "bytesInOutput": 3543
6969
6969
  }
6970
6970
  },
6971
- "bytes": 320605
6971
+ "bytes": 322583
6972
6972
  }
6973
6973
  }
6974
6974
  }
package/dist/runtime.mjs CHANGED
@@ -7709,6 +7709,13 @@ var FleetService = class {
7709
7709
  throw error;
7710
7710
  }
7711
7711
  if (agent === null) return this.#notFound(input.name);
7712
+ if (agent.summary.state === "failed") {
7713
+ const code = agent.summary.error?.code ?? "agent_failed";
7714
+ return err({
7715
+ code,
7716
+ message: `Agent ${input.name} is failed (${code}) and has no current successful response.`
7717
+ });
7718
+ }
7712
7719
  if (agent.latestAssistantText === null || agent.responseObservedAt === null) {
7713
7720
  return err({
7714
7721
  code: "no_response",
@@ -7822,6 +7829,8 @@ var FleetService = class {
7822
7829
  async #dispatchSend(input, operationId, acceptedAt, initialAgent, ordinal) {
7823
7830
  let agent = initialAgent;
7824
7831
  let incarnationId = null;
7832
+ let startingProcess = null;
7833
+ let restoring = false;
7825
7834
  try {
7826
7835
  let coordinator = this.#coordinators.get(input.name);
7827
7836
  if (this.#launcher !== void 0 && coordinator === void 0) {
@@ -7846,6 +7855,7 @@ var FleetService = class {
7846
7855
  message: `Pi Fleet has reached its ${String(this.#limits.maxResidentProcesses)} process limit.`
7847
7856
  });
7848
7857
  } else {
7858
+ restoring = true;
7849
7859
  agent = await this.#markRestoring(agent);
7850
7860
  incarnationId = randomUUID2();
7851
7861
  await this.store.putIncarnation({
@@ -7854,7 +7864,7 @@ var FleetService = class {
7854
7864
  pid: null,
7855
7865
  state: "starting"
7856
7866
  });
7857
- const process2 = await this.#launcher.start(agent.launch, true, async (pid) => {
7867
+ startingProcess = await this.#launcher.start(agent.launch, true, async (pid) => {
7858
7868
  await this.store.putIncarnation({
7859
7869
  incarnationId,
7860
7870
  agentName: input.name,
@@ -7862,6 +7872,7 @@ var FleetService = class {
7862
7872
  state: "starting"
7863
7873
  });
7864
7874
  });
7875
+ const process2 = startingProcess;
7865
7876
  await this.store.putIncarnation({
7866
7877
  incarnationId,
7867
7878
  agentName: input.name,
@@ -7886,6 +7897,7 @@ var FleetService = class {
7886
7897
  };
7887
7898
  await this.store.putAgent(agent);
7888
7899
  coordinator = this.#attachCoordinator(agent, process2, incarnationId);
7900
+ restoring = false;
7889
7901
  }
7890
7902
  }
7891
7903
  await this.store.putSend({
@@ -7919,7 +7931,49 @@ var FleetService = class {
7919
7931
  agent: { id: agent.summary.id, name: agent.summary.name },
7920
7932
  acceptedAt
7921
7933
  });
7922
- } catch {
7934
+ } catch (error) {
7935
+ if (restoring && incarnationId !== null) {
7936
+ let cleanupUncertain = error instanceof PiCleanupUncertainError;
7937
+ let cleanupPid = error instanceof PiCleanupUncertainError ? error.pid : null;
7938
+ if (startingProcess !== null) {
7939
+ cleanupPid = startingProcess.pid;
7940
+ try {
7941
+ await startingProcess.stop();
7942
+ } catch {
7943
+ cleanupUncertain = true;
7944
+ }
7945
+ }
7946
+ const code = cleanupUncertain ? "incarnation_cleanup_uncertain" : "pi_start_failed";
7947
+ agent = {
7948
+ ...agent,
7949
+ summary: {
7950
+ ...agent.summary,
7951
+ state: "failed",
7952
+ process: { state: cleanupUncertain ? "cleanup_uncertain" : "absent" },
7953
+ error: { code }
7954
+ }
7955
+ };
7956
+ await this.store.putAgent(agent);
7957
+ await this.store.putIncarnation({
7958
+ incarnationId,
7959
+ agentName: input.name,
7960
+ pid: cleanupPid,
7961
+ state: cleanupUncertain ? "cleanup_uncertain" : "gone"
7962
+ });
7963
+ await this.store.putSend({
7964
+ sendId: operationId,
7965
+ agentName: input.name,
7966
+ ordinal,
7967
+ message: input.message,
7968
+ state: "failed",
7969
+ acceptedAt
7970
+ });
7971
+ if (!cleanupUncertain) this.#releaseProcessSlot(input.name);
7972
+ return err({
7973
+ code,
7974
+ message: cleanupUncertain ? `Fleet could not prove the failed Pi restoration for ${input.name} was removed.` : `Pi failed to restore for ${input.name}; the message was not dispatched.`
7975
+ });
7976
+ }
7923
7977
  if (!this.#coordinators.has(input.name)) this.#releaseProcessSlot(input.name);
7924
7978
  if (incarnationId !== null && !this.#coordinators.has(input.name)) {
7925
7979
  await this.store.putIncarnation({