@sema-agent/server 7.150.0 → 7.151.0

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 (341) hide show
  1. package/MIGRATION.md +185 -0
  2. package/USAGE.md +53 -25
  3. package/deploy/sema-up/README.md +7 -1
  4. package/deploy/sema-up/chart/Chart.yaml +1 -1
  5. package/deploy/sema-up/chart/templates/NOTES.txt +5 -0
  6. package/deploy/sema-up/chart/templates/_helpers.tpl +15 -16
  7. package/deploy/sema-up/chart/templates/server-v4pro.yaml +5 -3
  8. package/deploy/sema-up/chart/templates/server.yaml +5 -3
  9. package/deploy/sema-up/chart/values-full-single.yaml +3 -1
  10. package/deploy/sema-up/chart/values.yaml +8 -1
  11. package/deploy/sema-up/cluster-up.sh +1 -0
  12. package/deploy/sema-up/kube-up.sh +1 -1
  13. package/deploy/sema-up/lib/flagshape.sh +1 -1
  14. package/deploy/sema-up/lib/helm-values-cluster.py +2 -0
  15. package/deploy/sema-up/lib/helm-values-kube.py +2 -0
  16. package/dist/adoption/import.js +3 -3
  17. package/dist/approval-ask-machine.d.ts +1 -1
  18. package/dist/approval-card.d.ts +2 -2
  19. package/dist/approval-gate-currency.d.ts +1 -1
  20. package/dist/auth-bridge.d.ts +20 -0
  21. package/dist/auth-bridge.js +9 -0
  22. package/dist/background-session-reap.d.ts +1 -1
  23. package/dist/bake-runner/main.d.ts +4 -2
  24. package/dist/bind-host.d.ts +2 -3
  25. package/dist/bind-host.js +2 -4
  26. package/dist/boot/budget-tracing.js +1 -1
  27. package/dist/boot/engine-lease.d.ts +5 -0
  28. package/dist/boot/engine-lease.js +1 -0
  29. package/dist/boot/execution-env.d.ts +8 -14
  30. package/dist/boot/execution-env.js +54 -17
  31. package/dist/boot/execution-lane.js +32 -5
  32. package/dist/boot/late-binds.d.ts +8 -4
  33. package/dist/boot/late-binds.js +7 -1
  34. package/dist/boot/memory-consolidation.d.ts +3 -2
  35. package/dist/boot/memory-consolidation.js +6 -6
  36. package/dist/boot/reapers.d.ts +5 -0
  37. package/dist/boot/reapers.js +12 -1
  38. package/dist/boot/resolve-spec.d.ts +3 -3
  39. package/dist/boot/resolve-spec.js +31 -22
  40. package/dist/boot/runner-deps.d.ts +9 -2
  41. package/dist/boot/runner-deps.js +3 -3
  42. package/dist/boot/session-age-out.d.ts +36 -0
  43. package/dist/boot/session-age-out.js +101 -0
  44. package/dist/boot/session-faces.d.ts +5 -14
  45. package/dist/boot/session-faces.js +9 -5
  46. package/dist/boot/stage-01-config.js +2 -0
  47. package/dist/boot/stage-05-execution-env.d.ts +5 -3
  48. package/dist/boot/stage-05-execution-env.js +2 -2
  49. package/dist/boot/stage-06-runners.d.ts +7 -4
  50. package/dist/boot/stage-06-runners.js +15 -6
  51. package/dist/boot/stage-07-capability-layer.d.ts +7 -4
  52. package/dist/boot/stage-07-capability-layer.js +2 -1
  53. package/dist/boot/stage-08-reapers.d.ts +7 -4
  54. package/dist/boot/stage-08-reapers.js +4 -2
  55. package/dist/boot/stage-09-leader.d.ts +11 -5
  56. package/dist/boot/stage-09-leader.js +12 -3
  57. package/dist/boot/stage-10-http-server.d.ts +11 -5
  58. package/dist/boot/stage-10-http-server.js +3 -6
  59. package/dist/boot/web-admin.js +3 -1
  60. package/dist/boot/workflow-orchestration.d.ts +7 -2
  61. package/dist/boot/workflow-orchestration.js +24 -7
  62. package/dist/bounded-rotation.d.ts +29 -0
  63. package/dist/bounded-rotation.js +24 -0
  64. package/dist/capability-facts.d.ts +22 -13
  65. package/dist/capability-facts.js +28 -18
  66. package/dist/center-credential.d.ts +25 -6
  67. package/dist/center-credential.js +25 -5
  68. package/dist/config-catalog.d.ts +26 -7
  69. package/dist/config-catalog.js +14 -11
  70. package/dist/config-invariants.d.ts +2 -1
  71. package/dist/config-invariants.js +4 -4
  72. package/dist/config-types.d.ts +10 -4
  73. package/dist/config.d.ts +51 -2
  74. package/dist/config.js +35 -24
  75. package/dist/deployment-shape.d.ts +9 -1
  76. package/dist/deployment-shape.js +2 -1
  77. package/dist/device-protocol.d.ts +5 -4
  78. package/dist/device-protocol.js +1 -1
  79. package/dist/device-ws-hub.js +3 -2
  80. package/dist/device-ws-protocol.d.ts +63 -10
  81. package/dist/device-ws-protocol.js +56 -25
  82. package/dist/engine-identity.d.ts +19 -7
  83. package/dist/engine-identity.js +10 -2
  84. package/dist/entry-mode-clamp-notice.d.ts +2 -1
  85. package/dist/execution-env-refusal.d.ts +23 -0
  86. package/dist/execution-env-refusal.js +5 -0
  87. package/dist/execution-lane-caps.d.ts +3 -1
  88. package/dist/field-conflict.d.ts +1 -1
  89. package/dist/file-history-capture.d.ts +11 -4
  90. package/dist/file-history-capture.js +9 -6
  91. package/dist/file-history-disclosure.d.ts +7 -5
  92. package/dist/file-history-disclosure.js +7 -5
  93. package/dist/fleet/drain-entry.d.ts +4 -0
  94. package/dist/hooks/hook-runner.js +2 -2
  95. package/dist/host-lsp-manager.d.ts +2 -2
  96. package/dist/http/admission.js +17 -2
  97. package/dist/http/approval-sweeps.js +5 -5
  98. package/dist/http/checkpoint-ctx.d.ts +2 -0
  99. package/dist/http/checkpoint-ctx.js +1 -0
  100. package/dist/http/dispatch.d.ts +2 -1
  101. package/dist/http/dispatch.js +34 -27
  102. package/dist/http/durable-run-leg.js +16 -16
  103. package/dist/http/health-self-report.d.ts +9 -1
  104. package/dist/http/health-self-report.js +2 -0
  105. package/dist/http/owner-access.d.ts +31 -11
  106. package/dist/http/owner-access.js +37 -6
  107. package/dist/http/resume-ctx-read.js +25 -3
  108. package/dist/http/resume-legs.d.ts +2 -1
  109. package/dist/http/resume-legs.js +259 -79
  110. package/dist/http/route-ctx.d.ts +18 -8
  111. package/dist/http/route-table.d.ts +1 -1
  112. package/dist/http/routes/admin-memory-optout.d.ts +1 -1
  113. package/dist/http/routes/agents-roster.js +2 -3
  114. package/dist/http/routes/approvals-assistant.js +4 -3
  115. package/dist/http/routes/background.d.ts +3 -3
  116. package/dist/http/routes/capabilities.js +8 -5
  117. package/dist/http/routes/fleet.js +10 -8
  118. package/dist/http/routes/projects.d.ts +3 -2
  119. package/dist/http/routes/projects.js +4 -5
  120. package/dist/http/routes/runs.js +102 -36
  121. package/dist/http/routes/session-sync.d.ts +4 -3
  122. package/dist/http/routes/session-sync.js +172 -77
  123. package/dist/http/routes/sessions-list.js +13 -7
  124. package/dist/http/routes/sessions.js +10 -6
  125. package/dist/http/routes/tasks.js +30 -16
  126. package/dist/http/routes/trace-usage.js +2 -2
  127. package/dist/http/server.d.ts +21 -27
  128. package/dist/http/server.js +2 -2
  129. package/dist/http/submit-ctx.js +5 -4
  130. package/dist/http/wire-types.d.ts +14 -4
  131. package/dist/identity-source.d.ts +20 -3
  132. package/dist/identity-source.js +14 -0
  133. package/dist/index.d.ts +4 -0
  134. package/dist/lane-home-probe.d.ts +3 -7
  135. package/dist/lane-home-probe.js +0 -1
  136. package/dist/leader/leader.d.ts +2 -1
  137. package/dist/leg-facts.d.ts +13 -5
  138. package/dist/leg-facts.js +2 -1
  139. package/dist/memory-scope.d.ts +5 -4
  140. package/dist/memory-scope.js +4 -4
  141. package/dist/memory-sync-client.d.ts +30 -2
  142. package/dist/memory-sync-client.js +16 -9
  143. package/dist/observability/err-text.d.ts +7 -0
  144. package/dist/observability/err-text.js +5 -0
  145. package/dist/observability/fail-open.d.ts +7 -3
  146. package/dist/observability/fail-open.js +7 -3
  147. package/dist/observability/metrics.js +1 -0
  148. package/dist/orchestration/workflow-notify-journal.d.ts +18 -1
  149. package/dist/orchestration/workflow-notify-journal.js +12 -1
  150. package/dist/orchestration/workflow-park-decision.d.ts +70 -18
  151. package/dist/orchestration/workflow-park-decision.js +49 -10
  152. package/dist/orchestration/workflow-park-holder.d.ts +65 -0
  153. package/dist/orchestration/workflow-park-holder.js +98 -0
  154. package/dist/orchestration/workflow-record-fence.d.ts +36 -0
  155. package/dist/orchestration/workflow-record-fence.js +42 -0
  156. package/dist/owner-faces.d.ts +1 -1
  157. package/dist/parked-decide.d.ts +104 -53
  158. package/dist/parked-decide.js +153 -117
  159. package/dist/peer-directory.d.ts +2 -2
  160. package/dist/peer-inbound-face.d.ts +2 -6
  161. package/dist/peer-inbound-face.js +0 -3
  162. package/dist/permission-mode-admission.d.ts +41 -5
  163. package/dist/permission-mode-admission.js +29 -3
  164. package/dist/plugins/adoption-log-sql.d.ts +3 -1
  165. package/dist/plugins/adoption-log-sql.js +7 -1
  166. package/dist/plugins/approval-ask-store-file.d.ts +10 -2
  167. package/dist/plugins/approval-ask-store-file.js +8 -0
  168. package/dist/plugins/approval-ask-store-memory.d.ts +6 -1
  169. package/dist/plugins/approval-ask-store-memory.js +28 -9
  170. package/dist/plugins/approval-ask-store-sql.d.ts +43 -2
  171. package/dist/plugins/approval-ask-store-sql.js +34 -5
  172. package/dist/plugins/approval-exemption-store.js +3 -0
  173. package/dist/plugins/approval-nonce-store.js +2 -0
  174. package/dist/plugins/breaker-state-sql.js +2 -0
  175. package/dist/plugins/caching-session-store.d.ts +9 -15
  176. package/dist/plugins/caching-session-store.js +6 -0
  177. package/dist/plugins/device-store-sql.js +6 -0
  178. package/dist/plugins/error-origin.d.ts +18 -0
  179. package/dist/plugins/error-origin.js +10 -0
  180. package/dist/plugins/execution-placement-sql.js +6 -6
  181. package/dist/plugins/image-bake-store-sql.js +6 -0
  182. package/dist/plugins/image-index-sql.js +4 -0
  183. package/dist/plugins/landed-attendants.d.ts +212 -0
  184. package/dist/plugins/landed-attendants.js +161 -0
  185. package/dist/plugins/leader-run-store-sql.js +4 -0
  186. package/dist/plugins/local-session-live-reference.d.ts +40 -0
  187. package/dist/plugins/local-session-live-reference.js +39 -0
  188. package/dist/plugins/local-session-store.d.ts +71 -33
  189. package/dist/plugins/local-session-store.js +129 -27
  190. package/dist/plugins/memory-engine-pg.js +4 -0
  191. package/dist/plugins/memory-engine-sql-apply.js +5 -2
  192. package/dist/plugins/memory-engine-tidb.js +4 -0
  193. package/dist/plugins/memory-optout-grant-store-sql.js +4 -0
  194. package/dist/plugins/memory-sync-store-pg.js +5 -0
  195. package/dist/plugins/memory-sync-store-tidb.js +5 -0
  196. package/dist/plugins/one-time-migrations.d.ts +57 -63
  197. package/dist/plugins/one-time-migrations.js +162 -90
  198. package/dist/plugins/org-delivery-quota-store.js +4 -1
  199. package/dist/plugins/outcome-ledger-sql.js +2 -0
  200. package/dist/plugins/permission-rule-store-sql.js +11 -4
  201. package/dist/plugins/pg-cost-quota.js +4 -0
  202. package/dist/plugins/pg-pool.js +24 -1
  203. package/dist/plugins/pg-rate-limiter.js +2 -0
  204. package/dist/plugins/posix-shell-fs.d.ts +6 -1
  205. package/dist/plugins/posix-shell-fs.js +4 -1
  206. package/dist/plugins/remote-env-adb.d.ts +19 -15
  207. package/dist/plugins/remote-env-adb.js +41 -15
  208. package/dist/plugins/remote-env-connect-seat.d.ts +105 -0
  209. package/dist/plugins/remote-env-connect-seat.js +72 -0
  210. package/dist/plugins/remote-env-device.d.ts +22 -5
  211. package/dist/plugins/remote-env-device.js +106 -8
  212. package/dist/plugins/remote-env-e2b.d.ts +15 -6
  213. package/dist/plugins/remote-env-e2b.js +42 -32
  214. package/dist/plugins/remote-env-file-error.js +6 -2
  215. package/dist/plugins/remote-env-host.d.ts +17 -0
  216. package/dist/plugins/remote-env-host.js +30 -38
  217. package/dist/plugins/remote-env-k8s.d.ts +41 -39
  218. package/dist/plugins/remote-env-k8s.js +53 -30
  219. package/dist/plugins/remote-env-local-docker.d.ts +13 -8
  220. package/dist/plugins/remote-env-local-docker.js +34 -41
  221. package/dist/plugins/remote-env-ssh.d.ts +18 -12
  222. package/dist/plugins/remote-env-ssh.js +60 -59
  223. package/dist/plugins/remote-shell.d.ts +98 -1
  224. package/dist/plugins/remote-shell.js +218 -0
  225. package/dist/plugins/resume-anchor-store-sql.d.ts +11 -2
  226. package/dist/plugins/resume-anchor-store-sql.js +12 -5
  227. package/dist/plugins/retention-lane-store-sql.js +4 -0
  228. package/dist/plugins/retention-sql.d.ts +20 -2
  229. package/dist/plugins/retention-sql.js +11 -0
  230. package/dist/plugins/run-store-sql.d.ts +21 -2
  231. package/dist/plugins/run-store-sql.js +31 -7
  232. package/dist/plugins/scenario-prefix-switch-m42.d.ts +1 -1
  233. package/dist/plugins/scenario-prefix-switch-m42.js +2 -2
  234. package/dist/plugins/schema-consistency.d.ts +4 -2
  235. package/dist/plugins/schema-consistency.js +19 -2
  236. package/dist/plugins/send-file-ledger.js +3 -0
  237. package/dist/plugins/serving-requirement.d.ts +26 -7
  238. package/dist/plugins/serving-requirement.js +11 -4
  239. package/dist/plugins/session-birth.d.ts +6 -2
  240. package/dist/plugins/session-capture-record-store-sql.js +2 -0
  241. package/dist/plugins/session-ext-table.d.ts +14 -1
  242. package/dist/plugins/session-ext-table.js +5 -1
  243. package/dist/plugins/session-row-sql.d.ts +49 -2
  244. package/dist/plugins/session-row-sql.js +56 -13
  245. package/dist/plugins/session-store-sql.d.ts +34 -18
  246. package/dist/plugins/session-store-sql.js +98 -17
  247. package/dist/plugins/shared-memory-store-sql.d.ts +1 -0
  248. package/dist/plugins/shared-memory-store-sql.js +6 -2
  249. package/dist/plugins/sql-driver.d.ts +2 -1
  250. package/dist/plugins/sql-driver.js +18 -3
  251. package/dist/plugins/sql-errors.d.ts +11 -6
  252. package/dist/plugins/sql-errors.js +5 -6
  253. package/dist/plugins/stop-then-start-sentence.d.ts +10 -4
  254. package/dist/plugins/stop-then-start-sentence.js +14 -10
  255. package/dist/plugins/stop-then-start.d.ts +109 -0
  256. package/dist/plugins/stop-then-start.js +104 -0
  257. package/dist/plugins/store-backend.d.ts +40 -13
  258. package/dist/plugins/store-backend.js +169 -27
  259. package/dist/plugins/store-boundary.d.ts +57 -0
  260. package/dist/plugins/store-boundary.js +139 -0
  261. package/dist/plugins/store-contracts.d.ts +17 -0
  262. package/dist/plugins/store-fault-sentence-m53.d.ts +7 -0
  263. package/dist/plugins/store-fault-sentence-m53.js +25 -0
  264. package/dist/plugins/store-fault.d.ts +26 -7
  265. package/dist/plugins/store-fault.js +18 -2
  266. package/dist/plugins/task-attachment-store.js +9 -0
  267. package/dist/plugins/task-list-store-sql.d.ts +2 -2
  268. package/dist/plugins/task-list-store-sql.js +10 -8
  269. package/dist/plugins/tidb-cost-quota.js +4 -0
  270. package/dist/plugins/tidb-pool.js +2 -1
  271. package/dist/plugins/tidb-rate-limiter.js +4 -0
  272. package/dist/plugins/user-input-ledger-sql.js +4 -0
  273. package/dist/plugins/workflow-run-store-sql.d.ts +28 -10
  274. package/dist/plugins/workflow-run-store-sql.js +64 -4
  275. package/dist/plugins/workspace-fill.d.ts +4 -7
  276. package/dist/plugins/workspace-fill.js +2 -1
  277. package/dist/plugins/write-behind-counter.js +5 -0
  278. package/dist/project-context.d.ts +0 -2
  279. package/dist/project-context.js +4 -8
  280. package/dist/project-registry.d.ts +46 -0
  281. package/dist/project-registry.js +44 -0
  282. package/dist/request-key-closure.js +1 -1
  283. package/dist/request-value-closure.d.ts +4 -0
  284. package/dist/request-value-closure.js +10 -0
  285. package/dist/run-acceptance.d.ts +3 -2
  286. package/dist/run-acceptance.js +4 -6
  287. package/dist/run-local.js +1 -0
  288. package/dist/runs.d.ts +37 -8
  289. package/dist/runs.js +53 -12
  290. package/dist/runtime-governance.d.ts +5 -4
  291. package/dist/security.d.ts +30 -32
  292. package/dist/security.js +41 -7
  293. package/dist/server-secret-env.d.ts +12 -10
  294. package/dist/server-secret-env.js +24 -15
  295. package/dist/session-bindings.d.ts +82 -0
  296. package/dist/session-bindings.js +18 -0
  297. package/dist/session-children-retire.d.ts +2 -2
  298. package/dist/session-children-retire.js +2 -6
  299. package/dist/session-deletion.d.ts +16 -1
  300. package/dist/session-error-wire.d.ts +3 -3
  301. package/dist/session-error-wire.js +3 -3
  302. package/dist/session-incarnation.d.ts +10 -0
  303. package/dist/session-incarnation.js +10 -1
  304. package/dist/session-kind.d.ts +57 -0
  305. package/dist/session-kind.js +22 -0
  306. package/dist/session-row.d.ts +21 -1
  307. package/dist/session-row.js +7 -1
  308. package/dist/session-sync-kernel.d.ts +24 -14
  309. package/dist/session-sync-kernel.js +3 -6
  310. package/dist/session-sync.d.ts +4 -98
  311. package/dist/session-sync.js +1 -71
  312. package/dist/session-titler.d.ts +10 -3
  313. package/dist/session-titler.js +19 -6
  314. package/dist/ssh-host-key.d.ts +5 -0
  315. package/dist/ssh-host-key.js +3 -0
  316. package/dist/stores-sql/file-history-store-sql.d.ts +52 -2
  317. package/dist/stores-sql/file-history-store-sql.js +108 -70
  318. package/dist/stores-sql/pg-session-storage.d.ts +34 -7
  319. package/dist/stores-sql/pg-session-storage.js +37 -13
  320. package/dist/stores-sql/retention-store-sql.d.ts +1 -9
  321. package/dist/stores-sql/retention-store-sql.js +2 -10
  322. package/dist/stores-sql/session-policy-store-sql.d.ts +30 -7
  323. package/dist/stores-sql/session-policy-store-sql.js +61 -44
  324. package/dist/stores-sql/session-write-hooks.d.ts +11 -0
  325. package/dist/stores-sql/tidb-session-store.d.ts +58 -7
  326. package/dist/stores-sql/tidb-session-store.js +37 -13
  327. package/dist/submission-exit.d.ts +3 -2
  328. package/dist/submission-exit.js +9 -1
  329. package/dist/task-cwd.d.ts +2 -2
  330. package/dist/task-settings.d.ts +6 -5
  331. package/dist/terminal.d.ts +33 -2
  332. package/dist/terminal.js +139 -9
  333. package/dist/tool-approval.d.ts +140 -6
  334. package/dist/tool-approval.js +165 -72
  335. package/dist/trace/self-minted-wire.d.ts +290 -27
  336. package/dist/trace/self-minted-wire.js +101 -13
  337. package/docs/DEVICE-EXECUTOR-PROTOCOL.md +78 -27
  338. package/package.json +2 -2
  339. package/wire-changes/server@7.151.0.json +762 -0
  340. package/dist/http/session-inherit-env.d.ts +0 -36
  341. package/dist/http/session-inherit-env.js +0 -6
