@senpi/runtime 3.0.210 → 3.0.213

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 (77) hide show
  1. package/dist/cli/deploy-render.d.ts +14 -0
  2. package/dist/cli/deploy-render.d.ts.map +1 -1
  3. package/dist/cli/deploy-render.js +5 -0
  4. package/dist/cli/deploy-render.js.map +1 -1
  5. package/dist/cli/guide-commands.d.ts.map +1 -1
  6. package/dist/cli/guide-commands.js +4 -0
  7. package/dist/cli/guide-commands.js.map +1 -1
  8. package/dist/cli/senpi-commands.d.ts.map +1 -1
  9. package/dist/cli/senpi-commands.js +2 -1
  10. package/dist/cli/senpi-commands.js.map +1 -1
  11. package/dist/cli/update-command.d.ts +3 -1
  12. package/dist/cli/update-command.d.ts.map +1 -1
  13. package/dist/cli/update-command.js +9 -1
  14. package/dist/cli/update-command.js.map +1 -1
  15. package/dist/cli/validate-command.d.ts.map +1 -1
  16. package/dist/cli/validate-command.js +2 -0
  17. package/dist/cli/validate-command.js.map +1 -1
  18. package/dist/deploy/deadlines.d.ts +11 -3
  19. package/dist/deploy/deadlines.d.ts.map +1 -1
  20. package/dist/deploy/deadlines.js +18 -4
  21. package/dist/deploy/deadlines.js.map +1 -1
  22. package/dist/deploy/messages.d.ts +48 -1
  23. package/dist/deploy/messages.d.ts.map +1 -1
  24. package/dist/deploy/messages.js +72 -4
  25. package/dist/deploy/messages.js.map +1 -1
  26. package/dist/deploy/orchestrator.d.ts +17 -3
  27. package/dist/deploy/orchestrator.d.ts.map +1 -1
  28. package/dist/deploy/orchestrator.js +188 -137
  29. package/dist/deploy/orchestrator.js.map +1 -1
  30. package/dist/deploy/package.d.ts.map +1 -1
  31. package/dist/deploy/package.js +6 -2
  32. package/dist/deploy/package.js.map +1 -1
  33. package/dist/deploy/register.d.ts.map +1 -1
  34. package/dist/deploy/register.js +2 -0
  35. package/dist/deploy/register.js.map +1 -1
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +4 -0
  38. package/dist/index.js.map +1 -1
  39. package/dist/runtime/update-handler.d.ts +6 -0
  40. package/dist/runtime/update-handler.d.ts.map +1 -1
  41. package/dist/runtime/update-handler.js +14 -3
  42. package/dist/runtime/update-handler.js.map +1 -1
  43. package/dist/runtime/update-register.d.ts +3 -1
  44. package/dist/runtime/update-register.d.ts.map +1 -1
  45. package/dist/runtime/update-register.js.map +1 -1
  46. package/dist/runtime/update-report.d.ts +5 -0
  47. package/dist/runtime/update-report.d.ts.map +1 -1
  48. package/dist/runtime/update-report.js +7 -0
  49. package/dist/runtime/update-report.js.map +1 -1
  50. package/dist/scanners/external/scaffold/preflight.py +6 -5
  51. package/dist/senpi/__tests__/helpers/fake-paper-mcp.d.ts +2 -2
  52. package/dist/senpi/__tests__/helpers/fake-paper-mcp.d.ts.map +1 -1
  53. package/dist/senpi/__tests__/helpers/fake-paper-mcp.js +1 -1
  54. package/dist/senpi/__tests__/helpers/fake-paper-mcp.js.map +1 -1
  55. package/dist/senpi/strategy-status.d.ts +8 -0
  56. package/dist/senpi/strategy-status.d.ts.map +1 -1
  57. package/dist/senpi/strategy-status.js +12 -0
  58. package/dist/senpi/strategy-status.js.map +1 -1
  59. package/dist/senpi/types.d.ts +1 -1
  60. package/dist/validate/index.d.ts +1 -1
  61. package/dist/validate/index.d.ts.map +1 -1
  62. package/dist/validate/index.js +1 -1
  63. package/dist/validate/index.js.map +1 -1
  64. package/dist/validate/live-stage.d.ts +6 -2
  65. package/dist/validate/live-stage.d.ts.map +1 -1
  66. package/dist/validate/live-stage.js +26 -7
  67. package/dist/validate/live-stage.js.map +1 -1
  68. package/dist/validate/proof.d.ts +8 -0
  69. package/dist/validate/proof.d.ts.map +1 -1
  70. package/dist/validate/proof.js +19 -2
  71. package/dist/validate/proof.js.map +1 -1
  72. package/dist/validate/run.d.ts +17 -4
  73. package/dist/validate/run.d.ts.map +1 -1
  74. package/dist/validate/run.js +81 -17
  75. package/dist/validate/run.js.map +1 -1
  76. package/openclaw.plugin.json +1 -1
  77. package/package.json +1 -1
