@linnlabs/linnkit 0.35.0 → 0.36.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.
@@ -134,7 +134,7 @@ interface RunSupervisor<TRequest extends RunRequestSnapshot = RunRequestSnapshot
134
134
  findByConversation(conversationId: string, opts?: FindRunsByConversationOptions): Promise<RunSnapshot[]>;
135
135
  drain(opts?: RunWaitForTerminalOptions): Promise<RunOutcome[]>;
136
136
  recoverOnBoot(reason?: string): Promise<RunOutcome[]>;
137
- pause(runId: RunId, reason?: string): Promise<void>;
137
+ pause(runId: RunId, reason?: string, expectedExecutionId?: ExecutionId): Promise<void>;
138
138
  resumePausedRun(input: {
139
139
  readonly runId: RunId;
140
140
  readonly expectedUpdatedAt: number;
@@ -154,6 +154,8 @@ interface DefaultRunSupervisorOptions<TRequest extends RunRequestSnapshot = RunR
154
154
  runIdFactory?: () => RunId;
155
155
  now?: () => number;
156
156
  maxActiveRuns?: number;
157
+ /** 原子 checkpoint Host 在持久提交后自行写等待态,不能由未提交的实时事件提前写入。 */
158
+ awaitingUserStateOwner?: 'supervisor' | 'host';
157
159
  /** 仅识别具有 Host 恢复输入的 run;不在启动时执行它。旧 run 默认仍 abandoned。 */
158
160
  canRestoreRun?: (record: RunRecord) => Promise<boolean>;
159
161
  }
@@ -134,7 +134,7 @@ interface RunSupervisor<TRequest extends RunRequestSnapshot = RunRequestSnapshot
134
134
  findByConversation(conversationId: string, opts?: FindRunsByConversationOptions): Promise<RunSnapshot[]>;
135
135
  drain(opts?: RunWaitForTerminalOptions): Promise<RunOutcome[]>;
136
136
  recoverOnBoot(reason?: string): Promise<RunOutcome[]>;
137
- pause(runId: RunId, reason?: string): Promise<void>;
137
+ pause(runId: RunId, reason?: string, expectedExecutionId?: ExecutionId): Promise<void>;
138
138
  resumePausedRun(input: {
139
139
  readonly runId: RunId;
140
140
  readonly expectedUpdatedAt: number;
@@ -154,6 +154,8 @@ interface DefaultRunSupervisorOptions<TRequest extends RunRequestSnapshot = RunR
154
154
  runIdFactory?: () => RunId;
155
155
  now?: () => number;
156
156
  maxActiveRuns?: number;
157
+ /** 原子 checkpoint Host 在持久提交后自行写等待态,不能由未提交的实时事件提前写入。 */
158
+ awaitingUserStateOwner?: 'supervisor' | 'host';
157
159
  /** 仅识别具有 Host 恢复输入的 run;不在启动时执行它。旧 run 默认仍 abandoned。 */
158
160
  canRestoreRun?: (record: RunRecord) => Promise<boolean>;
159
161
  }
@@ -1,5 +1,5 @@
1
1
  import { EventBus } from '../execution/event-bus.cjs';
2
- import { RunId } from '../../contracts/identity/definitions.cjs';
2
+ import { RunId, ExecutionId } from '../../contracts/identity/definitions.cjs';
3
3
  import { RuntimeEvent } from '../../contracts/events.cjs';
4
4
  import { RunSupervisor, DefaultRunSupervisorOptions, RunRegistrationSpec, RunWaitForTerminalOptions, RunOutcome, FindActiveByConversationOptions, RunSnapshot, FindRunsByConversationOptions, RunResumeInteraction, RunResumeClaim } from './definitions/runSupervisorContracts.cjs';
5
5
  export { RunExecutionContext, RunExecutorPort, RunResumeActivation, RunTerminalError, RunTerminalEvent, RunTerminalStatus } from './definitions/runSupervisorContracts.cjs';
@@ -44,7 +44,7 @@ declare class DefaultRunSupervisor<TRequest extends RunRequestSnapshot = RunRequ
44
44
  findByConversation(conversationId: string, opts?: FindRunsByConversationOptions): Promise<RunSnapshot[]>;
45
45
  drain(opts?: RunWaitForTerminalOptions): Promise<RunOutcome[]>;
46
46
  recoverOnBoot(reason?: string): Promise<RunOutcome[]>;
47
- pause(runId: RunId, reason?: string): Promise<void>;
47
+ pause(runId: RunId, reason?: string, expectedExecutionId?: ExecutionId): Promise<void>;
48
48
  resumePausedRun(input: Parameters<RunSupervisor<TRequest>['resumePausedRun']>[0]): Promise<RunHandle<TRequest>>;
49
49
  claimResume(runId: RunId, interaction: RunResumeInteraction, eventBus: EventBus, parentSignal?: AbortSignal): Promise<RunResumeClaim<TRequest>>;
50
50
  runTree(_rootRunId: RunId): Promise<never>;
@@ -1,5 +1,5 @@
1
1
  import { EventBus } from '../execution/event-bus.js';
2
- import { RunId } from '../../contracts/identity/definitions.js';
2
+ import { RunId, ExecutionId } from '../../contracts/identity/definitions.js';
3
3
  import { RuntimeEvent } from '../../contracts/events.js';
4
4
  import { RunSupervisor, DefaultRunSupervisorOptions, RunRegistrationSpec, RunWaitForTerminalOptions, RunOutcome, FindActiveByConversationOptions, RunSnapshot, FindRunsByConversationOptions, RunResumeInteraction, RunResumeClaim } from './definitions/runSupervisorContracts.js';
5
5
  export { RunExecutionContext, RunExecutorPort, RunResumeActivation, RunTerminalError, RunTerminalEvent, RunTerminalStatus } from './definitions/runSupervisorContracts.js';
@@ -44,7 +44,7 @@ declare class DefaultRunSupervisor<TRequest extends RunRequestSnapshot = RunRequ
44
44
  findByConversation(conversationId: string, opts?: FindRunsByConversationOptions): Promise<RunSnapshot[]>;
45
45
  drain(opts?: RunWaitForTerminalOptions): Promise<RunOutcome[]>;
46
46
  recoverOnBoot(reason?: string): Promise<RunOutcome[]>;
47
- pause(runId: RunId, reason?: string): Promise<void>;
47
+ pause(runId: RunId, reason?: string, expectedExecutionId?: ExecutionId): Promise<void>;
48
48
  resumePausedRun(input: Parameters<RunSupervisor<TRequest>['resumePausedRun']>[0]): Promise<RunHandle<TRequest>>;
49
49
  claimResume(runId: RunId, interaction: RunResumeInteraction, eventBus: EventBus, parentSignal?: AbortSignal): Promise<RunResumeClaim<TRequest>>;
50
50
  runTree(_rootRunId: RunId): Promise<never>;
@@ -2992,13 +2992,21 @@ var GraphExecutor = class {
2992
2992
  if (existing) {
2993
2993
  throw new Error(`Graph checkpoint already exists: ${checkpointKey}`);
2994
2994
  }
2995
- this.ephemeralLocals.set(checkpointKey, { ...local });
2995
+ const initialLocal = this.executionCheckpointPort ? {
2996
+ ...local,
2997
+ executorLocal: {
2998
+ ...isRecord4(local.executorLocal) ? local.executorLocal : {},
2999
+ stepCount: 0,
3000
+ maxSteps: options.maxSteps ?? this.config.maxSteps
3001
+ }
3002
+ } : local;
3003
+ this.ephemeralLocals.set(checkpointKey, { ...initialLocal });
2996
3004
  await this.commitCheckpoint(checkpointKey, {
2997
3005
  nodeId,
2998
3006
  ...this.executionCheckpointPort ? { executionStatus: "ready" } : {},
2999
3007
  revision: 1,
3000
3008
  schemaVersion: ENGINE_STATE_SCHEMA_VERSION,
3001
- local: sanitizeCheckpointLocal(local)
3009
+ local: sanitizeCheckpointLocal(initialLocal)
3002
3010
  });
3003
3011
  return this.runUntilYieldQueued(
3004
3012
  checkpointKey,
@@ -13299,7 +13307,7 @@ function createAwaitingUserWatcher(options) {
13299
13307
  const onClose = () => {
13300
13308
  dispose();
13301
13309
  };
13302
- eventBus.on("event", onEvent);
13310
+ if (options.stateOwner !== "host") eventBus.on("event", onEvent);
13303
13311
  eventBus.on("close", onClose);
13304
13312
  return dispose;
13305
13313
  }
@@ -13775,6 +13783,7 @@ var DefaultRunSupervisor = class {
13775
13783
  this.runSlotLimiter = createRunSlotLimiter({ maxActiveRuns: options.maxActiveRuns });
13776
13784
  this.runConcurrencyKeys = createRunConcurrencyKeyRegistry();
13777
13785
  this.awaitingUserWatcher = createAwaitingUserWatcher({
13786
+ stateOwner: options.awaitingUserStateOwner,
13778
13787
  markAwaitingUser: (runId, patch) => this.getHandle(runId).markAwaitingUser(patch),
13779
13788
  onDisposed: (runId) => {
13780
13789
  this.eventWatchDisposers.delete(runId);
@@ -13971,8 +13980,17 @@ var DefaultRunSupervisor = class {
13971
13980
  canRestoreRun: this.canRestoreRun
13972
13981
  });
13973
13982
  }
13974
- async pause(runId, reason) {
13975
- await this.withRunControlLock(runId, () => this.getHandle(runId).pause(reason));
13983
+ async pause(runId, reason, expectedExecutionId) {
13984
+ await this.withRunControlLock(runId, async () => {
13985
+ const handle = this.getHandle(runId);
13986
+ if (expectedExecutionId !== void 0) {
13987
+ const record = await this.registryStore.load(runId);
13988
+ if (record?.metadata?.executionId !== expectedExecutionId) {
13989
+ throw new RunInteractionConflictError(runId, "pause execution ownership has changed");
13990
+ }
13991
+ }
13992
+ await handle.pause(reason);
13993
+ });
13976
13994
  }
13977
13995
  async resumePausedRun(input) {
13978
13996
  return this.withRunControlLock(input.runId, async () => {