@sema-agent/server 7.139.0 → 7.141.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 (328) hide show
  1. package/MIGRATION.md +471 -0
  2. package/README.md +1 -1
  3. package/README.zh-CN.md +1 -1
  4. package/USAGE.md +94 -26
  5. package/dist/adoption/runner.js +1 -1
  6. package/dist/adoption/sql.js +1 -1
  7. package/dist/approval-batch-census.d.ts +27 -0
  8. package/dist/approval-batch-census.js +27 -0
  9. package/dist/approval-card.d.ts +37 -22
  10. package/dist/approval-card.js +6 -3
  11. package/dist/approval.d.ts +15 -0
  12. package/dist/approval.js +10 -0
  13. package/dist/audit.d.ts +4 -2
  14. package/dist/audit.js +2 -2
  15. package/dist/bench/s1/live-deps.js +3 -2
  16. package/dist/bench/s1/row.d.ts +5 -2
  17. package/dist/bench/s1/row.js +2 -22
  18. package/dist/boot/adoption.js +1 -1
  19. package/dist/boot/device-lane.d.ts +11 -0
  20. package/dist/boot/device-lane.js +16 -0
  21. package/dist/boot/engine-lease.d.ts +24 -3
  22. package/dist/boot/engine-lease.js +9 -2
  23. package/dist/boot/execution-env.js +18 -12
  24. package/dist/boot/execution-lane.d.ts +8 -0
  25. package/dist/boot/execution-lane.js +6 -1
  26. package/dist/boot/memory-boundary.d.ts +16 -53
  27. package/dist/boot/memory-boundary.js +10 -20
  28. package/dist/boot/memory-consolidation.d.ts +16 -12
  29. package/dist/boot/memory-consolidation.js +24 -13
  30. package/dist/boot/reapers.d.ts +2 -2
  31. package/dist/boot/resolve-spec.d.ts +3 -5
  32. package/dist/boot/resolve-spec.js +9 -8
  33. package/dist/boot/runner-deps.d.ts +3 -3
  34. package/dist/boot/runner-deps.js +1 -0
  35. package/dist/boot/session-faces.d.ts +1 -1
  36. package/dist/boot/session-faces.js +4 -3
  37. package/dist/boot/shutdown.js +5 -0
  38. package/dist/boot/stage-03-store-backend.d.ts +2 -6
  39. package/dist/boot/stage-03-store-backend.js +2 -3
  40. package/dist/boot/stage-04-stores.d.ts +2 -6
  41. package/dist/boot/stage-04-stores.js +5 -5
  42. package/dist/boot/stage-05-execution-env.d.ts +2 -6
  43. package/dist/boot/stage-05-execution-env.js +3 -1
  44. package/dist/boot/stage-06-runners.d.ts +2 -8
  45. package/dist/boot/stage-06-runners.js +3 -3
  46. package/dist/boot/stage-07-capability-layer.d.ts +2 -7
  47. package/dist/boot/stage-07-capability-layer.js +8 -10
  48. package/dist/boot/stage-08-reapers.d.ts +2 -7
  49. package/dist/boot/stage-09-leader.d.ts +2 -7
  50. package/dist/boot/stage-10-http-server.d.ts +2 -7
  51. package/dist/boot/stage-10-http-server.js +6 -4
  52. package/dist/boot/stores.d.ts +3 -6
  53. package/dist/boot/stores.js +37 -44
  54. package/dist/boot/task-list-lane.d.ts +1 -1
  55. package/dist/boot/task-list-lane.js +1 -1
  56. package/dist/boot/web-admin.js +36 -9
  57. package/dist/capabilities/execution-lane.d.ts +2 -2
  58. package/dist/capabilities/scenarios.d.ts +1 -1
  59. package/dist/capability-facts.d.ts +9 -0
  60. package/dist/capability-facts.js +9 -0
  61. package/dist/card-void.d.ts +38 -0
  62. package/dist/card-void.js +23 -0
  63. package/dist/config-catalog.js +12 -8
  64. package/dist/config-provider.d.ts +18 -17
  65. package/dist/config-provider.js +28 -36
  66. package/dist/config-types.d.ts +36 -9
  67. package/dist/config.js +56 -46
  68. package/dist/delegated-session-owner.d.ts +23 -20
  69. package/dist/delegated-session-owner.js +2 -2
  70. package/dist/deployment-shape.d.ts +9 -8
  71. package/dist/deployment-shape.js +4 -4
  72. package/dist/device-store.d.ts +7 -0
  73. package/dist/device-store.js +3 -0
  74. package/dist/execution-config-root.d.ts +22 -0
  75. package/dist/execution-config-root.js +35 -0
  76. package/dist/execution-lane-caps.d.ts +145 -107
  77. package/dist/execution-lane-caps.js +144 -83
  78. package/dist/execution-placement.d.ts +3 -0
  79. package/dist/execution-placement.js +7 -0
  80. package/dist/fleet/drain-entry.d.ts +3 -0
  81. package/dist/hosted-posture.d.ts +8 -0
  82. package/dist/hosted-posture.js +4 -0
  83. package/dist/http/admission.js +3 -3
  84. package/dist/http/caller-trust.d.ts +3 -2
  85. package/dist/http/caller-trust.js +2 -1
  86. package/dist/http/dispatch.js +4 -0
  87. package/dist/http/live-frame.d.ts +24 -0
  88. package/dist/http/live-frame.js +16 -0
  89. package/dist/http/memory-compliance-failure-reply.d.ts +3 -1
  90. package/dist/http/memory-compliance-failure-reply.js +5 -0
  91. package/dist/http/memory-layer-reply.d.ts +30 -0
  92. package/dist/http/memory-layer-reply.js +24 -0
  93. package/dist/http/resume-legs.js +49 -35
  94. package/dist/http/retired-service-deps.d.ts +1 -1
  95. package/dist/http/retired-service-deps.js +1 -1
  96. package/dist/http/route-table.js +2 -0
  97. package/dist/http/routes/adoption.js +1 -1
  98. package/dist/http/routes/approvals-assistant.js +1 -0
  99. package/dist/http/routes/capabilities.js +5 -4
  100. package/dist/http/routes/diagnostics.d.ts +0 -19
  101. package/dist/http/routes/diagnostics.js +16 -2
  102. package/dist/http/routes/memory-bundle.d.ts +2 -2
  103. package/dist/http/routes/memory-bundle.js +4 -1
  104. package/dist/http/routes/memory-compliance.js +9 -2
  105. package/dist/http/routes/memory-consolidation.js +12 -1
  106. package/dist/http/routes/memory-origin.js +14 -2
  107. package/dist/http/routes/memory-policy.js +7 -2
  108. package/dist/http/routes/run-permission-mode.d.ts +75 -0
  109. package/dist/http/routes/run-permission-mode.js +170 -0
  110. package/dist/http/routes/session-sync.d.ts +3 -6
  111. package/dist/http/routes/session-sync.js +7 -2
  112. package/dist/http/routes/sessions.js +33 -15
  113. package/dist/http/routes/tasks.js +67 -68
  114. package/dist/http/run-read-face.js +3 -3
  115. package/dist/http/send.d.ts +1 -1
  116. package/dist/http/send.js +2 -2
  117. package/dist/http/server.d.ts +14 -27
  118. package/dist/http/server.js +2 -2
  119. package/dist/http/sse-log.d.ts +3 -8
  120. package/dist/http/stored-body-replay.d.ts +3 -3
  121. package/dist/http/stored-body-replay.js +3 -1
  122. package/dist/identity-source.d.ts +1 -1
  123. package/dist/identity-source.js +1 -1
  124. package/dist/instruction-source-notice.d.ts +7 -0
  125. package/dist/instruction-source-notice.js +6 -6
  126. package/dist/lane-home-probe.d.ts +68 -42
  127. package/dist/lane-home-probe.js +53 -30
  128. package/dist/leader/wire.js +5 -4
  129. package/dist/mcp-assertion-header.d.ts +4 -0
  130. package/dist/mcp-assertion-header.js +5 -0
  131. package/dist/memory-bundle-engine.d.ts +16 -9
  132. package/dist/memory-bundle-engine.js +29 -6
  133. package/dist/memory-operator-faces.d.ts +85 -30
  134. package/dist/memory-operator-faces.js +136 -30
  135. package/dist/memory-posture.d.ts +1 -1
  136. package/dist/memory-project-layer.d.ts +3 -21
  137. package/dist/memory-project-layer.js +11 -8
  138. package/dist/memory-scope-stores.d.ts +73 -0
  139. package/dist/memory-scope-stores.js +86 -0
  140. package/dist/memory-scope.d.ts +33 -9
  141. package/dist/memory-scope.js +17 -5
  142. package/dist/memory-sync-client.d.ts +34 -9
  143. package/dist/memory-sync-client.js +108 -28
  144. package/dist/observability/fail-open.d.ts +30 -2
  145. package/dist/observability/fail-open.js +30 -2
  146. package/dist/observability/metrics.js +0 -1
  147. package/dist/observability/run-terminal.d.ts +6 -2
  148. package/dist/observability/run-terminal.js +25 -26
  149. package/dist/observability/secret-env-scrub.d.ts +20 -1
  150. package/dist/observability/secret-env-scrub.js +14 -0
  151. package/dist/orchestration/workflow-completion-inbox.d.ts +5 -2
  152. package/dist/orchestration/workflow-completion-inbox.js +13 -5
  153. package/dist/orchestration/workflow-notify-journal.d.ts +5 -3
  154. package/dist/orchestration/workflow-notify-journal.js +2 -1
  155. package/dist/permission-mode-admission.d.ts +68 -0
  156. package/dist/permission-mode-admission.js +23 -0
  157. package/dist/permission-rule-list.d.ts +55 -6
  158. package/dist/permission-rule-list.js +52 -5
  159. package/dist/plugins/adoption-log-sql.js +4 -4
  160. package/dist/plugins/approval-ask-store-sql.js +14 -14
  161. package/dist/plugins/approval-nonce-store.js +4 -4
  162. package/dist/plugins/blob-backend.d.ts +4 -4
  163. package/dist/plugins/blob-backend.js +7 -7
  164. package/dist/plugins/breaker-state-sql.js +2 -2
  165. package/dist/plugins/caching-session-store.d.ts +6 -0
  166. package/dist/plugins/caching-session-store.js +3 -0
  167. package/dist/plugins/checkpoint-index-columns.js +2 -2
  168. package/dist/plugins/checkpoint-store-sql.d.ts +65 -17
  169. package/dist/plugins/checkpoint-store-sql.js +90 -19
  170. package/dist/plugins/device-store-sql.d.ts +5 -2
  171. package/dist/plugins/device-store-sql.js +23 -20
  172. package/dist/plugins/ensure-index.d.ts +1 -2
  173. package/dist/plugins/execution-placement-sql.d.ts +19 -9
  174. package/dist/plugins/execution-placement-sql.js +20 -9
  175. package/dist/plugins/file-history-store-sql.d.ts +2 -2
  176. package/dist/plugins/file-history-store-sql.js +4 -4
  177. package/dist/plugins/file-run-store.d.ts +2 -2
  178. package/dist/plugins/file-run-store.js +1 -1
  179. package/dist/plugins/fork-routing-session-store.d.ts +10 -32
  180. package/dist/plugins/fork-routing-session-store.js +2 -61
  181. package/dist/plugins/image-bake-store-sql.js +9 -9
  182. package/dist/plugins/image-index-sql.js +11 -11
  183. package/dist/plugins/k8s-exec-protocol.d.ts +4 -1
  184. package/dist/plugins/k8s-exec-protocol.js +6 -1
  185. package/dist/plugins/leader-run-store-sql.js +4 -4
  186. package/dist/plugins/local-checkpoint-store.d.ts +10 -1
  187. package/dist/plugins/local-checkpoint-store.js +22 -0
  188. package/dist/plugins/local-session-store.d.ts +227 -35
  189. package/dist/plugins/local-session-store.js +518 -37
  190. package/dist/plugins/local-session-window.d.ts +17 -3
  191. package/dist/plugins/local-session-window.js +7 -13
  192. package/dist/plugins/mailbox-store-sql.d.ts +2 -1
  193. package/dist/plugins/mailbox-store-sql.js +4 -4
  194. package/dist/plugins/memory-engine-tidb.js +5 -5
  195. package/dist/plugins/memory-optout-grant-store-sql.js +1 -1
  196. package/dist/plugins/memory-run-store.d.ts +2 -2
  197. package/dist/plugins/memory-run-store.js +1 -1
  198. package/dist/plugins/memory-sync-store-tidb.js +3 -3
  199. package/dist/plugins/one-time-migrations.d.ts +52 -11
  200. package/dist/plugins/one-time-migrations.js +101 -39
  201. package/dist/plugins/org-delivery-quota-store.js +2 -2
  202. package/dist/plugins/outcome-ledger-sql.js +2 -2
  203. package/dist/plugins/permission-rule-store-sql.d.ts +4 -4
  204. package/dist/plugins/permission-rule-store-sql.js +16 -16
  205. package/dist/plugins/pg-pool.js +3 -2
  206. package/dist/plugins/pg-session-storage.d.ts +2 -0
  207. package/dist/plugins/pg-session-storage.js +3 -2
  208. package/dist/plugins/remote-env-adb.d.ts +7 -24
  209. package/dist/plugins/remote-env-adb.js +22 -5
  210. package/dist/plugins/remote-env-device.d.ts +2 -28
  211. package/dist/plugins/remote-env-device.js +2 -1
  212. package/dist/plugins/remote-env-e2b.d.ts +40 -27
  213. package/dist/plugins/remote-env-e2b.js +180 -20
  214. package/dist/plugins/remote-env-file-error.d.ts +1 -1
  215. package/dist/plugins/remote-env-file-error.js +8 -2
  216. package/dist/plugins/remote-env-host.d.ts +19 -35
  217. package/dist/plugins/remote-env-host.js +26 -3
  218. package/dist/plugins/remote-env-k8s.d.ts +22 -14
  219. package/dist/plugins/remote-env-k8s.js +150 -26
  220. package/dist/plugins/remote-env-local-docker.d.ts +27 -24
  221. package/dist/plugins/remote-env-local-docker.js +91 -24
  222. package/dist/plugins/remote-env-ssh.d.ts +4 -24
  223. package/dist/plugins/remote-env-ssh.js +4 -3
  224. package/dist/plugins/resume-anchor-store-sql.js +2 -2
  225. package/dist/plugins/retention-lane-store-sql.d.ts +1 -1
  226. package/dist/plugins/retention-lane-store-sql.js +2 -2
  227. package/dist/plugins/retention-store-sql.d.ts +1 -1
  228. package/dist/plugins/retention-store-sql.js +6 -6
  229. package/dist/plugins/run-store-sql.d.ts +3 -3
  230. package/dist/plugins/run-store-sql.js +19 -18
  231. package/dist/plugins/sandbox-read-floor.d.ts +273 -0
  232. package/dist/plugins/sandbox-read-floor.js +608 -0
  233. package/dist/plugins/schema-consistency.d.ts +6 -6
  234. package/dist/plugins/schema-consistency.js +1 -1
  235. package/dist/plugins/schema-ensure-legs.d.ts +2 -3
  236. package/dist/plugins/schema-ensure-legs.js +2 -2
  237. package/dist/plugins/schema-live-columns.d.ts +1 -1
  238. package/dist/plugins/session-capture-record-store-sql.js +1 -1
  239. package/dist/plugins/session-ownership.d.ts +2 -1
  240. package/dist/plugins/session-placement.d.ts +17 -4
  241. package/dist/plugins/session-placement.js +2 -1
  242. package/dist/plugins/session-rules-column.d.ts +1 -1
  243. package/dist/plugins/session-rules-column.js +1 -1
  244. package/dist/plugins/session-store.d.ts +18 -20
  245. package/dist/plugins/session-store.js +4 -12
  246. package/dist/plugins/session-workspace-cell.d.ts +1 -1
  247. package/dist/plugins/session-workspace-cell.js +1 -1
  248. package/dist/plugins/shared-memory-store-sql.js +2 -2
  249. package/dist/plugins/sql-driver.d.ts +10 -5
  250. package/dist/plugins/sql-driver.js +6 -6
  251. package/dist/plugins/sql-errors.js +1 -1
  252. package/dist/plugins/store-backend.d.ts +35 -6
  253. package/dist/plugins/store-backend.js +27 -10
  254. package/dist/plugins/store-contracts.d.ts +9 -2
  255. package/dist/plugins/task-list-store-sql.js +11 -11
  256. package/dist/plugins/tidb-pool.js +7 -6
  257. package/dist/plugins/tidb-session-storage.js +4 -4
  258. package/dist/plugins/tidb-session-store.d.ts +4 -1
  259. package/dist/plugins/tidb-session-store.js +16 -15
  260. package/dist/plugins/tool-result-store-sql.d.ts +2 -2
  261. package/dist/plugins/tool-result-store-sql.js +3 -3
  262. package/dist/plugins/user-input-ledger-sql.js +2 -2
  263. package/dist/plugins/workflow-journal-store-sql.js +5 -5
  264. package/dist/plugins/workflow-run-store-sql.js +19 -19
  265. package/dist/plugins/write-behind-counter.d.ts +2 -3
  266. package/dist/plugins/write-behind-counter.js +5 -5
  267. package/dist/resource-suspend.d.ts +14 -12
  268. package/dist/resource-suspend.js +1 -1
  269. package/dist/resource-window.d.ts +4 -3
  270. package/dist/run-cancel-context.d.ts +34 -0
  271. package/dist/run-cancel-context.js +7 -0
  272. package/dist/run-local.js +14 -19
  273. package/dist/runs.d.ts +47 -16
  274. package/dist/runs.js +112 -113
  275. package/dist/security.d.ts +2 -2
  276. package/dist/server-secret-env.d.ts +2 -1
  277. package/dist/server-secret-env.js +2 -4
  278. package/dist/session-error-wire.d.ts +22 -4
  279. package/dist/session-error-wire.js +16 -0
  280. package/dist/session-incarnation.d.ts +10 -4
  281. package/dist/session-incarnation.js +1 -1
  282. package/dist/session-policy-wire.d.ts +1 -1
  283. package/dist/session-sync-kernel.d.ts +42 -1
  284. package/dist/session-sync-kernel.js +17 -0
  285. package/dist/session-sync.js +16 -4
  286. package/dist/sql-engine-coordinates.d.ts +49 -0
  287. package/dist/sql-engine-coordinates.js +27 -0
  288. package/dist/sql-engine-posture.d.ts +1 -1
  289. package/dist/sql-engine-posture.js +1 -1
  290. package/dist/standing-answer-grant.d.ts +31 -2
  291. package/dist/standing-answer-grant.js +14 -2
  292. package/dist/store-posture.d.ts +1 -1
  293. package/dist/{plugins → stores-sql}/background-agent-store-sql.d.ts +2 -2
  294. package/dist/{plugins → stores-sql}/background-agent-store-sql.js +8 -8
  295. package/dist/{plugins → stores-sql}/session-policy-store-sql.d.ts +7 -5
  296. package/dist/{plugins → stores-sql}/session-policy-store-sql.js +12 -12
  297. package/dist/{plugins → stores-sql}/usage-window-store-sql.d.ts +1 -1
  298. package/dist/{plugins → stores-sql}/usage-window-store-sql.js +3 -3
  299. package/dist/task-a2a.d.ts +1 -1
  300. package/dist/task-a2a.js +5 -6
  301. package/dist/task-mcp.d.ts +21 -8
  302. package/dist/task-mcp.js +17 -9
  303. package/dist/task-settings.d.ts +52 -25
  304. package/dist/task-settings.js +91 -28
  305. package/dist/terminal.d.ts +103 -19
  306. package/dist/terminal.js +72 -20
  307. package/dist/trace/core-keyset-guard.d.ts +79 -2
  308. package/dist/trace/exit-seat.d.ts +7 -0
  309. package/dist/trace/exit-seat.js +1 -0
  310. package/dist/trace/model-segment.d.ts +2 -2
  311. package/dist/trace/redact.d.ts +3 -1
  312. package/dist/trace/redact.js +395 -110
  313. package/dist/trace/self-minted-wire.d.ts +226 -2
  314. package/dist/trace/self-minted-wire.js +79 -0
  315. package/dist/verifier-pause-card.d.ts +8 -0
  316. package/dist/verifier-pause-card.js +19 -0
  317. package/dist/web-admin-client/apply-effective.d.ts +5 -7
  318. package/dist/web-admin-client/apply-effective.js +2 -2
  319. package/dist/web-admin-client/candidate-gate.d.ts +11 -7
  320. package/dist/web-admin-client/candidate-gate.js +1 -1
  321. package/dist/web-admin-client/http-client.d.ts +5 -4
  322. package/dist/web-admin-client/http-client.js +2 -2
  323. package/dist/web-admin-client/read-warnings.d.ts +7 -17
  324. package/dist/web-admin-client/read-warnings.js +5 -9
  325. package/docs/DEVICE-EXECUTOR-PROTOCOL.md +3 -2
  326. package/package.json +2 -2
  327. package/wire-changes/server@7.140.0.json +184 -0
  328. package/wire-changes/server@7.141.0.json +367 -0