@@ -0,0 +1,104 @@
1
+ import { REPLICA_CAPABILITIES, knowsCapability, readReplicaRegistrations } from "./replica-registration.js";
2
+ import { compareReleaseTriples, releaseTriple } from "./release-version.js";
3
+ import { runningHeartbeatPredicate } from "./run-store-sql.js";
4
+ const isCapability = (id) => REPLICA_CAPABILITIES.includes(id);
5
+ const sameChange = (a, b) => JSON.stringify(a) === JSON.stringify(b);
6
+ export function judgeStopThenStart(entry) {
7
+ const faults = [];
8
+ if (!isCapability(entry.id))
9
+ faults.push(`${entry.id} is not in REPLICA_CAPABILITIES (a stop-then-start migration reads evidence only under a capability name)`);
10
+ if (entry.reason.trim() === "")
11
+ faults.push(`${entry.id}: reason is empty`);
12
+ const fence = entry.fence;
13
+ switch (fence.kind) {
14
+ case "structural":
15
+ if (!(entry.shapeChanges ?? []).some((c) => sameChange(c, fence.fencedBy)))
16
+ faults.push(`${entry.id}: structural fencedBy is not one of the row's shapeChanges`);
17
+ if (fence.fencedBy.kind === "add")
18
+ faults.push(`${entry.id}: structural fencedBy is an "add" (adding a column fences no earlier writer)`);
19
+ break;
20
+ case "per-write": {
21
+ const since = releaseTriple(fence.fencedSince);
22
+ const introduced = releaseTriple(entry.introducedIn);
23
+ if (since === undefined)
24
+ faults.push(`${entry.id}: per-write fencedSince "${fence.fencedSince}" is not x.y.z`);
25
+ if (introduced === undefined)
26
+ faults.push(`${entry.id}: introducedIn "${entry.introducedIn}" is not x.y.z`);
27
+ if (since !== undefined && introduced !== undefined && compareReleaseTriples(since, introduced) >= 0) {
28
+ faults.push(`${entry.id}: per-write fencedSince ${fence.fencedSince} is not earlier than introducedIn ${entry.introducedIn} (the fencing writes must ship at least one release before the migration)`);
29
+ }
30
+ if (fence.statements.trim() === "")
31
+ faults.push(`${entry.id}: per-write statements is empty`);
32
+ break;
33
+ }
34
+ case "accepted":
35
+ if (fence.residual.trim() === "")
36
+ faults.push(`${entry.id}: accepted residual is empty`);
37
+ break;
38
+ default: {
39
+ const unhandled = fence;
40
+ faults.push(`${entry.id}: unknown fence kind ${String(unhandled.kind)}`);
41
+ }
42
+ }
43
+ return faults;
44
+ }
45
+ export async function readOlderReplicaEvidence(db, dialect, input, migrationId) {
46
+ const scope = dialect === "mysql" ? "DATABASE()" : "current_schema()";
47
+ if ((await db.rows(`SELECT 1 AS present FROM information_schema.tables WHERE table_schema = ${scope} AND table_name = 'task_run'`)).length === 0)
48
+ return undefined;
49
+ const live = runningHeartbeatPredicate(dialect, "live", { nowMs: Date.now(), windowMs: input.liveRunWindowMs }, 1);
50
+ const groups = (await db.rows(`SELECT instance_id, COUNT(*) AS n, MAX(updated_at) AS newest FROM task_run WHERE ${live.sql} GROUP BY instance_id`, [live.param]))
51
+ .map((r) => ({ holder: typeof r["instance_id"] === "string" ? r["instance_id"] : undefined, runs: Number(r["n"] ?? 0), newest: r["newest"] }))
52
+ .filter((g) => g.runs > 0);
53
+ if (groups.length === 0)
54
+ return undefined;
55
+ const registered = await readReplicaRegistrations({ query: async (sql, params) => ({ rows: await db.rows(sql, params), affected: 0 }) }, dialect, groups.flatMap((g) => (g.holder === undefined ? [] : [g.holder])));
56
+ let unregisteredRuns = 0;
57
+ let newestMs = Number.NaN;
58
+ const registeredWithout = [];
59
+ for (const g of groups) {
60
+ const r = g.holder === undefined ? undefined : registered.get(g.holder);
61
+ if (r !== undefined && knowsCapability(r.capabilities, migrationId))
62
+ continue;
63
+ if (r === undefined)
64
+ unregisteredRuns += g.runs;
65
+ else
66
+ registeredWithout.push({ instanceId: r.instanceId, releaseLine: r.releaseLine, hostName: r.hostName, pid: r.pid, runs: g.runs });
67
+ const cell = g.newest instanceof Date ? g.newest : new Date(String(g.newest));
68
+ if (!Number.isNaN(cell.getTime()) && !(cell.getTime() <= newestMs))
69
+ newestMs = cell.getTime();
70
+ }
71
+ const liveRuns = unregisteredRuns + registeredWithout.reduce((n, h) => n + h.runs, 0);
72
+ if (liveRuns === 0)
73
+ return undefined;
74
+ const now = Date.now();
75
+ const restartAtMs = (Number.isNaN(newestMs) ? now : newestMs) + input.liveRunWindowMs;
76
+ return {
77
+ migration: migrationId,
78
+ liveRuns,
79
+ windowSec: Math.round(input.liveRunWindowMs / 1000),
80
+ restartAfter: new Date(restartAtMs).toISOString(),
81
+ after: `${new Date(restartAtMs).toISOString()} (${Math.max(0, Math.ceil((restartAtMs - now) / 1000))}s from now)`,
82
+ unregisteredRuns,
83
+ registeredWithout: registeredWithout.sort((a, b) => a.instanceId.localeCompare(b.instanceId)),
84
+ };
85
+ }
86
+ export function assertStopThenStartDeclarations(entries) {
87
+ const faults = entries.flatMap((e) => judgeStopThenStart(e));
88
+ if (faults.length > 0) {
89
+ throw new Error(`stop-then-start: this build declares a stop-then-start migration that contradicts its fence class (a build defect; refused before any statement reached the database): ${faults.join("; ")}`);
90
+ }
91
+ }
92
+ export async function guardOwedStopThenStart(db, dialect, input, entries) {
93
+ const read = (sql) => db.rows(sql);
94
+ for (const entry of entries) {
95
+ if (!(await entry.owedOn(read, dialect)))
96
+ continue;
97
+ if (!isCapability(entry.id))
98
+ throw new Error(`stop-then-start: ${entry.id} is not in REPLICA_CAPABILITIES`);
99
+ const evidence = await readOlderReplicaEvidence(db, dialect, input, entry.id);
100
+ if (evidence !== undefined)
101
+ throw await entry.refuse(evidence, read, dialect);
102
+ }
103
+ }
104
+ //# sourceMappingURL=stop-then-start.js.map
@@ -3,12 +3,14 @@ import type { Pool as PgPool } from "pg";
3
3
  import type { SessionStore, SessionPolicyStore, FileHistoryStore, FileHistoryBlobExchange, FileHistoryError, WorkflowJournalStore, ToolResultStore, SessionCaptureRecordStore, UsageWindowStore } from "@sema-agent/core";