@@ -1,6 +1,7 @@
1
- import type { StrategyLimits, StrategySummary } from "../senpi/types.js";
1
+ import type { StrategyCloseResult, StrategyLimits, StrategySummary } from "../senpi/types.js";
2
2
  import { type StrategyCatalogCopy, type StrategyFacts } from "../strategy/facts.js";
3
3
  import { type DeployPackage } from "./package.js";
4
+ import type { MeasureOutcome, ScannerMeasurement, UnmeasuredScanner } from "../validate/index.js";
4
5
  export type JobPhase = "reconcile" | "preflight" | "create" | "install" | "observe";
5
6
  export type StepName = "reconcile" | "preflight" | "create" | "install" | "observe";
6
7
  export type StepStatus = "ok" | "skipped" | "pending" | "refused" | "failed" | "unobserved";
@@ -136,6 +137,11 @@ export interface DeployDeps {
136
137
  getScannerRows(runtimeId: string): Promise<ScannerRowLite[] | null>;
137
138
  /** H4: the registry row exists AND its `run()` handle is alive — a row alone proves nothing. */
138
139
  runtimeIsLive(id: string): Promise<boolean>;
140
+ /**
141
+ * Measure every scanner the proof beside this recipe has no size for, and record the size on
142
+ * that proof (`measureProof` in validate). Paper deploys only. Never refuses.
143
+ */
144
+ measureProof(recipeDir: string): Promise<MeasureOutcome>;
139
145
  /**
140
146
  * Is an install on this wallet running RIGHT NOW inside the gateway (`index.ts` installsInFlight)?
141
147
  *
@@ -160,13 +166,13 @@ export interface DeployDeps {
160
166
  * strategy_close via client.closeStrategy(wallet) — returns funds to the owner wallet on its own
161
167
  * (D-7), once the strategy reaches CLOSED. Resolves the client's `StrategyCloseResult`.
162
168
  */
163
- closeStrategy(wallet: string): Promise<unknown>;
169
+ closeStrategy(wallet: string): Promise<StrategyCloseResult>;
164
170
  /**
165
171
  * strategy_close by strategy id (client.closeStrategyById), live world. Only for a paper create
166
172
  * the MCP turned into a live strategy, closed by the id the create returned once it is closable.
167
173
  * Resolves the client's `StrategyCloseResult`.
168
174
  */
169
- closeStrategyById(strategyId: string): Promise<unknown>;
175
+ closeStrategyById(strategyId: string): Promise<StrategyCloseResult>;
170
176
  /** narration only — journaled by job.ts; MUST NOT affect flow */
171
177
  emit(event: DeployEventBody): void;
172
178
  /**
@@ -307,6 +313,14 @@ export interface DeployReport {
307
313
  * a pending decision, so this never changes `overall`.
308
314
  */
309
315
  boxCapNote?: string;
316
+ /** Paper only: what this deploy measured for the simulation's size, per instance and scanner. */
317
+ measurements?: (ScannerMeasurement & {
318
+ instance: string;
319
+ })[];
320
+ /** Paper only: scanners this deploy tried to measure and could not, with the reason. Never blocks. */
321
+ unmeasured?: (UnmeasuredScanner & {
322
+ instance: string;
323
+ })[];
310
324
  }
