@botbotgo/agent-harness 0.0.290 → 0.0.291

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 (134) hide show
  1. package/README.md +20 -20
  2. package/README.zh.md +14 -14
  3. package/dist/acp.d.ts +5 -5
  4. package/dist/acp.js +3 -3
  5. package/dist/api.d.ts +20 -21
  6. package/dist/api.js +38 -50
  7. package/dist/cli.js +47 -43
  8. package/dist/config/agents/orchestra.yaml +3 -3
  9. package/dist/config/knowledge/knowledge-runtime.yaml +4 -4
  10. package/dist/config/runtime/runtime-memory.yaml +7 -7
  11. package/dist/config/runtime/workspace.yaml +7 -7
  12. package/dist/contracts/core.d.ts +1 -1
  13. package/dist/contracts/runtime.d.ts +35 -40
  14. package/dist/contracts/workspace.d.ts +2 -2
  15. package/dist/flow/build-flow-graph.js +20 -33
  16. package/dist/flow/export-sequence-mermaid.js +4 -4
  17. package/dist/flow/types.d.ts +2 -2
  18. package/dist/index.d.ts +4 -4
  19. package/dist/index.js +1 -1
  20. package/dist/init-project.js +10 -10
  21. package/dist/knowledge/module.js +37 -45
  22. package/dist/mcp.d.ts +9 -9
  23. package/dist/mcp.js +6 -6
  24. package/dist/package-version.d.ts +1 -1
  25. package/dist/package-version.js +1 -1
  26. package/dist/persistence/file-store.d.ts +69 -69
  27. package/dist/persistence/file-store.js +224 -221
  28. package/dist/persistence/sqlite-request-context-store.d.ts +22 -0
  29. package/dist/persistence/sqlite-request-context-store.js +64 -0
  30. package/dist/persistence/sqlite-request-queue-store.d.ts +41 -0
  31. package/dist/persistence/sqlite-request-queue-store.js +120 -0
  32. package/dist/persistence/sqlite-store.d.ts +72 -72
  33. package/dist/persistence/sqlite-store.js +361 -361
  34. package/dist/persistence/types.d.ts +84 -84
  35. package/dist/protocol/a2a/http.js +79 -74
  36. package/dist/protocol/ag-ui/http.d.ts +7 -7
  37. package/dist/protocol/ag-ui/http.js +20 -20
  38. package/dist/resource/resource-impl.js +1 -1
  39. package/dist/runtime/adapter/compat/deepagent-compat.d.ts +2 -2
  40. package/dist/runtime/adapter/flow/invocation-flow.d.ts +6 -5
  41. package/dist/runtime/adapter/flow/invocation-flow.js +6 -5
  42. package/dist/runtime/adapter/flow/stream-runtime.d.ts +3 -3
  43. package/dist/runtime/adapter/flow/stream-runtime.js +5 -4
  44. package/dist/runtime/adapter/invocation-result.d.ts +6 -5
  45. package/dist/runtime/adapter/invocation-result.js +5 -4
  46. package/dist/runtime/adapter/middleware-assembly.js +3 -2
  47. package/dist/runtime/adapter/tool/tool-hitl.js +1 -1
  48. package/dist/runtime/adapter/upstream-configurable-keys.d.ts +2 -0
  49. package/dist/runtime/adapter/upstream-configurable-keys.js +2 -0
  50. package/dist/runtime/agent-runtime-adapter.d.ts +11 -8
  51. package/dist/runtime/agent-runtime-adapter.js +36 -32
  52. package/dist/runtime/harness/events/events.d.ts +8 -8
  53. package/dist/runtime/harness/events/events.js +25 -19
  54. package/dist/runtime/harness/events/listener-runtime.d.ts +5 -4
  55. package/dist/runtime/harness/events/listener-runtime.js +7 -3
  56. package/dist/runtime/harness/events/runtime-event-operations.d.ts +7 -7
  57. package/dist/runtime/harness/events/runtime-event-operations.js +5 -5
  58. package/dist/runtime/harness/events/streaming.d.ts +8 -7
  59. package/dist/runtime/harness/events/streaming.js +20 -19
  60. package/dist/runtime/harness/events/timeline.js +6 -6
  61. package/dist/runtime/harness/index.d.ts +1 -1
  62. package/dist/runtime/harness/index.js +1 -1
  63. package/dist/runtime/harness/run/helpers.d.ts +14 -11
  64. package/dist/runtime/harness/run/helpers.js +10 -7
  65. package/dist/runtime/harness/run/inspection.d.ts +3 -2
  66. package/dist/runtime/harness/run/inspection.js +7 -7
  67. package/dist/runtime/harness/run/operator-overview.d.ts +2 -2
  68. package/dist/runtime/harness/run/operator-overview.js +18 -17
  69. package/dist/runtime/harness/run/queue-diagnostics.js +6 -6
  70. package/dist/runtime/harness/run/recovery.d.ts +15 -15
  71. package/dist/runtime/harness/run/recovery.js +53 -50
  72. package/dist/runtime/harness/run/resources.d.ts +2 -2
  73. package/dist/runtime/harness/run/resources.js +8 -8
  74. package/dist/runtime/harness/run/resume.d.ts +3 -3
  75. package/dist/runtime/harness/run/resume.js +4 -4
  76. package/dist/runtime/harness/run/routing.d.ts +4 -4
  77. package/dist/runtime/harness/run/routing.js +8 -8
  78. package/dist/runtime/harness/run/run-lifecycle.d.ts +12 -12
  79. package/dist/runtime/harness/run/run-lifecycle.js +26 -26
  80. package/dist/runtime/harness/run/run-operations.d.ts +45 -45
  81. package/dist/runtime/harness/run/run-operations.js +79 -78
  82. package/dist/runtime/harness/run/run-queue.d.ts +8 -8
  83. package/dist/runtime/harness/run/run-queue.js +16 -16
  84. package/dist/runtime/harness/run/run-slot-acquisition.d.ts +32 -32
  85. package/dist/runtime/harness/run/run-slot-acquisition.js +41 -41
  86. package/dist/runtime/harness/run/{thread-records.d.ts → session-records.d.ts} +6 -13
  87. package/dist/runtime/harness/run/{thread-records.js → session-records.js} +14 -60
  88. package/dist/runtime/harness/run/start-run.d.ts +36 -36
  89. package/dist/runtime/harness/run/start-run.js +55 -36
  90. package/dist/runtime/harness/run/startup-runtime.d.ts +9 -9
  91. package/dist/runtime/harness/run/startup-runtime.js +22 -20
  92. package/dist/runtime/harness/run/stream-run.d.ts +18 -18
  93. package/dist/runtime/harness/run/stream-run.js +52 -52
  94. package/dist/runtime/harness/runtime-defaults.d.ts +2 -2
  95. package/dist/runtime/harness/runtime-defaults.js +7 -7
  96. package/dist/runtime/harness/system/health-monitor.d.ts +3 -3
  97. package/dist/runtime/harness/system/health-monitor.js +18 -18
  98. package/dist/runtime/harness/system/mem0-ingestion-sync.d.ts +6 -6
  99. package/dist/runtime/harness/system/mem0-ingestion-sync.js +36 -27
  100. package/dist/runtime/harness/system/runtime-memory-candidates.js +2 -2
  101. package/dist/runtime/harness/system/runtime-memory-manager.d.ts +13 -13
  102. package/dist/runtime/harness/system/runtime-memory-manager.js +41 -38
  103. package/dist/runtime/harness/system/runtime-memory-policy.d.ts +1 -1
  104. package/dist/runtime/harness/system/runtime-memory-policy.js +1 -1
  105. package/dist/runtime/harness/system/runtime-memory-records.d.ts +4 -2
  106. package/dist/runtime/harness/system/runtime-memory-records.js +21 -8
  107. package/dist/runtime/harness/system/runtime-memory-sync.d.ts +6 -6
  108. package/dist/runtime/harness/system/runtime-memory-sync.js +47 -44
  109. package/dist/runtime/harness/system/{thread-memory-sync.d.ts → session-memory-sync.d.ts} +7 -7
  110. package/dist/runtime/harness/system/{thread-memory-sync.js → session-memory-sync.js} +28 -28
  111. package/dist/runtime/harness.d.ts +33 -45
  112. package/dist/runtime/harness.js +273 -291
  113. package/dist/runtime/maintenance/checkpoint-maintenance.js +2 -2
  114. package/dist/runtime/maintenance/file-checkpoint-saver.d.ts +1 -1
  115. package/dist/runtime/maintenance/file-checkpoint-saver.js +6 -6
  116. package/dist/runtime/maintenance/runtime-record-maintenance.d.ts +1 -1
  117. package/dist/runtime/maintenance/runtime-record-maintenance.js +33 -33
  118. package/dist/runtime/maintenance/sqlite-checkpoint-saver.d.ts +1 -1
  119. package/dist/runtime/maintenance/sqlite-checkpoint-saver.js +30 -10
  120. package/dist/runtime/support/harness-support.d.ts +2 -2
  121. package/dist/runtime/support/harness-support.js +7 -7
  122. package/dist/runtime/support/runtime-adapter-options.d.ts +2 -2
  123. package/dist/runtime/support/runtime-adapter-options.js +3 -3
  124. package/dist/runtime/support/runtime-factories.d.ts +2 -2
  125. package/dist/runtime/support/runtime-factories.js +10 -10
  126. package/dist/workspace/agent-binding-compiler.js +3 -3
  127. package/dist/workspace/object-loader.js +1 -1
  128. package/dist/workspace/support/workspace-ref-utils.d.ts +4 -3
  129. package/dist/workspace/support/workspace-ref-utils.js +5 -4
  130. package/package.json +1 -1
  131. package/dist/persistence/sqlite-run-context-store.d.ts +0 -22
  132. package/dist/persistence/sqlite-run-context-store.js +0 -64
  133. package/dist/persistence/sqlite-run-queue-store.d.ts +0 -41
  134. package/dist/persistence/sqlite-run-queue-store.js +0 -120
@@ -9,20 +9,20 @@ import { createBackgroundEventRuntime } from "./harness/background-runtime.js";
9
9
  import { PolicyEngine } from "./harness/system/policy-engine.js";
10
10
  import { getConcurrencyConfig, getRecoveryConfig, getRoutingDefaultAgentId, getRoutingRules, } from "../workspace/support/workspace-ref-utils.js";
11
11
  import { createHarnessEvent, inferRoutingBindings, renderRuntimeFailure, } from "./support/harness-support.js";
12
- import { ThreadMemorySync } from "./harness/system/thread-memory-sync.js";
12
+ import { SessionMemorySync } from "./harness/system/session-memory-sync.js";
13
13
  import { RuntimeMemorySync, readRuntimeMemorySyncConfig } from "./harness/system/runtime-memory-sync.js";
14
14
  import { SqliteBackedStore } from "./harness/system/store.js";
15
15
  import { HealthMonitor, readHealthMonitorConfig, } from "./harness/system/health-monitor.js";
16
- import { normalizeInvocationEnvelope, normalizeRunPriority, resolveRunListeners, } from "./harness/run/helpers.js";
16
+ import { normalizeInvocationEnvelope, normalizeRequestPriority, resolveRequestListeners, } from "./harness/run/helpers.js";
17
17
  import { emitHarnessEvent, } from "./harness/events/events.js";