4
4
  import { FileStorageBackend } from "@sema-agent/core";
5
5
  import { type OutcomeSink } from "./file-outcome-sink.js";
6
- import { type InboxWarn } from "./workflow-run-store-sql.js";
6
+ import { SqlWorkflowRunStore, type InboxWarn } from "./workflow-run-store-sql.js";
7
7
  import { FileRunStore } from "./file-run-store.js";
8
+ import { type WorkflowParkDecisionStore, type WorkflowRecordFenceStore } from "../orchestration/workflow-park-decision.js";
8
9
  import { type RunStallWiring } from "./store-contracts.js";
9
10
  import { type StoreOpenLane } from "./store-open-refusal.js";
10
11
  import { type OneTimeMigrationReport, type SqlOneTimeMigrationInput } from "./one-time-migrations.js";
11
12
  import { LocalSessionStore } from "./local-session-store.js";
13
+ import { type LocalWorkflowRunsReader } from "./local-session-live-reference.js";
12
14
  import { type LocalStoreDeclaration } from "../local-store-declaration.js";
13
15
  import type { LocalSessionRows } from "./local-session-window.js";
14
16
  import type { SessionHeadReader } from "./caching-session-store.js";
@@ -22,7 +24,9 @@ import { type MemoryOptOutGrantStore } from "./memory-optout-grant-store-sql.js"
22
24
  import { type SendFileLedger } from "./send-file-ledger.js";
