@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.
Files changed (45) hide show
  1. package/dist/deploy/deadlines.d.ts +11 -3
  2. package/dist/deploy/deadlines.d.ts.map +1 -1
  3. package/dist/deploy/deadlines.js +18 -4
  4. package/dist/deploy/deadlines.js.map +1 -1
  5. package/dist/deploy/messages.d.ts +48 -1
  6. package/dist/deploy/messages.d.ts.map +1 -1
  7. package/dist/deploy/messages.js +72 -4
  8. package/dist/deploy/messages.js.map +1 -1
  9. package/dist/deploy/orchestrator.d.ts +3 -3
  10. package/dist/deploy/orchestrator.d.ts.map +1 -1
  11. package/dist/deploy/orchestrator.js +163 -137
  12. package/dist/deploy/orchestrator.js.map +1 -1
  13. package/dist/deploy/package.d.ts.map +1 -1
  14. package/dist/deploy/package.js +6 -2
  15. package/dist/deploy/package.js.map +1 -1
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +6 -2
  18. package/dist/index.js.map +1 -1
  19. package/dist/runtime/auto-update/coordinator.d.ts +15 -0
  20. package/dist/runtime/auto-update/coordinator.d.ts.map +1 -1
  21. package/dist/runtime/auto-update/coordinator.js +49 -2
  22. package/dist/runtime/auto-update/coordinator.js.map +1 -1
  23. package/dist/runtime/auto-update/resolve-package-name.d.ts +7 -0
  24. package/dist/runtime/auto-update/resolve-package-name.d.ts.map +1 -1
  25. package/dist/runtime/auto-update/resolve-package-name.js +16 -0
  26. package/dist/runtime/auto-update/resolve-package-name.js.map +1 -1
  27. package/dist/runtime/auto-update/run-update-command.d.ts +8 -0
  28. package/dist/runtime/auto-update/run-update-command.d.ts.map +1 -1
  29. package/dist/runtime/auto-update/run-update-command.js +19 -0
  30. package/dist/runtime/auto-update/run-update-command.js.map +1 -1
  31. package/dist/runtime/auto-update/tarball-source.d.ts +19 -0
  32. package/dist/runtime/auto-update/tarball-source.d.ts.map +1 -0
  33. package/dist/runtime/auto-update/tarball-source.js +47 -0
  34. package/dist/runtime/auto-update/tarball-source.js.map +1 -0
  35. package/dist/senpi/__tests__/helpers/fake-paper-mcp.d.ts +2 -2
  36. package/dist/senpi/__tests__/helpers/fake-paper-mcp.d.ts.map +1 -1
  37. package/dist/senpi/__tests__/helpers/fake-paper-mcp.js +1 -1
  38. package/dist/senpi/__tests__/helpers/fake-paper-mcp.js.map +1 -1
  39. package/dist/senpi/strategy-status.d.ts +8 -0
  40. package/dist/senpi/strategy-status.d.ts.map +1 -1
  41. package/dist/senpi/strategy-status.js +12 -0
  42. package/dist/senpi/strategy-status.js.map +1 -1
  43. package/dist/senpi/types.d.ts +1 -1
  44. package/openclaw.plugin.json +1 -1
  45. 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, isClosable, isClosing, isDead, isInitializing, } from "../senpi/strategy-status.js";
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
- * Read a `strategy_close` answer. Only an explicit `success: true` means the close was accepted, and
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 readCloseOutcome(result) {
233
- const record = typeof result === "object" && result !== null
234
- ? result
235
- : undefined;
236
- if (record?.success === true) {
237
- const status = typeof record.status === "string" ? record.status : undefined;
238
- if (status?.toUpperCase() === "CLOSED")
239
- return { kind: "closed", result };
240
- const strategyId = typeof record.strategyId === "string" ? record.strategyId : undefined;
241
- return { kind: "closing", status, strategyId, result };
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, false, (s) => !isInitializing(s));
1936
- if (status === undefined || (!isClosable(status) && !isClosing(status) && !isDead(status))) {
1937
- return { kind: "unclosable", ...(status ? { status } : {}) };
1938
- }
1939
- if (isDead(status))
1940
- return { kind: "closed", status };
1941
- let outcome;
1942
- if (isClosing(status)) {
1943
- outcome = await pollUntilClosed(strategyId, { kind: "closing", status, strategyId, result: undefined }, false);
1944
- }
1945
- else {
1946
- try {
1947
- const accepted = readCloseOutcome(await deps.closeStrategyById(strategyId));
1948
- outcome = accepted.kind === "closing" ? await pollUntilClosed(strategyId, accepted, false) : accepted;
1949
- }
1950
- catch (err) {
1951
- return { kind: "close-failed", status, reason: errorText(err) };
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
- switch (outcome.kind) {
1955
- case "closed":
1956
- return { kind: "closed", status: "CLOSED" };
1986
+ if (after === undefined)
1987
+ return { kind: "closing" };
1988
+ switch (classifyCloseRead(after)) {
1957
1989
  case "closing":
1958
- return { kind: "closing", ...(outcome.status ? { status: outcome.status } : {}) };
1959
- case "failed":
1960
- return { kind: "close-failed", status, reason: outcome.reason };
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. A close still in progress at
2264
- * the wait's end is E_ROLLBACK_INCOMPLETE too: the funds are not confirmed back, and that code's
2265
- * readers already keep the funded figure and defer every other remediation to it.
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 ${funded} — ` +
2278
- `closing it and returning the funds`,
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
- return "incomplete";
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 an accepted close back until the strategy is CLOSED. A read that throws is not a CLOSED
2329
- * read, so it only costs one poll.
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 pollUntilClosed(strategyId, closing, paper) {
2378
+ async function pollWhileClosing(strategyId, status, paper) {
2332
2379
  if (strategyId === undefined)
2333
- return closing;
2334
- const status = (await pollStatus(strategyId, paper, (s) => s.toUpperCase() === "CLOSED")) ?? closing.status;
2335
- return status?.toUpperCase() === "CLOSED" ? { kind: "closed", result: closing.result } : { ...closing, strategyId, status };
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, on the ACTIVE poll's budget and cadence
2339
- * (`--max-wait`, {@link CREATE_POLL_MS}) and the job's deadline. Resolves the last status read,
2340
- * undefined when no read returned one.
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, paper, settled) {
2343
- const deadline = deps.now() + maxWaitSec * 1000;
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 || deps.shouldAbandon())
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) {