311
325
  /**
312
326
  * 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;AAwGtB,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;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C,EAAE,CAAC;CAC3D;AA6fD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAE1F;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAEpG;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,QAAQ,CAAC,CAAC,EAC9B,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,EAC1B,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,EAC3B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACrB,OAAO,CAAC,CAAC,CAAC,CAkBZ;AA+BD;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,iBAAiB,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAEvF;AAED;;;;GAIG;AACH,wBAAsB,SAAS,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC,CAwsE7F"}
@@ -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.
@@ -589,6 +612,8 @@ export async function runDeploy(params, deps) {
589
612
  */
590
613
  const soft = { min: null, under: [] };
591
614
  let boxCapNote;
615
+ const measurements = [];
616
+ const unmeasured = [];
592
617
  /** Narration is fire-and-forget: a broken journal must never change what a deploy does. */
593
618
  const emit = (event) => {
594
619
  try {
@@ -978,6 +1003,24 @@ export async function runDeploy(params, deps) {
978
1003
  return "refused";
979
1004
  });
980
1005
  }
1006
+ if (pkg.paper && !halted()) {
1007
+ await span("deploy.measure", { "senpi.deploy.step": "measure" }, async () => {
1008
+ for (const inst of pkg.instances) {
1009
+ if (boundaryAbandoned())
1010
+ return "skipped";
1011
+ const outcome = await deps.measureProof(inst.runtimeYamlDir);
1012
+ for (const m of outcome.measured) {
1013
+ measurements.push({ instance: inst.name, ...m });
1014
+ emitPhase("reconcile", `measured ${m.scanner} (${inst.name}): ${describeMeasurement(m)}`);
1015
+ }
1016
+ for (const u of outcome.unmeasured) {
1017
+ unmeasured.push({ instance: inst.name, ...u });
1018
+ emitPhase("reconcile", `not measured ${u.scanner} (${inst.name}): ${u.reason}`);
1019
+ }
1020
+ }
1021
+ return "ok";
1022
+ });
1023
+ }
981
1024
  // S-1 (user rulings 2026-08-07): the live-universe gate — the deploy-side consumer of the
982
1025
  // reusable `checkPackageUniverse` (universe.ts owns the decision; this block only records it).
983
1026
  // A dead hardcoded name does not error — the scan skips it and the strategy silently trades
@@ -1912,32 +1955,47 @@ export async function runDeploy(params, deps) {
1912
1955
  });
1913
1956
  }
1914
1957
  async function closeLiveCreate(strategyId) {
1915
- const status = await pollStatus(strategyId, false, (s) => !isInitializing(s));
1916
- if (status === undefined || (!isClosable(status) && !isClosing(status) && !isDead(status))) {
1917
- return { kind: "unclosable", ...(status ? { status } : {}) };
1918
- }
1919
- if (isDead(status))
1920
- return { kind: "closed", status };
1921
- let outcome;
1922
- if (isClosing(status)) {
1923
- outcome = await pollUntilClosed(strategyId, { kind: "closing", status, strategyId, result: undefined }, false);
1924
- }
1925
- else {
1926
- try {
1927
- const accepted = readCloseOutcome(await deps.closeStrategyById(strategyId));
1928
- outcome = accepted.kind === "closing" ? await pollUntilClosed(strategyId, accepted, false) : accepted;
1929
- }
1930
- catch (err) {
1931
- 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;
1932
1982
  }
1983
+ default:
1984
+ return settledLiveCreate(status);
1933
1985
  }
1934
- switch (outcome.kind) {
1935
- case "closed":
1936
- return { kind: "closed", status: "CLOSED" };
1986
+ if (after === undefined)
1987
+ return { kind: "closing" };
1988
+ switch (classifyCloseRead(after)) {
1937
1989
  case "closing":
1938
- return { kind: "closing", ...(outcome.status ? { status: outcome.status } : {}) };
1939
- case "failed":
1940
- 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);
1941
1999
  }
1942
2000
  }
1943
2001
  /**
@@ -2240,9 +2298,10 @@ export async function runDeploy(params, deps) {
2240
2298
  *
2241
2299
  * D-7: `strategy_close` returns the funds to the owner embedded wallet on its own, so the unwind
2242
2300
  * is one call — there is no separate withdraw step to get half-done. It does so asynchronously,
2243
- * so the refund is reported only once the strategy reads CLOSED. A close still in progress at
2244
- * the wait's end is E_ROLLBACK_INCOMPLETE too: the funds are not confirmed back, and that code's
2245
- * 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.
2246
2305
  */