23
25
  import type { UserInputLedgerStore } from "../user-input-ledger.js";
24
26
  import { TiDBResumeAnchorStore, PgResumeAnchorStore } from "./resume-anchor-store-sql.js";
25
- import { type SessionPolicyStoreLogger } from "../stores-sql/session-policy-store-sql.js";
27
+ import { SqlSessionPolicyStore } from "../stores-sql/session-policy-store-sql.js";
28
+ import { SqlFileHistoryStore } from "../stores-sql/file-history-store-sql.js";
29
+ import { type LandedAttendantSeat } from "./landed-attendants.js";
26
30
  import type { ServiceConfig } from "../config-types.js";
27
31
  import { TiDBRunStore, PgRunStore } from "./run-store-sql.js";
28
32
  import { TiDBCheckpointStore, PgCheckpointStore } from "../stores-sql/checkpoint-store-sql.js";
@@ -66,7 +70,9 @@ export type RunStore = TiDBRunStore | PgRunStore | FileRunStore;
66
70
  /** E18 resume-at eventId→entryId anchor map — tidb/pg/local 3-backend (works LOCAL; needs only the session tree +
67
71
  * this map, no cloud-only checkpoint). Union = the three nominal twins; consumers use put/resolve/deleteBySession.
68
72
  * FileResumeAnchorStore is the FILE-backed local twin (P0.5 variant-1; survives restart). */
