@sema-agent/server 7.103.2 → 7.104.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 (175) hide show
  1. package/MIGRATION.md +346 -2
  2. package/README.md +6 -1
  3. package/README.zh-CN.md +5 -1
  4. package/USAGE.md +271 -16
  5. package/deploy/sema-up/README.md +57 -7
  6. package/deploy/sema-up/cluster-up.sh +18 -4
  7. package/deploy/sema-up/kube-up.sh +16 -0
  8. package/deploy/sema-up/lib/dataroot.sh +142 -0
  9. package/deploy/sema-up/lib/flagshape.sh +69 -0
  10. package/deploy/sema-up/lib/lanes.py +14 -4
  11. package/deploy/sema-up/lib/shell-access.sh +41 -0
  12. package/deploy/sema-up/preflight.sh +14 -1
  13. package/deploy/sema-up/sema-up.sh +134 -37
  14. package/deploy/sema-up/smoke.sh +5 -0
  15. package/dist/auto-mode-face.js +3 -4
  16. package/dist/boot/budget-tracing.js +1 -1
  17. package/dist/boot/config-center.d.ts +6 -2
  18. package/dist/boot/config-center.js +5 -59
  19. package/dist/boot/execution-env.d.ts +11 -0
  20. package/dist/boot/execution-env.js +14 -0
  21. package/dist/boot/execution-lane.d.ts +25 -0
  22. package/dist/boot/execution-lane.js +95 -0
  23. package/dist/boot/memory-consolidation.d.ts +185 -9
  24. package/dist/boot/memory-consolidation.js +192 -32
  25. package/dist/boot/resolve-spec.d.ts +2 -0
  26. package/dist/boot/resolve-spec.js +28 -24
  27. package/dist/boot/runner-deps.d.ts +6 -2
  28. package/dist/boot/runner-deps.js +4 -0
  29. package/dist/boot/session-faces.d.ts +5 -0
  30. package/dist/boot/session-faces.js +18 -2
  31. package/dist/boot/session-incarnation-seat.d.ts +41 -0
  32. package/dist/boot/session-incarnation-seat.js +69 -0
  33. package/dist/boot/stage-01-config.js +2 -2
  34. package/dist/boot/stage-02-registry-pull.js +3 -1
  35. package/dist/boot/stage-04-stores.d.ts +2 -0
  36. package/dist/boot/stage-04-stores.js +3 -1
  37. package/dist/boot/stage-05-execution-env.d.ts +4 -0
  38. package/dist/boot/stage-05-execution-env.js +2 -2
  39. package/dist/boot/stage-06-runners.d.ts +4 -1
  40. package/dist/boot/stage-06-runners.js +7 -14
  41. package/dist/boot/stage-07-capability-layer.d.ts +4 -1
  42. package/dist/boot/stage-08-reapers.d.ts +4 -1
  43. package/dist/boot/stage-09-leader.d.ts +6 -1
  44. package/dist/boot/stage-09-leader.js +2 -1
  45. package/dist/boot/stage-10-http-server.d.ts +6 -1
  46. package/dist/boot/stage-10-http-server.js +4 -1
  47. package/dist/brain.d.ts +1 -1
  48. package/dist/config-catalog.d.ts +16 -1
  49. package/dist/config-catalog.js +9 -9
  50. package/dist/config-center/restart-signal.d.ts +4 -4
  51. package/dist/config-invariants.d.ts +7 -1
  52. package/dist/config-invariants.js +37 -6
  53. package/dist/config-provider.d.ts +42 -10
  54. package/dist/config-provider.js +18 -16
  55. package/dist/config-types.d.ts +37 -16
  56. package/dist/config-types.js +1 -0
  57. package/dist/config.d.ts +13 -28
  58. package/dist/config.js +53 -70
  59. package/dist/env-facts.d.ts +13 -3
  60. package/dist/env-facts.js +15 -3
  61. package/dist/execution-lane-caps.d.ts +15 -0
  62. package/dist/execution-lane-caps.js +8 -0
  63. package/dist/file-history-capture.d.ts +42 -35
  64. package/dist/file-history-capture.js +15 -10
  65. package/dist/http/admission.d.ts +11 -4
  66. package/dist/http/admission.js +5 -1
  67. package/dist/http/dispatch.js +3 -3
  68. package/dist/http/principal-gate.d.ts +22 -0
  69. package/dist/http/principal-gate.js +20 -0
  70. package/dist/http/resume-legs.js +9 -5
  71. package/dist/http/routes/agents-roster.d.ts +7 -0
  72. package/dist/http/routes/agents-roster.js +6 -2
  73. package/dist/http/routes/approvals-assistant.d.ts +48 -19
  74. package/dist/http/routes/approvals-assistant.js +117 -50
  75. package/dist/http/routes/capabilities.js +3 -2
  76. package/dist/http/routes/config-catalog.js +1 -0
  77. package/dist/http/routes/memory-consolidation.d.ts +3 -2
  78. package/dist/http/routes/memory-policy.js +3 -3
  79. package/dist/http/routes/rules.js +2 -2
  80. package/dist/http/routes/runs.js +27 -2
  81. package/dist/http/routes/session-sync.js +8 -14
  82. package/dist/http/routes/sessions-list.js +3 -2
  83. package/dist/http/routes/sessions.js +44 -23
  84. package/dist/http/routes/shared-memory.js +2 -2
  85. package/dist/http/routes/tasks.js +22 -19
  86. package/dist/http/routes/trace-usage.js +4 -4
  87. package/dist/http/send.d.ts +12 -0
  88. package/dist/http/send.js +12 -1
  89. package/dist/http/server.d.ts +21 -4
  90. package/dist/http/server.js +7 -4
  91. package/dist/http/sync-submit-body.d.ts +43 -0
  92. package/dist/http/sync-submit-body.js +4 -0
  93. package/dist/http/wire-types.d.ts +23 -5
  94. package/dist/index.d.ts +1 -0
  95. package/dist/index.js +1 -0
  96. package/dist/leader/merge.d.ts +8 -3
  97. package/dist/memory-incident-sink.js +2 -1
  98. package/dist/model-select.d.ts +9 -0
  99. package/dist/model-select.js +5 -1
  100. package/dist/observability/corrupt-read-seat.d.ts +151 -16
  101. package/dist/observability/corrupt-read-seat.js +158 -15
  102. package/dist/observability/fail-open.d.ts +12 -0
  103. package/dist/observability/fail-open.js +12 -0
  104. package/dist/observability/run-terminal.d.ts +15 -1
  105. package/dist/observability/run-terminal.js +4 -0
  106. package/dist/parked-decide.d.ts +8 -3
  107. package/dist/parked-decide.js +56 -20
  108. package/dist/parked-revive-surface.d.ts +14 -7
  109. package/dist/parked-revive-surface.js +5 -1
  110. package/dist/plugins/approval-ask-store-file.d.ts +4 -1
  111. package/dist/plugins/approval-ask-store-file.js +9 -12
  112. package/dist/plugins/approval-ask-store-sql.d.ts +4 -0
  113. package/dist/plugins/approval-ask-store-sql.js +4 -1
  114. package/dist/plugins/approval-exemption-store.d.ts +21 -1
  115. package/dist/plugins/approval-exemption-store.js +36 -7
  116. package/dist/plugins/approval-nonce-store.d.ts +16 -2
  117. package/dist/plugins/approval-nonce-store.js +17 -7
  118. package/dist/plugins/caching-session-store.d.ts +5 -0
  119. package/dist/plugins/caching-session-store.js +3 -0
  120. package/dist/plugins/file-resume-anchor-store.d.ts +7 -2
  121. package/dist/plugins/file-resume-anchor-store.js +19 -5
  122. package/dist/plugins/file-run-store.d.ts +21 -8
  123. package/dist/plugins/file-run-store.js +60 -38
  124. package/dist/plugins/local-session-store.d.ts +22 -0
  125. package/dist/plugins/local-session-store.js +74 -11
  126. package/dist/plugins/memory-run-store.d.ts +7 -5
  127. package/dist/plugins/memory-run-store.js +11 -4
  128. package/dist/plugins/one-time-migrations.d.ts +38 -1
  129. package/dist/plugins/one-time-migrations.js +143 -15
  130. package/dist/plugins/permission-rule-store-file.d.ts +9 -2
  131. package/dist/plugins/permission-rule-store-file.js +37 -51
  132. package/dist/plugins/pg-session-storage.d.ts +3 -0
  133. package/dist/plugins/pg-session-storage.js +19 -10
  134. package/dist/plugins/run-store-sql.d.ts +12 -4
  135. package/dist/plugins/run-store-sql.js +15 -13
  136. package/dist/plugins/send-file-ledger.d.ts +5 -1
  137. package/dist/plugins/send-file-ledger.js +11 -6
  138. package/dist/plugins/session-event-payload.d.ts +14 -4
  139. package/dist/plugins/session-event-payload.js +5 -2
  140. package/dist/plugins/store-backend.d.ts +7 -3
  141. package/dist/plugins/store-backend.js +10 -6
  142. package/dist/plugins/store-contracts.d.ts +7 -2
  143. package/dist/plugins/tidb-pool.js +8 -2
  144. package/dist/plugins/tidb-session-store.d.ts +6 -1
  145. package/dist/plugins/tidb-session-store.js +17 -10
  146. package/dist/project-identity.d.ts +4 -6
  147. package/dist/request-key-closure.js +1 -1
  148. package/dist/request-value-closure.d.ts +72 -3
  149. package/dist/request-value-closure.js +12 -4
  150. package/dist/roster-bound-http-status.d.ts +6 -0
  151. package/dist/roster-bound-http-status.js +6 -0
  152. package/dist/run-local.js +22 -27
  153. package/dist/runs.d.ts +22 -2
  154. package/dist/runs.js +29 -7
  155. package/dist/sealed-key.d.ts +31 -4
  156. package/dist/sealed-key.js +9 -0
  157. package/dist/security.d.ts +5 -1
  158. package/dist/session-children-retire.d.ts +92 -0
  159. package/dist/session-children-retire.js +85 -0
  160. package/dist/session-error-wire.d.ts +58 -0
  161. package/dist/session-error-wire.js +38 -0
  162. package/dist/session-incarnation.d.ts +61 -0
  163. package/dist/session-incarnation.js +43 -0
  164. package/dist/session-records-skipped-notice.d.ts +20 -0
  165. package/dist/session-records-skipped-notice.js +27 -0
  166. package/dist/tool-approval.d.ts +65 -0
  167. package/dist/tool-approval.js +36 -9
  168. package/dist/trace/core-keyset-guard.d.ts +8 -7
  169. package/dist/trace/engine-notice-wire.d.ts +3 -1
  170. package/dist/trace/engine-notice-wire.js +2 -0
  171. package/dist/trace/project.d.ts +1 -1
  172. package/dist/trace/project.js +9 -0
  173. package/dist/trace/wire-projection-faces.d.ts +10 -3
  174. package/dist/trace/wire-projection-faces.js +8 -2
  175. package/package.json +2 -2
