@senpi/runtime 3.0.197 → 3.0.199

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 (36) hide show
  1. package/dist/cli/deploy-render.d.ts +2 -0
  2. package/dist/cli/deploy-render.d.ts.map +1 -1
  3. package/dist/cli/deploy-render.js +2 -0
  4. package/dist/cli/deploy-render.js.map +1 -1
  5. package/dist/deploy/messages.d.ts +34 -14
  6. package/dist/deploy/messages.d.ts.map +1 -1
  7. package/dist/deploy/messages.js +83 -30
  8. package/dist/deploy/messages.js.map +1 -1
  9. package/dist/deploy/orchestrator.d.ts +14 -7
  10. package/dist/deploy/orchestrator.d.ts.map +1 -1
  11. package/dist/deploy/orchestrator.js +230 -55
  12. package/dist/deploy/orchestrator.js.map +1 -1
  13. package/dist/deploy/package.d.ts +13 -0
  14. package/dist/deploy/package.d.ts.map +1 -1
  15. package/dist/deploy/package.js +18 -1
  16. package/dist/deploy/package.js.map +1 -1
  17. package/dist/deploy/register.js +3 -3
  18. package/dist/deploy/register.js.map +1 -1
  19. package/dist/senpi/__tests__/helpers/fake-paper-mcp.d.ts +8 -0
  20. package/dist/senpi/__tests__/helpers/fake-paper-mcp.d.ts.map +1 -1
  21. package/dist/senpi/__tests__/helpers/fake-paper-mcp.js +21 -2
  22. package/dist/senpi/__tests__/helpers/fake-paper-mcp.js.map +1 -1
  23. package/dist/senpi/client.d.ts +9 -4
  24. package/dist/senpi/client.d.ts.map +1 -1
  25. package/dist/senpi/client.js +23 -9
  26. package/dist/senpi/client.js.map +1 -1
  27. package/dist/senpi/index.d.ts +1 -1
  28. package/dist/senpi/index.d.ts.map +1 -1
  29. package/dist/senpi/strategy-status.d.ts +3 -0
  30. package/dist/senpi/strategy-status.d.ts.map +1 -1
  31. package/dist/senpi/strategy-status.js +5 -0
  32. package/dist/senpi/strategy-status.js.map +1 -1
  33. package/dist/senpi/types.d.ts +10 -0
  34. package/dist/senpi/types.d.ts.map +1 -1
  35. package/openclaw.plugin.json +1 -1
  36. package/package.json +1 -1