69
- export type ResumeAnchorStore = TiDBResumeAnchorStore | PgResumeAnchorStore | FileResumeAnchorStore;
73
+ /** 回退锚店的部署面:读(`resolve` / `listBySession`)与按会话删 —— **没有写**。锚的生产写口只有落定席位的 `putAnchors`
74
+ * ({@link StoreBackend.landedAttendants}:段首锁会话根行判住客,迟到的写落不进别一代住客或空闲 id);店类上的 `put` 是夹具与契约面的同一句语句。 */
75
+ export type ResumeAnchorStore = Pick<TiDBResumeAnchorStore | PgResumeAnchorStore | FileResumeAnchorStore, "resolve" | "listBySession" | "deleteBySession">;
70
76
  export type { ApprovalExemptionStore } from "./approval-exemption-store.js";
71
77
  /** 会话树根的写(事务内钩的写闭集,`stores-sql/session-write-hooks.ts`):本组合座转口给目录外的判官(`execution-placement.ts` 的 `judgeSessionWrite`;local 店的写锁内同一组词)。 */
72
78
  export type { SessionWrite } from "../stores-sql/session-write-hooks.js";
@@ -193,7 +199,7 @@ export interface StoreBackend {
193
199
  close(): Promise<void>;
194
200
  run(): RunStore;
195
201
  /** E18 resume-at eventId→entryId map. REQUIRED on all backends (works local — needs only the session tree + this
196
- * map, no cloud-only checkpoint), unlike the optional cloud-only stores below. */
202
+ * map, no cloud-only checkpoint), unlike the optional cloud-only stores below. **恒同一只**(附随店的律见 {@link landedAttendants})。 */
197
203
  resumeAnchor(): ResumeAnchorStore;
