@rowan-agent/agent 0.9.22 → 0.9.24

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.
package/dist/index.d.ts CHANGED
@@ -2407,6 +2407,19 @@ declare class InMemoryStore implements DurableStore {
2407
2407
  private writeReceipt;
2408
2408
  private replayOperation;
2409
2409
  private writeOperationReceipt;
2410
+ /**
2411
+ * A Claim receipt exists for idempotent replay of one live Execution Attempt
2412
+ * and carries that Attempt's history. Dropping it when the Attempt ends keeps
2413
+ * one history snapshot per Agent instead of one per Attempt.
2414
+ */
2415
+ private dropClaimReceipt;
2416
+ /**
2417
+ * A new owner fences the Execution Attempts of the previous one, so no Claim
2418
+ * receipt from before the takeover can be replayed. Sweeping them reclaims
2419
+ * the history snapshots a store accumulated while no Attempt ended under
2420
+ * this Runtime.
2421
+ */
2422
+ dropSettledClaimReceipts(): void;
2410
2423
  private requireAgent;
2411
2424
  private requireRun;
2412
2425
  private requireToolCall;
package/dist/index.js CHANGED
@@ -5848,6 +5848,7 @@ function selectedRefs(refs, names) {
5848
5848
  var DEFAULT_CONCURRENCY = 10;
5849
5849
  var DEFAULT_POLL_MS = 25;
5850
5850
  var MAX_CONSUMER_IDLE_POLL_MS = 250;
5851
+ var RUN_STATE_CHECK_INTERVAL_MS = 1e3;
5851
5852
  var OWNER_LEASE_MS = 3e4;
5852
5853
  var OWNER_RENEWAL_MS = 1e4;
5853
5854
  var MAX_INLINE_TOOL_RESULT_BYTES = 16 * 1024;
@@ -6652,15 +6653,25 @@ var AgentRuntime = class _AgentRuntime {
6652
6653
  async *observe(runId, options = {}) {
6653
6654
  let cursor = options.after;
6654
6655
  const subscription = this.transientEvents.subscribe(runId);
6656
+ let nextRunStateCheckAtMs = 0;
6655
6657
  try {
6656
6658
  while (true) {
6659
+ const published = subscription.shift();
6660
+ if (published) {
6661
+ yield published;
6662
+ continue;
6663
+ }
6657
6664
  const observationVersion = subscription.checkpoint();
6658
- const snapshot = await this.owned.snapshotRun(runId);
6659
- const terminal = ["completed", "failed", "cancelled"].includes(snapshot.state);
6660
- if (options.signal?.aborted && !terminal) throw abortError();
6661
- if (terminal) {
6662
- const pending = await this.owned.listEvents(cursor ? { after: cursor } : {});
6663
- if (!pending.some((event) => event.runId === runId)) return;
6665
+ const aborted = options.signal?.aborted === true;
6666
+ if (aborted || Date.now() >= nextRunStateCheckAtMs) {
6667
+ nextRunStateCheckAtMs = Date.now() + RUN_STATE_CHECK_INTERVAL_MS;
6668
+ const snapshot = await this.owned.snapshotRun(runId);
6669
+ const terminal = ["completed", "failed", "cancelled"].includes(snapshot.state);
6670
+ if (aborted && !terminal) throw abortError();
6671
+ if (terminal) {
6672
+ const pending = await this.owned.listEvents(cursor ? { after: cursor } : {});
6673
+ if (!pending.some((event) => event.runId === runId)) return;
6674
+ }
6664
6675
  }
6665
6676
  const events = await this.owned.listEvents(cursor ? { after: cursor } : {});
6666
6677
  for (const event of events) {
@@ -6957,6 +6968,7 @@ var InMemoryStore = class _InMemoryStore {
6957
6968
  const failure = indeterminateToolCallIds.length > 0 ? { code: "tool_indeterminate", message, toolCallIds: indeterminateToolCallIds } : { code: "runtime_interrupted", message, ownerEpoch };
6958
6969
  run.state = "failed";
6959
6970
  run.failure = failure;
6971
+ this.dropClaimReceipt(run.execution);
6960
6972
  delete run.execution;
6961
6973
  run.revision += 1;
6962
6974
  run.updatedAt = createTimestamp();
@@ -6977,6 +6989,7 @@ var InMemoryStore = class _InMemoryStore {
6977
6989
  return new MemoryOwnedStore(this, clone(this.owner));
6978
6990
  }
6979
6991
  if (this.owner) this.interruptOwner(this.owner.epoch);
6992
+ this.dropSettledClaimReceipts();
6980
6993
  this.ownerEpoch += 1;
6981
6994
  this.owner = {
6982
6995
  ownerId: input.ownerId,
@@ -7186,6 +7199,7 @@ var InMemoryStore = class _InMemoryStore {
7186
7199
  delete run.openInputRequest;
7187
7200
  delete run.checkpoint;
7188
7201
  }
7202
+ this.dropClaimReceipt(run.execution);
7189
7203
  delete run.execution;
7190
7204
  run.state = "cancelled";
7191
7205
  run.cancellationReason = "Run superseded by Message revision.";
@@ -7369,6 +7383,7 @@ var InMemoryStore = class _InMemoryStore {
7369
7383
  delete run.openInteractions;
7370
7384
  delete run.interactionAnswers;
7371
7385
  }
7386
+ this.dropClaimReceipt(run.execution);
7372
7387
  delete run.execution;
7373
7388
  run.revision += 1;
7374
7389
  run.updatedAt = createTimestamp();
@@ -7623,6 +7638,7 @@ var InMemoryStore = class _InMemoryStore {
7623
7638
  };
7624
7639
  run.state = "failed";
7625
7640
  run.failure = failure;
7641
+ this.dropClaimReceipt(run.execution);
7626
7642
  delete run.execution;
7627
7643
  run.revision += 1;
7628
7644
  run.updatedAt = createTimestamp();
@@ -7653,6 +7669,7 @@ var InMemoryStore = class _InMemoryStore {
7653
7669
  run.state = nextState;
7654
7670
  if (input.outcome) run.outcome = clone(input.outcome);
7655
7671
  if (input.failure) run.failure = clone(input.failure);
7672
+ this.dropClaimReceipt(run.execution);
7656
7673
  delete run.execution;
7657
7674
  delete run.openInteractions;
7658
7675
  delete run.interactionAnswers;
@@ -7699,6 +7716,7 @@ var InMemoryStore = class _InMemoryStore {
7699
7716
  run.state = "failed";
7700
7717
  run.failure = failure;
7701
7718
  delete run.cancellationReason;
7719
+ this.dropClaimReceipt(run.execution);
7702
7720
  delete run.execution;
7703
7721
  delete run.openInputRequest;
7704
7722
  delete run.openInteractions;
@@ -7712,6 +7730,7 @@ var InMemoryStore = class _InMemoryStore {
7712
7730
  }
7713
7731
  run.state = "cancelled";
7714
7732
  run.cancellationReason = input.reason;
7733
+ this.dropClaimReceipt(run.execution);
7715
7734
  delete run.execution;
7716
7735
  delete run.openInputRequest;
7717
7736
  delete run.openInteractions;
@@ -7885,6 +7904,31 @@ var InMemoryStore = class _InMemoryStore {
7885
7904
  writeOperationReceipt(key, payload, result) {
7886
7905
  this.operationReceipts.set(key, { payload, result: clone(result) });
7887
7906
  }
7907
+ /**
7908
+ * A Claim receipt exists for idempotent replay of one live Execution Attempt
7909
+ * and carries that Attempt's history. Dropping it when the Attempt ends keeps
7910
+ * one history snapshot per Agent instead of one per Attempt.
7911
+ */
7912
+ dropClaimReceipt(execution) {
7913
+ if (execution) this.operationReceipts.delete(`claim:${execution.executionId}`);
7914
+ }
7915
+ /**
7916
+ * A new owner fences the Execution Attempts of the previous one, so no Claim
7917
+ * receipt from before the takeover can be replayed. Sweeping them reclaims
7918
+ * the history snapshots a store accumulated while no Attempt ended under
7919
+ * this Runtime.
7920
+ */
7921
+ dropSettledClaimReceipts() {
7922
+ const liveExecutions = /* @__PURE__ */ new Set();
7923
+ for (const run of this.runs.values()) {
7924
+ if (run.state === "running" && run.execution) liveExecutions.add(String(run.execution.executionId));
7925
+ }
7926
+ for (const key of [...this.operationReceipts.keys()]) {
7927
+ if (key.startsWith("claim:") && !liveExecutions.has(key.slice("claim:".length))) {
7928
+ this.operationReceipts.delete(key);
7929
+ }
7930
+ }
7931
+ }
7888
7932
  requireAgent(agentId) {
7889
7933
  const agent = this.agents.get(agentId);
7890
7934
  if (!agent) throw new RuntimeError("agent_not_found", { agentId });
@@ -8429,6 +8473,7 @@ var SqliteStore = class {
8429
8473
  released_epoch: row.released_epoch
8430
8474
  };
8431
8475
  this.writeOwner(next);
8476
+ memory.dropSettledClaimReceipts();
8432
8477
  this.persistState(memory.exportState());
8433
8478
  return {
8434
8479
  ownerId: input.ownerId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rowan-agent/agent",
3
- "version": "0.9.22",
3
+ "version": "0.9.24",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",