@@ -154,16 +154,17 @@ export interface DeployDeps {
154
154
  span<T>(name: string, attrs: Record<string, unknown>, fn: () => Promise<T>): Promise<T>;
155
155
  /** true when the wallet holds zero open positions (client.listOpenPositions(wallet).length === 0) */
156
156
  walletIsFlat(wallet: string): Promise<boolean>;
157
- /** strategy_close via client.closeStrategy(wallet) — returns funds to the owner wallet on its own (D-7) */
157
+ /**
158
+ * strategy_close via client.closeStrategy(wallet) — returns funds to the owner wallet on its own
159
+ * (D-7), once the strategy reaches CLOSED. Resolves the client's `StrategyCloseResult`.
160
+ */
158
161
  closeStrategy(wallet: string): Promise<unknown>;
159
162
  /**
160
163
  * strategy_close by strategy id (client.closeStrategyById), live world. Only for a paper create
161
- * the MCP turned into a live strategy: it is closed by the id the create returned, at once.
164
+ * the MCP turned into a live strategy, closed by the id the create returned once it is closable.
165
+ * Resolves the client's `StrategyCloseResult`.
162
166
  */
163
- closeStrategyById(strategyId: string): Promise<{
164
- success: boolean;
165
- message?: string;
166
- }>;
167
+ closeStrategyById(strategyId: string): Promise<unknown>;
167
168
  /** narration only — journaled by job.ts; MUST NOT affect flow */
168
169
  emit(event: DeployEventBody): void;
169
170
  /**
@@ -217,7 +218,7 @@ export interface InstanceReport {
217
218
  strategyId?: string;
218
219
  funded?: number;
219
220
  runtimeId?: string;
220
- /** D-6: this job created the wallet, its install failed, and the close+refund completed. */
221
+ /** D-6: this job created the wallet, its install failed, and the strategy read back CLOSED. */
221
222
  rolledBack?: boolean;
222
223
  steps: {
223
224
  reconcile: StepOutcome;
@@ -298,6 +299,12 @@ export interface DeployReport {
298
299
  * USER to establish the real figure. Mutually exclusive per wallet by construction.
299
300
  */
300
301
  fundedUnreadableNote?: string;
302
+ /**
303
+ * The `[W_BOX_RUNTIME_CAP_ADOPTED]` warn, verbatim: adopted wallets with no runtime on this box
304
+ * take it past its cap. The cap refuses only new wallets; whether it should also refuse these is
305
+ * a pending decision, so this never changes `overall`.
306
+ */
307
+ boxCapNote?: string;
301
308
  }
302
309
  /**
303
310
  * Record that an instance is bound to `strategyId` — the WRITE half of the reconcile claim ledger
@@ -1 +1 @@
1
- {"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["../../src/deploy/orchestrator.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGzE,OAAO,EAA8B,KAAK,mBAAmB,EAAE,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAOhH,OAAO,EAaL,KAAK,aAAa,EAGnB,MAAM,cAAc,CAAC;AAmGtB,MAAM,MAAM,QAAQ,GAAG,WAAW,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;AACpF,MAAM,MAAM,QAAQ,GAAG,WAAW,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;AACpF,MAAM,MAAM,UAAU,GAAG,IAAI,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,YAAY,CAAC;AAE5F,qGAAqG;AACrG,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,KAAK,GAAG,MAAM,CAAC;IACrB,sBAAsB;IACtB,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,oBAAoB;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,yCAAyC;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,WAAY,SAAQ,eAAe;IAClD,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,qGAAqG;AACrG,MAAM,WAAW,cAAc;IAC7B,SAAS,EAA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AAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC,CA+pE7F"}
@@ -27,7 +27,7 @@ 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, isDead, isInitializing, } from "../senpi/strategy-status.js";
30
+ import { DEAD_STATUSES, INITIALIZING_STATUSES, isClosable, isClosing, isDead, isInitializing, } from "../senpi/strategy-status.js";
31
31
  import { MIN_WALLET, accessibleUsd, closeCommand, statusCommand, planFunding, resumeCommand, sharesOverAuthorization, underfundedNote, usd, } from "./funding.js";
32
32
  import { 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";
@@ -35,7 +35,7 @@ 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, buildPaperRoutingUnprovenRefusal, buildPaperCreateWentLiveDetail, buildPartialFundNote, buildScannerEnabledUnsupportedRefusal, buildBoxRuntimeCapRefusal, 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, 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";
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,26 +221,34 @@ 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
- * Did the D-6 rollback's `strategy_close` actually run? Returns the reason it did not, or null when
225
- * the close is PROVEN — only an explicit `success: true` proves it.
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.
226
226
  *
227
227
  * The client resolves a tool-level `strategy_close` failure as `{ success: false }` and maps an
228
228
  * unrecognizable payload onto that same shape (senpi/client.ts); it throws only on an RPC fault. So
229
229
  * "the promise resolved" is not evidence, and reading it as one reported funds returned from a
230
230
  * wallet that is still live and still funded.
231
231
  */
232
- function describeCloseFailure(result) {
232
+ function readCloseOutcome(result) {
233
233
  const record = typeof result === "object" && result !== null
234
234
  ? result
235
235
  : undefined;
236
- if (record?.success === true)
237
- return null;
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 };
242
+ }
238
243
  const message = typeof record?.message === "string" && record.message.length > 0
239
244
  ? record.message
240
245
  : "";
241
- return message
242
- ? `\`strategy_close\` reported failure: ${message}`
243
- : `\`strategy_close\` did not report success (it returned ${JSON.stringify(result) ?? String(result)})`;
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
+ };
244
252
  }