198
204
  /** Per-session per-toolName approval exemption ("本会话不再询问") — an approval MEMORY the F4
199
205
  * ask-gate consults after deny/neverAuto. REQUIRED on all backends (works local, like resumeAnchor). */
@@ -250,12 +256,20 @@ export interface StoreBackend {
250
256
  userInputLedger(): UserInputLedgerStore;
251
257
  /** E6 durable SessionPolicyStore (operator-tightened per-session tool rules). REQUIRED on all backends — works local
252
258
  * (local = core's FileSessionPolicyStore), like resumeAnchor. Backs core's RunnerDeps.sessionPolicyStore.
253
- * `logger`:SQL 孪生抹除封键那一臂([ref])的点名口(装配点缺省交日志出口接缝的 logger);local(core 的 File 店)不收。 */
254
- sessionPolicy(logger?: SessionPolicyStoreLogger): ServiceSessionPolicyStore;
259
+ * **恒同一只**(附随店的律见 {@link landedAttendants}):服务面的规则读口、引擎的规则席、E21 抹除与落定席位的规则写都是这一只。
260
+ * SQL 孪生抹除封键那一臂([ref])的 warn 经开后端时交的 warn 座(`createStoreBackend` 第二参;缺席 ⇒ 日志出口接缝的缺省 logger)。 */
261
+ sessionPolicy(): ServiceSessionPolicyStore;
255
262
  /** [ref] per-edited-file rewind FileHistoryStore (trackEdit/annulTrack/snapshot/restore over the tracked set;
256
263
  * also the 2c history-transfer store). REQUIRED on all backends (local = core's file-backed
257
- * `FileFileHistoryStore` under the data root). Backs core's RunnerDeps.fileHistoryStore. */
264
+ * `FileFileHistoryStore` under the data root). Backs core's RunnerDeps.fileHistoryStore. **恒同一只**(附随店的律见 {@link landedAttendants})。 */
258
265
  fileHistory(): ServiceFileHistoryStore;