@@ -41,9 +41,11 @@ import { DeferredSandboxPathEnv, isSandboxPathAdjudicationLane, sandboxPathEnvSl
41
41
  import { executionLaneCaps, executionLaneHomeDir, executionLaneOf } from "../execution-lane-caps.js";
42
42
  import { effectiveMemoryPersistenceCapable } from "./memory-boundary.js";
43
43
  import { memoryFaceMounted } from "../memory-scope.js";
44
+ import { createAssemblyIncarnationRead, sessionFaceReaderOf } from "./session-incarnation-seat.js";
44
45
  export function createResolveSpec(ctx) {
45
- const { config, logger, metrics, localRoot, scenarios, principalCaps, centerRuntimeCapsResolver, getCenterPrompts, getKeyResolver, taskAttachmentStore, perSessionCwd, setSessionCwd, setSessionShellEnv, fenceSessionOwner, hookLlm, hookAgent, fleetBus, hookWakeBus, noteSessionShellGate, resumeAnchorStore, ownerAware, taskLimitCaps, taskTimeoutSec, selectEnvTool, sendUserFileToolSpec, memoryEngine, durableEnabled, approvalExemptionStore, checkpointStore, deploymentHooks, imageIndex, perTaskImage, sessionEnvSelection, liveQuestionFace, approverSeat, lockedKeys, } = ctx;
46
+ const { config, logger, metrics, localRoot, scenarios, principalCaps, centerRuntimeCapsResolver, getCenterPrompts, getKeyResolver, taskAttachmentStore, perSessionCwd, setSessionCwd, setSessionShellEnv, fenceSessionOwner, noteSessionIncarnation, hookLlm, hookAgent, fleetBus, hookWakeBus, noteSessionShellGate, resumeAnchorStore, ownerAware, taskLimitCaps, taskTimeoutSec, selectEnvTool, sendUserFileToolSpec, memoryEngine, durableEnabled, approvalExemptionStore, checkpointStore, deploymentHooks, imageIndex, perTaskImage, sessionEnvSelection, liveQuestionFace, approverSeat, lockedKeys, } = ctx;
46
47
  assertGuardPatternsUsable(config);
48
+ const assemblyIncarnationRead = createAssemblyIncarnationRead(sessionFaceReaderOf(ownerAware), (e, f) => logger.warn(e, f));
47
49
  const onlySensitiveBaseline = buildOnlySensitiveBaselineWarning(config, {
48
50
  approvalSeat: durableEnabled ? "durable" : "absent",
49
51
  singleUserAutoAcceptBaseline: singleUserAutoAcceptBaselineApplies(config),
@@ -87,6 +89,8 @@ export function createResolveSpec(ctx) {
87
89
  }
88
90
  noteSessionShellGate?.(auth?.sessionId, effMode !== undefined && shellGateForMode(effMode) === "off");
89
91
  const lane = bindSettingsCwdEnvAndModel(body, auth, gated, effMode, opts);
92
+ if (auth?.sessionId && assemblyIncarnationRead)
93
+ noteSessionIncarnation(auth.sessionId, await assemblyIncarnationRead(auth.sessionId));
90
94
  const anchors = await resolveHistoryAnchors(body, auth);
91
95
  const spec = assembleSpecLiteral(body, auth, req, opts, { ...gated, ...lane, ...anchors }, effMode);
92
96
  const folded = await foldGovernanceAndSettings(body, auth, spec, gated, effMode);
@@ -315,6 +319,7 @@ export function createResolveSpec(ctx) {
315
319
  acceptPartialRestore: body.acceptPartialRestore === true ? true : undefined,
316
320
  ...(body.rewindFiles === true ? { rewindFiles: true } : {}),
317
321
  rewindFilesTo: rewindFilesToEntryId,
322
+ ...(body.fileHistory === "disabled" ? { fileHistory: "disabled" } : {}),
318
323
  additionalDirectories,
319
324
  additionalReadDirectories,
320
325
  enablePlanMode: config.planModeEnabled ? true : undefined,
@@ -510,7 +515,9 @@ export function createResolveSpec(ctx) {
510
515
  warn: (msg, meta) => logger.warn(msg, { ...(meta ?? {}), sessionId: auth?.sessionId ?? null }),
511
516
  });
512
517
  const scratchpadDir = shellScratchpad ??
513
- (hostSemanticsLane && auth?.sessionId ? await ensureScratchpadDir(config.localDataRoot ?? localRoot, auth.sessionId) : undefined);
518
+ (hostSemanticsLane && auth?.sessionId
519
+ ? await ensureScratchpadDir(config.localDataRoot ?? localRoot, auth.sessionId, (msg, meta) => logger.warn(msg, { ...(meta ?? {}), sessionId: auth.sessionId }))
520
+ : undefined);
514
521
  if (effectiveSettings) {
515
522
  const gateCommon = {
516
523
  ...(approvalExemptionStore && auth?.sessionId
@@ -616,28 +623,25 @@ export function createResolveSpec(ctx) {
616
623
  perTaskImage.set(auth.sessionId, resolved.ref);
617
624
  resolvedImageCaps = resolved.capabilities;
618
625
  }
619
- if (config.envFactsEnabled) {
620
- const pkgSourceLane = config.remoteExec?.provider === "e2b" || config.remoteExec?.provider === "k8s";
621
- const remoteScratchpadDir = !hostSemanticsLane && isRemoteScratchpadLane(config.remoteExec?.provider)
622
- ? remoteScratchpadDirFor(auth?.sessionId)
623
- : undefined;
624
- const factScratchpadDir = scratchpadDir ?? remoteScratchpadDir;
625
- const facts = buildEnvFacts({
626
- profile: taskImageProfile,
627
- capabilities: resolvedImageCaps,
628
- ...(pkgSourceLane ? { pkgSource: config.sandboxPkgSource } : {}),
629
- egress: egressForRemoteExec(config.remoteExec),
630
- ...(factScratchpadDir ? { scratchpadDir: factScratchpadDir } : {}),
631
- resumeFacts: resumeFactsForLane(config.remoteExec?.provider, config.remoteExec?.provider === "k8s" ? { k8sSnapshot: Boolean(config.remoteExec.s3Snapshot) } : undefined),
632
- });
633
- if (facts)
634
- governed = { ...governed, envFacts: facts };
635
- }
636
- if (scratchpadDir !== undefined) {
637
- const dirs = governed.additionalDirectories ?? [];
638
- if (!dirs.includes(scratchpadDir))
639
- governed = { ...governed, additionalDirectories: [...dirs, scratchpadDir] };
640
- }
626
+ const remoteScratchpadDir = !hostSemanticsLane && isRemoteScratchpadLane(config.remoteExec?.provider)
627
+ ? remoteScratchpadDirFor(auth?.sessionId)
628
+ : undefined;
629
+ const declaredScratchpadDir = scratchpadDir ?? remoteScratchpadDir;
630
+ const pkgSourceLane = config.remoteExec?.provider === "e2b" || config.remoteExec?.provider === "k8s";
631
+ const facts = buildEnvFacts({
632
+ ...(declaredScratchpadDir ? { scratchpadDir: declaredScratchpadDir } : {}),
633
+ ...(config.envFactsEnabled
634
+ ? {
635
+ profile: taskImageProfile,
636
+ capabilities: resolvedImageCaps,
637
+ ...(pkgSourceLane ? { pkgSource: config.sandboxPkgSource } : {}),
638
+ egress: egressForRemoteExec(config.remoteExec),
639
+ resumeFacts: resumeFactsForLane(config.remoteExec?.provider, config.remoteExec?.provider === "k8s" ? { k8sSnapshot: Boolean(config.remoteExec.s3Snapshot) } : undefined),
640
+ }
641
+ : {}),
642
+ });
643
+ if (facts)
644
+ governed = { ...governed, envFacts: facts };
641
645
  if (config.routerEnabled) {
642
646
  const isolatedExecEnv = isIsolatedExecEnv(config.remoteExec?.provider, config.remoteExec?.provider === "k8s" ? config.remoteExec.runtimeClass : undefined);
643
647
  const decision = routeServiceTask({
@@ -86,6 +86,9 @@ export interface RunnerDepsCtx {
86
86
  promptSource: RunnerDeps["promptSource"];
87
87
  rosterStore: RunnerDeps["rosterStore"];
88
88
  backgroundAgentStore: RunnerDeps["backgroundAgentStore"];
89
+ /** S-506([ref] §5):本副本 per-session 登记簿的**同步**化身读腿(装配期由 resolve-spec 写入)。在场 ⇒ 铸
90
+ * `RunnerDeps.memorySessionIncarnation` 座;缺席 ⇒ 座不铸(core 口径:按 id 绑定 = 修前行为)。 */
91
+ sessionIncarnationOf: ((sessionId: string) => string | undefined) | undefined;
89
92
  mailboxStore: RunnerDeps["mailboxStore"];
90
93
  /**
91
94
  * [ref]:mailbox 的**收件人生命周期面**(预删除态)。与 `mailboxStore` **成对**(`boot/stores.ts` 同段铸,
@@ -157,7 +160,8 @@ export interface RunnerDepsCtx {
157
160
  } | undefined;
158
161
  /**
159
162
  * S-399(core 7.21.1)—— 记忆整理的**已解析座**(`boot/memory-consolidation.ts` 的
160
- * `resolveConsolidationDriverSeat` 产物),在场 **iff** `MEMORY_CONSOLIDATION_DRIVER=on` 且记忆引擎接了线。
163
+ * `resolveConsolidationDriverSeat` 产物),在场 **iff** 整理阀门开着(`resolveConsolidationValve` 的判决:
164
+ * `MEMORY_CONSOLIDATION_DRIVER=on`,或未设而 S-824 / [ref] 出厂缺省派生成开)且记忆引擎接了线。
161
165
  *
162
166
  * 🔴 **一座两用,不是两次装配**:同一只座同时喂 admin 阀门的操作面引擎与这里的引擎面两席
163
167
  * (`RunnerDeps.memoryConsolidation` + `memoryConsolidationDriver`)。第二次解析会让「谁在花钱」
@@ -192,7 +196,7 @@ export interface RunnerDepsCtx {
192
196
  runtimeCapsResolver: RunnerDeps["runtimeCapsResolver"];
193
197
  /** [ref] per-edited-file rewind history (core `RunnerDeps.fileHistoryStore`; replaces the retired E19
194
198
  * whole-tree snapshot seat — core 94632197 renamed the seat, not a coexistence). WIRING IS THE OPT-IN.
195
- * S-589:值 = `assembleFileHistory` 的捕获脸(后端 ∧ `FILE_HISTORY_CAPTURE`)。 */
199
+ * S-724:值 = `assembleFileHistory` 的店(后端在即在,与旋钮无关 —— 旋钮关的部署照样还原已存历史)。 */
196
200
  fileHistoryStore: ReturnType<StoreBackend["fileHistory"]> | undefined;
197
201
  /** [ref] 车二:持久化权限规则店 provider(core `RunnerDeps.permissionRuleStore`)。缺席 ⇒ 引擎的
198
202
  * `permissionRules.storeWired` 如实报 false、`AskRequest.ruleOffers` 不铸(诚实缺席)。 */
@@ -3,6 +3,7 @@ import { join } from "node:path";
3
3
  import { listCollabWorkflows, resolveCollabWorkflow } from "../capabilities/collab-workflows.js";
4
4
  import { fleetBackgroundChildPublisher, FleetEventBus } from "../fleet/fleet-bus.js";
5
5
  import { createMemoryEngineIncidentSink } from "../memory-incident-sink.js";
6
+ import { createMemorySessionIncarnationSeat, sessionFaceReaderOf } from "./session-incarnation-seat.js";
6
7
  import { assertAutoConsolidationWirable } from "./memory-consolidation.js";
7
8
  import { createHardenedVmRunner } from "../orchestration/hardened-vm-runner.js";
8
9
  import { createWorkerHardenedVmRunner } from "../orchestration/hardened-vm-worker-runner.js";
@@ -16,6 +17,7 @@ import { workflowModelAllowlistFor } from "../task-workflow.js";
16
17
  import { buildCrossSessionInboundLayers, crossSessionDialogExpiryOf } from "../cross-session-settings.js";
17
18
  import { createPeerDirectory } from "../peer-directory.js";
18
19
  import { targetOutsideStoreInIncident } from "../memory-store-refusal.js";
20
+ import { coreFileHistoryCaptureSeat } from "../file-history-capture.js";
19
21
  export function createRunnerDepsOnAsk(toolApproval) {
20
22
  if (!toolApproval)
21
23
  return undefined;
@@ -186,6 +188,7 @@ export function createRunnerDeps(ctx) {
186
188
  memoryBackend: memoryEngine ? memoryEngine.backend : undefined,
187
189
  memoryEngineDir: memoryEngine ? memoryEngine.root : undefined,
188
190
  memoryCaptureRecordStore: sessionCaptureRecords !== undefined ? (plane) => sessionCaptureRecords(plane) : undefined,
191
+ memorySessionIncarnation: ctx.sessionIncarnationOf !== undefined && sessionFaceReaderOf(sessionStore) !== undefined ? createMemorySessionIncarnationSeat(ctx.sessionIncarnationOf, (e, f) => logger.warn(e, f)) : undefined,
189
192
  onMemoryHarvestReport: memoryEngine
190
193
  ? (report, info) => {
191
194
  metrics.inc("memory_harvest_total", { ok: String(report.ok), phase: info.phase, incident: report.incident?.kind ?? "none" });
@@ -212,6 +215,7 @@ export function createRunnerDeps(ctx) {
212
215
  : undefined,
213
216
  runtimeCapsResolver: runtimeCapsResolver ? runtimeCapsResolver : undefined,
214
217
  fileHistoryStore: fileHistoryStore ? fileHistoryStore : undefined,
218
+ fileHistoryCapture: coreFileHistoryCaptureSeat(fileHistoryStore, config.fileHistoryCapture),
215
219
  permissionRuleStore: permissionRuleStore ? permissionRuleStore : undefined,
216
220
  onBackgroundChildEvent: fleetBackgroundChildPublisher(fleetBus, (msg, fields) => logger.info(msg, fields)),
217
221
  loadProjectMemory: config.requirePrincipal !== true && config.projectMemoryEnabled
@@ -40,6 +40,9 @@ export interface SessionFacesCtx {
40
40
  * (`boot/stores.ts` 同段铸);缺席 = 本部署无耐久 mailbox ⇒ 无箱可退役。 */
41
41
  mailboxStore: RunnerDeps["mailboxStore"];
42
42
  mailboxRecipientLifecycle: MailboxRecipientLifecycle | undefined;
43
+ /** S-790 件B:后台子代的耐久店(与 `RunnerDeps.backgroundAgentStore` 同实例)—— 删除协调器据它枚举以本会话为根的子代并结束
44
+ * 它们(E21 级联的一条腿,做完才删元数据)。缺席 = 本部署没有耐久后台子代(纯内存 dev);那一形只剩本进程登记表里的活行,照样停。 */
45
+ backgroundAgentStore: RunnerDeps["backgroundAgentStore"];
43
46
  }
44
47
  export declare function createSessionFaces(ctx: SessionFacesCtx): {
45
48
  ownerAware: OwnerAwareSessionStore;
@@ -67,6 +70,8 @@ export declare function createSessionFaces(ctx: SessionFacesCtx): {
67
70
  deleted: boolean;
68
71
  } | {
69
72
  active: string;
73
+ } | {
74
+ childrenAlive: readonly string[];
70
75
  }>) | undefined;
71
76
  instrumentDegenerate: ((result: import("@sema-agent/core").TaskResult) => void) | undefined;
72
77
  planCacheProbe: PlanCacheProbe;
@@ -4,10 +4,11 @@ import { PlanCacheProbe } from "../plan-cache-probe.js";
4
4
  import { purgeScratchpadDir } from "../env-facts.js";
5
5
  import { setLeafAdvanceListener } from "../session-leaf-bus.js";
6
6
  import { SessionWatchRegistry, posIntEnv } from "../session-watch.js";
7
- import { peerSessionBoxHandle } from "@sema-agent/core";
7
+ import { defaultTaskRegistry, peerSessionBoxHandle } from "@sema-agent/core";
8
8
  import { reapSessionBackgroundHard } from "../background-session-reap.js";
9
+ import { probeSessionChildren, retireSessionChildren, SessionChildrenStopIncompleteError } from "../session-children-retire.js";
9
10
  export function createSessionFaces(ctx) {
10
- const { config, logger, metrics, localRoot, backend, sessionStore, runStore, checkpointStore, toolResultStore, resumeAnchorStore, approvalExemptionStore, sessionPolicyStore, taskAttachmentStore, fileHistoryErasure, workflowCompletionInbox, taskListLane, deviceStore, dropSessionScoped, mailboxStore, mailboxRecipientLifecycle, } = ctx;
11
+ const { config, logger, metrics, localRoot, backend, sessionStore, runStore, checkpointStore, toolResultStore, resumeAnchorStore, approvalExemptionStore, sessionPolicyStore, taskAttachmentStore, fileHistoryErasure, workflowCompletionInbox, taskListLane, deviceStore, dropSessionScoped, mailboxStore, mailboxRecipientLifecycle, backgroundAgentStore, } = ctx;
11
12
  const mysqlPool = backend?.mysqlPool();
12
13
  const auditPgPool = backend?.pgPool();
13
14
  const auditLocalRoot = backend?.kind === "local" ? (config.localDataRoot ?? localRoot) : undefined;
@@ -39,9 +40,24 @@ export function createSessionFaces(ctx) {
39
40
  if (stillOwner !== owner)
40
41
  return { deleted: false };
41
42
  }
43
+ const childScope = owner ?? "default";
44
+ const reach = await probeSessionChildren({ agentStore: backgroundAgentStore, checkpointStore, registry: defaultTaskRegistry }, sessionId, childScope);
45
+ if (!reach.reachable) {
46
+ logger.warn("session_delete_children_still_alive", { sessionId, remaining: reach.unreachableHandles.length, handles: reach.unreachableHandles });
47
+ return { childrenAlive: reach.unreachableHandles };
48
+ }
42
49
  const runs = runStore ? await runStore.deleteBySession(sessionId, owner) : { removed: 0 };
43
50
  if ("active" in runs)
44
51
  return { active: runs.active };
52
+ {
53
+ const children = await retireSessionChildren({ agentStore: backgroundAgentStore, checkpointStore, registry: defaultTaskRegistry }, sessionId, childScope);
54
+ if (children.found > 0)
55
+ logger.info("session_children_retired", { sessionId, found: children.found, stopped: children.stopped, rounds: children.rounds });
56
+ if (children.stopped === "incomplete") {
57
+ logger.warn("session_delete_children_stop_incomplete", { sessionId, remaining: children.remainingHandles.length, handles: children.remainingHandles });
58
+ throw new SessionChildrenStopIncompleteError(sessionId, children.remainingHandles.length);
59
+ }
60
+ }
45
61
  if (checkpointStore)
46
62
  await checkpointStore.deleteBySession(sessionId, owner);
47
63
  if (toolResultStore) {
@@ -0,0 +1,41 @@
1
+ /**
2
+ * S-506([ref] §5)—— 记忆引擎的会话化身座 `RunnerDeps.memorySessionIncarnation` 的装配件。
3
+ *
4
+ * core 的座是**同步**签名(`({ sessionId }) => string | undefined`),而会话化身住在会话元数据里、读它是异步的 ⇒ 两段:
5
+ * · **写**(装配期):resolve-spec 每次提交(fresh 与 resume 腿同经)经 {@link createAssemblyIncarnationRead} 造的读口异步读一次会话面,
6
+ * 记进本副本的 per-session 登记簿(`boot/execution-env.ts` 的 `noteSessionIncarnation`,与 cwd / shellEnv 同一只 LRU、同一条围栏、
7
+ * 同一条删除);
8
+ * · **读**(运行期):{@link createMemorySessionIncarnationSeat} 从登记簿同步取。
9
+ *
10
+ * ## 读口缺席是装配期事实(合并复审 F2)
11
+ * 「会话店有没有 `sessionFaceOf`」由 {@link sessionFaceReaderOf} 判,resolve-spec 与 runner-deps 读同一只:缺席(内存会话店 /
12
+ * 多租户裸 boot / 降级到内存的副本)⇒ resolve-spec **构造时** warn 一次、请求路径上不再判不再打;记忆座不装(恒答 undefined 的座与不装
13
+ * 同义,core 按 id 绑定 = 修前行为)。修前是每一次提交打一行。
14
+ *
15
+ * ## 读不到的臂([ref]:响亮,不静默)
16
+ * 会话不在 / 读口抛(含空化身的响亮拒)⇒ 这一轮没有化身 ⇒ 座答 `undefined`(core 口径:按 id 绑定 —— 今天的行为,且是**保守**方向:
17
+ * 上一位住客的 opt-out / 污染标记仍会约束这一位,不会让任何一条被放过)+ warn,**按会话去重**(同一只会话连着读不到只说一次,读到了再
18
+ * 读不到重新说)。没有「读不到就沿用上次」的臂:装配期读失败会把登记簿那一格**清掉**,座随之答 undefined。
19
+ *
20
+ * ## 令牌不出本进程的内存
21
+ * 不上 wire、不进模型上下文;warn 行只带会话 id —— 缺席的那一臂根本没有令牌可打。
22
+ */
23
+ import type { RunnerDeps } from "@sema-agent/core";
24
+ import type { SessionFaceReader } from "../session-incarnation.js";
25
+ /** warn 口(logger 的子集)。 */
26
+ type Warn = (event: string, fields: Record<string, unknown>) => void;
27
+ /** 会话店的「属主 + 化身」读口 —— 装配期判一次(resolve-spec 与 runner-deps 读同一只,判据不各写一份)。缺席 = 这只会话店没有它。 */
28
+ export declare function sessionFaceReaderOf(store: unknown): SessionFaceReader | undefined;
29
+ /**
30
+ * 装配期化身读口(resolve-spec **构造时**建一次)。读口缺席 ⇒ 当场 warn 一次、返回 `undefined`(请求路径上不再判不再打);
31
+ * 在场 ⇒ 返回一只读:读到 ⇒ 化身;会话不在 / 读抛 ⇒ `undefined` + 按会话去重的 warn。不抛:这是记忆座的输入,不是提交的准入门
32
+ * (提交的属主门在 authorizer;读失败的那一格由座答 undefined 兜成保守绑定)。
33
+ */
34
+ export declare function createAssemblyIncarnationRead(read: SessionFaceReader | undefined, warn: Warn): ((sessionId: string) => Promise<string | undefined>) | undefined;
35
+ /**
36
+ * `RunnerDeps.memorySessionIncarnation` 的同步座:从本副本的 per-session 登记簿取装配期读数。缺席 ⇒ `undefined` + 每个会话一行 warn。
37
+ * 命名照工厂律:返回的是带行为的闭包 ⇒ `create*`。
38
+ */
39
+ export declare function createMemorySessionIncarnationSeat(incarnationOf: (sessionId: string) => string | undefined, warn: Warn): NonNullable<RunnerDeps["memorySessionIncarnation"]>;
40
+ export {};
41
+ //# sourceMappingURL=session-incarnation-seat.d.ts.map
@@ -0,0 +1,69 @@
1
+ const MISS_WARNED_MAX = 4096;
2
+ export function sessionFaceReaderOf(store) {
3
+ const s = store;
4
+ return typeof s?.sessionFaceOf === "function" ? s.sessionFaceOf.bind(s) : undefined;
5
+ }
6
+ function createPerSessionWarn(warn) {
7
+ const warned = new Set();
8
+ return {
9
+ once(sessionId, fields) {
10
+ if (warned.has(sessionId))
11
+ return;
12
+ if (warned.size >= MISS_WARNED_MAX)
13
+ warned.clear();
14
+ warned.add(sessionId);
15
+ warn("session_incarnation_unavailable", { sessionId, ...fields });
16
+ },
17
+ clear(sessionId) {
18
+ warned.delete(sessionId);
19
+ },
20
+ };
21
+ }
22
+ export function createAssemblyIncarnationRead(read, warn) {
23
+ if (read === undefined) {
24
+ warn("session_incarnation_unavailable", {
25
+ reason: "no_session_face_read",
26
+ note: "this deployment's session store has no sessionFaceOf read (an in-memory session store) — session incarnations are not read and memory records bind by id alone; stated once at assembly",
27
+ });
28
+ return undefined;
29
+ }
30
+ const perSession = createPerSessionWarn(warn);
31
+ return async (sessionId) => {
32
+ try {
33
+ const face = await read(sessionId);
34
+ if (face === undefined) {
35
+ perSession.once(sessionId, { reason: "session_absent", note: "no session row at assembly — memory records for this session bind by id alone this run" });
36
+ return undefined;
37
+ }
38
+ perSession.clear(sessionId);
39
+ return face.incarnation;
40
+ }
41
+ catch (e) {
42
+ const code = e?.code;
43
+ perSession.once(sessionId, {
44
+ reason: typeof code === "string" ? code : "read_failed",
45
+ note: "the session face could not be read at assembly — memory records for this session bind by id alone this run",
46
+ });
47
+ return undefined;
48
+ }
49
+ };
50
+ }
51
+ export function createMemorySessionIncarnationSeat(incarnationOf, warn) {
52
+ const warned = new Set();
53
+ return ({ sessionId }) => {
54
+ const incarnation = incarnationOf(sessionId);
55
+ if (incarnation !== undefined)
56
+ return incarnation;
57
+ if (!warned.has(sessionId)) {
58
+ if (warned.size >= MISS_WARNED_MAX)
59
+ warned.clear();
60
+ warned.add(sessionId);
61
+ warn("memory_session_incarnation_unknown", {
62
+ sessionId,
63
+ note: "no incarnation was read for this session on this replica (not assembled here, or its read failed) — the memory engine binds this session's records by id alone",
64
+ });
65
+ }
66
+ return undefined;
67
+ };
68
+ }
69
+ //# sourceMappingURL=session-incarnation-seat.js.map
@@ -1,6 +1,6 @@
1
1
  import { homedir } from "node:os";
2
- import { join } from "node:path";
3
2
  import { loadConfig, logConfigDiagnostics, splitLocalRoots } from "../config.js";
3
+ import { configLocalRoot } from "../config-provider.js";
4
4
  import { crossInvariant } from "../config-invariants.js";
5
5
  import { drainNumEnvWarnings } from "../plugins/remote-shell.js";
6
6
  import { setWebSearchBadPayloadObserver } from "../plugins/web-search.js";
@@ -44,7 +44,7 @@ export function runStage01() {
44
44
  else
45
45
  logger.info("run_failed", fields);
46
46
  });
47
- const localRoot = config.configLocalDir ?? process.env.AGENT_DATA_DIR ?? join(homedir(), ".ai-agent");
47
+ const localRoot = configLocalRoot(config);
48
48
  const rootsSplit = splitLocalRoots({
49
49
  localDataRoot: config.localDataRoot,
50
50
  configLocalDir: config.configLocalDir,
@@ -1,8 +1,11 @@
1
1
  import { createUnpricedCeilingVerdict } from "./unpriced-ceiling-verdict.js";
2
2
  import { createConfigCenterRuntime } from "./config-center.js";
3
+ import { composeExecutionLane, FILE_SOURCED_LANES } from "./execution-lane.js";
4
+ import { serviceConfigSourceKind } from "../config-provider.js";
3
5
  import { defaultModelRefusal, refusedNameMintedRefusal } from "../model-entry-refusal.js";
4
6
  export async function runStage02(ctx) {
5
7
  const { config, localRoot, logger, metrics } = ctx;
8
+ await composeExecutionLane(config, { configSource: serviceConfigSourceKind(config), localRoot, logger, drivesFromFile: FILE_SOURCED_LANES });
6
9
  const configCenter = await createConfigCenterRuntime({ config, logger, metrics, localRoot });
7
10
  const noDefaultModel = defaultModelRefusal(config, "env");
8
11
  if (noDefaultModel !== undefined) {
@@ -12,7 +15,6 @@ export async function runStage02(ctx) {
12
15
  if (mintedRefused !== undefined) {
13
16
  throw new Error(mintedRefused);
14
17
  }
15
- await configCenter.applyLocalRemoteExec();
16
18
  const ceilingVerdict = createUnpricedCeilingVerdict({ config, logger });
17
19
  ceilingVerdict.judge();
18
20
  return { ...ctx, ceilingVerdict, configCenter };
@@ -1,6 +1,8 @@
1
1
  import type { runStage03 } from "./stage-03-store-backend.js";
2
2
  export declare function runStage04(ctx: Awaited<ReturnType<typeof runStage03>>): Promise<{
3
3
  brain: import("@sema-agent/core").Brain;
4
+ consolidationSeatWatch: import("./memory-consolidation.js").ConsolidationSeatWatch | undefined;
5
+ consolidationValve: import("./memory-consolidation.js").ConsolidationValve;
4
6
  costQuota: import("../observability/cost-quota.js").CostQuota | import("../plugins/pg-cost-quota.js").PgCostQuota | import("../plugins/tidb-cost-quota.js").TiDBCostQuota;
5
7
  degradeRouteWatch: import("../brain.js").DegradeRouteWatch;
6
8
  counterDegradeHook: (info: {
@@ -5,6 +5,7 @@ import { runAdoptionBootScan } from "./adoption.js";
5
5
  import { auditDormantPermissionRules } from "./permission-rules-audit.js";
6
6
  import { createBudgetAndTracing } from "./budget-tracing.js";
7
7
  import { createRuleConsentLane } from "../rules-consent.js";
8
+ import { createConsolidationValve } from "./memory-consolidation.js";
8
9
  export async function runStage04(ctx) {
9
10
  const { backend, breakerState, config, logger, memoryEngine, metrics, sessionCaptureRecordStore } = ctx;
10
11
  const memoryBundleFaces = memoryEngine ? createMemoryBundleFaces(memoryEngine, { ...(sessionCaptureRecordStore !== undefined ? { captureRecordStore: sessionCaptureRecordStore } : {}) }) : undefined;
@@ -23,6 +24,7 @@ export async function runStage04(ctx) {
23
24
  const sessionMemoryStatusFace = memoryEngine
24
25
  ? createSessionMemoryStatusFace(memoryEngine, { ...(sessionCaptureRecordStore !== undefined ? { captureRecordStore: sessionCaptureRecordStore } : {}) })
25
26
  : undefined;
27
+ const { valve: consolidationValve, watch: consolidationSeatWatch } = createConsolidationValve({ config, memoryEngine, logger });
26
28
  const adoptionBoot = await runAdoptionBootScan({ backend, logger });
27
29
  if (adoptionBoot.scanned > 0 || adoptionBoot.error !== undefined) {
28
30
  logger.info("adoption_boot_scan", { ...adoptionBoot });
@@ -44,6 +46,6 @@ export async function runStage04(ctx) {
44
46
  });
45
47
  }
46
48
  await auditDormantPermissionRules({ stores: permissionRuleStores, logger, explicit: config.permissionRulesEnabledExplicit });
47
- return { ...ctx, brain, costQuota, degradeRouteWatch, counterDegradeHook, fileHistoryErasure, fileHistoryStore, fleetLease, fleetUsage, memoryBundleFaces, memoryComplianceFaces, memoryOriginFaces, modelUsageTracker, permissionRuleProvider, permissionRuleStores, pricing, promptManifestTracker, ruleConsent, sessionMemoryStatusFace, sessionPolicyStore, sideQueryAccounting, toolResultStore, tracer };
49
+ return { ...ctx, brain, consolidationSeatWatch, consolidationValve, costQuota, degradeRouteWatch, counterDegradeHook, fileHistoryErasure, fileHistoryStore, fleetLease, fleetUsage, memoryBundleFaces, memoryComplianceFaces, memoryOriginFaces, modelUsageTracker, permissionRuleProvider, permissionRuleStores, pricing, promptManifestTracker, ruleConsent, sessionMemoryStatusFace, sessionPolicyStore, sideQueryAccounting, toolResultStore, tracer };
48
50
  }
49
51
  //# sourceMappingURL=stage-04-stores.js.map
@@ -6,14 +6,18 @@ export declare function runStage05(ctx: Awaited<ReturnType<typeof runStage04>>):
6
6
  executionEnvFactory: import("@sema-agent/core").ExecutionEnvFactory | undefined;
7
7
  fenceSessionOwner: (sid: string, owner: string | null) => void;
8
8
  lspManager: import("@sema-agent/core").NodeLspManager | import("../lsp/manager.js").E2bLspManager | undefined;
9
+ noteSessionIncarnation: (sid: string, incarnation: string | undefined) => void;
9
10
  perSessionCwd: Map<string, string>;
10
11
  perTaskImage: import("../per-task-image.js").PerTaskImageRegistry;
11
12
  sendUserFileTaskEnvs: import("../capabilities/sandbox-file-send.js").TaskEnvRegistry | undefined;
12
13
  sessionEnvSelection: import("../capabilities/select-environment-tool.js").SessionEnvironmentSelection;
14
+ sessionIncarnationOf: (sid: string) => string | undefined;
13
15
  setSessionCwd: (sid: string, cwd: string) => void;
14
16
  setSessionShellEnv: (sid: string, env: Record<string, string>) => void;
15
17
  worktreeReap: (() => Promise<void>) | undefined;
16
18
  brain: import("@sema-agent/core").Brain;
19
+ consolidationSeatWatch: import("./memory-consolidation.js").ConsolidationSeatWatch | undefined;
20
+ consolidationValve: import("./memory-consolidation.js").ConsolidationValve;
17
21
  costQuota: import("../observability/cost-quota.js").CostQuota | import("../plugins/pg-cost-quota.js").PgCostQuota | import("../plugins/tidb-cost-quota.js").TiDBCostQuota;
18
22
  degradeRouteWatch: import("../brain.js").DegradeRouteWatch;
19
23
  counterDegradeHook: (info: {
@@ -5,7 +5,7 @@ import { createExecutionEnv } from "./execution-env.js";
5
5
  export function runStage05(ctx) {
6
6
  const { backend, config, instanceId, logger, metrics, taskAttachmentStore } = ctx;
7
7
  const deviceLane = config.remoteExec?.provider === "device" ? createDeviceLane({ config, logger, metrics, backend, replicaId: instanceId }) : undefined;
8
- const { perTaskImage, sessionEnvSelection, perSessionCwd, setSessionCwd, setSessionShellEnv, fenceSessionOwner, dropSessionScoped, executionEnvFactory, worktreeReap, sendUserFileTaskEnvs, lspManager, } = createExecutionEnv({ config, logger, metrics, taskAttachmentStore, ...(deviceLane ? { deviceLane } : {}) });
8
+ const { perTaskImage, sessionEnvSelection, perSessionCwd, setSessionCwd, setSessionShellEnv, fenceSessionOwner, dropSessionScoped, noteSessionIncarnation, sessionIncarnationOf, executionEnvFactory, worktreeReap, sendUserFileTaskEnvs, lspManager, } = createExecutionEnv({ config, logger, metrics, taskAttachmentStore, ...(deviceLane ? { deviceLane } : {}) });
9
9
  assertDeviceLaneWired(config.remoteExec?.provider === "device", deviceLane, executionEnvFactory !== undefined);
10
10
  const toolTracer = config.toolTrace ? createToolTracer(logger) : undefined;
11
11
  if (toolTracer)
@@ -14,6 +14,6 @@ export function runStage05(ctx) {
14
14
  ...(toolTracer ? composeHooks(createPermissionDeniedMeter(metrics), toolTracer) : createPermissionDeniedMeter(metrics)),
15
15
  ...(config.hooksTimeoutMs !== undefined ? { timeoutMs: config.hooksTimeoutMs } : {}),
16
16
  };
17
- return { ...ctx, deploymentHooks, deviceLane, dropSessionScoped, executionEnvFactory, fenceSessionOwner, lspManager, perSessionCwd, perTaskImage, sendUserFileTaskEnvs, sessionEnvSelection, setSessionCwd, setSessionShellEnv, worktreeReap };
17
+ return { ...ctx, deploymentHooks, deviceLane, dropSessionScoped, executionEnvFactory, fenceSessionOwner, lspManager, noteSessionIncarnation, perSessionCwd, perTaskImage, sendUserFileTaskEnvs, sessionEnvSelection, sessionIncarnationOf, setSessionCwd, setSessionShellEnv, worktreeReap };
18
18
  }
19
19
  //# sourceMappingURL=stage-05-execution-env.js.map
@@ -13,7 +13,6 @@ export declare function runStage06(ctx: Awaited<ReturnType<typeof runStage05>>):
13
13
  approvalAskAudit: import("../approval-ask-audit-store.js").FileApprovalAskAuditStore | undefined;
14
14
  centerRuntimeCapsResolver: ((principal: string | undefined) => Promise<import("@sema-agent/core").RuntimeCaps | undefined>) | undefined;
15
15
  checkpointStore: import("../plugins/store-backend.js").CheckpointStoreFull | undefined;
16
- consolidationSeatWatch: import("./memory-consolidation.js").ConsolidationSeatWatch | undefined;
17
16
  durableEnabled: boolean;
18
17
  elicitation: import("../elicitation.js").ElicitationCoordinator | undefined;
19
18
  fleetBus: import("../fleet/fleet-bus.js").FleetEventBus;
@@ -67,14 +66,18 @@ export declare function runStage06(ctx: Awaited<ReturnType<typeof runStage05>>):
67
66
  executionEnvFactory: import("@sema-agent/core").ExecutionEnvFactory | undefined;
68
67
  fenceSessionOwner: (sid: string, owner: string | null) => void;
69
68
  lspManager: import("@sema-agent/core").NodeLspManager | import("../lsp/manager.js").E2bLspManager | undefined;
69
+ noteSessionIncarnation: (sid: string, incarnation: string | undefined) => void;
70
70
  perSessionCwd: Map<string, string>;
71
71
  perTaskImage: import("../per-task-image.js").PerTaskImageRegistry;
72
72
  sendUserFileTaskEnvs: import("../capabilities/sandbox-file-send.js").TaskEnvRegistry | undefined;
73
73
  sessionEnvSelection: import("../capabilities/select-environment-tool.js").SessionEnvironmentSelection;
74
+ sessionIncarnationOf: (sid: string) => string | undefined;
74
75
  setSessionCwd: (sid: string, cwd: string) => void;
75
76
  setSessionShellEnv: (sid: string, env: Record<string, string>) => void;
76
77
  worktreeReap: (() => Promise<void>) | undefined;
77
78
  brain: import("@sema-agent/core").Brain;
79
+ consolidationSeatWatch: import("./memory-consolidation.js").ConsolidationSeatWatch | undefined;
80
+ consolidationValve: import("./memory-consolidation.js").ConsolidationValve;
78
81
  costQuota: import("../observability/cost-quota.js").CostQuota | import("../plugins/pg-cost-quota.js").PgCostQuota | import("../plugins/tidb-cost-quota.js").TiDBCostQuota;
79
82
  degradeRouteWatch: import("../brain.js").DegradeRouteWatch;
80
83
  counterDegradeHook: (info: {
@@ -7,10 +7,9 @@ import { withoutExecutionEnv } from "../capabilities/hands-lane.js";
7
7
  import { redactSecrets } from "../trace/redact.js";
8
8
  import { hasServiceAuth } from "../http/server.js";
9
9
  import { workflowModelAllowlistFor } from "../task-workflow.js";
10
- import { backendOwnsControlPlane } from "../memory-operator-faces.js";
11
10
  import { createHookLlm, buildHookFailureText } from "../hooks/hook-llm.js";
12
11
  import { assertRetentionLaneWirable } from "./retention-lane.js";
13
- import { assertConsolidationDriverWirable, buildConsolidationValveAudit, createConsolidationSeatWatch, createMemoryConsolidationFaces, resolveConsolidationDriverSeat } from "./memory-consolidation.js";
12
+ import { buildConsolidationValveAudit, createMemoryConsolidationFaces, resolveConsolidationDriverSeat } from "./memory-consolidation.js";
14
13
  import { createPerModelAuthSeat } from "./side-query-lane.js";
15
14
  import { createWorkflowOrchestration } from "./workflow-orchestration.js";
16
15
  import { createLiveCoordinators } from "./coordinators.js";
@@ -22,7 +21,7 @@ import { createGovernanceSeams } from "./governance-seams.js";
22
21
  import { createSharedMemoryScopeAuthorizer } from "../shared-memory-scope-authorizer.js";
23
22
  import { parkedAskRedeem, runStore } from "./late-binds.js";
24
23
  export function runStage06(ctx) {
25
- const { backend, backgroundAgentStore, brain, config, configCenter, deploymentHooks, executionEnvFactory, fileHistoryStore, localRoot, logger, lspManager, mailboxRecipientLifecycle, mailboxStore, memoryEngine, memorySyncRunner, metrics, perSessionCwd, permissionRuleProvider, pricing, rosterStore, ruleConsent, sendUserFileTaskEnvs, sessionCaptureRecordStore, sessionCaptureRecords, sessionPolicyStore, sessionStore, taskAttachmentStore, taskListLane, toolResultStore, tracer, usageWindowStore } = ctx;
24
+ const { backend, backgroundAgentStore, brain, sessionIncarnationOf, config, configCenter, consolidationValve, deploymentHooks, executionEnvFactory, fileHistoryStore, localRoot, logger, lspManager, mailboxRecipientLifecycle, mailboxStore, memoryEngine, memorySyncRunner, metrics, perSessionCwd, permissionRuleProvider, pricing, rosterStore, ruleConsent, sendUserFileTaskEnvs, sessionCaptureRecordStore, sessionCaptureRecords, sessionPolicyStore, sessionStore, taskAttachmentStore, taskListLane, toolResultStore, tracer, usageWindowStore } = ctx;
26
25
  const { sqlWorkflowRunStore, workflowNotifyJournal, workflowCompletionInbox, deliverWorkflowCompletion, workflowNotifyGate, fleetBus, workflowRunStore, workflowJournalStore, outcomeSink, workflowRecoverOpts, workflowAgentRegistry, subagentSteerRegistry, workflowAgentSessionIndex, } = createWorkflowOrchestration({ config, logger, metrics, localRoot, backend, getRunStore: () => runStore });
27
26
  const { elicitation, question, toolApproval, durableEnabled, streamApprovalGate, approvalAskAudit, sendUserFileEmitter, sendFileLedger, sendUserFileToolSpec } = createLiveCoordinators({
28
27
  config, logger, backend, sendUserFileTaskEnvs, ruleConsent,
@@ -56,14 +55,7 @@ export function runStage06(ctx) {
56
55
  ],
57
56
  locked: (config.lockedConfigKeys ?? []).includes("retentionPolicy"),
58
57
  });
59
- assertConsolidationDriverWirable({
60
- enabled: config.memoryConsolidationDriver.enabled,
61
- memoryEngineWired: memoryEngine !== undefined,
62
- controlPlaneOwned: backendOwnsControlPlane(memoryEngine?.backend),
63
- memoryEngineBackend: config.memoryEngineBackend,
64
- ...(config.memoryProvenance !== undefined ? { provenance: config.memoryProvenance } : {}),
65
- });
66
- const consolidationSeat = config.memoryConsolidationDriver.enabled && memoryEngine
58
+ const consolidationSeat = consolidationValve.enabled && memoryEngine
67
59
  ? resolveConsolidationDriverSeat({
68
60
  brain,
69
61
  models: config.models,
@@ -72,7 +64,6 @@ export function runStage06(ctx) {
72
64
  getApiKeyAndHeaders: createPerModelAuthSeat(() => configCenter.getKeyResolver()),
73
65
  })
74
66
  : undefined;
75
- const consolidationSeatWatch = consolidationSeat ? createConsolidationSeatWatch(() => ({ models: config.models, tiers: config.tiers, roles: config.roles })) : undefined;
76
67
  const memoryConsolidationFaces = consolidationSeat && memoryEngine
77
68
  ? createMemoryConsolidationFaces(memoryEngine, {
78
69
  seat: consolidationSeat,
@@ -84,7 +75,7 @@ export function runStage06(ctx) {
84
75
  })
85
76
  : undefined;
86
77
  for (const w of buildConsolidationValveAudit({
87
- enabled: config.memoryConsolidationDriver.enabled,
78
+ valve: consolidationValve,
88
79
  operatorPrincipals: config.operatorPrincipals,
89
80
  hasServiceAuth: hasServiceAuth(config),
90
81
  allowUnauthedWrites: config.allowUnauthedWrites ?? false,
@@ -93,6 +84,7 @@ export function runStage06(ctx) {
93
84
  }
94
85
  if (memoryConsolidationFaces !== undefined) {
95
86
  logger.info("memory_consolidation_driver_armed", {
87
+ valve: consolidationValve.source,
96
88
  seat: memoryConsolidationFaces.seat,
97
89
  model: memoryConsolidationFaces.model,
98
90
  scopes: memoryConsolidationFaces.scopes,
@@ -118,6 +110,7 @@ export function runStage06(ctx) {
118
110
  hands: commitHands,
119
111
  mcpRevocations,
120
112
  sessionShellGateExplicitlyOff: sessionShellGateRegistry.explicitlyOff,
113
+ sessionIncarnationOf,
121
114
  config, logger, metrics, localRoot, promptSource: configCenter.promptSource, rosterStore, backgroundAgentStore, mailboxStore, mailboxRecipientLifecycle, usageWindowStore, brain,
122
115
  pricing, tracer, outcomeSink, elicitation, question, toolApproval, sessionStore, memoryEngine,
123
116
  sessionCaptureRecords,
@@ -212,6 +205,6 @@ export function runStage06(ctx) {
212
205
  };
213
206
  const subRunner = new Runner(subRunnerDeps);
214
207
  const handslessSubRunner = new Runner(withoutExecutionEnv(subRunnerDeps));
215
- return { ...ctx, approvalAskAudit, centerRuntimeCapsResolver, checkpointStore, consolidationSeatWatch, durableEnabled, elicitation, fleetBus, governanceSeams, handslessRunner, handslessSubRunner, hookAgent, hookAgentRunner, hookLlm, mcpRevocations, memoryConsolidationFaces, memoryOptOutGrantStore, orgMemoryAdmission, outcomeSink, principalCaps, question, retentionExecutor, retentionLaneStore, runner, runnerDeps, runtimeCapsPeekResolver, sendFileLedger, sendUserFileEmitter, sendUserFileToolSpec, sessionShellGateRegistry, sessionTitler, sharedMemoryStore, sqlWorkflowRunStore, streamApprovalGate, subRunner, subRunnerSessions, subagentSteerRegistry, toolApproval, workflowAgentRegistry, workflowAgentSessionIndex, workflowCompletionInbox, workflowJournalStore, workflowModelAllowlistSnapshot, workflowNotifyGate, workflowNotifyJournal, workflowRecoverOpts, workflowRunStore, workflowsCapable };
208
+ return { ...ctx, approvalAskAudit, centerRuntimeCapsResolver, checkpointStore, durableEnabled, elicitation, fleetBus, governanceSeams, handslessRunner, handslessSubRunner, hookAgent, hookAgentRunner, hookLlm, mcpRevocations, memoryConsolidationFaces, memoryOptOutGrantStore, orgMemoryAdmission, outcomeSink, principalCaps, question, retentionExecutor, retentionLaneStore, runner, runnerDeps, runtimeCapsPeekResolver, sendFileLedger, sendUserFileEmitter, sendUserFileToolSpec, sessionShellGateRegistry, sessionTitler, sharedMemoryStore, sqlWorkflowRunStore, streamApprovalGate, subRunner, subRunnerSessions, subagentSteerRegistry, toolApproval, workflowAgentRegistry, workflowAgentSessionIndex, workflowCompletionInbox, workflowJournalStore, workflowModelAllowlistSnapshot, workflowNotifyGate, workflowNotifyJournal, workflowRecoverOpts, workflowRunStore, workflowsCapable };
216
209
  }
217
210
  //# sourceMappingURL=stage-06-runners.js.map
@@ -27,7 +27,6 @@ export declare function runStage07(ctx: Awaited<ReturnType<typeof runStage06>>):
27
27
  approvalAskAudit: import("../approval-ask-audit-store.js").FileApprovalAskAuditStore | undefined;
28
28
  centerRuntimeCapsResolver: ((principal: string | undefined) => Promise<import("@sema-agent/core").RuntimeCaps | undefined>) | undefined;
29
29
  checkpointStore: import("../plugins/store-backend.js").CheckpointStoreFull | undefined;
30
- consolidationSeatWatch: import("./memory-consolidation.js").ConsolidationSeatWatch | undefined;
31
30
  durableEnabled: boolean;
32
31
  elicitation: import("../elicitation.js").ElicitationCoordinator | undefined;
33
32
  fleetBus: import("../fleet/fleet-bus.js").FleetEventBus;
@@ -81,14 +80,18 @@ export declare function runStage07(ctx: Awaited<ReturnType<typeof runStage06>>):
81
80
  executionEnvFactory: import("@sema-agent/core").ExecutionEnvFactory | undefined;
82
81
  fenceSessionOwner: (sid: string, owner: string | null) => void;
83
82
  lspManager: import("@sema-agent/core").NodeLspManager | import("../lsp/manager.js").E2bLspManager | undefined;
83
+ noteSessionIncarnation: (sid: string, incarnation: string | undefined) => void;
84
84
  perSessionCwd: Map<string, string>;
85
85
  perTaskImage: import("../per-task-image.js").PerTaskImageRegistry;
86
86
  sendUserFileTaskEnvs: import("../capabilities/sandbox-file-send.js").TaskEnvRegistry | undefined;
87
87
  sessionEnvSelection: import("../capabilities/select-environment-tool.js").SessionEnvironmentSelection;
88
+ sessionIncarnationOf: (sid: string) => string | undefined;
88
89
  setSessionCwd: (sid: string, cwd: string) => void;
89
90
  setSessionShellEnv: (sid: string, env: Record<string, string>) => void;
90
91
  worktreeReap: (() => Promise<void>) | undefined;
91
92
  brain: import("@sema-agent/core").Brain;
93
+ consolidationSeatWatch: import("./memory-consolidation.js").ConsolidationSeatWatch | undefined;
94
+ consolidationValve: import("./memory-consolidation.js").ConsolidationValve;
92
95
  costQuota: import("../observability/cost-quota.js").CostQuota | import("../plugins/pg-cost-quota.js").PgCostQuota | import("../plugins/tidb-cost-quota.js").TiDBCostQuota;
93
96
  degradeRouteWatch: import("../brain.js").DegradeRouteWatch;
94
97
  counterDegradeHook: (info: {
@@ -40,7 +40,6 @@ export declare function runStage08(ctx: Awaited<ReturnType<typeof runStage07>>):
40
40
  approvalAskAudit: import("../approval-ask-audit-store.js").FileApprovalAskAuditStore | undefined;
41
41
  centerRuntimeCapsResolver: ((principal: string | undefined) => Promise<import("@sema-agent/core").RuntimeCaps | undefined>) | undefined;
42
42
  checkpointStore: import("../plugins/store-backend.js").CheckpointStoreFull | undefined;
43
- consolidationSeatWatch: import("./memory-consolidation.js").ConsolidationSeatWatch | undefined;
44
43
  durableEnabled: boolean;
45
44
  elicitation: import("../elicitation.js").ElicitationCoordinator | undefined;
46
45
  fleetBus: import("../fleet/fleet-bus.js").FleetEventBus;
@@ -94,14 +93,18 @@ export declare function runStage08(ctx: Awaited<ReturnType<typeof runStage07>>):
94
93
  executionEnvFactory: import("@sema-agent/core").ExecutionEnvFactory | undefined;
95
94
  fenceSessionOwner: (sid: string, owner: string | null) => void;
96
95
  lspManager: import("@sema-agent/core").NodeLspManager | import("../lsp/manager.js").E2bLspManager | undefined;
96
+ noteSessionIncarnation: (sid: string, incarnation: string | undefined) => void;
97
97
  perSessionCwd: Map<string, string>;
98
98
  perTaskImage: import("../per-task-image.js").PerTaskImageRegistry;
99
99
  sendUserFileTaskEnvs: import("../capabilities/sandbox-file-send.js").TaskEnvRegistry | undefined;
100
100
  sessionEnvSelection: import("../capabilities/select-environment-tool.js").SessionEnvironmentSelection;
101
+ sessionIncarnationOf: (sid: string) => string | undefined;
101
102
  setSessionCwd: (sid: string, cwd: string) => void;
102
103
  setSessionShellEnv: (sid: string, env: Record<string, string>) => void;
103
104
  worktreeReap: (() => Promise<void>) | undefined;
104
105
  brain: import("@sema-agent/core").Brain;
106
+ consolidationSeatWatch: import("./memory-consolidation.js").ConsolidationSeatWatch | undefined;
107
+ consolidationValve: import("./memory-consolidation.js").ConsolidationValve;
105
108
  costQuota: import("../observability/cost-quota.js").CostQuota | import("../plugins/pg-cost-quota.js").PgCostQuota | import("../plugins/tidb-cost-quota.js").TiDBCostQuota;
106
109
  degradeRouteWatch: import("../brain.js").DegradeRouteWatch;
107
110
  counterDegradeHook: (info: {