245
253
  /**
246
254
  * A call this job stopped waiting on at its own deadline, as opposed to one the backend failed.
@@ -372,6 +380,10 @@ function buildNext(overall, pkg, budget, runs) {
372
380
  // via `strategy_list` first) where that detail ran; this footer only names the command.
373
381
  return `re-run \`${resumeCommand(pkg, budget)}\` to resume — reconcile re-reads the live list before it creates anything, and what it finds there decides the rest`;
374
382
  case "failed":
383
+ if (runs.some((run) => run.report.steps.create.evidence?.wentLive === true)) {
384
+ return (`Read the [E_PAPER_CREATE_WENT_LIVE] step above and follow it. This report offers no re-run: ` +
385
+ `the MCP turned a simulation into a live strategy, and a re-run can do the same.`);
386
+ }
375
387
  // "Fix the cause, then re-run" is false for exactly one failure on this verb: an install this
376
388
  // deploy stopped WAITING on has no cause to fix — it was never cancelled, and its outcome is
377
389
  // unknown — so the footer that outranks every step line (an agent reads the report's `next`
@@ -576,6 +588,7 @@ export async function runDeploy(params, deps) {
576
588
  * having created, which is not known until the report is assembled.
577
589
  */
578
590
  const soft = { min: null, under: [] };
591
+ let boxCapNote;
579
592
  /** Narration is fire-and-forget: a broken journal must never change what a deploy does. */
