@senpi/runtime 3.0.211 → 3.0.214
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.
- package/dist/deploy/deadlines.d.ts +11 -3
- package/dist/deploy/deadlines.d.ts.map +1 -1
- package/dist/deploy/deadlines.js +18 -4
- package/dist/deploy/deadlines.js.map +1 -1
- package/dist/deploy/messages.d.ts +48 -1
- package/dist/deploy/messages.d.ts.map +1 -1
- package/dist/deploy/messages.js +72 -4
- package/dist/deploy/messages.js.map +1 -1
- package/dist/deploy/orchestrator.d.ts +3 -3
- package/dist/deploy/orchestrator.d.ts.map +1 -1
- package/dist/deploy/orchestrator.js +163 -137
- package/dist/deploy/orchestrator.js.map +1 -1
- package/dist/deploy/package.d.ts.map +1 -1
- package/dist/deploy/package.js +6 -2
- package/dist/deploy/package.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/runtime/auto-update/coordinator.d.ts +15 -0
- package/dist/runtime/auto-update/coordinator.d.ts.map +1 -1
- package/dist/runtime/auto-update/coordinator.js +49 -2
- package/dist/runtime/auto-update/coordinator.js.map +1 -1
- package/dist/runtime/auto-update/resolve-package-name.d.ts +7 -0
- package/dist/runtime/auto-update/resolve-package-name.d.ts.map +1 -1
- package/dist/runtime/auto-update/resolve-package-name.js +16 -0
- package/dist/runtime/auto-update/resolve-package-name.js.map +1 -1
- package/dist/runtime/auto-update/run-update-command.d.ts +8 -0
- package/dist/runtime/auto-update/run-update-command.d.ts.map +1 -1
- package/dist/runtime/auto-update/run-update-command.js +19 -0
- package/dist/runtime/auto-update/run-update-command.js.map +1 -1
- package/dist/runtime/auto-update/tarball-source.d.ts +19 -0
- package/dist/runtime/auto-update/tarball-source.d.ts.map +1 -0
- package/dist/runtime/auto-update/tarball-source.js +47 -0
- package/dist/runtime/auto-update/tarball-source.js.map +1 -0
- package/dist/senpi/__tests__/helpers/fake-paper-mcp.d.ts +2 -2
- package/dist/senpi/__tests__/helpers/fake-paper-mcp.d.ts.map +1 -1
- package/dist/senpi/__tests__/helpers/fake-paper-mcp.js +1 -1
- package/dist/senpi/__tests__/helpers/fake-paper-mcp.js.map +1 -1
- package/dist/senpi/strategy-status.d.ts +8 -0
- package/dist/senpi/strategy-status.d.ts.map +1 -1
- package/dist/senpi/strategy-status.js +12 -0
- package/dist/senpi/strategy-status.js.map +1 -1
- package/dist/senpi/types.d.ts +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
|
@@ -27,15 +27,15 @@ import { loadRuntimeConfig } from "../runtime/load-runtime-config.js";
|
|
|
27
27
|
import { catalogCopy, strategyFacts } from "../strategy/facts.js";
|
|
28
28
|
import { buildUniverseNotLiveRefusal, buildUniverseUnavailableDetail, checkPackageUniverse, describeUniverseVerdict, } from "../universe/package-universe.js";
|
|
29
29
|
import { instancesWithoutDslExit, nonLowercasePackageId, renderRuntimeYaml, runtimeUsesLlmDecisions, readRuntimeYaml, runtimeIdFor, scannersDeclaringEnabled, unboundWalletInstances, walletName, } from "./package.js";
|
|
30
|
-
import { DEAD_STATUSES, INITIALIZING_STATUSES,
|
|
30
|
+
import { DEAD_STATUSES, INITIALIZING_STATUSES, classifyCloseRead, isDead, isInitializing, } from "../senpi/strategy-status.js";
|
|
31
31
|
import { MIN_WALLET, accessibleUsd, closeCommand, statusCommand, planFunding, resumeCommand, sharesOverAuthorization, underfundedNote, usd, } from "./funding.js";
|
|
32
|
-
import { DEFAULT_MAX_WAIT_SEC, DEFAULT_TICK_WAIT_SEC, INSTALL_DEADLINE_MS, INSTALL_INDETERMINATE_CODE, isInstallDeadlineExceeded, } from "./deadlines.js";
|
|
32
|
+
import { CLOSE_POLL_BUDGET_MS, DEFAULT_MAX_WAIT_SEC, DEFAULT_TICK_WAIT_SEC, INSTALL_DEADLINE_MS, INSTALL_INDETERMINATE_CODE, isInstallDeadlineExceeded, } from "./deadlines.js";
|
|
33
33
|
import { packageMinBudget } from "./min-budget.js";
|
|
34
34
|
import { errorText } from "./error-text.js";
|
|
35
35
|
import { truncateForPush } from "../types/notification.js";
|
|
36
36
|
import { gateInstance } from "./install-gate-runner.js";
|
|
37
37
|
import { buildInstanceDirCollisionRefusal, buildProofRefusal, checkPackageProof, collidingInstanceDirs, proofRefusalParts, } from "./proof-gate.js";
|
|
38
|
-
import { buildAmbiguousRefusal, buildBindingUnknownRefusal, buildBudgetEscape, buildBudgetNotPositiveRefusal, buildBudgetRequiredRefusal, buildCreateAbandonedDetail, buildCreateDeadDetail, buildCreateNameRetryNotIssuedDetail, buildCreateNotDeployableDetail, buildCreatePendingDetail, buildDecisionModelEnvRefusal, buildDecisionModelRefusal, buildForeignPackageRefusal, buildFundedUnreadableNote, buildInstallGateRefusal, buildInstallGateUnavailableDetail, buildInstallIndeterminateDetail, buildInstallInFlightDetail, buildNoDslExitRefusal, buildNonLowercaseIdRefusal, buildNotDeployableRefusal, buildPaperCreateUnsupportedRefusal, buildPaperRoutingUnprovenRefusal, buildPaperCreateWentLiveDetail, buildPartialFundNote, buildScannerEnabledUnsupportedRefusal, buildBoxRuntimeCapRefusal, buildAdoptedOverBoxCapNote, buildShareOverrunRefusal, buildSoftBudgetNote, buildStrategyLimitRefusal, limitShort, buildUnboundWalletRefusal, buildUnobservedDetail, buildUnreadableWalletRefusal, buildUnwiredInstallDetail, buildRuntimeIdHeldByOtherWorldDetail, buildRuntimeIdHeldByOtherWorldRefusal, buildWalletWorldMismatchDetail, foreignCollisionClause, forwardTense, fundedClause, itsFunded, matchedByClause, reconcileCanMatchByName, rollbackFundedClause, } from "./messages.js";
|
|
38
|
+
import { buildAmbiguousRefusal, buildBindingUnknownRefusal, buildBudgetEscape, buildBudgetNotPositiveRefusal, buildBudgetRequiredRefusal, buildCreateAbandonedDetail, buildCreateDeadDetail, buildCreateNameRetryNotIssuedDetail, buildCreateNotDeployableDetail, buildCreatePendingDetail, buildDecisionModelEnvRefusal, buildDecisionModelRefusal, buildForeignPackageRefusal, buildFundedUnreadableNote, buildInstallGateRefusal, buildInstallGateUnavailableDetail, buildInstallIndeterminateDetail, buildInstallInFlightDetail, buildNoDslExitRefusal, buildNonLowercaseIdRefusal, buildNotDeployableRefusal, buildPaperCreateUnsupportedRefusal, buildPaperRoutingUnprovenRefusal, buildPaperCreateWentLiveDetail, buildPartialFundNote, buildRollbackIncomplete, buildScannerEnabledUnsupportedRefusal, buildBoxRuntimeCapRefusal, buildAdoptedOverBoxCapNote, buildShareOverrunRefusal, buildSoftBudgetNote, buildStrategyLimitRefusal, limitShort, buildUnboundWalletRefusal, buildUnobservedDetail, buildUnreadableWalletRefusal, buildUnwiredInstallDetail, buildRuntimeIdHeldByOtherWorldDetail, buildRuntimeIdHeldByOtherWorldRefusal, buildWalletWorldMismatchDetail, foreignCollisionClause, forwardTense, fundedClause, itsFunded, matchedByClause, reconcileCanMatchByName, rollbackFundedClause, } from "./messages.js";
|
|
39
39
|
/** Stands in for the wallet when rendering a recipe only to read its facts, which never include it. */
|
|
40
40
|
const FACTS_STAND_IN_WALLET = "0x0000000000000000000000000000000000000000";
|
|
41
41
|
const CREATE_POLL_MS = 10_000;
|
|
@@ -221,34 +221,57 @@ function isFreshError(row, sinceMs) {
|
|
|
221
221
|
/** deploy.py's `_budget_verdict` tolerance: below this fraction of the ask, say so out loud. */
|
|
222
222
|
const BUDGET_TOLERANCE = 0.9;
|
|
223
223
|
/**
|
|
224
|
-
*
|
|
225
|
-
* only a returned status of CLOSED means it finished.
|
|
224
|
+
* Why a `strategy_close` that did not answer `success: true` left the wallet open.
|
|
226
225
|
*
|
|
227
226
|
* The client resolves a tool-level `strategy_close` failure as `{ success: false }` and maps an
|
|
228
227
|
* unrecognizable payload onto that same shape (senpi/client.ts); it throws only on an RPC fault. So
|
|
229
228
|
* "the promise resolved" is not evidence, and reading it as one reported funds returned from a
|
|
230
229
|
* wallet that is still live and still funded.
|
|
231
230
|
*/
|
|
232
|
-
function
|
|
233
|
-
|
|
234
|
-
? result
|
|
235
|
-
:
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
231
|
+
function closeRefusalReason(result) {
|
|
232
|
+
return result.message
|
|
233
|
+
? `\`strategy_close\` reported failure: ${result.message}`
|
|
234
|
+
: `\`strategy_close\` did not report success (it returned ${JSON.stringify(result) ?? String(result)})`;
|
|
235
|
+
}
|
|
236
|
+
function isClosed(status) {
|
|
237
|
+
return status?.toUpperCase() === "CLOSED";
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* What the last status known after `strategy_close` makes of the rollback. `closeError` is what the
|
|
241
|
+
* close threw: it may still have run upstream, so only a status read decides what it did.
|
|
242
|
+
*/
|
|
243
|
+
function closeReadOutcome(status, closeError) {
|
|
244
|
+
if (status === undefined)
|
|
245
|
+
return closeError ? { kind: "unknown" } : { kind: "closing", status };
|
|
246
|
+
const read = classifyCloseRead(status);
|
|
247
|
+
switch (read) {
|
|
248
|
+
case "closed":
|
|
249
|
+
return "closed";
|
|
250
|
+
case "closing":
|
|
251
|
+
return { kind: "closing", status };
|
|
252
|
+
case "live":
|
|
253
|
+
return {
|
|
254
|
+
kind: "live",
|
|
255
|
+
status,
|
|
256
|
+
reason: closeError
|
|
257
|
+
? `\`strategy_close\` threw (${closeError}), and the strategy then read ${status}`
|
|
258
|
+
: `\`strategy_close\` was accepted, but the strategy then read ${status}, so the close did not take`,
|
|
259
|
+
};
|
|
260
|
+
case "dead":
|
|
261
|
+
case "other":
|
|
262
|
+
return { kind: read, status };
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
/** A went-live strategy's cleanup when its status needs no close and no wait: closed, dead or other. */
|
|
266
|
+
function settledLiveCreate(status) {
|
|
267
|
+
switch (classifyCloseRead(status)) {
|
|
268
|
+
case "closed":
|
|
269
|
+
return { kind: "closed", status };
|
|
270
|
+
case "dead":
|
|
271
|
+
return { kind: "dead", status };
|
|
272
|
+
default:
|
|
273
|
+
return { kind: "unclosable", status };
|
|
242
274
|
}
|
|
243
|
-
const message = typeof record?.message === "string" && record.message.length > 0
|
|
244
|
-
? record.message
|
|
245
|
-
: "";
|
|
246
|
-
return {
|
|
247
|
-
kind: "failed",
|
|
248
|
-
reason: message
|
|
249
|
-
? `\`strategy_close\` reported failure: ${message}`
|
|
250
|
-
: `\`strategy_close\` did not report success (it returned ${JSON.stringify(result) ?? String(result)})`,
|
|
251
|
-
};
|
|
252
275
|
}
|
|
253
276
|
/**
|
|
254
277
|
* A call this job stopped waiting on at its own deadline, as opposed to one the backend failed.
|
|
@@ -1932,32 +1955,47 @@ export async function runDeploy(params, deps) {
|
|
|
1932
1955
|
});
|
|
1933
1956
|
}
|
|
1934
1957
|
async function closeLiveCreate(strategyId) {
|
|
1935
|
-
const status = await pollStatus(strategyId,
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1958
|
+
const status = await pollStatus(strategyId, {
|
|
1959
|
+
paper: false,
|
|
1960
|
+
budgetMs: maxWaitSec * 1000,
|
|
1961
|
+
settled: (read) => !isInitializing(read),
|
|
1962
|
+
});
|
|
1963
|
+
if (status === undefined)
|
|
1964
|
+
return { kind: "unclosable" };
|
|
1965
|
+
let after;
|
|
1966
|
+
switch (classifyCloseRead(status)) {
|
|
1967
|
+
case "closing":
|
|
1968
|
+
after = await pollWhileClosing(strategyId, status, false);
|
|
1969
|
+
break;
|
|
1970
|
+
case "live": {
|
|
1971
|
+
let close;
|
|
1972
|
+
try {
|
|
1973
|
+
close = await deps.closeStrategyById(strategyId);
|
|
1974
|
+
}
|
|
1975
|
+
catch (err) {
|
|
1976
|
+
return { kind: "close-failed", status, reason: errorText(err) };
|
|
1977
|
+
}
|
|
1978
|
+
if (!close.success)
|
|
1979
|
+
return { kind: "close-failed", status, reason: closeRefusalReason(close) };
|
|
1980
|
+
after = isClosed(close.status) ? close.status : await pollWhileClosing(strategyId, close.status, false);
|
|
1981
|
+
break;
|
|
1952
1982
|
}
|
|
1983
|
+
default:
|
|
1984
|
+
return settledLiveCreate(status);
|
|
1953
1985
|
}
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1986
|
+
if (after === undefined)
|
|
1987
|
+
return { kind: "closing" };
|
|
1988
|
+
switch (classifyCloseRead(after)) {
|
|
1957
1989
|
case "closing":
|
|
1958
|
-
return { kind: "closing",
|
|
1959
|
-
case "
|
|
1960
|
-
return {
|
|
1990
|
+
return { kind: "closing", status: after };
|
|
1991
|
+
case "live":
|
|
1992
|
+
return {
|
|
1993
|
+
kind: "close-failed",
|
|
1994
|
+
status: after,
|
|
1995
|
+
reason: `the strategy read ${after} after the close, so the close did not take`,
|
|
1996
|
+
};
|
|
1997
|
+
default:
|
|
1998
|
+
return settledLiveCreate(after);
|
|
1961
1999
|
}
|
|
1962
2000
|
}
|
|
1963
2001
|
/**
|
|
@@ -2260,9 +2298,10 @@ export async function runDeploy(params, deps) {
|
|
|
2260
2298
|
*
|
|
2261
2299
|
* D-7: `strategy_close` returns the funds to the owner embedded wallet on its own, so the unwind
|
|
2262
2300
|
* is one call — there is no separate withdraw step to get half-done. It does so asynchronously,
|
|
2263
|
-
* so the refund is reported only once the strategy reads CLOSED.
|
|
2264
|
-
*
|
|
2265
|
-
* readers already keep the funded figure and defer
|
|
2301
|
+
* so the refund is reported only once the strategy reads CLOSED. Anything else is
|
|
2302
|
+
* E_ROLLBACK_INCOMPLETE, with the next step `classifyCloseRead` gives the last status read: the
|
|
2303
|
+
* funds are not confirmed back, and that code's readers already keep the funded figure and defer
|
|
2304
|
+
* every other remediation to it.
|
|
2266
2305
|
*/
|
|
2267
2306
|
async function rollbackWallet(run) {
|
|
2268
2307
|
await span("deploy.rollback", { "senpi.deploy.step": "rollback" }, () => rollbackWalletBody(run));
|
|
@@ -2270,123 +2309,110 @@ export async function runDeploy(params, deps) {
|
|
|
2270
2309
|
/** Resolves with the rollback's result — the wiring turns it into `senpi.deploy.rollback.count`. */
|
|
2271
2310
|
async function rollbackWalletBody(run) {
|
|
2272
2311
|
const wallet = run.report.wallet;
|
|
2273
|
-
const funded = rollbackFundedClause(run.report.funded);
|
|
2274
2312
|
emit({
|
|
2275
2313
|
type: "job",
|
|
2276
2314
|
phase: "install",
|
|
2277
|
-
detail: `install failed on wallet ${wallet}, which this job created and
|
|
2278
|
-
|
|
2279
|
-
});
|
|
2280
|
-
const incomplete = (reason) => record(run, "create", {
|
|
2281
|
-
status: "failed",
|
|
2282
|
-
detail: `[E_ROLLBACK_INCOMPLETE] wallet ${wallet} was created by this deploy and ${funded}, ` +
|
|
2283
|
-
`its install failed, and the automatic close did not complete: ${reason}. The wallet is ` +
|
|
2284
|
-
`live and unwatched. Reclaim the funds from THIS wallet: MCP \`strategy_close\` on ` +
|
|
2285
|
-
`${wallet}${buildStrandedCloseCaveat(pkg, runs, run)}`,
|
|
2286
|
-
evidence: { wallet, funded: run.report.funded, reason },
|
|
2315
|
+
detail: `install failed on wallet ${wallet}, which this job created and ` +
|
|
2316
|
+
`${rollbackFundedClause(run.report.funded)} — closing it and returning the funds`,
|
|
2287
2317
|
});
|
|
2318
|
+
let strategyId = run.report.strategyId;
|
|
2319
|
+
let close = null;
|
|
2320
|
+
let closeError;
|
|
2321
|
+
const incomplete = (why) => {
|
|
2322
|
+
record(run, "create", {
|
|
2323
|
+
status: "failed",
|
|
2324
|
+
...buildRollbackIncomplete({
|
|
2325
|
+
wallet,
|
|
2326
|
+
strategyId,
|
|
2327
|
+
funded: run.report.funded,
|
|
2328
|
+
closeCaveat: buildStrandedCloseCaveat(pkg, runs, run),
|
|
2329
|
+
closeResult: close,
|
|
2330
|
+
closeError,
|
|
2331
|
+
}, why),
|
|
2332
|
+
});
|
|
2333
|
+
return "incomplete";
|
|
2334
|
+
};
|
|
2288
2335
|
try {
|
|
2289
2336
|
if (!(await deps.walletIsFlat(wallet))) {
|
|
2290
|
-
incomplete("the wallet holds open positions — refusing to auto-close");
|
|
2291
|
-
return "incomplete";
|
|
2292
|
-
}
|
|
2293
|
-
const result = await deps.closeStrategy(wallet);
|
|
2294
|
-
const accepted = readCloseOutcome(result);
|
|
2295
|
-
const outcome = accepted.kind === "closing"
|
|
2296
|
-
? await pollUntilClosed(run.report.strategyId ?? accepted.strategyId, accepted, pkg.paper)
|
|
2297
|
-
: accepted;
|
|
2298
|
-
switch (outcome.kind) {
|
|
2299
|
-
case "failed":
|
|
2300
|
-
incomplete(outcome.reason);
|
|
2301
|
-
return "incomplete";
|
|
2302
|
-
case "closing":
|
|
2303
|
-
recordClosePending(run, outcome);
|
|
2304
|
-
return "incomplete";
|
|
2305
|
-
case "closed": {
|
|
2306
|
-
// The structured facts the report leads with must agree with the step detail: this wallet
|
|
2307
|
-
// is closed and the funds are back with the owner, so it is no longer a funded wallet. The
|
|
2308
|
-
// amount survives in the step evidence, where it reads as history rather than as a holding.
|
|
2309
|
-
const fundedBeforeRollback = run.report.funded;
|
|
2310
|
-
run.report.funded = 0;
|
|
2311
|
-
run.report.rolledBack = true;
|
|
2312
|
-
record(run, "create", {
|
|
2313
|
-
status: "ok",
|
|
2314
|
-
detail: `wallet ${wallet} was created by this deploy and its install failed — rolled back: strategy ` +
|
|
2315
|
-
`closed, funds returned to the owner wallet (close result: ${JSON.stringify(result)})`,
|
|
2316
|
-
evidence: { wallet, funded: fundedBeforeRollback, rolledBack: true, closeResult: result },
|
|
2317
|
-
});
|
|
2318
|
-
return "ok";
|
|
2319
|
-
}
|
|
2337
|
+
return incomplete({ kind: "live", reason: "the wallet holds open positions — refusing to auto-close" });
|
|
2320
2338
|
}
|
|
2321
2339
|
}
|
|
2322
2340
|
catch (err) {
|
|
2323
|
-
incomplete(errorText(err));
|
|
2324
|
-
|
|
2341
|
+
return incomplete({ kind: "live", reason: errorText(err) });
|
|
2342
|
+
}
|
|
2343
|
+
try {
|
|
2344
|
+
close = await deps.closeStrategy(wallet);
|
|
2325
2345
|
}
|
|
2346
|
+
catch (err) {
|
|
2347
|
+
closeError = errorText(err);
|
|
2348
|
+
}
|
|
2349
|
+
if (close && !close.success)
|
|
2350
|
+
return incomplete({ kind: "live", reason: closeRefusalReason(close) });
|
|
2351
|
+
strategyId ??= close?.strategyId;
|
|
2352
|
+
const outcome = closeReadOutcome(isClosed(close?.status) ? close?.status : await pollWhileClosing(strategyId, close?.status, pkg.paper), closeError);
|
|
2353
|
+
if (outcome !== "closed")
|
|
2354
|
+
return incomplete(outcome);
|
|
2355
|
+
// The structured facts the report leads with must agree with the step detail: this wallet is
|
|
2356
|
+
// closed and the funds are back with the owner, so it is no longer a funded wallet. The amount
|
|
2357
|
+
// survives in the step evidence, where it reads as history rather than as a holding.
|
|
2358
|
+
const fundedBeforeRollback = run.report.funded;
|
|
2359
|
+
run.report.funded = 0;
|
|
2360
|
+
run.report.rolledBack = true;
|
|
2361
|
+
const how = close
|
|
2362
|
+
? `close result: ${JSON.stringify(close)}`
|
|
2363
|
+
: `\`strategy_close\` threw (${closeError}), and the strategy read CLOSED after it`;
|
|
2364
|
+
record(run, "create", {
|
|
2365
|
+
status: "ok",
|
|
2366
|
+
detail: `wallet ${wallet} was created by this deploy and its install failed — rolled back: strategy ` +
|
|
2367
|
+
`closed, funds returned to the owner wallet (${how})`,
|
|
2368
|
+
evidence: { wallet, funded: fundedBeforeRollback, rolledBack: true, closeResult: close },
|
|
2369
|
+
});
|
|
2370
|
+
return "ok";
|
|
2326
2371
|
}
|
|
2327
2372
|
/**
|
|
2328
|
-
* Read
|
|
2329
|
-
*
|
|
2373
|
+
* Read a close back while the strategy reads a closing status, within
|
|
2374
|
+
* {@link CLOSE_POLL_BUDGET_MS} and the job's deadline. Any other status settles the close one way
|
|
2375
|
+
* or the other, so it ends the wait at once. Resolves with the last status known: the close's own
|
|
2376
|
+
* answer until a read replaces it.
|
|
2330
2377
|
*/
|
|
2331
|
-
async function
|
|
2378
|
+
async function pollWhileClosing(strategyId, status, paper) {
|
|
2332
2379
|
if (strategyId === undefined)
|
|
2333
|
-
return
|
|
2334
|
-
|
|
2335
|
-
|
|
2380
|
+
return status;
|
|
2381
|
+
return pollStatus(strategyId, {
|
|
2382
|
+
paper,
|
|
2383
|
+
budgetMs: CLOSE_POLL_BUDGET_MS,
|
|
2384
|
+
status,
|
|
2385
|
+
settled: (read) => classifyCloseRead(read) !== "closing",
|
|
2386
|
+
});
|
|
2336
2387
|
}
|
|
2337
2388
|
/**
|
|
2338
|
-
* Read one strategy's status until `settled` holds,
|
|
2339
|
-
*
|
|
2340
|
-
*
|
|
2389
|
+
* Read one strategy's status in `paper`'s world until `settled` holds, within `budgetMs` and the
|
|
2390
|
+
* job's deadline, at {@link CREATE_POLL_MS}. A read that throws or finds no row leaves the status
|
|
2391
|
+
* as it was. Resolves with the last status known, starting from `status`.
|
|
2341
2392
|
*/
|
|
2342
|
-
async function pollStatus(strategyId,
|
|
2343
|
-
const deadline = deps.now() +
|
|
2344
|
-
let status;
|
|
2393
|
+
async function pollStatus(strategyId, poll) {
|
|
2394
|
+
const deadline = deps.now() + poll.budgetMs;
|
|
2395
|
+
let status = poll.status;
|
|
2345
2396
|
for (;;) {
|
|
2397
|
+
// Before the read, not after: the watchdog's grace after a soft stop can be shorter than one
|
|
2398
|
+
// read, and a hard stop drops this wallet and its money from the final report.
|
|
2399
|
+
if (deps.shouldAbandon())
|
|
2400
|
+
return status;
|
|
2346
2401
|
try {
|
|
2347
|
-
const [live] = await deps.listStrategies({ paper, strategyIds: [strategyId] });
|
|
2402
|
+
const [live] = await deps.listStrategies({ paper: poll.paper, strategyIds: [strategyId] });
|
|
2348
2403
|
if (live?.status)
|
|
2349
2404
|
status = live.status;
|
|
2350
2405
|
}
|
|
2351
2406
|
catch (err) {
|
|
2352
2407
|
log(`deploy: reading strategy ${strategyId} failed: ${errorText(err)}`);
|
|
2353
2408
|
}
|
|
2354
|
-
if (status !== undefined && settled(status))
|
|
2409
|
+
if (status !== undefined && poll.settled(status))
|
|
2355
2410
|
return status;
|
|
2356
|
-
if (deps.now() >= deadline
|
|
2411
|
+
if (deps.now() >= deadline)
|
|
2357
2412
|
return status;
|
|
2358
2413
|
await deps.sleep(CREATE_POLL_MS);
|
|
2359
2414
|
}
|
|
2360
2415
|
}
|
|
2361
|
-
/**
|
|
2362
|
-
* The close was accepted and never read back CLOSED. The funds may still be in the wallet, so
|
|
2363
|
-
* `funded` stays and nothing claims the refund. The follow-up starts with a status read, because
|
|
2364
|
-
* a second `strategy_close` on a closing strategy is only a no-op.
|
|
2365
|
-
*/
|
|
2366
|
-
function recordClosePending(run, closing) {
|
|
2367
|
-
const wallet = run.report.wallet;
|
|
2368
|
-
const strategy = closing.strategyId ? `strategy ${closing.strategyId}` : `the strategy on wallet ${wallet}`;
|
|
2369
|
-
const read = closing.status ? `still read ${closing.status}` : "reported no status";
|
|
2370
|
-
record(run, "create", {
|
|
2371
|
-
status: "failed",
|
|
2372
|
-
detail: `[E_ROLLBACK_INCOMPLETE] wallet ${wallet} was created by this deploy and ` +
|
|
2373
|
-
`${rollbackFundedClause(run.report.funded)}, its install failed, and the automatic close was ` +
|
|
2374
|
-
`accepted but not confirmed: ${strategy} ${read} when this deploy stopped waiting for CLOSED. ` +
|
|
2375
|
-
`The funds are NOT confirmed back with the owner wallet. Read ${strategy} with MCP ` +
|
|
2376
|
-
`\`strategy_list\`: CLOSED means the funds are back and nothing is left to do. ACTIVE or ` +
|
|
2377
|
-
`PAUSED means the close did not take, so run MCP \`strategy_close\` on ` +
|
|
2378
|
-
`${wallet}${buildStrandedCloseCaveat(pkg, runs, run)} Any other status is a close still in ` +
|
|
2379
|
-
`progress: read it again later.`,
|
|
2380
|
-
evidence: {
|
|
2381
|
-
wallet,
|
|
2382
|
-
strategyId: closing.strategyId,
|
|
2383
|
-
funded: run.report.funded,
|
|
2384
|
-
close: "closing",
|
|
2385
|
-
lastStatus: closing.status ?? null,
|
|
2386
|
-
closeResult: closing.result,
|
|
2387
|
-
},
|
|
2388
|
-
});
|
|
2389
|
-
}
|
|
2390
2416
|
// ── observe ───────────────────────────────────────────────────────────────
|
|
2391
2417
|
const observable = runs.filter((run) => run.report.runtimeId && ["ok", "skipped"].includes(run.report.steps.install.status));
|
|
2392
2418
|
if (!halted() && observable.length > 0) {
|