@springbrand/agent-runtime 0.2.0-alpha.51 → 0.2.0-alpha.52

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/runtime.ts +14 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@springbrand/agent-runtime",
3
- "version": "0.2.0-alpha.51",
3
+ "version": "0.2.0-alpha.52",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src",
package/src/runtime.ts CHANGED
@@ -442,6 +442,7 @@ export abstract class AgentRuntimeKernel<
442
442
  private readonly approvals: ApprovalLifecycle<StoredSubmission>;
443
443
  private readonly interactions: InteractionLifecycle<StoredSubmission>;
444
444
  private runtimeLoadTracker?: RuntimeLoadTracker;
445
+ private runtimeEventDrainTail?: Promise<void>;
445
446
  private readonly streamBySubmission = new Map<string, string>();
446
447
  private migratedSubmissionIds?: Set<string>;
447
448
  private db!: RuntimeDatabase;
@@ -1153,7 +1154,19 @@ export abstract class AgentRuntimeKernel<
1153
1154
  );
1154
1155
  }
1155
1156
 
1156
- private async drainRuntimeEvents(idempotentRetry = true): Promise<void> {
1157
+ private drainRuntimeEvents(idempotentRetry = true): Promise<void> {
1158
+ const drain = (this.runtimeEventDrainTail ?? Promise.resolve())
1159
+ .catch(() => undefined)
1160
+ .then(() => this.deliverRuntimeEvents(idempotentRetry));
1161
+ this.runtimeEventDrainTail = drain;
1162
+ return drain.finally(() => {
1163
+ if (this.runtimeEventDrainTail === drain) {
1164
+ this.runtimeEventDrainTail = undefined;
1165
+ }
1166
+ });
1167
+ }
1168
+
1169
+ private async deliverRuntimeEvents(idempotentRetry: boolean): Promise<void> {
1157
1170
  const turnEvents = this.turnEventsPort();
1158
1171
  if (!turnEvents) return;
1159
1172