580
593
  const emit = (event) => {
581
594
  try {
@@ -1346,8 +1359,13 @@ export async function runDeploy(params, deps) {
1346
1359
  await span("deploy.preflight", { "senpi.deploy.step": "preflight" }, async () => {
1347
1360
  if (!boundaryAbandoned()) {
1348
1361
  try {
1349
- if (!(await refusedOnRuntimeIdHeldByOtherWorld()) && needing.length > 0)
1350
- await runPreflight();
1362
+ if (!(await refusedOnRuntimeIdHeldByOtherWorld())) {
1363
+ if (needing.length > 0)
1364
+ await runPreflight();
1365
+ // Only a warning can come of it here, so a failed read must not refuse the deploy.
1366
+ else
1367
+ await refusedOnBoxRuntimeCap().catch((err) => log(`deploy: box cap read failed: ${errorText(err)}`));
1368
+ }
1351
1369
  }
1352
1370
  catch (err) {
1353
1371
  // A thrown preflight is fail-closed: no balance was proven, so nothing is created.
@@ -1483,15 +1501,36 @@ export async function runDeploy(params, deps) {
1483
1501
  }
1484
1502
  return true;
1485
1503
  }
1504
+ /**
1505
+ * Refuses new wallets past the cap. Adopted wallets that still need a runtime count too, but only
1506
+ * toward a warning ({@link DeployReport.boxCapNote}).
1507
+ */
1486
1508
  async function refusedOnBoxRuntimeCap() {
1487
- const box = await deps.boxRuntimes();
1509
+ const adopted = await adoptedWalletsNeedingRuntime().catch((err) => {
1510
+ log(`deploy: counting adopted wallets for the box cap failed: ${errorText(err)}`);
1511
+ return [];
1512
+ });
1488
1513
  const needed = needing.length;
1489
- if (box.running + needed <= box.cap)
1514
+ if (needed === 0 && adopted.length === 0)
1490
1515
  return false;
1516
+ const box = await deps.boxRuntimes();
1517
+ const replaced = await rowsReplacedByNewWallets();
1518
+ const after = box.running - replaced.length + needed;
1519
+ if (needed === 0 || after <= box.cap) {
1520
+ if (after + adopted.length > box.cap) {
1521
+ boxCapNote = buildAdoptedOverBoxCapNote(adopted, after + adopted.length, box.cap, pkg.paper);
1522
+ log(`deploy: ${boxCapNote}`);
1523
+ }
1524
+ return false;
1525
+ }
1491
1526
  refused = true;
1492
- const detail = buildBoxRuntimeCapRefusal(needed, box, pkg, budget);
1527
+ const detail = buildBoxRuntimeCapRefusal(needed, box, pkg, budget, replaced);
1493
1528
  for (const run of needing) {
1494
- record(run, "preflight", { status: "refused", detail, evidence: { needed, ...box } });
1529
+ record(run, "preflight", {
1530
+ status: "refused",
1531
+ detail,
1532
+ evidence: { needed, ...box, ...(replaced.length > 0 ? { replaced } : {}) },
1533
+ });
1495
1534
  }
1496
1535
  return true;
1497
1536
  }
@@ -1525,6 +1564,40 @@ export async function runDeploy(params, deps) {
1525
1564
  }
1526
1565
  return true;
1527
1566
  }
1567
+ /**
1568
+ * Instances whose existing strategy gets its first runtime on this box: no row on its wallet and
1569
+ * no same-world row on its runtime id (a row on another wallet there is replaced, not added).
1570
+ */
1571
+ async function adoptedWalletsNeedingRuntime() {
1572
+ const names = [];
1573
+ for (const run of installing) {
1574
+ if (run.needsWallet)
1575
+ continue;
1576
+ const wallet = run.report.wallet;
1577
+ if (wallet && (await deps.registryFindByWallet(wallet)))
1578
+ continue;
1579
+ const row = await deps.registryFindById(runtimeIdFor(pkg, run.inst));
1580
+ if (row && !registryRowIsOtherWorld(row, pkg.paper))
1581
+ continue;
1582
+ names.push(run.inst.name);
1583
+ }
1584
+ return names;
1585
+ }
1586
+ /**
1587
+ * Registry rows on a new wallet's runtime id. Install deletes such a row and recreates it on the
1588
+ * new wallet, so it is not a runtime this deploy adds. A row from the other world on that id is
1589
+ * never replaced (install refuses it), so it is not one of them.
1590
+ */
1591
+ async function rowsReplacedByNewWallets() {
1592
+ const replaced = [];
1593
+ for (const run of needing) {
1594
+ const id = runtimeIdFor(pkg, run.inst);
1595
+ const row = await deps.registryFindById(id);
1596
+ if (row && !registryRowIsOtherWorld(row, pkg.paper))
1597
+ replaced.push(id);
1598
+ }
1599
+ return replaced;
1600
+ }
1528
1601
  /**
1529
1602
  * The SOFT calculated-minimum tier. The package-level figure is computed over the WHOLE package
1530
1603
  * (every sleeve's share of a hypothetical fresh deploy) and rides the report as CONTEXT — but the
@@ -1778,7 +1851,8 @@ export async function runDeploy(params, deps) {
1778
1851
  if (probe.routed)
1779
1852
  return true;
1780
1853
  refused = true;
1781
- const detail = buildPaperRoutingUnprovenRefusal(probe.reason);
1854
+ const createdEarlier = needing.filter((other) => other.report.strategyId !== undefined).map((other) => other.inst.name);
1855
+ const detail = buildPaperRoutingUnprovenRefusal(probe.reason, createdEarlier);
1782
1856
  for (const target of [run, ...needing.filter((other) => other !== run && !other.recorded.has("create"))]) {
1783
1857
  if (target.recorded.has("create"))
1784
1858
  continue;
@@ -1788,11 +1862,12 @@ export async function runDeploy(params, deps) {
1788
1862
  }
1789
1863
  /**
1790
1864
  * A paper create returned a LIVE strategy id: the MCP dropped `paper` and created a funded live
1791
- * strategy. Close it by that id at once, before any poll or install, then stop the run. Nothing
1792
- * else is created; the step fails loudly with whether the close went through.
1865
+ * strategy. Nothing else is created and the run stops. The MCP closes only an ACTIVE or PAUSED
1866
+ * strategy, so the job waits for one of those on the ACTIVE poll's budget, closes it by id and
1867
+ * reads it back CLOSED, before any install. The step fails with where that left it.
1793
1868
  *
1794
- * The id is journaled before the close is awaited. A process that dies during the close leaves
1795
- * no other record of it, and paper recovery reads only the paper world.
1869
+ * The id is journaled before the wait. A process that dies during it leaves no other record of
1870
+ * the strategy, and paper recovery reads only the paper world.
1796
1871
  */
1797
1872
  async function stopOnLiveCreate(run, strategyId) {
1798
1873
  wentLive = true;
@@ -1803,23 +1878,50 @@ export async function runDeploy(params, deps) {
1803
1878
  evidence: { instance: run.inst.name, world: "live", unexpectedStrategyId: strategyId },
1804
1879
  });
1805
1880
  log(`deploy: paper create for "${run.inst.name}" returned live strategy ${strategyId} — closing it`);
1806
- let closed = false;
1807
- let closeError;
1808
- try {
1809
- const result = await deps.closeStrategyById(strategyId);
1810
- closed = result.success === true;
1811
- if (!closed)
1812
- closeError = result.message ?? "the close reported no success";
1813
- }
1814
- catch (err) {
1815
- closeError = errorText(err);
1816
- }
1881
+ const cleanup = await closeLiveCreate(strategyId);
1817
1882
  record(run, "create", {
1818
1883
  status: "failed",
1819
- detail: buildPaperCreateWentLiveDetail({ strategyId, closed, ...(closeError ? { closeError } : {}) }),
1820
- evidence: { strategyId, paper: true, closed, ...(closeError ? { closeError } : {}) },
1884
+ detail: buildPaperCreateWentLiveDetail(strategyId, cleanup),
1885
+ evidence: {
1886
+ strategyId,
1887
+ paper: true,
1888
+ wentLive: true,
1889
+ closed: cleanup.kind === "closed",
1890
+ cleanup: cleanup.kind,
1891
+ lastStatus: cleanup.status ?? null,
1892
+ ...(cleanup.kind === "close-failed" ? { closeError: cleanup.reason } : {}),
1893
+ },
1821
1894
  });
1822
1895
  }
1896
+ async function closeLiveCreate(strategyId) {
1897
+ const status = await pollStatus(strategyId, false, (s) => !isInitializing(s));
1898
+ if (status === undefined || (!isClosable(status) && !isClosing(status) && !isDead(status))) {
1899
+ return { kind: "unclosable", ...(status ? { status } : {}) };
1900
+ }
1901
+ if (isDead(status))
1902
+ return { kind: "closed", status };
1903
+ let outcome;
1904
+ if (isClosing(status)) {
1905
+ outcome = await pollUntilClosed(strategyId, { kind: "closing", status, strategyId, result: undefined }, false);
1906
+ }
1907
+ else {
1908
+ try {
1909
+ const accepted = readCloseOutcome(await deps.closeStrategyById(strategyId));
1910
+ outcome = accepted.kind === "closing" ? await pollUntilClosed(strategyId, accepted, false) : accepted;
1911
+ }
1912
+ catch (err) {
1913
+ return { kind: "close-failed", status, reason: errorText(err) };
1914
+ }
1915
+ }
1916
+ switch (outcome.kind) {
1917
+ case "closed":
1918
+ return { kind: "closed", status: "CLOSED" };
1919
+ case "closing":
1920
+ return { kind: "closing", ...(outcome.status ? { status: outcome.status } : {}) };
1921
+ case "failed":
1922
+ return { kind: "close-failed", status, reason: outcome.reason };
1923
+ }
1924
+ }
1823
1925
  /**
1824
1926
  * What the create carries beside attribution (ticket 125): the instance's StrategyFacts and the
1825
1927
  * package's catalog copy. Descriptive only, so it never stops a create: facts that cannot be
@@ -2119,7 +2221,10 @@ export async function runDeploy(params, deps) {
2119
2221
  * A close that cannot run or fails is E_ROLLBACK_INCOMPLETE — a stranded wallet is never silent.
2120
2222
  *
2121
2223
  * D-7: `strategy_close` returns the funds to the owner embedded wallet on its own, so the unwind
2122
- * is one call — there is no separate withdraw step to get half-done.
2224
+ * is one call — there is no separate withdraw step to get half-done. It does so asynchronously,
2225
+ * so the refund is reported only once the strategy reads CLOSED. A close still in progress at
2226
+ * the wait's end is E_ROLLBACK_INCOMPLETE too: the funds are not confirmed back, and that code's
2227
+ * readers already keep the funded figure and defer every other remediation to it.
2123
2228
  */
2124
2229
  async function rollbackWallet(run) {
2125
2230
  await span("deploy.rollback", { "senpi.deploy.step": "rollback" }, () => rollbackWalletBody(run));
@@ -2148,33 +2253,102 @@ export async function runDeploy(params, deps) {
2148
2253
  return "incomplete";
2149
2254
  }
2150
2255
  const result = await deps.closeStrategy(wallet);
2151
- // A resolved close proves nothing on its own: `strategy_close` reports a tool-level failure
2152
- // by RESOLVING `{ success: false }`, never by throwing. Treating that as done zeroed `funded`
2153
- // and told the operator the funds were back while the wallet was still live and funded.
2154
- const closeFailure = describeCloseFailure(result);
2155
- if (closeFailure) {
2156
- incomplete(closeFailure);
2157
- return "incomplete";
2256
+ const accepted = readCloseOutcome(result);
2257
+ const outcome = accepted.kind === "closing"
2258
+ ? await pollUntilClosed(run.report.strategyId ?? accepted.strategyId, accepted, pkg.paper)
2259
+ : accepted;
2260
+ switch (outcome.kind) {
2261
+ case "failed":
2262
+ incomplete(outcome.reason);
2263
+ return "incomplete";
2264
+ case "closing":
2265
+ recordClosePending(run, outcome);
2266
+ return "incomplete";
2267
+ case "closed": {
2268
+ // The structured facts the report leads with must agree with the step detail: this wallet
2269
+ // is closed and the funds are back with the owner, so it is no longer a funded wallet. The
2270
+ // amount survives in the step evidence, where it reads as history rather than as a holding.
2271
+ const fundedBeforeRollback = run.report.funded;
2272
+ run.report.funded = 0;
2273
+ run.report.rolledBack = true;
2274
+ record(run, "create", {
2275
+ status: "ok",
2276
+ detail: `wallet ${wallet} was created by this deploy and its install failed — rolled back: strategy ` +
2277
+ `closed, funds returned to the owner wallet (close result: ${JSON.stringify(result)})`,
2278
+ evidence: { wallet, funded: fundedBeforeRollback, rolledBack: true, closeResult: result },
2279
+ });
2280
+ return "ok";
2281
+ }
2158
2282
  }
2159
- // The structured facts the report leads with must agree with the step detail: this wallet is
2160
- // closed and the funds are back with the owner, so it is no longer a funded wallet. The
2161
- // amount survives in the step evidence, where it reads as history rather than as a holding.
2162
- const fundedBeforeRollback = run.report.funded;
2163
- run.report.funded = 0;
2164
- run.report.rolledBack = true;
2165
- record(run, "create", {
2166
- status: "ok",
2167
- detail: `wallet ${wallet} was created by this deploy and its install failed — rolled back: strategy ` +
2168
- `closed, funds returned to the owner wallet (close result: ${JSON.stringify(result)})`,
2169
- evidence: { wallet, funded: fundedBeforeRollback, rolledBack: true, closeResult: result },
2170
- });
2171
- return "ok";
2172
2283
  }
2173
2284
  catch (err) {
2174
2285
  incomplete(errorText(err));
2175
2286
  return "incomplete";
2176
2287
  }
2177
2288
  }
2289
+ /**
2290
+ * Read an accepted close back until the strategy is CLOSED. A read that throws is not a CLOSED
2291
+ * read, so it only costs one poll.
2292
+ */
2293
+ async function pollUntilClosed(strategyId, closing, paper) {
2294
+ if (strategyId === undefined)
2295
+ return closing;
2296
+ const status = (await pollStatus(strategyId, paper, (s) => s.toUpperCase() === "CLOSED")) ?? closing.status;
2297
+ return status?.toUpperCase() === "CLOSED" ? { kind: "closed", result: closing.result } : { ...closing, strategyId, status };
2298
+ }
2299
+ /**
2300
+ * Read one strategy's status until `settled` holds, on the ACTIVE poll's budget and cadence
2301
+ * (`--max-wait`, {@link CREATE_POLL_MS}) and the job's deadline. Resolves the last status read,
2302
+ * undefined when no read returned one.
2303
+ */
2304
+ async function pollStatus(strategyId, paper, settled) {
2305
+ const deadline = deps.now() + maxWaitSec * 1000;
2306
+ let status;
2307
+ for (;;) {
2308
+ try {
2309
+ const [live] = await deps.listStrategies({ paper, strategyIds: [strategyId] });
2310
+ if (live?.status)
2311
+ status = live.status;
2312
+ }
2313
+ catch (err) {
2314
+ log(`deploy: reading strategy ${strategyId} failed: ${errorText(err)}`);
2315
+ }
2316
+ if (status !== undefined && settled(status))
2317
+ return status;
2318
+ if (deps.now() >= deadline || deps.shouldAbandon())
2319
+ return status;
2320
+ await deps.sleep(CREATE_POLL_MS);
2321
+ }
2322
+ }
2323
+ /**
2324
+ * The close was accepted and never read back CLOSED. The funds may still be in the wallet, so
2325
+ * `funded` stays and nothing claims the refund. The follow-up starts with a status read, because
2326
+ * a second `strategy_close` on a closing strategy is only a no-op.
2327
+ */
2328
+ function recordClosePending(run, closing) {
2329
+ const wallet = run.report.wallet;
2330
+ const strategy = closing.strategyId ? `strategy ${closing.strategyId}` : `the strategy on wallet ${wallet}`;
2331
+ const read = closing.status ? `still read ${closing.status}` : "reported no status";
2332
+ record(run, "create", {
2333
+ status: "failed",
2334
+ detail: `[E_ROLLBACK_INCOMPLETE] wallet ${wallet} was created by this deploy and ` +
2335
+ `${rollbackFundedClause(run.report.funded)}, its install failed, and the automatic close was ` +
2336
+ `accepted but not confirmed: ${strategy} ${read} when this deploy stopped waiting for CLOSED. ` +
2337
+ `The funds are NOT confirmed back with the owner wallet. Read ${strategy} with MCP ` +
2338
+ `\`strategy_list\`: CLOSED means the funds are back and nothing is left to do. ACTIVE or ` +
2339
+ `PAUSED means the close did not take, so run MCP \`strategy_close\` on ` +
2340
+ `${wallet}${buildStrandedCloseCaveat(pkg, runs, run)} Any other status is a close still in ` +
2341
+ `progress: read it again later.`,
2342
+ evidence: {
2343
+ wallet,
2344
+ strategyId: closing.strategyId,
2345
+ funded: run.report.funded,
2346
+ close: "closing",
2347
+ lastStatus: closing.status ?? null,
2348
+ closeResult: closing.result,
2349
+ },
2350
+ });
2351
+ }
2178
2352
  // ── observe ───────────────────────────────────────────────────────────────
2179
2353
  const observable = runs.filter((run) => run.report.runtimeId && ["ok", "skipped"].includes(run.report.steps.install.status));
2180
2354
  if (!halted() && observable.length > 0) {
@@ -2457,6 +2631,7 @@ export async function runDeploy(params, deps) {
2457
2631
  ...(unreadableFunded.length > 0
2458
2632
  ? { fundedUnreadableNote: buildFundedUnreadableNote(pkg, unreadableFunded, reassures()) }
2459
2633
  : {}),
2634
+ ...(boxCapNote ? { boxCapNote } : {}),
2460
2635
  };
2461
2636
  }
2462
2637
  /**