@@ -16,6 +16,12 @@
16
16
  * branch below the floor — so the record the engine reads is the one the run's walk reaches.
17
17
  * Read-only: the log is read once (`exportEntries`, pure), no append log is opened, and the window refuses writes.
18
18
  *
19
+ * ## The metadata is the store's, not the archive's
20
+ * Both halves come from the local session store ({@link LocalSessionRows}) — this module opens no repo of its own. The metadata is the
21
+ * store's one projection of the session's row (`LocalSessionStore.sessionMetadataOf`: owner, creation time and fork lineage read from the
22
+ * session-meta cell, the same projection the store hands the engine), never the archive header's copy — an archive rebuilt by a log swap
23
+ * keeps the row's creation time. The log is the store's export of the archive.
24
+ *
19
25
  * ## Cost: one linear walk, the engine's
20
26
  * The branch is core's own `getPathToRoot` over the whole log (the walk every engine read of a local session makes, with its stop
21
27
  * rules: an entry without a parent ends it, a parent the log does not hold is `invalid_session`, an unknown leaf is `not_found`).
@@ -29,7 +35,15 @@
29
35
  * by `getPathToRoot` and the run's resume ancestor scan (the two walks core 7.54.1 guards; this module has no walker of its own left).
30
36
  * Pinned in `test/session-log-parent-cycle.test.ts`.
