@tangle-network/agent-app 0.60.46 → 0.60.47
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.
|
@@ -1835,9 +1835,13 @@ function abortedToolCall(parts) {
|
|
|
1835
1835
|
}
|
|
1836
1836
|
return void 0;
|
|
1837
1837
|
}
|
|
1838
|
-
function
|
|
1838
|
+
function admittedWorkIsLive(status, runsByTurnId, admittedTurnIds, dispatchMayBePending) {
|
|
1839
1839
|
if (status.status !== "queued" && status.status !== "running") return false;
|
|
1840
|
-
|
|
1840
|
+
if (status.raw?.state === "stale") return false;
|
|
1841
|
+
return admittedTurnIds.some((turnId) => {
|
|
1842
|
+
const run = runsByTurnId.get(turnId);
|
|
1843
|
+
return run ? run.status === "active" : dispatchMayBePending;
|
|
1844
|
+
});
|
|
1841
1845
|
}
|
|
1842
1846
|
function missingTurnReceipt(turnId, error) {
|
|
1843
1847
|
return { turnId, state: "failed", text: "", parts: [], usage: {}, error };
|
|
@@ -1873,8 +1877,11 @@ async function observeNativeCompletion(options) {
|
|
|
1873
1877
|
]));
|
|
1874
1878
|
}
|
|
1875
1879
|
const exactSession = session;
|
|
1880
|
+
const dispatchMayBePending = now - options.registeredAt < (options.absentDispatchDeadlineMs ?? DEFAULT_ABSENT_DISPATCH_DEADLINE_MS);
|
|
1881
|
+
let runsByTurnId;
|
|
1882
|
+
const readRuns = async () => runsByTurnId ??= new Map((await exactSession.runs()).map((run) => [run.executionId, run]));
|
|
1876
1883
|
if (admission.state === "open") {
|
|
1877
|
-
if (
|
|
1884
|
+
if (admittedWorkIsLive(status, await readRuns(), admission.admittedTurnIds, dispatchMayBePending)) {
|
|
1878
1885
|
admission = await options.admissionStore.renew(options.executionId, new Date(now)) ?? admission;
|
|
1879
1886
|
} else if (leaseUntil <= now) {
|
|
1880
1887
|
admission = await options.admissionStore.closeExpired(options.executionId, new Date(now)) ?? admission;
|
|
@@ -1885,18 +1892,15 @@ async function observeNativeCompletion(options) {
|
|
|
1885
1892
|
if (admittedTurnIds.length === 0 || admittedTurnIds[0] !== options.turnId) {
|
|
1886
1893
|
throw new Error("Native completion admission has an invalid turn sequence");
|
|
1887
1894
|
}
|
|
1888
|
-
const
|
|
1889
|
-
const
|
|
1890
|
-
|
|
1891
|
-
if (
|
|
1892
|
-
return { state: "running" };
|
|
1893
|
-
}
|
|
1894
|
-
if (admittedTurnIds.some((turnId) => runsByTurnId.get(turnId)?.status === "active")) return { state: "running" };
|
|
1895
|
+
const ledger = await readRuns();
|
|
1896
|
+
const missingExecution = admittedTurnIds.find((turnId) => !ledger.has(turnId));
|
|
1897
|
+
if (missingExecution && dispatchMayBePending) return { state: "running" };
|
|
1898
|
+
if (admittedTurnIds.some((turnId) => ledger.get(turnId)?.status === "active")) return { state: "running" };
|
|
1895
1899
|
const since = Math.max(0, options.registeredAt - MESSAGE_READ_SKEW_MS);
|
|
1896
1900
|
let messages;
|
|
1897
1901
|
const recovered = [];
|
|
1898
1902
|
for (const turnId of admittedTurnIds) {
|
|
1899
|
-
const run =
|
|
1903
|
+
const run = ledger.get(turnId);
|
|
1900
1904
|
if (!run) {
|
|
1901
1905
|
recovered.push(missingTurnReceipt(turnId, "Native Sandbox execution ledger is missing the admitted turn"));
|
|
1902
1906
|
continue;
|