2247
2306
  async function rollbackWallet(run) {
2248
2307
  await span("deploy.rollback", { "senpi.deploy.step": "rollback" }, () => rollbackWalletBody(run));
@@ -2250,123 +2309,110 @@ export async function runDeploy(params, deps) {
2250
2309
  /** Resolves with the rollback's result — the wiring turns it into `senpi.deploy.rollback.count`. */
2251
2310
  async function rollbackWalletBody(run) {
2252
2311
  const wallet = run.report.wallet;
2253
- const funded = rollbackFundedClause(run.report.funded);
2254
2312
  emit({
2255
2313
  type: "job",
2256
2314
  phase: "install",
2257
- detail: `install failed on wallet ${wallet}, which this job created and ${funded} — ` +
2258
- `closing it and returning the funds`,
2259
- });
2260
- const incomplete = (reason) => record(run, "create", {
2261
- status: "failed",
2262
- detail: `[E_ROLLBACK_INCOMPLETE] wallet ${wallet} was created by this deploy and ${funded}, ` +
2263
- `its install failed, and the automatic close did not complete: ${reason}. The wallet is ` +
2264
- `live and unwatched. Reclaim the funds from THIS wallet: MCP \`strategy_close\` on ` +
2265
- `${wallet}${buildStrandedCloseCaveat(pkg, runs, run)}`,
2266
- 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`,
2267
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
+ };
2268
2335
  try {
2269
2336
  if (!(await deps.walletIsFlat(wallet))) {
2270
- incomplete("the wallet holds open positions — refusing to auto-close");
2271
- return "incomplete";
2272
- }
2273
- const result = await deps.closeStrategy(wallet);
2274
- const accepted = readCloseOutcome(result);
2275
- const outcome = accepted.kind === "closing"
2276
- ? await pollUntilClosed(run.report.strategyId ?? accepted.strategyId, accepted, pkg.paper)
2277
- : accepted;
2278
- switch (outcome.kind) {
2279
- case "failed":
2280
- incomplete(outcome.reason);
2281
- return "incomplete";
2282
- case "closing":
2283
- recordClosePending(run, outcome);
2284
- return "incomplete";
2285
- case "closed": {
2286
- // The structured facts the report leads with must agree with the step detail: this wallet
2287
- // is closed and the funds are back with the owner, so it is no longer a funded wallet. The
2288
- // amount survives in the step evidence, where it reads as history rather than as a holding.
2289
- const fundedBeforeRollback = run.report.funded;
2290
- run.report.funded = 0;
2291
- run.report.rolledBack = true;
2292
- record(run, "create", {
2293
- status: "ok",
2294
- detail: `wallet ${wallet} was created by this deploy and its install failed — rolled back: strategy ` +
2295
- `closed, funds returned to the owner wallet (close result: ${JSON.stringify(result)})`,
2296
- evidence: { wallet, funded: fundedBeforeRollback, rolledBack: true, closeResult: result },
2297
- });
2298
- return "ok";
2299
- }
2337
+ return incomplete({ kind: "live", reason: "the wallet holds open positions — refusing to auto-close" });
2300
2338
  }
2301
2339
  }
2302
2340
  catch (err) {
2303
- incomplete(errorText(err));
2304
- return "incomplete";
2341
+ return incomplete({ kind: "live", reason: errorText(err) });
2342
+ }
2343
+ try {
2344
+ close = await deps.closeStrategy(wallet);
2305
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";
2306
2371
  }
2307
2372
  /**
2308
- * Read an accepted close back until the strategy is CLOSED. A read that throws is not a CLOSED
2309
- * 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.
2310
2377
  */
2311
- async function pollUntilClosed(strategyId, closing, paper) {
2378
+ async function pollWhileClosing(strategyId, status, paper) {
2312
2379
  if (strategyId === undefined)
2313
- return closing;
2314
- const status = (await pollStatus(strategyId, paper, (s) => s.toUpperCase() === "CLOSED")) ?? closing.status;
2315
- 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
+ });
2316
2387
  }
2317
2388
  /**
2318
- * Read one strategy's status until `settled` holds, on the ACTIVE poll's budget and cadence
2319
- * (`--max-wait`, {@link CREATE_POLL_MS}) and the job's deadline. Resolves the last status read,
2320
- * 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`.
2321
2392
  */
2322
- async function pollStatus(strategyId, paper, settled) {
2323
- const deadline = deps.now() + maxWaitSec * 1000;
2324
- let status;
2393
+ async function pollStatus(strategyId, poll) {
2394
+ const deadline = deps.now() + poll.budgetMs;
2395
+ let status = poll.status;
2325
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;
2326
2401
  try {
2327
- const [live] = await deps.listStrategies({ paper, strategyIds: [strategyId] });
2402
+ const [live] = await deps.listStrategies({ paper: poll.paper, strategyIds: [strategyId] });
2328
2403
  if (live?.status)
2329
2404
  status = live.status;
2330
2405
  }
2331
2406
  catch (err) {
2332
2407
  log(`deploy: reading strategy ${strategyId} failed: ${errorText(err)}`);
2333
2408
  }
2334
- if (status !== undefined && settled(status))
2409
+ if (status !== undefined && poll.settled(status))
2335
2410
  return status;
2336
- if (deps.now() >= deadline || deps.shouldAbandon())
2411
+ if (deps.now() >= deadline)
2337
2412
  return status;
2338
2413
  await deps.sleep(CREATE_POLL_MS);
2339
2414
  }
2340
2415
  }
2341
- /**
2342
- * The close was accepted and never read back CLOSED. The funds may still be in the wallet, so
2343
- * `funded` stays and nothing claims the refund. The follow-up starts with a status read, because
2344
- * a second `strategy_close` on a closing strategy is only a no-op.
2345
- */
2346
- function recordClosePending(run, closing) {
2347
- const wallet = run.report.wallet;
2348
- const strategy = closing.strategyId ? `strategy ${closing.strategyId}` : `the strategy on wallet ${wallet}`;
2349
- const read = closing.status ? `still read ${closing.status}` : "reported no status";
2350
- record(run, "create", {
2351
- status: "failed",
2352
- detail: `[E_ROLLBACK_INCOMPLETE] wallet ${wallet} was created by this deploy and ` +
2353
- `${rollbackFundedClause(run.report.funded)}, its install failed, and the automatic close was ` +
2354
- `accepted but not confirmed: ${strategy} ${read} when this deploy stopped waiting for CLOSED. ` +
2355
- `The funds are NOT confirmed back with the owner wallet. Read ${strategy} with MCP ` +
2356
- `\`strategy_list\`: CLOSED means the funds are back and nothing is left to do. ACTIVE or ` +
2357
- `PAUSED means the close did not take, so run MCP \`strategy_close\` on ` +
2358
- `${wallet}${buildStrandedCloseCaveat(pkg, runs, run)} Any other status is a close still in ` +
2359
- `progress: read it again later.`,
2360
- evidence: {
2361
- wallet,
2362
- strategyId: closing.strategyId,
2363
- funded: run.report.funded,
2364
- close: "closing",
2365
- lastStatus: closing.status ?? null,
2366
- closeResult: closing.result,
2367
- },
2368
- });
2369
- }
2370
2416
  // ── observe ───────────────────────────────────────────────────────────────
2371
2417
  const observable = runs.filter((run) => run.report.runtimeId && ["ok", "skipped"].includes(run.report.steps.install.status));
2372
2418
  if (!halted() && observable.length > 0) {
@@ -2650,8 +2696,13 @@ export async function runDeploy(params, deps) {
2650
2696
  ? { fundedUnreadableNote: buildFundedUnreadableNote(pkg, unreadableFunded, reassures()) }
2651
2697
  : {}),
2652
2698
  ...(boxCapNote ? { boxCapNote } : {}),
2699
+ ...(measurements.length > 0 ? { measurements } : {}),
2700
+ ...(unmeasured.length > 0 ? { unmeasured } : {}),
2653
2701
  };
2654
2702
  }
2703
+ function describeMeasurement(m) {
2704
+ return `peak ${m.peak_rss_mb} MB, ${m.cpu_seconds_per_tick} CPU s/tick, ${m.calls_per_tick} calls/tick`;
2705
+ }
2655
2706
  /**
2656
2707
  * Refusals and abandonment outrank outcomes, and an unobserved tick can never
2657
2708
  * read as success — the precedence order is the fail-closed one.