266
+ /** 会话附随物(文件历史图 · 会话规则行 · 回退锚)的**唯一写口** —— 落定席位(`plugins/landed-attendants.ts`):每一笔写在一只先锁会话根行、判过住客的段里,
267
+ * 住客不是那一位 ⇒ 零写。会话同步的落定腿、`PUT /v1/sessions/:id/policy`、运行腿的每轮回退锚都经它。**必选**:SQL 两只后端交一只事务形(与会话店同一只池),
268
+ * local 后端交会话写锁一节形;自建后端的嵌入方实现它(没有它,会话同步族答 501)。
269
+ * 🔴 **附随店的律**:一只后端对 {@link sessionPolicy} / {@link fileHistory} / {@link resumeAnchor} 与本席位各恒交同一只实例,席位写的就是那三只读口交出的店
270
+ * (服务面 `ServiceDeps` 上附随店只有这一条读法 —— `deps.backend` —— 没有第二个注入位)。随包三只后端都如此;自建后端的嵌入方同守(写经一只、读经另一只 ⇒
271
+ * `PUT …/policy` 答 200 而 `GET` 与引擎读不到这条收紧)。 */
272
+ landedAttendants(): LandedAttendantSeat;
259
273
  /** [ref] §3.1 / [ref] §一([ref] S-2):per-principal **memory-capture opt-out 授权表**
260
274
  * (`memory_optout_grant`)—— `RuntimeCaps.allowMemoryOptOut` 的本地 verdict 源(三层折叠:per-principal
261
275
  * 行 → 部署缺省哨兵行 → 代码缺省 allow)+ `/v1/admin/memory-optout` 四端点的持久层。
@@ -319,7 +333,7 @@ export interface StoreBackend {
319
333
  /** P1 (fleet failover): durable cross-replica WorkflowRunStore + completion-inbox twins. OPTIONAL —
320
334
  * SQL backends only (local keeps the File pair: single box, no cross-replica surface). main.ts prefers
321
335
  * these under WORKFLOW_RUN_STORE=auto (the default). */
322
- workflowRun?(onWarn?: InboxWarn): import("@sema-agent/core").WorkflowRunStore;
336
+ workflowRun?(onWarn?: InboxWarn): SqlWorkflowRunStore;
323
337
  completionInbox?(onWarn?: InboxWarn): import("../orchestration/workflow-completion-inbox.js").WorkflowCompletionInbox;
324
338
  /** 1.108 review fix (lens③ HIGH): the notify-JOURNAL twin — third leg of the same axis (a SQL run store +
325
339
  * inbox with a replica-LOCAL File journal stranded a dead replica's un-acked notify forever). */