18
18
  import { createRuntimeEventOperations } from "./harness/events/runtime-event-operations.js";
19
- import { appendAssistantMessage as appendLifecycleAssistantMessage, finalizeCancelledRun as finalizeLifecycleCancelledRun, finalizeContinuedRun as finalizeLifecycleContinuedRun, } from "./harness/run/run-lifecycle.js";
19
+ import { appendAssistantMessage as appendLifecycleAssistantMessage, finalizeCancelledRequest as finalizeLifecycleCancelledRequest, finalizeContinuedRequest as finalizeLifecycleContinuedRequest, } from "./harness/run/run-lifecycle.js";
20
20
  import { createListenerDispatchRuntime } from "./harness/events/listener-runtime.js";
21
21
  import { buildResumePayload as buildHarnessResumePayload, resolveApprovalRecord as resolveHarnessApprovalRecord, } from "./harness/run/resume.js";
22
- import { cancelRunOperation, executeQueuedRunOperation, resumeRun } from "./harness/run/run-operations.js";
22
+ import { cancelRequestOperation, executeQueuedRequestOperation, resumeRequest } from "./harness/run/run-operations.js";
23
23
  import { projectOperatorOverview } from "./harness/run/operator-overview.js";
24
- import { acquireRunSlot as acquireHarnessRunSlot } from "./harness/run/run-slot-acquisition.js";
25
- import { dropPendingRunSlot, enqueuePendingRunSlot } from "./harness/run/run-queue.js";
24
+ import { acquireRequestSlot as acquireHarnessRunSlot } from "./harness/run/run-slot-acquisition.js";
25
+ import { dropPendingRequestSlot, enqueuePendingRequestSlot } from "./harness/run/run-queue.js";
26
26
  import { getDefaultRuntimeEntryAgentId, resolveSelectedAgentId, routeAgentId } from "./harness/run/routing.js";
27
27
  import { resolveStoreFromConfig, resolveVectorStore, } from "./harness/run/resources.js";
28
28
  import { createRuntimeMcpServer, createToolMcpServerFromTools, serveRuntimeMcpOverStdio, serveToolsOverStdioFromHarness, } from "../mcp.js";
@@ -30,20 +30,20 @@ import { closeMcpClientsForWorkspace } from "../resource/mcp-tool-support.js";
30
30
  import { getBindingRuntimeExecutionMode, } from "./support/compiled-binding.js";
31
31
  import { bindingSupportsRunningReplay, getWorkspaceBinding, resolveWorkspaceAgentTools, } from "./harness/bindings.js";
32
32
  import { describeWorkspaceInventory, getAgentInventoryRecord, listAgentSkills as listWorkspaceAgentSkills, } from "./harness/system/inventory.js";
33
- import { createDefaultHealthSnapshot, isInventoryEnabled, isThreadMemorySyncEnabled, } from "./harness/runtime-defaults.js";
33
+ import { createDefaultHealthSnapshot, isInventoryEnabled, isSessionMemorySyncEnabled, } from "./harness/runtime-defaults.js";
34
34
  import { Mem0IngestionSync, Mem0SemanticRecall, readMem0RuntimeConfig, } from "./harness/system/mem0-ingestion-sync.js";
35
35
  import { createRuntimeMemoryManager, RuntimeMemoryFormationSync, readRuntimeMemoryFormationConfig, } from "./harness/system/runtime-memory-manager.js";
36
36
  import { readRuntimeMemoryMaintenanceConfig, readRuntimeMemoryPolicyConfig, resolveMemoryNamespace, } from "./harness/system/runtime-memory-policy.js";
37
37
  import { resolveRuntimeAdapterOptions } from "./support/runtime-adapter-options.js";
38
38
  import { resolveKnowledgeStorePath } from "./support/runtime-layout.js";
39
- import { initializeHarnessRuntime, reclaimExpiredClaimedRuns as reclaimHarnessExpiredClaimedRuns, recoverStartupRuns as recoverHarnessStartupRuns, isStaleRunningRun as isHarnessStaleRunningRun, } from "./harness/run/startup-runtime.js";
39
+ import { initializeHarnessRuntime, reclaimExpiredClaimedRequests as reclaimHarnessExpiredClaimedRequests, recoverStartupRequests as recoverHarnessStartupRequests, isStaleRunningRequest as isHarnessStaleRunningRequest, } from "./harness/run/startup-runtime.js";
40
40
  import { traceStartupStage } from "./startup-tracing.js";
41
41
  import { normalizeProcessExecutablePath } from "./support/runtime-env.js";
42
42
  import { streamHarnessRun } from "./harness/run/stream-run.js";
43
43
  import { defaultRequestedAgentId, prepareRunStart } from "./harness/run/start-run.js";
44
- import { buildRequestInspectionRecord, buildSessionInspectionRecord, deleteSessionRecord, deleteThreadRecord, getPublicApproval, listPublicApprovals, } from "./harness/run/thread-records.js";
44
+ import { buildRequestInspectionRecord, buildSessionInspectionRecord, deleteSessionRecord, getPublicApproval, listPublicApprovals, } from "./harness/run/session-records.js";
45
45
  import { createKnowledgeModule } from "../knowledge/index.js";
