@agimon-ai/doompi-core 0.0.1-alpha.100 → 0.0.1-alpha.102

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.
@@ -989,6 +989,14 @@ async function createDirectHarnessRuntime(options) {
989
989
  return await operation();
990
990
  } finally {
991
991
  externalOperationActive = false;
992
+ if (drainRequested && !disposed) {
993
+ drainRequested = false;
994
+ drainAutomatic().catch((error) => emitFrame({
995
+ type: FRAME_ERROR,
996
+ code: "queue_drain",
997
+ error: require_harnessErrorMessage.harnessErrorMessage(error)
998
+ }));
999
+ }
992
1000
  }
993
1001
  };
994
1002
  let admissionLine = Promise.resolve();
@@ -1007,12 +1015,13 @@ async function createDirectHarnessRuntime(options) {
1007
1015
  };
1008
1016
  let drainingAutomatic = false;
1009
1017
  let drainRequested = false;
1010
- const drive = async (operationId) => {
1018
+ const drive = async (operationId, pollDeferred = false) => {
1011
1019
  settlingOperationId = operationId;
1012
1020
  let failure;
1013
1021
  try {
1014
1022
  const result = await writable(() => lane.drive({
1015
1023
  operationId,
1024
+ pollDeferred,
1016
1025
  waitForRetry: true
1017
1026
  }, context));
1018
1027
  if (!result.ok) resultError(result);
@@ -1056,14 +1065,22 @@ async function createDirectHarnessRuntime(options) {
1056
1065
  return;
1057
1066
  }
1058
1067
  drainingAutomatic = true;
1068
+ let releaseAutomatic;
1059
1069
  try {
1060
1070
  while (!disposed) {
1071
+ releaseAutomatic?.();
1072
+ releaseAutomatic = void 0;
1061
1073
  if ((await lane.inspectExecution(context)).current !== null) return;
1062
1074
  const operationId = (0, node_crypto.randomUUID)();
1063
1075
  const claimed = await changeRecord((record) => {
1064
1076
  if (record.paused || record.abortOperationId !== void 0) return { result: void 0 };
1065
1077
  const item = record.queue.find((candidate) => candidate.disposition === "pending" && candidate.scheduling === "automatic" && candidate.delivery !== "steer");
1066
1078
  if (!item) return { result: void 0 };
1079
+ if (externalOperationActive) {
1080
+ drainRequested = true;
1081
+ return { result: void 0 };
1082
+ }
1083
+ releaseAutomatic = acquireAgentOperation();
1067
1084
  return {
1068
1085
  record: {
1069
1086
  ...record,
@@ -1145,8 +1162,9 @@ async function createDirectHarnessRuntime(options) {
1145
1162
  }
1146
1163
  }
1147
1164
  } finally {
1165
+ releaseAutomatic?.();
1148
1166
  drainingAutomatic = false;
1149
- if (drainRequested && !disposed) {
1167
+ if (drainRequested && !externalOperationActive && !disposed) {
1150
1168
  drainRequested = false;
1151
1169
  drainAutomatic().catch((error) => emitFrame({
1152
1170
  type: FRAME_ERROR,
@@ -1747,21 +1765,46 @@ async function createDirectHarnessRuntime(options) {
1747
1765
  await reconcileNativeQueue();
1748
1766
  await publishLifecycle();
1749
1767
  };
1750
- const resume = () => runAgentOperation(async () => {
1751
- await recover();
1752
- if ((await readRecord()).paused) return false;
1753
- const result = await writable(() => lane.resume(context));
1754
- if (!result.ok && result.error._tag === "NothingToResume") {
1755
- drainAutomatic().catch((error) => emitFrame({
1756
- type: FRAME_ERROR,
1757
- code: "queue_drain",
1758
- error: require_harnessErrorMessage.harnessErrorMessage(error)
1759
- }));
1760
- return false;
1768
+ const admitResume = async () => {
1769
+ const release = acquireAgentOperation();
1770
+ try {
1771
+ await recover();
1772
+ const submission = await serializeAdmission(async () => {
1773
+ guardWritable();
1774
+ if ((await readRecord()).paused) return {
1775
+ resumed: false,
1776
+ settled: Promise.resolve()
1777
+ };
1778
+ const execution = await lane.inspectExecution(context);
1779
+ if (execution.current === null) return {
1780
+ resumed: false,
1781
+ settled: Promise.resolve()
1782
+ };
1783
+ return {
1784
+ resumed: true,
1785
+ settled: drive(execution.current.id, true)
1786
+ };
1787
+ });
1788
+ if (submission.resumed) submission.settled.then(release, release);
1789
+ else {
1790
+ release();
1791
+ drainAutomatic().catch((error) => emitFrame({
1792
+ type: FRAME_ERROR,
1793
+ code: "queue_drain",
1794
+ error: require_harnessErrorMessage.harnessErrorMessage(error)
1795
+ }));
1796
+ }
1797
+ return submission;
1798
+ } catch (error) {
1799
+ release();
1800
+ throw error;
1761
1801
  }
1762
- if (!result.ok) resultError(result);
1763
- return true;
1764
- });
1802
+ };
1803
+ const resume = async () => {
1804
+ const submission = await admitResume();
1805
+ await submission.settled;
1806
+ return submission.resumed;
1807
+ };
1765
1808
  const readState = async () => {
1766
1809
  const [lifecycle, retained, persisted, stats, thinking] = await Promise.all([
1767
1810
  readLifecycle(),
@@ -1951,6 +1994,7 @@ async function createDirectHarnessRuntime(options) {
1951
1994
  abort,
1952
1995
  interrupt,
1953
1996
  compact,
1997
+ admitResume,
1954
1998
  resume,
1955
1999
  dispose
1956
2000
  };