@@ -329,11 +343,12 @@ export interface StoreBackend {
329
343
  * 缺席**是一个真答案**:那里的索引家在 run 店同一间屋子里(`LocalWorkflowAgentSessionIndex`,文件账本
330
344
  * 或纯内存),不需要经过 backend。契约与单写者纪律的属主 = orchestration/workflow-agent-session-index.ts。 */
331
345
  workflowAgentSessionIndex?(): import("../orchestration/workflow-agent-session-index.js").WorkflowAgentSessionIndex;
332
- /** workflow 子代停驻卡的耐久决定行(一张卡一行,键 = 子代 checkpoint 的 token),**绑在本后端的 {@link run} 那只 run 店上**(每一笔写都在它的会话认领栅栏里落)。
333
- * 与 `run()` 同形:无参、恒交同一只(三孪生同),所以这只决定店绑的就是部署的 run 店。SQL 后端 = 跨副本表,读写走 run 店的池;`local` 后端 = 进程内,
334
- * 账本位置由后端按自己的数据根与 `WORKFLOW_RUN_STORE` 定(`<数据根>/workflows/workflow-park-decisions/decisions.jsonl`;`memory` ⇒ 纯内存)。
346
+ /** workflow 子代停驻卡的耐久决定行(一张卡一行,键 = 子代 checkpoint 的 token),**绑两只栅栏**:本后端的 {@link run} 那只 run 店(认领栅栏)与 `records` ——
347
+ * 本服务全部 workflow 记录写者经它写的那只记录店(记录栅栏:SQL 后端 = 本后端 `workflowRun()` 交出的 SQL 记录店,同一只池;local 后端 = 基店外那只按 runId 互斥的装饰器)。
348
+ * 恒交同一只(三孪生同):记录栅栏在第一次交出时绑定,以另一只记录店再取 ⇒ 响亮抛(两只栅栏各管各的就不是同一个仲裁点)。SQL 后端 = 跨副本表,读写走 run 店的池;
349
+ * `local` 后端 = 进程内,账本位置由后端按自己的数据根与 `WORKFLOW_RUN_STORE` 定(`<数据根>/workflows/workflow-park-decisions/decisions.jsonl`;`memory` ⇒ 纯内存)。
335
350
  * 契约与律的属主 = orchestration/workflow-park-decision.ts。 */
336
- workflowParkDecisions?(): import("../orchestration/workflow-park-decision.js").WorkflowParkDecisionStore;
351
+ workflowParkDecisions?(records: WorkflowRecordFenceStore): WorkflowParkDecisionStore;
337
352
  /** Cloud-only stores below are OPTIONAL: the `local` (in-memory/file) backend omits them (it has no core
338
353
  * in-memory twin carrying the service extras, and these are fleet/multi-replica concepts), so a local HTTP
339
354
  * service degrades EXACTLY like today's no-DB env (the consumers gate on `backend?.X?.()`). TiDB/PG provide all. */
@@ -434,6 +449,11 @@ export interface StoreBackend {
434
449
  fileUsageWindowStore?(): UsageWindowStore;
435
450
  /** **local 后端专有**:构造时交给两半店(会话店顶层、检查点店)的那一份声明(唯一读者 `localStoreDeclarationOf`)—— 装配值从这里读回,不重算。SQL 后端省略。 */
436
451
  localStoreDeclaration?(): LocalStoreDeclaration;
452
+ /**
453
+ * 会话店活引用判的 workflow 那一腿(会话种类的老化;`local-session-live-reference.ts`):本后端的会话店读不到 workflow run 店时(local:那只店在 boot 第 6 段才铸),
454
+ * 第 6 段把这台部署的 workflow run 店交过来(不起 workflow ⇒ `"none"`);绑一次。SQL 两孪生不实现(它们的判是一句 SQL,读 `workflow_run` 表)。
455
+ */
456
+ bindWorkflowRunReader?(reader: LocalWorkflowRunsReader | "none"): void;
437
457
  }
438
458
  /**
439
459
  * 托管留存执行器的**组合**:引擎座表那一半(`SqlRetentionStore`,事务属主)+ 部署那一半(hold / 审计 / 认领判 / 十三张部署表,
@@ -467,8 +487,13 @@ export declare function createSqlSessionEraser(db: SqlDriver, opts: RetentionExe
467
487
  * ({@link SQL_BLOB_POSTURE_FACTS})。云形缺 MinIO ⇒ fail-loud(启动了才是假安全);`SNAPSHOT_BLOB_ALLOW_SQL_BYTES=true` =
468
488
  * 显式接受 SQL 店 + per-blob 帽(单机/测试台形;pg 上帽只来自 `SNAPSHOT_BLOB_SQL_MAX_BYTES`)。local 后端不经此门(file 店,无 SQL 包墙)。 */
469
489
  export declare function assertCloudSnapshotBlobPosture(kind: "mysql" | "pg" | "local", config: Pick<ServiceConfig, "snapshotBlobStore" | "snapshotBlobAllowSql">): void;
470
- /** SQL 一次性迁移段的输入(两只 SQL 后端同一份;各条目那一半的来源见 `SqlOneTimeMigrationInput`):M32 的车道表 · M52 的判活窗(停-迁-起证据的心跳一半)= 收割器的同一个窗 · M48 的部署形读数(表里那一行)。 */
490
+ /** SQL 一次性迁移段的输入(两只 SQL 后端同一份;各条目那一半的来源见 `SqlOneTimeMigrationInput`):M32 的车道表 · 停-迁-起证据读法的判活窗(守卫段与 M43 读,`stop-then-start.ts`)= 收割器的同一个窗 · M48 的部署形读数(表里那一行)。 */
471
491
  export declare function buildSqlOneTimeMigrationInput(config: ServiceConfig): SqlOneTimeMigrationInput;
492
+ /**
493
+ * SQL 落定席位的组装(两只 SQL 后端同一只;进程内夹具也经它):席位跑在 `db`(这台后端的池)上,写经的就是交进来的这两只店 —— 后端交的是它自己的那一只
494
+ * (`fileHistory()` / `sessionPolicy()`,读者读的同一只实例);席位只调它们的**语句片**(出口表的 `in-store`)与两只不拨库的判官 / 披露口,锚的语句片住 `resume-anchor-store-sql.ts`。
495
+ */
496
+ export declare function sqlLandedAttendantsOf(db: SqlDriver, history: SqlFileHistoryStore, policy: SqlSessionPolicyStore): LandedAttendantSeat;
472
497
  /**
473
498
  * LOCAL backend (clay 2026-06-25 seamless local↔cloud; P0.5 variant-2 + variant-1 file-backed 2026-06-26): a DB-less StoreBackend
474
499
  * so a locally-run HTTP service serves the SAME contract a cloud worker does (runs + trace + sessions + resume;
@@ -527,6 +552,8 @@ export interface LocalStoreBackend extends StoreBackend {
527
552
  fileUsageWindowStore(): UsageWindowStore;
528
553
  /** local 后端恒有(构造时交给两半店的声明;接口上可选的那一口在这里必在)。 */
529
554
  localStoreDeclaration(): LocalStoreDeclaration;
555
+ /** local 后端恒有(会话店活引用判的 workflow 晚绑座;接口上可选的那一口在这里必在)。 */
556
+ bindWorkflowRunReader(reader: LocalWorkflowRunsReader | "none"): void;
530
557
  }
531
558
  /** 引擎 File 后端上会话店之外、本仓没有自己一份口的店(run-local 的 Runner 接它们;工具结果 / 用量窗 / 会话规则走既有的 `toolResult()` / `fileUsageWindowStore()` / `sessionPolicy()` 口)。 */
532
559
  export type LocalEngineFileStores = Pick<FileStorageBackend, "checkpointStore" | "backgroundAgentStore" | "mailboxStore" | "rosterStore">;