46
- const ACTIVE_RUN_STATES = [
46
+ const ACTIVE_REQUEST_STATES = [
47
47
  "queued",
48
48
  "claimed",
49
49
  "running",
@@ -51,10 +51,10 @@ const ACTIVE_RUN_STATES = [
51
51
  "resuming",
52
52
  "cancelling",
53
53
  ];
54
- function toPublicRunResultShape(result) {
54
+ function toPublicRequestResultShape(result) {
55
55
  return {
56
- sessionId: result.sessionId ?? result.threadId ?? "",
57
- requestId: result.requestId ?? result.runId ?? "",
56
+ sessionId: result.sessionId ?? result.legacySessionId ?? "",
57
+ requestId: result.requestId ?? result.legacyRequestId ?? "",
58
58
  state: result.state,
59
59
  output: result.output,
60
60
  finalMessageText: result.finalMessageText,
@@ -109,7 +109,7 @@ function toPublicHarnessStreamItem(item) {
109
109
  case "result":
110
110
  return {
111
111
  type: "result",
112
- result: toPublicRunResultShape(item.result),
112
+ result: toPublicRequestResultShape(item.result),
113
113
  };
114
114
  default:
115
115
  return item;
@@ -165,9 +165,9 @@ export class AgentHarnessRuntime {
165
165
  workspace;
166
166
  runtimeAdapterOptions;
167
167
  static BACKGROUND_EVENT_TYPES = new Set([
168
- "run.created",
169
- "run.queued",
170
- "run.dequeued",
168
+ "request.created",
169
+ "request.queued",
170
+ "request.dequeued",
171
171
  "output.delta",
172
172
  ]);
173
173
  eventBus = new EventBus();
@@ -180,15 +180,15 @@ export class AgentHarnessRuntime {
180
180
  vectorStores = new Map();
181
181
  runtimeEntryBindings;
182
182
  defaultRuntimeEntryBinding;
183
- defaultRunRootValue;
183
+ defaultRuntimeRootValue;
184
184
  defaultStore;
185
185
  runtimeMemoryStore;
186
186
  runtimeMemoryPolicy;
187
187
  runtimeMemoryMaintenanceConfig;
188
188
  routingRules;
189
189
  routingDefaultAgentId;
190
- threadMemorySync;
191
- unregisterThreadMemorySync;
190
+ sessionMemorySync;
191
+ unregisterSessionMemorySync;
192
192
  runtimeMemorySync;
193
193
  unregisterRuntimeMemorySync;
194
194
  mem0IngestionSync;
@@ -205,9 +205,9 @@ export class AgentHarnessRuntime {
205
205
  concurrencyConfig;
206
206
  backgroundTasks = new Set();
207
207
  workerId = `worker-${createPersistentId()}`;
208
- activeRunSlots = 0;
208
+ activeRequestSlots = 0;
209
209
  pendingRunInsertionOrder = 0;
210
- pendingRunSlots = [];
210
+ pendingRequestSlots = [];
211
211
  runtimeEventSequence = 0;
212
212
  initialized = false;
213
213
  closed = false;
@@ -226,20 +226,20 @@ export class AgentHarnessRuntime {
226
226
  return null;
227
227
  }
228
228
  }
229
- defaultRunRoot() {
230
- return this.defaultRunRootValue;
229
+ defaultRuntimeRoot() {
230
+ return this.defaultRuntimeRootValue;
231
231
  }
232
232
  getDefaultRuntimeEntryAgentId() {
233
233
  return getDefaultRuntimeEntryAgentId(this.workspace, this.routingDefaultAgentId);
234
234
  }
235
- async resolveSelectedAgentId(input, requestedAgentId, threadId) {
235
+ async resolveSelectedAgentId(input, requestedAgentId, sessionId) {
236
236
  return resolveSelectedAgentId({
237
237
  workspace: this.workspace,
238
238
  input,
239
239
  requestedAgentId,
240
- threadId,
240
+ sessionId,
241
241
  preferredRuntimeEntryAgentId: this.routingDefaultAgentId,
242
- getThreadSummary: (currentThreadId) => this.getSession(currentThreadId),
242
+ getSessionSummary: (currentSessionId) => this.getSessionSummaryRecord(currentSessionId),
243
243
  });
244
244
  }
245
245
  createPrepareRunStartRuntime() {
@@ -247,9 +247,9 @@ export class AgentHarnessRuntime {
247
247
  workspace: this.workspace,
248
248
  policyEngine: this.policyEngine,
249
249
  persistence: this.persistence,
250
- resolveSelectedAgentId: (input, requestedAgentId, threadId) => this.resolveSelectedAgentId(input, requestedAgentId, threadId),
251
- emitRunCreated: (threadId, runId, payload) => this.runtimeEventOperations.emitRunCreated(threadId, runId, payload),
252
- acquireRunSlot: (threadId, runId, activeState, priority) => this.acquireRunSlot(threadId, runId, activeState, priority),
250
+ resolveSelectedAgentId: (input, requestedAgentId, sessionId) => this.resolveSelectedAgentId(input, requestedAgentId, sessionId),
251
+ emitRequestCreated: (sessionId, requestId, payload) => this.runtimeEventOperations.emitRequestCreated(sessionId, requestId, payload),
252
+ acquireRequestSlot: (sessionId, requestId, activeState, priority) => this.acquireRequestSlot(sessionId, requestId, activeState, priority),
253
253
  };
254
254
  }
255
255
  constructor(workspace, runtimeAdapterOptions = {}) {
@@ -258,16 +258,16 @@ export class AgentHarnessRuntime {
258
258
  normalizeProcessExecutablePath();
259
259
  this.runtimeEntryBindings = inferRoutingBindings(this.workspace).runtimeEntryBindings;
260
260
  this.defaultRuntimeEntryBinding = this.runtimeEntryBindings[0];
261
- this.defaultRunRootValue = this.defaultRuntimeEntryBinding?.harnessRuntime.runRoot ?? `${this.workspace.workspaceRoot}/.agent`;
262
- const runRoot = this.defaultRunRoot();
263
- this.persistence = new SqlitePersistence(runRoot);
261
+ this.defaultRuntimeRootValue = this.defaultRuntimeEntryBinding?.harnessRuntime.runtimeRoot ?? `${this.workspace.workspaceRoot}/.agent`;
262
+ const runtimeRoot = this.defaultRuntimeRoot();
263
+ this.persistence = new SqlitePersistence(runtimeRoot);
264
264
  const defaultStoreConfig = this.defaultRuntimeEntryBinding?.harnessRuntime.store;
265
- this.defaultStore = resolveStoreFromConfig(this.stores, defaultStoreConfig, runRoot) ?? new SqliteBackedStore(resolveKnowledgeStorePath(runRoot));
265
+ this.defaultStore = resolveStoreFromConfig(this.stores, defaultStoreConfig, runtimeRoot) ?? new SqliteBackedStore(resolveKnowledgeStorePath(runtimeRoot));
266
266
  const runtimeMemoryStoreConfig = typeof this.defaultRuntimeEntryBinding?.harnessRuntime.runtimeMemory?.store === "object" &&
267
267
  this.defaultRuntimeEntryBinding?.harnessRuntime.runtimeMemory?.store
268
268
  ? this.defaultRuntimeEntryBinding.harnessRuntime.runtimeMemory.store
269
269
  : undefined;
270
- this.runtimeMemoryStore = resolveStoreFromConfig(this.stores, runtimeMemoryStoreConfig, runRoot) ?? this.defaultStore;
270
+ this.runtimeMemoryStore = resolveStoreFromConfig(this.stores, runtimeMemoryStoreConfig, runtimeRoot) ?? this.defaultStore;
271
271
  this.runtimeMemoryPolicy = readRuntimeMemoryPolicyConfig(this.defaultRuntimeEntryBinding?.harnessRuntime.runtimeMemory, this.workspace.workspaceRoot) ?? null;
272
272
  this.runtimeMemoryMaintenanceConfig =
273
273
  readRuntimeMemoryMaintenanceConfig(this.defaultRuntimeEntryBinding?.harnessRuntime.runtimeMemory) ?? null;
@@ -279,7 +279,7 @@ export class AgentHarnessRuntime {
279
279
  defaultStore: this.defaultStore,
280
280
  embeddingModels: this.embeddingModels,
281
281
  vectorStores: this.vectorStores,
282
- getDefaultRunRoot: () => this.defaultRunRoot(),
282
+ getDefaultRuntimeRoot: () => this.defaultRuntimeRoot(),
283
283
  });
284
284
  this.runtimeAdapter = new AgentRuntimeAdapter(this.resolvedRuntimeAdapterOptions);
285
285
  this.backgroundEventRuntime = createBackgroundEventRuntime({
@@ -291,32 +291,33 @@ export class AgentHarnessRuntime {
291
291
  this.runtimeEventOperations = createRuntimeEventOperations(this.backgroundEventRuntime);
292
292
  this.routingRules = getRoutingRules(workspace.refs);
293
293
  this.routingDefaultAgentId = getRoutingDefaultAgentId(workspace.refs);
294
- if (isThreadMemorySyncEnabled(workspace)) {
295
- this.threadMemorySync = new ThreadMemorySync(this.persistence, this.runtimeMemoryStore, {
296
- resolveThreadNamespace: (sessionId) => {
294
+ if (isSessionMemorySyncEnabled(workspace)) {
295
+ this.sessionMemorySync = new SessionMemorySync(this.persistence, this.runtimeMemoryStore, {
296
+ resolveSessionNamespace: (sessionId) => {
297
297
  const binding = this.defaultRuntimeEntryBinding;
298
298
  if (!binding) {
299
299
  return ["memories", "sessions", sessionId];
300
300
  }
301
- return this.resolveMemoryNamespace("thread", binding, { sessionId });
301
+ return this.resolveMemoryNamespace("session", binding, { sessionId });
302
302
  },
303
303
  });
304
- this.unregisterThreadMemorySync = this.eventBus.registerProjection(this.threadMemorySync);
304
+ this.unregisterSessionMemorySync = this.eventBus.registerProjection(this.sessionMemorySync);
305
305
  }
306
306
  else {
307
- this.threadMemorySync = null;
308
- this.unregisterThreadMemorySync = () => { };
307
+ this.sessionMemorySync = null;
308
+ this.unregisterSessionMemorySync = () => { };
309
309
  }
310
310
  const runtimeMemorySyncConfig = readRuntimeMemorySyncConfig(this.defaultRuntimeEntryBinding?.harnessRuntime.runtimeMemory);
311
311
  if (runtimeMemorySyncConfig) {
312
312
  this.runtimeMemorySync = new RuntimeMemorySync(this.persistence, this.runtimeMemoryStore, runtimeMemorySyncConfig, {
313
- resolveThreadNamespace: (sessionId) => {
313
+ resolveSessionNamespace: (sessionId) => {
314
314
  const binding = this.defaultRuntimeEntryBinding;
315
315
  if (!binding) {
316
316
  return ["memories", "sessions", sessionId];
317
317
  }
318
- return this.resolveMemoryNamespace("thread", binding, { sessionId });
318
+ return this.resolveMemoryNamespace("session", binding, { sessionId });
319
319
  },
320
+ resolveRequestNamespace: (sessionId) => ["memories", "requests", sessionId],
320
321
  });
321
322
  this.unregisterRuntimeMemorySync = this.eventBus.registerProjection(this.runtimeMemorySync);
322
323
  }
@@ -326,7 +327,7 @@ export class AgentHarnessRuntime {
326
327
  }
327
328
  const mem0RuntimeConfig = readMem0RuntimeConfig(this.defaultRuntimeEntryBinding?.harnessRuntime.runtimeMemory, this.workspace.workspaceRoot);
328
329
  if (mem0RuntimeConfig) {
329
- this.mem0IngestionSync = new Mem0IngestionSync(this.persistence, mem0RuntimeConfig, runRoot);
330
+ this.mem0IngestionSync = new Mem0IngestionSync(this.persistence, mem0RuntimeConfig, runtimeRoot);
330
331
  this.unregisterMem0IngestionSync = this.eventBus.registerProjection(this.mem0IngestionSync);
331
332
  this.mem0SemanticRecall = new Mem0SemanticRecall(mem0RuntimeConfig);
332
333
  }
@@ -353,7 +354,7 @@ export class AgentHarnessRuntime {
353
354
  resolveNamespace: (scope, context) => {
354
355
  const binding = this.defaultRuntimeEntryBinding;
355
356
  if (!binding) {
356
- const identifier = scope === "thread"
357
+ const identifier = scope === "session"
357
358
  ? context.sessionId
358
359
  : scope === "agent"
359
360
  ? context.agentId
@@ -376,8 +377,8 @@ export class AgentHarnessRuntime {
376
377
  ? ({ candidates, context, existingRecords }) => this.runtimeMemoryManager.transform({
377
378
  candidates,
378
379
  binding: this.defaultRuntimeEntryBinding,
379
- threadId: context.sessionId ?? `memory-api-${context.requestId ?? "unknown"}`,
380
- runId: context.requestId ?? createPersistentId(new Date(context.recordedAt ?? new Date().toISOString())),
380
+ sessionId: context.sessionId ?? `memory-api-${context.requestId ?? "unknown"}`,
381
+ requestId: context.requestId ?? createPersistentId(new Date(context.recordedAt ?? new Date().toISOString())),
381
382
  recordedAt: context.recordedAt ?? new Date().toISOString(),
382
383
  existingRecords,
383
384
  })
@@ -386,14 +387,14 @@ export class AgentHarnessRuntime {
386
387
  });
387
388
  if (runtimeMemoryFormationConfig) {
388
389
  this.runtimeMemoryFormationSync = new RuntimeMemoryFormationSync(this.persistence, runtimeMemoryFormationConfig, (input) => this.knowledgeModule.memorizeCandidates(input.candidates, {
389
- sessionId: input.threadId,
390
- requestId: input.runId,
390
+ sessionId: input.sessionId,
391
+ requestId: input.requestId,
391
392
  agentId: input.agentId,
392
393
  workspaceId: this.getWorkspaceId(this.defaultRuntimeEntryBinding),
393
394
  userId: input.userId,
394
395
  projectId: input.projectId,
395
396
  recordedAt: input.recordedAt,
396
- }, { storeCandidateLog: false }).then(() => undefined), runRoot);
397
+ }, { storeCandidateLog: false }).then(() => undefined), runtimeRoot);
397
398
  this.unregisterRuntimeMemoryFormationSync = this.eventBus.registerProjection(this.runtimeMemoryFormationSync);
398
399
  }
399
400
  else {
@@ -409,8 +410,8 @@ export class AgentHarnessRuntime {
409
410
  return new HealthMonitor({
410
411
  workspace: this.workspace,
411
412
  persistence: this.persistence,
412
- getActiveRunSlots: () => this.activeRunSlots,
413
- getPendingRunSlots: () => this.pendingRunSlots.length,
413
+ getActiveRequestSlots: () => this.activeRequestSlots,
414
+ getPendingRequestSlots: () => this.pendingRequestSlots.length,
414
415
  getCheckpointMaintenanceStatus: () => null,
415
416
  getRuntimeRecordMaintenanceStatus: () => null,
416
417
  publishEvent: async (payload) => {
@@ -436,7 +437,7 @@ export class AgentHarnessRuntime {
436
437
  healthMonitor: this.healthMonitor,
437
438
  scheduleBackgroundTask: (task) => this.scheduleBackgroundStartupTask(task),
438
439
  });
439
- this.scheduleBackgroundStartupTask(traceStartupStage("runtime.initialize.startupRecovery", () => this.recoverStartupRuns()));
440
+ this.scheduleBackgroundStartupTask(traceStartupStage("runtime.initialize.startupRecovery", () => this.recoverStartupRequests()));
440
441
  this.initialized = true;
441
442
  }
442
443
  subscribe(listener) {
@@ -446,17 +447,17 @@ export class AgentHarnessRuntime {
446
447
  if (this.healthMonitor) {
447
448
  return this.healthMonitor.getSnapshot();
448
449
  }
449
- return createDefaultHealthSnapshot(this.activeRunSlots, this.pendingRunSlots.length);
450
+ return createDefaultHealthSnapshot(this.activeRequestSlots, this.pendingRequestSlots.length);
450
451
  }
451
452
  async getOperatorOverview(options) {
452
- const [health, runs, approvals] = await Promise.all([
453
+ const [health, requests, approvals] = await Promise.all([
453
454
  this.getHealth(),
454
- Promise.all(ACTIVE_RUN_STATES.map((state) => this.listRuns({ state }))).then((groups) => groups.flat()),
455
+ Promise.all(ACTIVE_REQUEST_STATES.map((state) => this.listRequests({ state }))).then((groups) => groups.flat()),
455
456
  this.listApprovals({ status: "pending" }),
456
457
  ]);
457
458
  return projectOperatorOverview({
458
459
  health,
459
- runs,
460
+ requests,
460
461
  approvals,
461
462
  limit: options?.limit,
462
463
  });
@@ -477,20 +478,17 @@ export class AgentHarnessRuntime {
477
478
  const sessions = await this.persistence.listSessionSummaries(filter);
478
479
  return sessions.map((session) => toSessionListSummary(session));
479
480
  }
480
- async listThreads(filter) {
481
- return this.listSessions(filter);
482
- }
483
481
  async listRequests(filter) {
484
- const requests = await this.persistence.listRuns({
482
+ const requests = await this.persistence.listRequests({
485
483
  agentId: filter?.agentId,
486
- threadId: filter?.sessionId,
484
+ sessionId: filter?.sessionId,
487
485
  state: filter?.state,
488
486
  });
489
487
  return requests.map((request) => ({
490
488
  requestId: request.requestId,
491
489
  sessionId: request.sessionId,
492
490
  agentId: request.agentId,
493
- parentRunId: request.parentRunId,
491
+ parentRequestId: request.parentRequestId,
494
492
  executionMode: request.executionMode,
495
493
  adapterKind: request.adapterKind,
496
494
  createdAt: request.createdAt,
@@ -506,13 +504,6 @@ export class AgentHarnessRuntime {
506
504
  runtimeSnapshot: request.runtimeSnapshot,
507
505
  }));
508
506
  }
509
- async listRuns(filter) {
510
- return this.listRequests({
511
- agentId: filter?.agentId,
512
- sessionId: filter?.threadId,
513
- state: filter?.state,
514
- });
515
- }
516
507
  async memorize(input) {
517
508
  const binding = this.defaultRuntimeEntryBinding;
518
509
  if (!binding) {
@@ -578,12 +569,9 @@ export class AgentHarnessRuntime {
578
569
  });
579
570
  }
580
571
  async getRequest(requestId) {
581
- const request = await this.persistence.getRun(requestId);
572
+ const request = await this.persistence.getRequest(requestId);
582
573
  return request ? buildRequestInspectionRecord(this.persistence, request) : null;
583
574
  }
584
- async getRun(runId) {
585
- return this.getRequest(runId);
586
- }
587
575
  async getSessionSummary(sessionId) {
588
576
  const session = await this.persistence.getSession(sessionId);
589
577
  return session
@@ -598,8 +586,11 @@ export class AgentHarnessRuntime {
598
586
  }
599
587
  : null;
600
588
  }
601
- async getSession(threadId) {
602
- return this.getSessionSummary(threadId);
589
+ async getSessionSummaryRecord(sessionId) {
590
+ return this.getSessionSummary(sessionId);
591
+ }
592
+ async getSession(sessionId) {
593
+ return this.getSessionRecord(sessionId);
603
594
  }
604
595
  async getSessionRecord(sessionId) {
605
596
  return buildSessionInspectionRecord({
@@ -607,16 +598,13 @@ export class AgentHarnessRuntime {
607
598
  getSession: (currentSessionId) => this.getSessionSummary(currentSessionId),
608
599
  }, sessionId);
609
600
  }
610
- async getThread(threadId) {
611
- return this.getSessionRecord(threadId);
612
- }
613
601
  async listApprovals(filter) {
614
602
  const approvals = await listPublicApprovals({
615
603
  persistence: this.persistence,
616
604
  }, {
617
605
  status: filter?.status,
618
- threadId: filter?.sessionId,
619
- runId: filter?.requestId,
606
+ sessionId: filter?.sessionId,
607
+ requestId: filter?.requestId,
620
608
  });
621
609
  return approvals;
622
610
  }
@@ -625,17 +613,14 @@ export class AgentHarnessRuntime {
625
613
  persistence: this.persistence,
626
614
  }, approvalId);
627
615
  }
628
- async listArtifacts(threadId, runId) {
629
- const listing = await this.persistence.listArtifacts(threadId, runId);
616
+ async listRequestArtifacts(sessionId, requestId) {
617
+ const listing = await this.persistence.listRequestArtifacts(sessionId, requestId);
630
618
  return {
631
619
  sessionId: listing.sessionId,
632
620
  requestId: listing.requestId,
633
621
  items: listing.items,
634
622
  };
635
623
  }
636
- async readArtifact(threadId, runId, artifactPath) {
637
- return this.persistence.readArtifact(threadId, runId, normalizeRecordedArtifactPath(artifactPath));
638
- }
639
624
  async recordArtifact(input) {
640
625
  const session = await this.getSessionRecord(input.sessionId);
641
626
  if (!session) {
@@ -655,27 +640,27 @@ export class AgentHarnessRuntime {
655
640
  ? input.createdAt.trim()
656
641
  : new Date().toISOString(),
657
642
  };
658
- return this.persistence.createArtifact(input.sessionId, input.requestId, artifact, input.content);
643
+ return this.persistence.createRequestArtifact(input.sessionId, input.requestId, artifact, input.content);
659
644
  }
660
- async listRequestEvents(sessionId, requestId) {
661
- return this.persistence.listRunEvents(sessionId, requestId);
645
+ async readRequestArtifact(sessionId, requestId, artifactPath) {
646
+ return this.persistence.readRequestArtifact(sessionId, requestId, artifactPath);
662
647
  }
663
- async listRunEvents(threadId, runId) {
664
- return this.listRequestEvents(threadId, runId);
648
+ async listRequestEvents(sessionId, requestId) {
649
+ return this.persistence.listRequestEvents(sessionId, requestId);
665
650
  }
666
651
  async exportRequestPackage(input) {
667
652
  const session = await this.getSessionRecord(input.sessionId);
668
653
  const request = await this.getRequest(input.requestId);
669
654
  const approvals = await this.listApprovals({ sessionId: input.sessionId, requestId: input.requestId });
670
- const transcript = await this.persistence.listThreadMessages(input.sessionId, 500);
655
+ const transcript = await this.persistence.listSessionMessages(input.sessionId, 500);
671
656
  const events = await this.listRequestEvents(input.sessionId, input.requestId);
672
657
  const artifactsListing = input.includeArtifacts === false
673
658
  ? { items: [] }
674
- : await this.persistence.listArtifacts(input.sessionId, input.requestId);
659
+ : await this.persistence.listRequestArtifacts(input.sessionId, input.requestId);
675
660
  const artifacts = await Promise.all(artifactsListing.items.map(async (artifact) => ({
676
661
  ...artifact,
677
662
  ...(input.includeArtifactContents === true
678
- ? { content: await this.persistence.readArtifact(input.sessionId, input.requestId, artifact.path) }
663
+ ? { content: await this.persistence.readRequestArtifact(input.sessionId, input.requestId, artifact.path) }
679
664
  : {}),
680
665
  })));
681
666
  const approvalSummary = summarizeApprovalEvidence(approvals);
@@ -708,7 +693,7 @@ export class AgentHarnessRuntime {
708
693
  async exportSessionPackage(input) {
709
694
  const session = await this.getSessionRecord(input.sessionId);
710
695
  const requestIds = Array.from(new Set((session?.requests ?? []).map((item) => item.requestId)));
711
- const runs = await Promise.all(requestIds.map((requestId) => this.exportRequestPackage({
696
+ const requestPackages = await Promise.all(requestIds.map((requestId) => this.exportRequestPackage({
712
697
  sessionId: input.sessionId,
713
698
  requestId,
714
699
  includeArtifacts: input.includeArtifacts,
@@ -717,7 +702,7 @@ export class AgentHarnessRuntime {
717
702
  })));
718
703
  const approvals = await this.listApprovals({ sessionId: input.sessionId });
719
704
  const approvalSummary = summarizeApprovalEvidence(approvals);
720
- const governanceRuns = runs
705
+ const governanceRequests = requestPackages
721
706
  .filter((item) => item.request?.requestId)
722
707
  .map((item) => ({
723
708
  requestId: item.request.requestId,
@@ -725,45 +710,45 @@ export class AgentHarnessRuntime {
725
710
  }));
726
711
  return {
727
712
  session,
728
- requests: runs.map((item) => item.request).filter((item) => Boolean(item)),
713
+ requests: requestPackages.map((item) => item.request).filter((item) => Boolean(item)),
729
714
  approvals,
730
- transcript: await this.persistence.listThreadMessages(input.sessionId, 500),
731
- runs,
715
+ transcript: await this.persistence.listSessionMessages(input.sessionId, 500),
716
+ requestsPackages: requestPackages,
732
717
  governance: {
733
- runs: governanceRuns,
718
+ requests: governanceRequests,
734
719
  approvalSummary,
735
- summary: `${governanceRuns.length} run evidence package(s), ${approvalSummary.total} approval record(s)`,
720
+ summary: `${governanceRequests.length} request evidence package(s), ${approvalSummary.total} approval record(s)`,
736
721
  },
737
722
  ...(input.includeRuntimeHealth === false ? {} : { runtimeHealth: await this.getHealth() }),
738
723
  };
739
724
  }
740
725
  async exportEvaluationBundle(input) {
741
- const thread = await this.getThread(input.sessionId);
742
- const run = await this.getRun(input.requestId);
743
- const runRequest = await this.persistence.getRunRequest(input.sessionId, input.requestId);
726
+ const session = await this.getSessionRecord(input.sessionId);
727
+ const request = await this.getRequest(input.requestId);
728
+ const requestInput = await this.persistence.getRequestInput(input.sessionId, input.requestId);
744
729
  const approvals = await this.listApprovals({ sessionId: input.sessionId, requestId: input.requestId });
745
- const transcript = await this.persistence.listThreadMessages(input.sessionId, 500);
746
- const events = await this.persistence.listRunEvents(input.sessionId, input.requestId);
730
+ const transcript = await this.persistence.listSessionMessages(input.sessionId, 500);
731
+ const events = await this.persistence.listRequestEvents(input.sessionId, input.requestId);
747
732
  const runtimeHealth = await this.getHealth();
748
733
  const artifactsListing = input.includeArtifacts === false
749
734
  ? { items: [] }
750
- : await this.persistence.listArtifacts(input.sessionId, input.requestId);
735
+ : await this.persistence.listRequestArtifacts(input.sessionId, input.requestId);
751
736
  const artifacts = await Promise.all(artifactsListing.items.map(async (artifact) => ({
752
737
  ...artifact,
753
738
  ...(input.includeArtifactContents === true
754
- ? { content: await this.persistence.readArtifact(input.sessionId, input.requestId, artifact.path) }
739
+ ? { content: await this.persistence.readRequestArtifact(input.sessionId, input.requestId, artifact.path) }
755
740
  : {}),
756
741
  })));
757
742
  return {
758
- session: thread ? toSessionRecord(thread) : null,
759
- request: run ? toRequestRecord(run) : null,
760
- runRequest: runRequest
743
+ session: session ? toSessionRecord(session) : null,
744
+ request: request ? toRequestRecord(request) : null,
745
+ requestInput: requestInput
761
746
  ? {
762
- input: runRequest.input,
763
- ...(runRequest.invocation ? { invocation: runRequest.invocation } : {}),
764
- ...(typeof runRequest.priority === "number" ? { priority: runRequest.priority } : {}),
747
+ input: requestInput.input,
748
+ ...(requestInput.invocation ? { invocation: requestInput.invocation } : {}),
749
+ ...(typeof requestInput.priority === "number" ? { priority: requestInput.priority } : {}),
765
750
  }
766
- : (deriveRunRequestFromTranscript(transcript, input.requestId) ?? null),
751
+ : (deriveRequestInputFromTranscript(transcript, input.requestId) ?? null),
767
752
  approvals,
768
753
  transcript,
769
754
  events,
@@ -786,15 +771,15 @@ export class AgentHarnessRuntime {
786
771
  if (!replayAgentId) {
787
772
  throw new Error("Evaluation replay requires an agentId on the replay input or exported bundle.");
788
773
  }
789
- const replayRequest = input.bundle.runRequest ?? deriveRunRequestFromTranscript(input.bundle.transcript, input.bundle.request?.requestId);
774
+ const replayRequest = input.bundle.requestInput ?? deriveRequestInputFromTranscript(input.bundle.transcript, input.bundle.request?.requestId);
790
775
  if (!replayRequest) {
791
- throw new Error("Evaluation replay requires bundle.runRequest from exportEvaluationBundle.");
776
+ throw new Error("Evaluation replay requires bundle.requestInput from exportEvaluationBundle.");
792
777
  }
793
778
  const invocation = input.invocation ?? replayRequest.invocation;
794
779
  const result = await this.run({
795
780
  agentId: replayAgentId,
796
781
  input: replayRequest.input,
797
- ...(input.sessionId ? { threadId: input.sessionId } : {}),
782
+ ...(input.sessionId ? { sessionId: input.sessionId } : {}),
798
783
  ...(invocation ? { invocation } : {}),
799
784
  });
800
785
  const expected = typeof input.bundle.expectedOutput === "string" ? input.bundle.expectedOutput.trim() : "";
@@ -829,7 +814,7 @@ export class AgentHarnessRuntime {
829
814
  ...options,
830
815
  });
831
816
  }
832
- async deleteThreadCheckpoints(threadId) {
817
+ async deleteSessionCheckpoints(sessionId) {
833
818
  const resolver = this.resolvedRuntimeAdapterOptions.checkpointerResolver;
834
819
  if (!resolver) {
835
820
  return;
@@ -841,29 +826,20 @@ export class AgentHarnessRuntime {
841
826
  continue;
842
827
  }
843
828
  seen.add(saver);
844
- const maybeDeleteThread = saver.deleteThread;
845
- if (typeof maybeDeleteThread === "function") {
846
- await maybeDeleteThread.call(saver, threadId);
829
+ const maybeDeleteSession = saver.deleteSession;
830
+ if (typeof maybeDeleteSession === "function") {
831
+ await maybeDeleteSession.call(saver, sessionId);
832
+ continue;
847
833
  }
848
834
  }
849
835
  }
850
836
  async deleteSession(sessionId) {
851
837
  return deleteSessionRecord({
852
838
  getSession: (currentSessionId) => this.getSessionRecord(currentSessionId),
853
- deleteSession: (currentSessionId) => this.persistence.deleteThread(currentSessionId),
854
- deleteSessionCheckpoints: (currentSessionId) => this.deleteThreadCheckpoints(currentSessionId),
839
+ deleteSession: (currentSessionId) => this.persistence.deleteSession(currentSessionId),
840
+ deleteSessionCheckpoints: (currentSessionId) => this.deleteSessionCheckpoints(currentSessionId),
855
841
  }, sessionId);
856
842
  }
857
- async deleteThread(threadId) {
858
- return this.deleteSession(threadId);
859
- }
860
- async deleteThreadLegacy(threadId) {
861
- return deleteThreadRecord({
862
- getThread: (currentThreadId) => this.getThread(currentThreadId),
863
- deleteThread: (currentThreadId) => this.persistence.deleteThread(currentThreadId),
864
- deleteThreadCheckpoints: (currentThreadId) => this.deleteThreadCheckpoints(currentThreadId),
865
- }, threadId);
866
- }
867
843
  async createToolMcpServer(options) {
868
844
  const tools = this.resolveToolMcpServerTools(options.agentId);
869
845
  return createToolMcpServerFromTools(tools, options);
@@ -884,16 +860,16 @@ export class AgentHarnessRuntime {
884
860
  input,
885
861
  routingRules: this.routingRules,
886
862
  routingDefaultAgentId: this.routingDefaultAgentId,
887
- threadId: options.threadId,
863
+ sessionId: options.sessionId,
888
864
  });
889
865
  }
890
- async emit(threadId, runId, sequence, eventType, payload, source = "runtime") {
866
+ async emit(sessionId, requestId, sequence, eventType, payload, source = "runtime") {
891
867
  return emitHarnessEvent({
892
868
  persistence: this.persistence,
893
869
  publishEvent: (event) => this.eventBus.publish(event),
894
870
  trackBackgroundTask: (task) => this.trackBackgroundTask(task),
895
871
  backgroundEventTypes: AgentHarnessRuntime.BACKGROUND_EVENT_TYPES,
896
- }, threadId, runId, sequence, eventType, payload, source);
872
+ }, sessionId, requestId, sequence, eventType, payload, source);
897
873
  }
898
874
  trackBackgroundTask(task) {
899
875
  this.backgroundTasks.add(task);
@@ -915,39 +891,39 @@ export class AgentHarnessRuntime {
915
891
  sourceTool: this.workspace.tools.get(compiledTool.id),
916
892
  }));
917
893
  }
918
- async loadPriorHistory(threadId, runId) {
919
- const history = await this.persistence.listThreadMessages(threadId);
920
- return history.filter((message) => message.requestId !== runId);
894
+ async loadPriorHistory(sessionId, requestId) {
895
+ const history = await this.persistence.listSessionMessages(sessionId);
896
+ return history.filter((message) => message.requestId !== requestId);
921
897
  }
922
- async loadRunInput(threadId, runId) {
923
- const history = await this.persistence.listThreadMessages(threadId, 100);
924
- const userTurn = history.find((message) => message.requestId === runId && message.role === "user");
898
+ async loadRequestInput(sessionId, requestId) {
899
+ const history = await this.persistence.listSessionMessages(sessionId, 100);
900
+ const userTurn = history.find((message) => message.requestId === requestId && message.role === "user");
925
901
  return userTurn?.content ?? "";
926
902
  }
927
- async getRunCancellation(runId) {
928
- const control = await this.persistence.getRunControl(runId);
903
+ async getRequestCancellation(requestId) {
904
+ const control = await this.persistence.getRequestControl(requestId);
929
905
  return {
930
906
  requested: control?.cancelRequested === true,
931
907
  ...(control?.cancelReason ? { reason: control.cancelReason } : {}),
932
908
  };
933
909
  }
934
- async finalizeCancelledRun(threadId, runId, previousState, reason) {
935
- return finalizeLifecycleCancelledRun({
910
+ async finalizeCancelledRequest(sessionId, requestId, previousState, reason) {
911
+ return finalizeLifecycleCancelledRequest({
936
912
  persistence: this.persistence,
937
- emit: (currentThreadId, currentRunId, sequence, eventType, payload, source) => this.emit(currentThreadId, currentRunId, sequence, eventType, payload, source),
938
- setRunStateAndEmit: (currentThreadId, currentRunId, sequence, state, options) => this.setRunStateAndEmit(currentThreadId, currentRunId, sequence, state, options),
939
- }, threadId, runId, previousState, reason);
913
+ emit: (currentSessionId, currentRequestId, sequence, eventType, payload, source) => this.emit(currentSessionId, currentRequestId, sequence, eventType, payload, source),
914
+ setRequestStateAndEmit: (currentSessionId, currentRequestId, sequence, state, options) => this.setRequestStateAndEmit(currentSessionId, currentRequestId, sequence, state, options),
915
+ }, sessionId, requestId, previousState, reason);
940
916
  }
941
- async invokeWithHistory(binding, input, threadId, runId, resumePayload, priorHistory, options = {}) {
942
- const history = priorHistory ?? await this.loadPriorHistory(threadId, runId);
943
- const memoryContext = options.memoryContext ?? await this.buildRuntimeMemoryContext(binding, threadId, input);
917
+ async invokeWithHistory(binding, input, sessionId, requestId, resumePayload, priorHistory, options = {}) {
918
+ const history = priorHistory ?? await this.loadPriorHistory(sessionId, requestId);
919
+ const memoryContext = options.memoryContext ?? await this.buildRuntimeMemoryContext(binding, sessionId, input);
944
920
  const startedAt = Date.now();
945
921
  try {
946
- const result = await this.runtimeAdapter.invoke(binding, input, threadId, runId, resumePayload, history, {
922
+ const result = await this.runtimeAdapter.invoke(binding, input, sessionId, requestId, resumePayload, history, {
947
923
  ...options,
948
924
  ...(memoryContext ? { memoryContext } : {}),
949
925
  });
950
- await this.persistRuntimeMemoryCandidates(binding, threadId, runId, result.metadata?.memoryCandidates);
926
+ await this.persistRuntimeMemoryCandidates(binding, sessionId, requestId, result.metadata?.memoryCandidates);
951
927
  this.recordLlmSuccess(startedAt);
952
928
  return result;
953
929
  }
@@ -971,18 +947,18 @@ export class AgentHarnessRuntime {
971
947
  const workspaceRoot = binding.harnessRuntime.workspaceRoot ?? this.workspace.workspaceRoot;
972
948
  return path.basename(workspaceRoot) || "default";
973
949
  }
974
- async buildRuntimeMemoryContext(binding, threadId, input) {
950
+ async buildRuntimeMemoryContext(binding, sessionId, input) {
975
951
  const query = typeof input === "string" ? input : JSON.stringify(input ?? "");
976
952
  return this.knowledgeModule.buildPromptContext({
977
953
  query,
978
954
  topK: this.runtimeMemoryPolicy?.retrieval.maxPromptMemories ?? 8,
979
955
  }, {
980
- sessionId: threadId,
956
+ sessionId,
981
957
  agentId: binding.agent.id,
982
958
  workspaceId: this.getWorkspaceId(binding),
983
959
  });
984
960
  }
985
- async persistRuntimeMemoryCandidates(binding, threadId, runId, value) {
961
+ async persistRuntimeMemoryCandidates(binding, sessionId, requestId, value) {
986
962
  if (!Array.isArray(value) || value.length === 0) {
987
963
  return;
988
964
  }
@@ -996,62 +972,62 @@ export class AgentHarnessRuntime {
996
972
  return;
997
973
  }
998
974
  await this.knowledgeModule.memorizeCandidates(candidates, {
999
- sessionId: threadId,
1000
- requestId: runId,
975
+ sessionId,
976
+ requestId,
1001
977
  agentId: binding.agent.id,
1002
978
  workspaceId: this.getWorkspaceId(binding),
1003
979
  recordedAt: new Date().toISOString(),
1004
980
  }, { storeCandidateLog: true });
1005
981
  }
1006
- async resolvePersistedRunPriority(threadId, runId) {
1007
- const persisted = await this.persistence.getRunRequest(threadId, runId);
1008
- return normalizeRunPriority(persisted?.priority);
982
+ async resolvePersistedRequestPriority(sessionId, requestId) {
983
+ const persisted = await this.persistence.getRequestInput(sessionId, requestId);
984
+ return normalizeRequestPriority(persisted?.priority);
1009
985
  }
1010
- enqueuePendingRunSlot(entry) {
1011
- return enqueuePendingRunSlot(this.pendingRunSlots, entry, this.pendingRunInsertionOrder++);
986
+ enqueuePendingRequestSlot(entry) {
987
+ return enqueuePendingRequestSlot(this.pendingRequestSlots, entry, this.pendingRunInsertionOrder++);
1012
988
  }
1013
- async executeQueuedRun(binding, input, threadId, runId, agentId, options = {}) {
1014
- return executeQueuedRunOperation({
989
+ async executeQueuedRequest(binding, input, sessionId, requestId, agentId, options = {}) {
990
+ return executeQueuedRequestOperation({
1015
991
  persistence: this.persistence,
1016
- getRunCancellation: (currentRunId) => this.getRunCancellation(currentRunId),
1017
- finalizeCancelledRun: (currentThreadId, currentRunId, previousRunState, reason) => this.finalizeCancelledRun(currentThreadId, currentRunId, previousRunState, reason),
1018
- emit: (currentThreadId, currentRunId, sequence, eventType, payload) => {
1019
- if (eventType === "run.dequeued") {
1020
- return this.emit(currentThreadId, currentRunId, sequence, eventType, {
992
+ getRequestCancellation: (currentRequestId) => this.getRequestCancellation(currentRequestId),
993
+ finalizeCancelledRequest: (currentSessionId, currentRequestId, previousRequestState, reason) => this.finalizeCancelledRequest(currentSessionId, currentRequestId, previousRequestState, reason),
994
+ emit: (currentSessionId, currentRequestId, sequence, eventType, payload) => {
995
+ if (eventType === "request.dequeued") {
996
+ return this.emit(currentSessionId, currentRequestId, sequence, eventType, {
1021
997
  ...payload,
1022
- activeRunCount: this.activeRunSlots,
998
+ activeRequestCount: this.activeRequestSlots,
1023
999
  maxConcurrentRuns: this.concurrencyConfig.maxConcurrentRuns,
1024
1000
  });
1025
1001
  }
1026
- return this.emit(currentThreadId, currentRunId, sequence, eventType, payload);
1002
+ return this.emit(currentSessionId, currentRequestId, sequence, eventType, payload);
1027
1003
  },
1028
- setRunStateAndEmit: (currentThreadId, currentRunId, sequence, state, stateOptions) => this.setRunStateAndEmit(currentThreadId, currentRunId, sequence, state, stateOptions),
1029
- invokeWithHistory: (activeBinding, activeInput, currentThreadId, currentRunId, resumePayload, priorHistory, invokeOptions) => this.invokeWithHistory(activeBinding, activeInput, currentThreadId, currentRunId, resumePayload, priorHistory, invokeOptions),
1030
- finalizeContinuedRun: (activeBinding, currentThreadId, currentRunId, currentInput, actual, finalizeOptions) => this.finalizeContinuedRun(activeBinding, currentThreadId, currentRunId, currentInput, actual, finalizeOptions),
1031
- emitSyntheticFallback: (currentThreadId, currentRunId, currentAgentId, error) => this.runtimeEventOperations.emitSyntheticFallback(currentThreadId, currentRunId, currentAgentId, error, 103),
1004
+ setRequestStateAndEmit: (currentSessionId, currentRequestId, sequence, state, stateOptions) => this.setRequestStateAndEmit(currentSessionId, currentRequestId, sequence, state, stateOptions),
1005
+ invokeWithHistory: (activeBinding, activeInput, currentSessionId, currentRequestId, resumePayload, priorHistory, invokeOptions) => this.invokeWithHistory(activeBinding, activeInput, currentSessionId, currentRequestId, resumePayload, priorHistory, invokeOptions),
1006
+ finalizeContinuedRequest: (activeBinding, currentSessionId, currentRequestId, currentInput, actual, finalizeOptions) => this.finalizeContinuedRequest(activeBinding, currentSessionId, currentRequestId, currentInput, actual, finalizeOptions),
1007
+ emitSyntheticFallback: (currentSessionId, currentRequestId, currentAgentId, error) => this.runtimeEventOperations.emitSyntheticFallback(currentSessionId, currentRequestId, currentAgentId, error, 103),
1032
1008
  renderRuntimeFailure,
1033
1009
  }, {
1034
1010
  binding,
1035
1011
  message: input,
1036
- threadId,
1037
- runId,
1012
+ sessionId,
1013
+ requestId,
1038
1014
  agentId,
1039
1015
  options,
1040
1016
  });
1041
1017
  }
1042
- async finalizeContinuedRun(binding, threadId, runId, input, actual, options) {
1043
- return finalizeLifecycleContinuedRun({
1018
+ async finalizeContinuedRequest(binding, sessionId, requestId, input, actual, options) {
1019
+ return finalizeLifecycleContinuedRequest({
1044
1020
  persistence: this.persistence,
1045
- emit: (currentThreadId, currentRunId, sequence, eventType, payload, source) => this.emit(currentThreadId, currentRunId, sequence, eventType, payload, source),
1046
- setRunStateAndEmit: (currentThreadId, currentRunId, sequence, state, lifecycleOptions) => this.setRunStateAndEmit(currentThreadId, currentRunId, sequence, state, lifecycleOptions),
1047
- requestApprovalAndEmit: (currentThreadId, currentRunId, lifecycleInput, interruptContent, checkpointRef, sequence) => this.requestApprovalAndEmit(currentThreadId, currentRunId, lifecycleInput, interruptContent, checkpointRef, sequence),
1048
- }, binding, threadId, runId, input, actual, options);
1021
+ emit: (currentSessionId, currentRequestId, sequence, eventType, payload, source) => this.emit(currentSessionId, currentRequestId, sequence, eventType, payload, source),
1022
+ setRequestStateAndEmit: (currentSessionId, currentRequestId, sequence, state, lifecycleOptions) => this.setRequestStateAndEmit(currentSessionId, currentRequestId, sequence, state, lifecycleOptions),
1023
+ requestApprovalAndEmit: (currentSessionId, currentRequestId, lifecycleInput, interruptContent, checkpointRef, sequence) => this.requestApprovalAndEmit(currentSessionId, currentRequestId, lifecycleInput, interruptContent, checkpointRef, sequence),
1024
+ }, binding, sessionId, requestId, input, actual, options);
1049
1025
  }
1050
- async setRunStateAndEmit(threadId, runId, sequence, state, options) {
1051
- return this.runtimeEventOperations.setRunStateAndEmit(threadId, runId, sequence, state, options);
1026
+ async setRequestStateAndEmit(sessionId, requestId, sequence, state, options) {
1027
+ return this.runtimeEventOperations.setRequestStateAndEmit(sessionId, requestId, sequence, state, options);
1052
1028
  }
1053
- async requestApprovalAndEmit(threadId, runId, input, interruptContent, checkpointRef, sequence) {
1054
- return this.runtimeEventOperations.requestApprovalAndEmit(threadId, runId, input, interruptContent, checkpointRef, sequence);
1029
+ async requestApprovalAndEmit(sessionId, requestId, input, interruptContent, checkpointRef, sequence) {
1030
+ return this.runtimeEventOperations.requestApprovalAndEmit(sessionId, requestId, input, interruptContent, checkpointRef, sequence);
1055
1031
  }
1056
1032
  isDecisionRun(options) {
1057
1033
  return "decision" in options;
@@ -1062,28 +1038,34 @@ export class AgentHarnessRuntime {
1062
1038
  }
1063
1039
  await listener(value);
1064
1040
  }
1065
- async acquireRunSlot(threadId, runId, activeState = "running", priority = 0) {
1041
+ async acquireRequestSlot(sessionId, requestId, activeState = "running", priority = 0) {
1066
1042
  return acquireHarnessRunSlot({
1067
- persistence: this.persistence,
1043
+ persistence: {
1044
+ claimQueuedRequest: ({ sessionId, requestId, workerId, claimedAt, leaseExpiresAt }) => this.persistence.claimQueuedRequest({ sessionId, requestId, workerId, claimedAt, leaseExpiresAt }),
1045
+ renewRequestLease: ({ requestId, workerId, heartbeatAt, leaseExpiresAt }) => this.persistence.renewRequestLease({ requestId, workerId, heartbeatAt, leaseExpiresAt }),
1046
+ releaseRequestClaim: (requestId) => this.persistence.releaseRequestClaim(requestId),
1047
+ enqueueRequest: ({ sessionId, requestId, priority }) => this.persistence.enqueueRequest({ sessionId, requestId, priority }),
1048
+ getRequest: (requestId) => this.persistence.getRequest(requestId),
1049
+ },
1068
1050
  workerId: this.workerId,
1069
1051
  concurrencyConfig: this.concurrencyConfig,
1070
- pendingRunSlots: this.pendingRunSlots,
1071
- getActiveRunSlots: () => this.activeRunSlots,
1072
- setActiveRunSlots: (count) => {
1073
- this.activeRunSlots = count;
1052
+ pendingRequestSlots: this.pendingRequestSlots,
1053
+ getActiveRequestSlots: () => this.activeRequestSlots,
1054
+ setActiveRequestSlots: (count) => {
1055
+ this.activeRequestSlots = count;
1074
1056
  },
1075
- enqueuePendingRunSlot: (entry) => this.enqueuePendingRunSlot(entry),
1076
- emit: (currentThreadId, currentRunId, sequence, eventType, payload) => this.emit(currentThreadId, currentRunId, sequence, eventType, payload),
1077
- setRunStateAndEmit: (currentThreadId, currentRunId, sequence, state, stateOptions) => this.setRunStateAndEmit(currentThreadId, currentRunId, sequence, state, stateOptions),
1057
+ enqueuePendingRequestSlot: (entry) => this.enqueuePendingRequestSlot(entry),
1058
+ emit: (currentSessionId, currentRequestId, sequence, eventType, payload) => this.emit(currentSessionId, currentRequestId, sequence, eventType, payload),
1059
+ setRequestStateAndEmit: (currentSessionId, currentRequestId, sequence, state, stateOptions) => this.setRequestStateAndEmit(currentSessionId, currentRequestId, sequence, state, stateOptions),
1078
1060
  }, {
1079
- threadId,
1080
- runId,
1061
+ sessionId,
1062
+ requestId,
1081
1063
  activeState,
1082
1064
  priority,
1083
1065
  });
1084
1066
  }
1085
- dropPendingRunSlot(runId) {
1086
- return dropPendingRunSlot(this.pendingRunSlots, runId);
1067
+ dropPendingRequestSlot(requestId) {
1068
+ return dropPendingRequestSlot(this.pendingRequestSlots, requestId);
1087
1069
  }
1088
1070
  async run(options) {
1089
1071
  if (this.isDecisionRun(options)) {
@@ -1096,52 +1078,52 @@ export class AgentHarnessRuntime {
1096
1078
  };
1097
1079
  return this.resume(resumeOptions);
1098
1080
  }
1099
- const resolvedListeners = resolveRunListeners(options);
1081
+ const resolvedListeners = resolveRequestListeners(options);
1100
1082
  if (resolvedListeners) {
1101
1083
  const result = await createListenerDispatchRuntime({
1102
1084
  notifyListener: (listener, value) => this.notifyListener(listener, value),
1103
- getThread: async (threadId) => {
1104
- const thread = await this.getThread(threadId);
1105
- return thread
1085
+ getSession: async (sessionId) => {
1086
+ const session = await this.getSessionRecord(sessionId);
1087
+ return session
1106
1088
  ? {
1107
- currentState: thread.currentState,
1108
- latestRequestId: thread.latestRequestId,
1109
- entryAgentId: thread.entryAgentId,
1110
- currentAgentId: thread.currentAgentId,
1111
- requests: thread.requests.map((run) => ({ agentId: run.agentId })),
1112
- pendingDecision: thread.pendingDecision,
1089
+ currentState: session.currentState,
1090
+ latestRequestId: session.latestRequestId,
1091
+ entryAgentId: session.entryAgentId,
1092
+ currentAgentId: session.currentAgentId,
1093
+ requests: session.requests.map((request) => ({ agentId: request.agentId })),
1094
+ pendingDecision: session.pendingDecision,
1113
1095
  }
1114
1096
  : null;
1115
1097
  },
1116
- }).dispatchRunListeners(this.streamEvents(options), resolvedListeners);
1117
- return toPublicRunResultShape(result);
1098
+ }).dispatchRequestListeners(this.streamEvents(options), resolvedListeners);
1099
+ return toPublicRequestResultShape(result);
1118
1100
  }
1119
1101
  const invocation = normalizeInvocationEnvelope(options);
1120
- const { binding, selectedAgentId, threadId, runId, isNewThread, runCreatedEventPromise, releaseRunSlotPromise, } = await prepareRunStart(this.createPrepareRunStartRuntime(), {
1102
+ const { binding, selectedAgentId, sessionId, requestId, isNewSession, requestCreatedEventPromise, releaseRequestSlotPromise, } = await prepareRunStart(this.createPrepareRunStartRuntime(), {
1121
1103
  options,
1122
1104
  invocation,
1123
- runCreatedPayload: (activeBinding, activeSelectedAgentId) => ({
1105
+ requestCreatedPayload: (activeBinding, activeSelectedAgentId) => ({
1124
1106
  agentId: activeBinding.agent.id,
1125
1107
  requestedAgentId: defaultRequestedAgentId(options.agentId),
1126
1108
  selectedAgentId: activeSelectedAgentId,
1127
1109
  executionMode: getBindingRuntimeExecutionMode(activeBinding),
1128
1110
  }),
1129
1111
  });
1130
- await runCreatedEventPromise;
1131
- const releaseRunSlot = await releaseRunSlotPromise;
1112
+ await requestCreatedEventPromise;
1113
+ const releaseRequestSlot = await releaseRequestSlotPromise;
1132
1114
  try {
1133
- return toPublicRunResultShape(await this.executeQueuedRun(binding, options.input, threadId, runId, selectedAgentId, {
1115
+ return toPublicRequestResultShape(await this.executeQueuedRequest(binding, options.input, sessionId, requestId, selectedAgentId, {
1134
1116
  context: invocation.context,
1135
1117
  state: invocation.state,
1136
1118
  files: invocation.files,
1137
1119
  previousState: "running",
1138
1120
  stateSequence: 6,
1139
1121
  approvalSequence: 7,
1140
- priorHistory: isNewThread ? [] : undefined,
1122
+ priorHistory: isNewSession ? [] : undefined,
1141
1123
  }));
1142
1124
  }
1143
1125
  finally {
1144
- await releaseRunSlot();
1126
+ await releaseRequestSlot();
1145
1127
  }
1146
1128
  }
1147
1129
  async *streamEvents(options) {
@@ -1156,10 +1138,10 @@ export class AgentHarnessRuntime {
1156
1138
  };
1157
1139
  return;
1158
1140
  }
1159
- const { threadId, runId, isNewThread, runCreatedEventPromise, releaseRunSlotPromise, } = await prepareRunStart(this.createPrepareRunStartRuntime(), {
1141
+ const { sessionId, requestId, isNewSession, requestCreatedEventPromise, releaseRequestSlotPromise, } = await prepareRunStart(this.createPrepareRunStartRuntime(), {
1160
1142
  options,
1161
1143
  invocation,
1162
- runCreatedPayload: (_binding, activeSelectedAgentId) => ({
1144
+ requestCreatedPayload: (_binding, activeSelectedAgentId) => ({
1163
1145
  agentId: activeSelectedAgentId,
1164
1146
  requestedAgentId: defaultRequestedAgentId(options.agentId),
1165
1147
  selectedAgentId: activeSelectedAgentId,
@@ -1172,53 +1154,53 @@ export class AgentHarnessRuntime {
1172
1154
  input: options.input,
1173
1155
  invocation: {
1174
1156
  ...invocation,
1175
- memoryContext: await this.buildRuntimeMemoryContext(binding, threadId, options.input),
1157
+ memoryContext: await this.buildRuntimeMemoryContext(binding, sessionId, options.input),
1176
1158
  },
1177
- threadId,
1178
- runId,
1159
+ sessionId,
1160
+ requestId,
1179
1161
  selectedAgentId,
1180
- isNewThread,
1181
- runCreatedEventPromise,
1182
- releaseRunSlotPromise,
1162
+ isNewSession: isNewSession,
1163
+ requestCreatedEventPromise,
1164
+ releaseRequestSlotPromise,
1183
1165
  getBinding: (agentId) => getWorkspaceBinding(this.workspace, agentId),
1184
- loadPriorHistory: (threadId, runId) => this.loadPriorHistory(threadId, runId),
1185
- stream: (binding, message, threadId, priorHistory, streamOptions) => this.runtimeAdapter.stream(binding, message, threadId, priorHistory, streamOptions),
1186
- invokeWithHistory: (binding, input, threadId, runId) => this.invokeWithHistory(binding, input, threadId, runId),
1187
- emit: (threadId, runId, sequence, eventType, payload) => this.emit(threadId, runId, sequence, eventType, payload),
1188
- setRunStateAndEmit: (threadId, runId, sequence, state, stateOptions) => this.setRunStateAndEmit(threadId, runId, sequence, state, stateOptions),
1189
- requestApprovalAndEmit: (threadId, runId, input, interruptContent, checkpointRef, sequence) => this.requestApprovalAndEmit(threadId, runId, input, interruptContent, checkpointRef, sequence),
1190
- appendAssistantMessage: (threadId, runId, content) => appendLifecycleAssistantMessage(this.persistence, threadId, runId, content),
1191
- clearRunRequest: (threadId, runId) => this.persistence.clearRunRequest(threadId, runId),
1192
- updateRunInspection: (threadId, runId, patch) => this.persistence.updateRunInspection(threadId, runId, patch),
1193
- appendRunTraceItem: (threadId, runId, item) => this.persistence.appendRunTraceItem(threadId, runId, item),
1194
- emitSyntheticFallback: (threadId, runId, selectedAgentId, error) => this.runtimeEventOperations.emitSyntheticFallback(threadId, runId, selectedAgentId, error),
1166
+ loadPriorHistory: (sessionId, requestId) => this.loadPriorHistory(sessionId, requestId),
1167
+ stream: (binding, message, sessionId, priorHistory, streamOptions) => this.runtimeAdapter.stream(binding, message, sessionId, priorHistory, streamOptions),
1168
+ invokeWithHistory: (binding, input, sessionId, requestId) => this.invokeWithHistory(binding, input, sessionId, requestId),
1169
+ emit: (sessionId, requestId, sequence, eventType, payload) => this.emit(sessionId, requestId, sequence, eventType, payload),
1170
+ setRequestStateAndEmit: (sessionId, requestId, sequence, state, stateOptions) => this.setRequestStateAndEmit(sessionId, requestId, sequence, state, stateOptions),
1171
+ requestApprovalAndEmit: (sessionId, requestId, input, interruptContent, checkpointRef, sequence) => this.requestApprovalAndEmit(sessionId, requestId, input, interruptContent, checkpointRef, sequence),
1172
+ appendAssistantMessage: (sessionId, requestId, content) => appendLifecycleAssistantMessage(this.persistence, sessionId, requestId, content),
1173
+ clearRequestInput: (sessionId, requestId) => this.persistence.clearRequestInput(sessionId, requestId),
1174
+ updateRequestInspection: (sessionId, requestId, patch) => this.persistence.updateRequestInspection(sessionId, requestId, patch),
1175
+ appendRequestTraceItem: (sessionId, requestId, item) => this.persistence.appendRequestTraceItem(sessionId, requestId, item),
1176
+ emitSyntheticFallback: (sessionId, requestId, selectedAgentId, error) => this.runtimeEventOperations.emitSyntheticFallback(sessionId, requestId, selectedAgentId, error),
1195
1177
  });
1196
1178
  for await (const item of stream) {
1197
1179
  yield toPublicHarnessStreamItem(item);
1198
1180
  }
1199
1181
  }
1200
1182
  async resume(options) {
1201
- return toPublicRunResultShape(await resumeRun({
1183
+ return toPublicRequestResultShape(await resumeRequest({
1202
1184
  getApprovalById: (approvalId) => this.persistence.getApproval(approvalId),
1203
- getSession: (threadId) => this.getSession(threadId),
1204
- resolveApprovalRecord: (resumeOptions, thread) => resolveHarnessApprovalRecord(this.persistence, resumeOptions, thread),
1185
+ getSession: (sessionId) => this.getSession(sessionId),
1186
+ resolveApprovalRecord: (resumeOptions, session) => resolveHarnessApprovalRecord(this.persistence, resumeOptions, session),
1205
1187
  getBinding: (agentId) => getWorkspaceBinding(this.workspace, agentId),
1206
1188
  buildResumePayload: (binding, approval, resumeOptions) => buildHarnessResumePayload(binding, approval, resumeOptions),
1207
- getRunCancellation: (runId) => this.getRunCancellation(runId),
1208
- finalizeCancelledRun: (threadId, runId, previousState, reason) => this.finalizeCancelledRun(threadId, runId, previousState, reason),
1209
- setRunState: (threadId, runId, state, checkpointRef) => this.persistence.setRunState(threadId, runId, state, checkpointRef),
1210
- acquireRunSlot: (threadId, runId, activeState, priority) => this.acquireRunSlot(threadId, runId, activeState, priority),
1211
- resolvePersistedRunPriority: (threadId, runId) => this.resolvePersistedRunPriority(threadId, runId),
1212
- saveRecoveryIntent: (threadId, runId, payload) => this.persistence.saveRecoveryIntent(threadId, runId, payload),
1213
- emit: (threadId, runId, sequence, eventType, payload) => this.emit(threadId, runId, sequence, eventType, payload),
1214
- resolveApproval: (threadId, runId, approvalId, resolution) => this.persistence.resolveApproval(threadId, runId, approvalId, resolution),
1215
- listThreadMessages: (threadId) => this.persistence.listThreadMessages(threadId),
1216
- loadRunInput: (threadId, runId) => this.loadRunInput(threadId, runId),
1217
- invoke: (binding, input, threadId, runId, resumePayload, priorHistory) => this.runtimeAdapter.invoke(binding, input, threadId, runId, resumePayload, priorHistory),
1189
+ getRequestCancellation: (requestId) => this.getRequestCancellation(requestId),
1190
+ finalizeCancelledRequest: (sessionId, requestId, previousState, reason) => this.finalizeCancelledRequest(sessionId, requestId, previousState, reason),
1191
+ setRequestState: (sessionId, requestId, state, checkpointRef) => this.persistence.setRequestState(sessionId, requestId, state, checkpointRef),
1192
+ acquireRequestSlot: (sessionId, requestId, activeState, priority) => this.acquireRequestSlot(sessionId, requestId, activeState, priority),
1193
+ resolvePersistedRequestPriority: (sessionId, requestId) => this.resolvePersistedRequestPriority(sessionId, requestId),
1194
+ saveRequestRecoveryIntent: (sessionId, requestId, payload) => this.persistence.saveRequestRecoveryIntent(sessionId, requestId, payload),
1195
+ emit: (sessionId, requestId, sequence, eventType, payload) => this.emit(sessionId, requestId, sequence, eventType, payload),
1196
+ resolveApproval: (sessionId, requestId, approvalId, resolution) => this.persistence.resolveApproval(sessionId, requestId, approvalId, resolution),
1197
+ listSessionMessages: (sessionId) => this.persistence.listSessionMessages(sessionId),
1198
+ loadRequestInput: (sessionId, requestId) => this.loadRequestInput(sessionId, requestId),
1199
+ invoke: (binding, input, sessionId, requestId, resumePayload, priorHistory) => this.runtimeAdapter.invoke(binding, input, sessionId, requestId, resumePayload, priorHistory),
1218
1200
  recordLlmSuccess: (startedAt) => this.recordLlmSuccess(startedAt),
1219
1201
  recordLlmFailure: (startedAt) => this.recordLlmFailure(startedAt),
1220
- clearRecoveryIntent: (threadId, runId) => this.persistence.clearRecoveryIntent(threadId, runId),
1221
- finalizeContinuedRun: (binding, threadId, runId, input, actual, operationOptions) => this.finalizeContinuedRun(binding, threadId, runId, input, actual, operationOptions),
1202
+ clearRequestRecoveryIntent: (sessionId, requestId) => this.persistence.clearRequestRecoveryIntent(sessionId, requestId),
1203
+ finalizeContinuedRequest: (binding, sessionId, requestId, input, actual, operationOptions) => this.finalizeContinuedRequest(binding, sessionId, requestId, input, actual, operationOptions),
1222
1204
  }, {
1223
1205
  ...options,
1224
1206
  }));
@@ -1229,11 +1211,11 @@ export class AgentHarnessRuntime {
1229
1211
  throw new Error(`Unknown session ${options.sessionId}`);
1230
1212
  }
1231
1213
  const sourceRequestId = session.latestRequestId;
1232
- const targetSessionId = options.mode === "restart-new-thread" ? createPersistentId() : options.sessionId;
1214
+ const targetSessionId = options.mode === "restart-new-session" ? createPersistentId() : options.sessionId;
1233
1215
  const result = await this.run({
1234
- agentId: session.agentId,
1216
+ agentId: session.currentAgentId ?? session.entryAgentId,
1235
1217
  input: options.input,
1236
- sessionId: options.mode === "restart-new-thread" ? undefined : targetSessionId,
1218
+ sessionId: options.mode === "restart-new-session" ? undefined : targetSessionId,
1237
1219
  });
1238
1220
  return {
1239
1221
  ...result,
@@ -1254,12 +1236,12 @@ export class AgentHarnessRuntime {
1254
1236
  }
1255
1237
  this.closed = true;
1256
1238
  await this.healthMonitor?.stop();
1257
- this.unregisterThreadMemorySync();
1239
+ this.unregisterSessionMemorySync();
1258
1240
  this.unregisterRuntimeMemorySync();
1259
1241
  this.unregisterMem0IngestionSync();
1260
1242
  this.unregisterRuntimeMemoryFormationSync();
1261
1243
  await Promise.allSettled(Array.from(this.backgroundTasks));
1262
- await this.threadMemorySync?.close();
1244
+ await this.sessionMemorySync?.close();
1263
1245
  await this.runtimeMemorySync?.close();
1264
1246
  await this.mem0IngestionSync?.close();
1265
1247
  await this.runtimeMemoryFormationSync?.close();
@@ -1269,17 +1251,17 @@ export class AgentHarnessRuntime {
1269
1251
  async stop() {
1270
1252
  await this.close();
1271
1253
  }
1272
- async cancelRun(options) {
1273
- return toPublicRunResultShape(await cancelRunOperation({
1274
- getRun: (runId) => this.persistence.getRun(runId),
1275
- requestRunCancel: (runId, reason) => this.persistence.requestRunCancel(runId, reason),
1276
- dropPendingRunSlot: (runId) => this.dropPendingRunSlot(runId),
1277
- finalizeCancelledRun: (threadId, runId, previousState, reason) => this.finalizeCancelledRun(threadId, runId, previousState, reason),
1278
- setRunStateAndEmit: (threadId, runId, sequence, state, stateOptions) => this.setRunStateAndEmit(threadId, runId, sequence, state, stateOptions),
1254
+ async cancelRequest(options) {
1255
+ return toPublicRequestResultShape(await cancelRequestOperation({
1256
+ getRequest: (requestId) => this.persistence.getRequest(requestId),
1257
+ requestRequestCancel: (requestId, reason) => this.persistence.requestRequestCancel(requestId, reason),
1258
+ dropPendingRequestSlot: (requestId) => this.dropPendingRequestSlot(requestId),
1259
+ finalizeCancelledRequest: (sessionId, requestId, previousState, reason) => this.finalizeCancelledRequest(sessionId, requestId, previousState, reason),
1260
+ setRequestStateAndEmit: (sessionId, requestId, sequence, state, stateOptions) => this.setRequestStateAndEmit(sessionId, requestId, sequence, state, stateOptions),
1279
1261
  }, options));
1280
1262
  }
1281
- async recoverStartupRuns() {
1282
- await recoverHarnessStartupRuns({
1263
+ async recoverStartupRequests() {
1264
+ await recoverHarnessStartupRequests({
1283
1265
  recoveryConfig: this.recoveryConfig,
1284
1266
  persistence: this.persistence,
1285
1267
  createStartupRecoveryContext: () => ({
@@ -1289,34 +1271,34 @@ export class AgentHarnessRuntime {
1289
1271
  recoveryConfig: this.recoveryConfig,
1290
1272
  concurrencyConfig: this.concurrencyConfig,
1291
1273
  getBinding: (agentId) => getWorkspaceBinding(this.workspace, agentId),
1292
- acquireRunSlot: (threadId, runId, activeState, priority) => this.acquireRunSlot(threadId, runId, activeState, priority),
1293
- executeQueuedRun: (binding, input, threadId, runId, agentId, options) => this.executeQueuedRun(binding, input, threadId, runId, agentId, options),
1294
- setRunStateAndEmit: (threadId, runId, sequence, state, options) => this.setRunStateAndEmit(threadId, runId, sequence, state, options),
1295
- emit: (threadId, runId, sequence, eventType, payload) => this.emit(threadId, runId, sequence, eventType, payload),
1296
- loadRunInput: (threadId, runId) => this.loadRunInput(threadId, runId),
1297
- finalizeContinuedRun: (binding, threadId, runId, input, actual, options) => this.finalizeContinuedRun(binding, threadId, runId, input, actual, options),
1274
+ acquireRequestSlot: (sessionId, requestId, activeState, priority) => this.acquireRequestSlot(sessionId, requestId, activeState, priority),
1275
+ executeQueuedRequest: (binding, input, sessionId, requestId, agentId, options) => this.executeQueuedRequest(binding, input, sessionId, requestId, agentId, options),
1276
+ setRequestStateAndEmit: (sessionId, requestId, sequence, state, options) => this.setRequestStateAndEmit(sessionId, requestId, sequence, state, options),
1277
+ emit: (sessionId, requestId, sequence, eventType, payload) => this.emit(sessionId, requestId, sequence, eventType, payload),
1278
+ loadRequestInput: (sessionId, requestId) => this.loadRequestInput(sessionId, requestId),
1279
+ finalizeContinuedRequest: (binding, sessionId, requestId, input, actual, options) => this.finalizeContinuedRequest(binding, sessionId, requestId, input, actual, options),
1298
1280
  supportsRunningReplay: (binding) => bindingSupportsRunningReplay(binding),
1299
- isStaleRunningRun: (thread, nowMs) => this.isStaleRunningRun(thread, nowMs),
1281
+ isStaleRunningRequest: (session, nowMs) => this.isStaleRunningRequest(session, nowMs),
1300
1282
  recordLlmSuccess: (startedAt) => this.recordLlmSuccess(startedAt),
1301
1283
  recordLlmFailure: (startedAt) => this.recordLlmFailure(startedAt),
1302
1284
  }),
1303
- reclaimExpiredClaimedRuns: (nowIso) => this.reclaimExpiredClaimedRuns(nowIso),
1285
+ reclaimExpiredClaimedRequests: (nowIso) => this.reclaimExpiredClaimedRequests(nowIso),
1304
1286
  });
1305
1287
  }
1306
- async reclaimExpiredClaimedRuns(nowIso = new Date().toISOString()) {
1307
- await reclaimHarnessExpiredClaimedRuns({
1288
+ async reclaimExpiredClaimedRequests(nowIso = new Date().toISOString()) {
1289
+ await reclaimHarnessExpiredClaimedRequests({
1308
1290
  persistence: this.persistence,
1309
- setRunStateAndEmit: (threadId, runId, sequence, state, options) => this.setRunStateAndEmit(threadId, runId, sequence, state, options),
1310
- emit: (threadId, runId, sequence, eventType, payload) => this.emit(threadId, runId, sequence, eventType, payload),
1291
+ setRequestStateAndEmit: (sessionId, requestId, sequence, state, options) => this.setRequestStateAndEmit(sessionId, requestId, sequence, state, options),
1292
+ emit: (sessionId, requestId, sequence, eventType, payload) => this.emit(sessionId, requestId, sequence, eventType, payload),
1311
1293
  concurrencyConfig: this.concurrencyConfig,
1312
- getActiveRunSlots: () => this.activeRunSlots,
1294
+ getActiveRequestSlots: () => this.activeRequestSlots,
1313
1295
  }, nowIso);
1314
1296
  }
1315
- async isStaleRunningRun(thread, nowMs = Date.now()) {
1316
- return isHarnessStaleRunningRun({
1297
+ async isStaleRunningRequest(session, nowMs = Date.now()) {
1298
+ return isHarnessStaleRunningRequest({
1317
1299
  persistence: this.persistence,
1318
1300
  concurrencyConfig: this.concurrencyConfig,
1319
- }, thread, nowMs);
1301
+ }, session, nowMs);
1320
1302
  }
1321
1303
  }
1322
1304
  function toRequestSummary(summary) {
@@ -1324,7 +1306,7 @@ function toRequestSummary(summary) {
1324
1306
  requestId: summary.requestId,
1325
1307
  sessionId: summary.sessionId,
1326
1308
  agentId: summary.agentId,
1327
- parentRunId: summary.parentRunId,
1309
+ parentRequestId: summary.parentRequestId,
1328
1310
  executionMode: summary.executionMode,
1329
1311
  adapterKind: summary.adapterKind,
1330
1312
  createdAt: summary.createdAt,
@@ -1361,7 +1343,7 @@ function toRequestRecord(record) {
1361
1343
  runtimeTimeline: record.runtimeTimeline,
1362
1344
  };
1363
1345
  }
1364
- function deriveRunRequestFromTranscript(transcript, requestId) {
1346
+ function deriveRequestInputFromTranscript(transcript, requestId) {
1365
1347
  const candidate = [...transcript]
1366
1348
  .reverse()
1367
1349
  .find((message) => message.role === "user" && (!requestId || message.requestId === requestId));