31
37
  */
32
- import { BaseSessionStorage } from "@sema-agent/core";
38
+ import { BaseSessionStorage, type SessionMetadata, type SessionTreeEntry } from "@sema-agent/core";
39
+ /**
40
+ * What the window reads, and from whom: the local session store's row projection and its export of the log (`LocalSessionStore` is the one
41
+ * implementation; `store-backend.ts#localSessionRowsOf` hands it out). `undefined` / `null` = no such session.
42
+ */
43
+ export interface LocalSessionRows {
44
+ sessionMetadataOf(sessionId: string): Promise<SessionMetadata | undefined>;
45
+ exportEntries(sessionId: string): Promise<SessionTreeEntry[] | null>;
46
+ }
33
47
  export declare class LocalSessionWindow extends BaseSessionStorage {
34
48
  /** The branch below the floor, root first (empty when the window is the whole branch). */
35
49
  private readonly below;
@@ -39,7 +53,7 @@ export declare class LocalSessionWindow extends BaseSessionStorage {
39
53
  /** `SessionStorage.getEpochAnchor?()` — the nearest carrier on the branch below the floor, as stored ({@link scanEpochAnchor}).
40
54
  * A row's `seq` is its position on the branch; the whole branch is in memory, so one page holds every row. */
41
55
  getEpochAnchor(): Promise<unknown>;
42
- /** Wake the window of `sessionId` under the local data root `root`; `null` if there is no such session. */
43
- static wake(root: string, sessionId: string): Promise<LocalSessionWindow | null>;
56
+ /** Wake the window of `sessionId` from the local session store's rows; `null` if there is no such session. */
57
+ static wake(rows: LocalSessionRows, sessionId: string): Promise<LocalSessionWindow | null>;
44
58
  }
45
59
  //# sourceMappingURL=local-session-window.d.ts.map
@@ -1,5 +1,4 @@
1
1
  import { BaseSessionStorage, InMemorySessionStorage, SessionError, boundedTail } from "@sema-agent/core";
2
- import { createLocalSessionRepo } from "./local-session-store.js";
3
2
  import { scanEpochAnchor } from "./session-epoch-anchor.js";
4
3
  export class LocalSessionWindow extends BaseSessionStorage {
5
4
  below;
@@ -16,18 +15,13 @@ export class LocalSessionWindow extends BaseSessionStorage {
16
15
  async getEpochAnchor() {
17
16
  return scanEpochAnchor(this.below.length, async (beforeSeq) => this.below.slice(0, beforeSeq).map((entry, seq) => ({ seq, entry })).reverse(), (row) => row.entry);
18
17
  }
19
- static async wake(root, sessionId) {
20
- const repo = createLocalSessionRepo(root);
21
- let log;
22
- try {
23
- log = await repo.exportEntries(sessionId);
24
- }
25
- catch (e) {
26
- if (e.code === "not_found")
27
- return null;
28
- throw e;
29
- }
30
- const metadata = (await repo.list()).find((m) => m.id === sessionId) ?? { id: sessionId, createdAt: new Date().toISOString() };
18
+ static async wake(rows, sessionId) {
19
+ const log = await rows.exportEntries(sessionId);
20
+ if (log === null)
21
+ return null;
22
+ const metadata = await rows.sessionMetadataOf(sessionId);
23
+ if (metadata === undefined)
24
+ return null;
31
25
  const whole = new InMemorySessionStorage({ entries: log });
32
26
  const leafId = await whole.getLeafId();
33
27
  const branch = await whole.getPathToRoot(leafId);
@@ -3,6 +3,7 @@ import type { Pool as PgPool } from "pg";
3
3
  import type { MailboxAckResult, MailboxAppendMessage, MailboxDecision, MailboxDecisionOutcome, MailboxLease, MailboxStore } from "@sema-agent/core";
4
4
  import { type IndexSpec } from "./ensure-index.js";
5
5
  import type { MailboxRecipientLifecycle, MailboxRecipientTombstone } from "./mailbox-recipient-lifecycle.js";
6
+ import type { SqlDialect } from "./sql-driver.js";
6
7
  export declare const MAILBOX_TABLE = "mailbox";
7
8
  export declare const MAILBOX_MSG_TABLE = "mailbox_message";
8
9
  /** [ref] 收件人墓碑表(预删除态的**唯一**真源;形与理由见 `mailbox-recipient-lifecycle.ts` 模块头)。
@@ -40,7 +41,7 @@ export declare function storedMailboxKeyless(scopeKey: unknown, handle: unknown)
40
41
  export declare const MAILBOX_KEYED_TABLES: readonly ["mailbox", "mailbox_message", "mailbox_tombstone"];
41
42
  export type MailboxKeyedTable = (typeof MAILBOX_KEYED_TABLES)[number];
42
43
  /** 按键删收件箱表族的一张表(两方言;参数 = [scope_key, handle])。 */
43
- export declare function mailboxKeyDeleteSql(dialect: "tidb" | "pg", table: MailboxKeyedTable): string;
44
+ export declare function mailboxKeyDeleteSql(dialect: SqlDialect, table: MailboxKeyedTable): string;
44
45
  /** 店侧日志座(可选;boot 注入 `Logger`)。7.58.0 合并重扫 [medium]:坏行的 fail-closed 抛必须**响亮**——core 唯一的
45
46
  * claimLease 调用方(peer-session-drain)吞掉该错,店不记这一笔就成了「静默永久卡箱」。抛之前记
46
47
  * `mailbox_message_column_corrupt`(scope/handle/seq/column/code),运维按 seq 修行。
@@ -73,7 +73,7 @@ export function storedMailboxKeyless(scopeKey, handle) {
73
73
  }
74
74
  export const MAILBOX_KEYED_TABLES = [MAILBOX_TABLE, MAILBOX_MSG_TABLE, MAILBOX_TOMBSTONE_TABLE];
75
75
  export function mailboxKeyDeleteSql(dialect, table) {
76
- return dialect === "tidb" ? `DELETE FROM ${table} WHERE scope_key = ? AND handle = ?` : `DELETE FROM ${table} WHERE scope_key = $1 AND handle = $2`;
76
+ return dialect === "mysql" ? `DELETE FROM ${table} WHERE scope_key = ? AND handle = ?` : `DELETE FROM ${table} WHERE scope_key = $1 AND handle = $2`;
77
77
  }
78
78
  function bufToStr(v) {
79
79
  return Buffer.isBuffer(v) ? v.toString("utf8") : String(v);
@@ -298,7 +298,7 @@ export class TiDBMailboxStore {
298
298
  if (tomb.length > 0)
299
299
  throw tombstonedRecipientError(scope, handle);
300
300
  if (rec.id !== undefined) {
301
- const [held] = await c.query(`SELECT seq, from_id, content, sent_at_ms, ${jsonColumnText("tidb", "hop_chain")}, ${jsonColumnText("tidb", "peer_meta")}, decision, record_id FROM ${MAILBOX_MSG_TABLE} WHERE scope_key = ? AND handle = ? AND record_id = ? FOR UPDATE`, [scope, handle, rec.id]);
301
+ const [held] = await c.query(`SELECT seq, from_id, content, sent_at_ms, ${jsonColumnText("mysql", "hop_chain")}, ${jsonColumnText("mysql", "peer_meta")}, decision, record_id FROM ${MAILBOX_MSG_TABLE} WHERE scope_key = ? AND handle = ? AND record_id = ? FOR UPDATE`, [scope, handle, rec.id]);
302
302
  const replay = replayedSeq(held, scope, handle, this.logger, { ...rec, content: asUtf8Stored(rec.content), ...(rec.from !== undefined ? { from: asUtf8Stored(rec.from) } : {}) });
303
303
  if (replay !== undefined)
304
304
  return replay;
@@ -323,7 +323,7 @@ export class TiDBMailboxStore {
323
323
  bufToStr(box.lease_owner) !== owner) {
324
324
  return null;
325
325
  }
326
- const [msgs] = (await c.query(`SELECT seq, from_id, content, sent_at_ms, ${jsonColumnText("tidb", "hop_chain")}, ${jsonColumnText("tidb", "peer_meta")}, decision, record_id FROM ${MAILBOX_MSG_TABLE} WHERE scope_key = ? AND handle = ? ORDER BY seq FOR UPDATE`, [scope, handle]));
326
+ const [msgs] = (await c.query(`SELECT seq, from_id, content, sent_at_ms, ${jsonColumnText("mysql", "hop_chain")}, ${jsonColumnText("mysql", "peer_meta")}, decision, record_id FROM ${MAILBOX_MSG_TABLE} WHERE scope_key = ? AND handle = ? ORDER BY seq FOR UPDATE`, [scope, handle]));
327
327
  if (msgs.length === 0)
328
328
  return null;
329
329
  const maxSeq = Number(msgs[msgs.length - 1].seq);
@@ -377,7 +377,7 @@ export class TiDBMailboxStore {
377
377
  return;
378
378
  await this.tx(async (c) => {
379
379
  for (const table of MAILBOX_KEYED_TABLES)
380
- await c.query(mailboxKeyDeleteSql("tidb", table), [scope, handle]);
380
+ await c.query(mailboxKeyDeleteSql("mysql", table), [scope, handle]);
381
381
  });
382
382
  }
383
383
  async reap(scope, now, opts) {
@@ -108,14 +108,14 @@ export class TiDBMemoryEngineBackend {
108
108
  const uniq = [...new Set(scopes)];
109
109
  if (uniq.length === 0)
110
110
  return [];
111
- const rows = await this.selectRows(`SELECT id, scope, slug, ${jsonColumnText("tidb", "frontmatter")}, rev, mtime_ms, size_bytes FROM ${TIDB_MEMORY_ENGINE_TABLES.entry} WHERE scope IN (${inPlaceholders(uniq.length)}) ORDER BY id`, uniq);
111
+ const rows = await this.selectRows(`SELECT id, scope, slug, ${jsonColumnText("mysql", "frontmatter")}, rev, mtime_ms, size_bytes FROM ${TIDB_MEMORY_ENGINE_TABLES.entry} WHERE scope IN (${inPlaceholders(uniq.length)}) ORDER BY id`, uniq);
112
112
  return rows.map((r) => this.headerFromRow(r));
113
113
  }
114
114
  async getByIds(ids) {
115
115
  const uniq = [...new Set(ids)];
116
116
  if (uniq.length === 0)
117
117
  return [];
118
- const rows = await this.selectRows(`SELECT id, scope, slug, ${jsonColumnText("tidb", "frontmatter")}, body, rev, mtime_ms, size_bytes FROM ${TIDB_MEMORY_ENGINE_TABLES.entry} WHERE id IN (${inPlaceholders(uniq.length)}) ORDER BY id`, uniq);
118
+ const rows = await this.selectRows(`SELECT id, scope, slug, ${jsonColumnText("mysql", "frontmatter")}, body, rev, mtime_ms, size_bytes FROM ${TIDB_MEMORY_ENGINE_TABLES.entry} WHERE id IN (${inPlaceholders(uniq.length)}) ORDER BY id`, uniq);
119
119
  return rows.map((r) => this.entryFromRow(r));
120
120
  }
121
121
  async search(query, scopes, opts) {
@@ -128,7 +128,7 @@ export class TiDBMemoryEngineBackend {
128
128
  if (q.size === 0)
129
129
  return [];
130
130
  const uniq = [...new Set(scopes)];
131
- const rows = await this.selectRows(`SELECT id, scope, slug, ${jsonColumnText("tidb", "frontmatter")}, body, rev, mtime_ms, size_bytes FROM ${TIDB_MEMORY_ENGINE_TABLES.entry} WHERE scope IN (${inPlaceholders(uniq.length)})`, uniq);
131
+ const rows = await this.selectRows(`SELECT id, scope, slug, ${jsonColumnText("mysql", "frontmatter")}, body, rev, mtime_ms, size_bytes FROM ${TIDB_MEMORY_ENGINE_TABLES.entry} WHERE scope IN (${inPlaceholders(uniq.length)})`, uniq);
132
132
  const scored = [];
133
133
  for (const raw of rows) {
134
134
  const r = raw;
@@ -210,7 +210,7 @@ export class TiDBMemoryEngineBackend {
210
210
  report.conflicts.push({ op: "add", id: entry.id, reason: "unstorable_bytes (utf8mb4 cannot store NUL/lone surrogates without mangling; strip them at the source — the store never rewrites content)" });
211
211
  return;
212
212
  }
213
- const prior = await this.selectRows(`SELECT scope, slug, rev, ${jsonColumnText("tidb", "frontmatter")} FROM ${T} WHERE id = ?`, [entry.id]);
213
+ const prior = await this.selectRows(`SELECT scope, slug, rev, ${jsonColumnText("mysql", "frontmatter")} FROM ${T} WHERE id = ?`, [entry.id]);
214
214
  const priorRow = prior.length > 0 ? prior[0] : undefined;
215
215
  let existsById = priorRow !== undefined;
216
216
  {
@@ -295,7 +295,7 @@ export class TiDBMemoryEngineBackend {
295
295
  slug = `${entry.slug}-${n}`;
296
296
  }
297
297
  }
298
- const cur = await this.selectRows(`SELECT slug, rev, scope, ${jsonColumnText("tidb", "frontmatter")} FROM ${T} WHERE id = ?`, [patch.id]);
298
+ const cur = await this.selectRows(`SELECT slug, rev, scope, ${jsonColumnText("mysql", "frontmatter")} FROM ${T} WHERE id = ?`, [patch.id]);
299
299
  if (cur.length === 0) {
300
300
  report.conflicts.push({ op: patch.op, id: patch.id, reason: "unknown id (entry not found in backend)" });
301
301
  return;
@@ -126,7 +126,7 @@ export class SqlMemoryOptOutGrantStore {
126
126
  }
127
127
  export class TiDBMemoryOptOutGrantStore extends SqlMemoryOptOutGrantStore {
128
128
  constructor(pool, now) {
129
- super(mysqlDriver(pool), "tidb", now);
129
+ super(mysqlDriver(pool), "mysql", now);
130
130
  }
131
131
  }
132
132
  export class PgMemoryOptOutGrantStore extends SqlMemoryOptOutGrantStore {
@@ -1,6 +1,6 @@
1
1
  import { type UsageRow } from "../usage-analytics.js";
2
2
  import type { TaskStatus } from "@sema-agent/core";
3
- import { type FenceLanded, type InProcessClaimFence, type CreateRunOutcome, type NewRunMeta, type RunIdemBinding, type RunListQuery, type RunRecord, type SessionSummary, type RunEvent, type PersistedTaskResult, type LatestRunRef } from "./store-contracts.js";
3
+ import { type FenceLanded, type FencedRun, type InProcessClaimFence, type CreateRunOutcome, type NewRunMeta, type RunIdemBinding, type RunListQuery, type RunRecord, type SessionSummary, type RunEvent, type PersistedTaskResult, type LatestRunRef } from "./store-contracts.js";
4
4
  import type { LedgerEventType } from "../trace/ledger-events.js";
5
5
  import { type SpaceCommitClaim, type SpaceCommitReading, type SpaceCommitState } from "../workspace-space-commit.js";
6
6
  /**
@@ -83,7 +83,7 @@ export declare class MemoryRunStore implements InProcessClaimFence {
83
83
  markResuming(taskId: string, instanceId: string): Promise<boolean>;
84
84
  getActiveTaskId(sessionId: string): Promise<string | undefined>;
85
85
  /** 认领当写栅栏用(契约 = `store-contracts.ts` 的 `InProcessClaimFence`):判、刷新活性与 `write` 是同一个同步段。 */
86
- whileHoldingClaim(sessionId: string, taskId: string, write: () => FenceLanded): boolean;
86
+ whileHoldingClaim(sessionId: string, taskId: string, write: (run: FencedRun) => FenceLanded): boolean;
87
87
  getRun(taskId: string): Promise<RunRecord | undefined>;
88
88
  /** Runs newest-first, keyset on (createdAt, taskId) DESC; optional exact-match filters (owner is exact, like the SQL). */
89
89
  listRuns(opts: RunListQuery): Promise<RunRecord[]>;
@@ -238,7 +238,7 @@ export class MemoryRunStore {
238
238
  if (this.active.get(sessionId) !== taskId || r === undefined || r.status !== "running")
239
239
  return false;
240
240
  r.updatedAt = new Date();
241
- write();
241
+ write({ instanceId: r.instanceId });
242
242
  return true;
243
243
  }
244
244
  async getRun(taskId) {
@@ -46,7 +46,7 @@ export class TiDBMemorySyncStore {
46
46
  this.claimLeaseMs = lease;
47
47
  }
48
48
  async getCursor(scope, peer) {
49
- const [rows] = await this.pool.query(`SELECT ${jsonColumnText("tidb", "base_revs")}, updated_at_ms FROM ${TIDB_MEMORY_SYNC_TABLES.syncCursor} WHERE scope = ? AND peer = ?`, [scope, peer]);
49
+ const [rows] = await this.pool.query(`SELECT ${jsonColumnText("mysql", "base_revs")}, updated_at_ms FROM ${TIDB_MEMORY_SYNC_TABLES.syncCursor} WHERE scope = ? AND peer = ?`, [scope, peer]);
50
50
  const row = rows[0];
51
51
  if (!row)
52
52
  return undefined;
@@ -72,7 +72,7 @@ export class TiDBMemorySyncStore {
72
72
  if (limit <= 0)
73
73
  return [];
74
74
  const leasedUntilMs = nowMs + this.claimLeaseMs;
75
- const [candidates] = await this.pool.query(`SELECT id, scope, entry_id, ${jsonColumnText("tidb", "payload")}, attempts, next_attempt_at_ms, last_error
75
+ const [candidates] = await this.pool.query(`SELECT id, scope, entry_id, ${jsonColumnText("mysql", "payload")}, attempts, next_attempt_at_ms, last_error
76
76
  FROM ${TIDB_MEMORY_SYNC_TABLES.pushQueue}
77
77
  WHERE next_attempt_at_ms <= ?
78
78
  ORDER BY next_attempt_at_ms, id
@@ -137,7 +137,7 @@ export class TiDBMemoryHistoryStore {
137
137
  ON DUPLICATE KEY UPDATE id = id`, params);
138
138
  }
139
139
  async historyOf(id) {
140
- const [rows] = await this.pool.query(`SELECT id, rev, prev_rev, op, scope, ${jsonColumnText("tidb", "snapshot")}, written_at_ms
140
+ const [rows] = await this.pool.query(`SELECT id, rev, prev_rev, op, scope, ${jsonColumnText("mysql", "snapshot")}, written_at_ms
141
141
  FROM ${TIDB_MEMORY_SYNC_TABLES.history}
142
142
  WHERE id = ?
143
143
  ORDER BY written_at_ms ASC, rev ASC`, [id]);
@@ -316,6 +316,18 @@
316
316
  * 或 `storage` 时权限 / 磁盘修好)后的下一次起服照常补放置;存档移走则它不再是本服务的会话(不补放置、不再点名;fork 创建的会话例外 —— 它的格还在,读作 fork 未落定,出路是同键重试那次 fork 或删除该会话)。
317
317
  * · **旧版在已切换库上**:≤7.137.x 起服建回空 `device_session`,随后列册对账见执行列为幽灵列拒启、零行写;再起本版 ⇒ ⓪ 删掉那张空表。回滚的唯一支持形 = 恢复切换前的备份。
318
318
  * 读数:`executionPlacementColumnsAdded` / `deviceBindingsMoved` / `deviceBindingsOrphaned`(非零 ⇒ 另一行 warn)/ `deviceBindingTablesDropped` / `executionPlacementsBackfilled` / `executionPlacementSessionsUnreadable`(点名数组 `{ sessionId, fault, errno? }`,只 local;一行一条 warn),收据只记起服日志行。
319
+ * · **M33 local 存档的行事实搬进行、带戳存档改写成匿名**(7.141.0;local 独有 —— SQL 孪生的行事实本来就只在 `session_meta` 行上)—— local 店的行事实(属主 / 化身 / 执行放置 /
320
+ * 建档时刻 / fork 谱系)只住在会话元数据边档的那一格,引擎仓是匿名内容仓(`local-session-store.ts` 头注「规则一」):本店交给引擎仓的写一律不交属主,交出的会话元数据是那一格的一只投影。
321
+ * ≤7.140.x 写下的存量 ① 格里没有建档时刻 / 谱系(那两样只在存档头上)② 换装 / 导入写下的存档头带着导入者的属主戳(及其 fork 后代 —— fork 抄戳)⇒ **一次性**:
322
+ * 步 0 恢复先行(上一次被打断留下的快照逐份消化,`LocalSessionStore.settleArchiveSnapshots`;起服 `ensureSchema` 先调,迁移开头再调)· 步 1 枚举(引擎仓列表 ∪ 边档全部键;
323
+ * 只在边档里、头读不出的 ⇒ 点名 unreadable)· 步 2 行回填(列表里每只存档:格缺 ⇒ 建一格、属主「从没被记下」;格缺建档时刻 / 谱系 ⇒ 从存档头补;一次边档提交 + 文件与目录各 fsync,
324
+ * 在这之前不碰任何存档)· 步 3 存档归一(每只带戳存档,在它的会话写锁里):整档一次读 → 读时跳过了记录 ⇒ 留着(`records_skipped`)→ 引擎导入闸先验(带发言者归属)不过 ⇒ 留着
325
+ * (`invalid`)→ 验后与原日志不逐条相等 ⇒ 留着(`normalizes`;迁移从不改内容)→ 快照记录(core `atomicWriteFile`)→ 以这一代为条件删存档 → 匿名导入 → 删快照。
326
+ * 留着的存档字节不动、点名(一行一条 warn);它们之后被 fork 拒、改日志的推送答 `conflict`(读、续跑、拉取照常),出路 = 删掉会话后重推。
327
+ * **快照目录的常设拒启臂**(`assertNoArchiveSnapshots`,无窗;删码后仍在):起服时数据根下的快照目录非空 ⇒ 拒启(`config.local_archive_snapshot_present`,`StoreBootRefusalError` 族)。
328
+ * **回滚**:边档对象形一格是严格形,上一版不认 `createdAt` / `forkedFrom` 两键 ⇒ 读本版写过的边档严格拒启 —— 回滚的唯一支持形 = 恢复升级前的数据根备份(MIGRATION 写了:升级前备份、先停光旧副本)。
329
+ * 读数:`localArchiveRowFactsBackfilled` / `localArchivesAnonymized` / `localArchivesKeptStamped`(点名数组 `{ sessionId, reason }`)/ `localArchivesUnreadable`(点名数组 `{ sessionId }`)/
330
+ * `localArchiveSnapshotsRecovered`;只 local(SQL 恒零 / 空)。
319
331
  *
320
332
  * ## 收据账(一次起服一只,每一条迁移同一只)
321
333
  * 每一步把它**已提交**的改写 / 删除与点名读数当场记进同一只收据账({@link MigrationReceipts}):计数随每次提交累加、行随每次提交追加、形读数在那一步落定时写。走完 ⇒
@@ -333,6 +345,7 @@
333
345
  import type { Pool as MysqlPool } from "mysql2/promise";
334
346
  import type { Pool as PgPool } from "pg";
335
347
  import { type AllowEntryInertReason, type GateKind } from "@sema-agent/core";
348
+ import { type SqlDialect } from "./sql-driver.js";
336
349
  import { StoreBootRefusalError } from "./store-contracts.js";
337
350
  import { type UndurableScopeRuleRow, type UnreadableRuleBucket } from "./permission-rule-store-sql.js";
338
351
  import type { SchemaProbeRead } from "./schema-live-columns.js";
@@ -423,6 +436,16 @@ export interface OneTimeMigrationReport {
423
436
  /** M32 local 腿:该回填放置、却读不出的会话 —— 有 run、存档读不出(会话头读不出 / 结构走不通 / 读存档文件时抛了别的故障:权限 / 磁盘 I/O / 超大)。一个字节没写,起服不挡:
424
437
  * 该会话的请求照旧答存档的故障;存档修好(从留存副本恢复,或权限 / 磁盘修好)后的下一次起服照常补放置。点名行数组(会话 id + 故障词,`storage` 再带 errno),一行一条 warn,每次起服都报直到处置。SQL 独有的反面:SQL 没有这一形(行就是会话);SQL 恒空。 */
425
438
  readonly executionPlacementSessionsUnreadable: readonly ExecutionPlacementSessionUnreadable[];
439
+ /** M33:本次补了行事实(建档时刻 / fork 谱系)的会话元数据格数(含为「有存档、没有格」的会话新建的格)。local 独有;SQL 恒 0。非零 = 真写了存量行。 */
440
+ readonly localArchiveRowFactsBackfilled: number;
441
+ /** M33:本次由带属主戳改写成匿名的存档数(条目逐条相等,内容不改)。local 独有;SQL 恒 0。非零 = 真写了存量存档。 */
442
+ readonly localArchivesAnonymized: number;
443
+ /** M33:留着带戳的存档(点名 + 原因,一行一条 warn,每次起服都报直到处置)。local 独有;SQL 恒空。 */
444
+ readonly localArchivesKeptStamped: readonly LocalArchiveKeptStamped[];
445
+ /** M33:存档读不出的会话(边档里有格而存档头读不出,或整档读抛;点名,一行一条 warn,每次起服都报直到处置)。local 独有;SQL 恒空。 */
446
+ readonly localArchivesUnreadable: readonly LocalArchiveUnreadable[];
447
+ /** M33:本次起服消化掉的快照记录数(上一次被打断的改写留下的;补回 / 丢弃)。local 独有;SQL 恒 0。 */
448
+ readonly localArchiveSnapshotsRecovered: number;
426
449
  }
427
450
  /** 退役的两只命令桶(引擎 7.51.0 起不是桶;只给 M17 点名认)。 */
428
451
  export type RetiredSessionRuleBucket = "commandAllow" | "commandDeny";
@@ -473,6 +496,24 @@ export interface ExecutionPlacementSessionUnreadable {
473
496
  /** 仅 `fault === "storage"` 且那只故障带字符串 `code` 时在场(`EACCES` / `EIO` / `ERR_STRING_TOO_LONG` ……)。 */
474
497
  readonly errno?: string;
475
498
  }
499
+ /**
500
+ * M33 留着带戳的一只存档的原因(闭集):`invalid` = 引擎导入闸不收这份日志(重导会被拒);`normalizes` = 引擎导入会改写它的内容(重导不再逐条相等);
501
+ * `records_skipped` = 读这只存档时跳过了读不出的记录(重写会把盘上那几行字节抹掉)。三种都一个字节不动。
502
+ */
503
+ export type LocalArchiveKeptReason = "invalid" | "normalizes" | "records_skipped";
504
+ /** M33 留着带戳的一只存档:会话 id 是点名坐标 + 原因。日志内容与盘上路径不出店。 */
505
+ export interface LocalArchiveKeptStamped {
506
+ readonly sessionId: string;
507
+ readonly reason: LocalArchiveKeptReason;
508
+ /** `reason: "invalid"` 时在场:引擎导入闸拒的那一句(条目 id + 结构毛病,不含条目内容)—— 运维据它找到挡住改写的那一条。 */
509
+ readonly detail?: string;
510
+ }
511
+ /** M33 读不出的一只:会话元数据边档里有它的格而存档头读不出(会话头坏),或列表读得出头、整档读抛。一个字节没写;会话的请求照旧答存档的故障。 */
512
+ export interface LocalArchiveUnreadable {
513
+ readonly sessionId: string;
514
+ /** 读的时候抛的那只故障带串型 `code` 时在场(`EACCES` / `EIO` / `corrupt_session` …);盘上路径与故障句不出店。 */
515
+ readonly errno?: string;
516
+ }
476
517
  /** 三个形读数(M9 主键 / M17 列名 / M24 scope 列)—— 那一步**落定**之前收据账里缺席(读数行要它们齐;被打断的那一行只带已落定的)。 */
477
518
  type ShapeReadingKey = "workflowParkIndexKey" | "sessionRuleColumn" | "workflowJournalScopeColumn";
478
519
  /**
@@ -543,8 +584,8 @@ export declare function migrationWindowOpen(window: Pick<OneTimeMigrationWindow,
543
584
  * 还没有日期可写)⇒ 响亮抛,不铸一句带空日期的句子。
544
585
  */
545
586
  export declare function migrationWindowEnd(id: string): string;
546
- /** local 车道上 SQL 独有的几条(M8 / M9 / M11 / M17 / M18 / M21 / M23 / M24 / M26 / M27 / M29)的读数(M6 与 M32 的回填两车道都有,local 腿的读数由 `LocalBackend.runOneTimeMigrations` 现算):那几张表 / 列在文件底座上从来不存在 ⇒ 如实答 absent / 0。 */
547
- export declare const NO_SQL_MIGRATIONS: Omit<OneTimeMigrationReport, "holderDeathCodeRowsBackfilled" | "executionPlacementsBackfilled" | "askExecutionLanesBackfilled" | "executionPlacementSessionsUnreadable">;
587
+ /** local 车道上 SQL 独有的几条(M8 / M9 / M11 / M17 / M18 / M21 / M23 / M24 / M26 / M27 / M29)的读数(M6 与 M32 的回填两车道都有、M33 只在 local,local 腿的读数由 `LocalBackend.runOneTimeMigrations` 现算):那几张表 / 列在文件底座上从来不存在 ⇒ 如实答 absent / 0。 */
588
+ export declare const NO_SQL_MIGRATIONS: Omit<OneTimeMigrationReport, "holderDeathCodeRowsBackfilled" | "executionPlacementsBackfilled" | "askExecutionLanesBackfilled" | "executionPlacementSessionsUnreadable" | "localArchiveRowFactsBackfilled" | "localArchivesAnonymized" | "localArchivesKeptStamped" | "localArchivesUnreadable" | "localArchiveSnapshotsRecovered">;
548
589
  /** 启动期的日志口(logger 的子集)。两级各有其用,见 {@link logOneTimeMigrations}。 */
549
590
  export interface MigrationLogSink {
550
591
  warn(msg: string, meta?: Record<string, unknown>): void;
@@ -577,7 +618,7 @@ export interface MigrationDb {
577
618
  * 本函数**不问**退役 schema:带着它的库在更早处就被 `ensureSchema()` 自身拒掉了(起服对账一族 `schema-consistency.ts` 的探针口,先于建表);走公开序列
578
619
  * `createStoreBackend()` → `ensureSchema()` → `runOneTimeMigrations()` 的嵌入方与本服务的起服序列一样,有这一问、零动作。
579
620
  */
580
- export declare function runSqlOneTimeMigrations(dialect: "tidb" | "pg", pool: MysqlPool | PgPool, input: ExecutionPlacementSwitchInput): Promise<OneTimeMigrationReport>;
621
+ export declare function runSqlOneTimeMigrations(dialect: SqlDialect, pool: MysqlPool | PgPool, input: ExecutionPlacementSwitchInput): Promise<OneTimeMigrationReport>;
581
622
  /** M32 的起服拒码(确定的拒启表态:再等也等不来另一个答案;不是线上 wire 码,与 `config.schema_mismatch` 同一族)。 */
582
623
  export declare const EXECUTION_PLACEMENT_SWITCH_REFUSED_CODE = "config.execution_placement_switch_refused";
583
624
  /** 拒因闭集:`fence` = 切换开始之后退役绑定表里又出现了行(旧版副本 / 手工写下的);`backfill_ambiguous` = 车道表不止一项而还有要回填的存量。 */
@@ -599,14 +640,14 @@ export interface ExecutionPlacementSwitchInput {
599
640
  * M32 的 **DDL 前只读探针**(与退役 schema 探针同层、同一只调用点:`store-backend.ts` 的 `withRetiredSchemaProbe`,先于第一条 CREATE):围栏与回填前提。
600
641
  * 拒在任何 DDL 之前 ⇒ 库零写。全新库(没有 `session_meta`)不判。纯读,不取 schema 锁(与退役 schema 探针同理)。
601
642
  */
602
- export declare function assertExecutionPlacementSwitchAdmissible(read: SchemaProbeRead, dialect: "tidb" | "pg", input: ExecutionPlacementSwitchInput): Promise<void>;
643
+ export declare function assertExecutionPlacementSwitchAdmissible(read: SchemaProbeRead, dialect: SqlDialect, input: ExecutionPlacementSwitchInput): Promise<void>;
603
644
  /** 探针口(入参形与本文件的迁移段入口 {@link runSqlOneTimeMigrations} 同:方言 + 它的池;借一条连接,用完即还)。 */
604
- export declare function assertExecutionPlacementSwitchAdmissibleOnPool(dialect: "tidb" | "pg", pool: MysqlPool | PgPool, input: ExecutionPlacementSwitchInput): Promise<void>;
645
+ export declare function assertExecutionPlacementSwitchAdmissibleOnPool(dialect: SqlDialect, pool: MysqlPool | PgPool, input: ExecutionPlacementSwitchInput): Promise<void>;
605
646
  /**
606
647
  * M32(规则与理由见头注 M32 段):切换已收尾(八列在 ∧ 两张绑定表都不在)⇒ 零动作;否则先复判围栏(探针之后、锁内这一刻又有旧版副本写进行 ⇒ 同一只拒),
607
648
  * 再按步骤表逐步收敛。跑在一次性迁移的锁里(与别的迁移步同一条连接)。导出给真库钉驱动「每步中断后续跑」。
608
649
  */
609
- export declare function switchExecutionPlacement(db: MigrationDb, dialect: "tidb" | "pg", receipts: MigrationReceipts, input: ExecutionPlacementSwitchInput): Promise<void>;
650
+ export declare function switchExecutionPlacement(db: MigrationDb, dialect: SqlDialect, receipts: MigrationReceipts, input: ExecutionPlacementSwitchInput): Promise<void>;
610
651
  /** {@link backfillLocalExecutionPlacements} 的结果:回填了几只会话 · 读不出而被跳过的会话(点名)。 */
611
652
  export interface LocalPlacementBackfill {
612
653
  readonly backfilled: number;
@@ -644,7 +685,7 @@ export declare function backfillLocalAskExecutionLanes(store: {
644
685
  * ⑤ **原子换名**:TiDB 一条 `RENAME TABLE 正 TO 待删, 暂存 TO 正`,之后删待删旧表;PG 两条换名、删旧表与主键约束名改回常规名在**同一个事务**里({@link execAtomically})
645
686
  * —— 中途死 = 整段回滚,盘上回到「正表旧形 + 暂存表」,下一次起动从 ① 重来。每一条 DDL 按后置条件收敛({@link execUntil} / {@link execAtomically})。
646
687
  */
647
- export declare function moveWorkflowJournalScope(db: MigrationDb, dialect: "tidb" | "pg", receipts: MigrationReceipts): Promise<void>;
688
+ export declare function moveWorkflowJournalScope(db: MigrationDb, dialect: SqlDialect, receipts: MigrationReceipts): Promise<void>;
648
689
  /**
649
690
  * M17 —— 一份存量规则体带哪几只退役命令桶(纯函数,点名判据):只认**对象上自有**的 `commandAllow` / `commandDeny` 键(不论值形 —— 坏形的退役桶照样是退役桶);
650
691
  * 不是对象 / 没有这两个键 / 条目文字里出现同名字样 ⇒ 空。不改写:新文法写不出旧命令桶的拒(头注 M17 段 ③)。
@@ -685,7 +726,7 @@ export declare function oldGrammarEntriesOf(body: unknown, rev: number): OldGram
685
726
  * 读数都记在收据账上(`sessionRuleColumn` 在落定时写:表不在(中央 DDL 之前被调到)⇒ `no-table`,不编读数;`renamed` = 本次把终名发布出来(含从进行中的名续判到底的那一次),
686
727
  * 终名改名提交之后才写;`current` = 起服时已是终名);点名的行随扫到追加。
687
728
  */
688
- export declare function migrateSessionRuleGrammar(db: MigrationDb, dialect: "tidb" | "pg", receipts: MigrationReceipts): Promise<void>;
729
+ export declare function migrateSessionRuleGrammar(db: MigrationDb, dialect: SqlDialect, receipts: MigrationReceipts): Promise<void>;
689
730
  /** M8 一行改写的结论:改写后的文本 / 这一行不用动 / 读不懂(解析错误原样交出,调用方计数进读数)。 */
690
731
  export type ShadowedRuleRewrite = {
691
732
  readonly kind: "rewrite";
@@ -738,7 +779,7 @@ export declare function parkedRowRepairOf(gateKindCell: unknown, gate: unknown,
738
779
  * 否则门上加 `approvalCard: "question"`、其余字节原样,经写腿的同一只编码器回写,按原文 CAS(MySQL 协议两边 `CAST(… AS BINARY)`,PG `text` 等值)+ `status = 'pending'`。
739
780
  * 每一次提交当场记进收据账。
740
781
  */
741
- export declare function repairParkedRows(db: MigrationDb, dialect: "tidb" | "pg", receipts: MigrationReceipts): Promise<void>;
782
+ export declare function repairParkedRows(db: MigrationDb, dialect: SqlDialect, receipts: MigrationReceipts): Promise<void>;
742
783
  /**
743
784
  * M29 —— 存量停驻行的 `approval_card` 列回填(规则、为什么、够不到的一格见头注 M29 段):列不在 ⇒ 延后(零扫描);只扫 `status = 'pending'` ∧ 列为 NULL ∧ 审批门型的行,
744
785
  * 按 `token` 键集分页,每行单独读整只文档、交给写口用的**同一只**判官({@link judgeCheckpointIndexCells} → `buildCheckpointIndexCells`,core `checkpointIndexFacts`):答出词 ⇒
@@ -746,7 +787,7 @@ export declare function repairParkedRows(db: MigrationDb, dialect: "tidb" | "pg"
746
787
  * 文档的门不是审批门)⇒ 不写;文档读不出、或派生读不了它(缺门 / 缺寄存行)⇒ 计数不写;答出的词超过列的容量(判官 {@link judgeCheckpointIndexCells} 的 `card_too_long`,
747
788
  * MySQL 协议 TEXT 65,535 UTF-8 字节)⇒ 计数 + 点名不写(同一个态度:一行手改数据不许挡整只部署起服)。每一次提交当场记进收据账。
748
789
  */
749
- export declare function backfillParkedApprovalCards(db: MigrationDb, dialect: "tidb" | "pg", receipts: MigrationReceipts): Promise<void>;
790
+ export declare function backfillParkedApprovalCards(db: MigrationDb, dialect: SqlDialect, receipts: MigrationReceipts): Promise<void>;
750
791
  /**
751
792
  * M23 —— 存量 placed 子代行的属主回填,**每次起服单趟、幂等**(规则、为什么、够不到的一格见头注 M23 段):键集分页扫完 placed ∧ 属主 NULL 的行,每一行按唯一判据判
752
793
  * (`judgeDelegatedOwner`,建行那一笔与停驻挂点同一只:来源顺序根、父;属主 = 这一读见证到的):
@@ -757,7 +798,7 @@ export declare function backfillParkedApprovalCards(db: MigrationDb, dialect: "t
757
798
  * · 扫到的任何一行化身为空 ⇒ 响亮拒(不论判不判得出属主;来源行同一条律)。
758
799
  * 不重扫、不拒启:残余由下一次起服或那一行的下一次停驻定下,期间只对 fleet 调用方放行(头注 M23 段)。
759
800
  */
760
- export declare function inheritPlacedSessionOwners(db: MigrationDb, dialect: "tidb" | "pg", receipts: MigrationReceipts): Promise<void>;
801
+ export declare function inheritPlacedSessionOwners(db: MigrationDb, dialect: SqlDialect, receipts: MigrationReceipts): Promise<void>;
761
802
  /**
762
803
  * 启动日志的读数行。零命中(第二跑起的常态)也照发 —— 「跑过了、什么都没改」与「压根没跑」必须可分辨。
763
804
  *