@mastra/spanner 1.9.2 → 1.9.3

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.
@@ -3,7 +3,7 @@ name: mastra-spanner
3
3
  description: Documentation for @mastra/spanner. Use when working with @mastra/spanner APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/spanner"
6
- version: "1.9.2"
6
+ version: "1.9.3"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.9.2",
2
+ "version": "1.9.3",
3
3
  "package": "@mastra/spanner",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -95,29 +95,32 @@ Set the `retention` field on the store config.
95
95
 
96
96
  Each domain specifies its age-prunable tables and the timestamp column that anchors comparison, chosen so `maxAge` matches the meaning of the data. Append-only logs use creation time, live state uses last activity, and jobs or runs use completion time so in-flight work isn't pruned.
97
97
 
98
- | Domain | Table key | Anchor column | `maxAge` measures |
99
- | ----------------- | ------------------ | ---------------- | ---------------------------------------------------------------- |
100
- | `memory` | `threads` | `createdAt` | Thread age |
101
- | `memory` | `messages` | `createdAt` | Message age |
102
- | `memory` | `resources` | `createdAt` | Resource age |
103
- | `threadState` | `threadState` | `updatedAt` | Inactivity: state for still-active threads survives |
104
- | `observability` | `spans` | `startedAt` | Span age |
105
- | `observability` | `metrics` | `timestamp` | Metric event age (vNext only) |
106
- | `observability` | `logs` | `timestamp` | Log event age (vNext only) |
107
- | `observability` | `scores` | `timestamp` | Score event age (vNext only) |
108
- | `observability` | `feedback` | `timestamp` | Feedback event age (vNext only) |
109
- | `scores` | `scorers` | `createdAt` | Score record age |
110
- | `workflows` | `workflowSnapshot` | `updatedAt` | Inactivity, suspended or long-running workflows survive |
111
- | `backgroundTasks` | `backgroundTasks` | `completedAt` | Time since completion, in-flight tasks (`NULL`) are never pruned |
112
- | `experiments` | `experiments` | `completedAt` | Time since completion, running experiments are never pruned |
113
- | `notifications` | `notifications` | `createdAt` | Notification age |
114
- | `harness` | `sessions` | `createdAt` | Session record age |
115
- | `schedules` | `triggers` | `actual_fire_at` | Fire-history age (epoch-ms column) |
98
+ | Domain | Table key | Anchor column | `maxAge` measures |
99
+ | ----------------- | ------------------ | ---------------- | -------------------------------------------------------------------------------------------------------------------------------- |
100
+ | `memory` | `threads` | `createdAt` | Thread age |
101
+ | `memory` | `messages` | `createdAt` | Message age |
102
+ | `memory` | `resources` | `createdAt` | Resource age |
103
+ | `memory` | `runFences` | `retiredAt` | Time since the durable agent execution holding the fence settled. Fences of running executions (`NULL`) are never pruned |
104
+ | `threadState` | `threadState` | `updatedAt` | Inactivity: state for still-active threads survives |
105
+ | `observability` | `spans` | `startedAt` | Span age |
106
+ | `observability` | `metrics` | `timestamp` | Metric event age (vNext only) |
107
+ | `observability` | `logs` | `timestamp` | Log event age (vNext only) |
108
+ | `observability` | `scores` | `timestamp` | Score event age (vNext only) |
109
+ | `observability` | `feedback` | `timestamp` | Feedback event age (vNext only) |
110
+ | `scores` | `scorers` | `createdAt` | Score record age |
111
+ | `workflows` | `workflowSnapshot` | `updatedAt` | Inactivity, suspended or long-running workflows survive |
112
+ | `workflows` | `runOwnership` | `updatedAt` | Inactivity. A running durable agent execution renews its claim every 10 seconds, so keep `maxAge` well above its 30-second lease |
113
+ | `backgroundTasks` | `backgroundTasks` | `completedAt` | Time since completion, in-flight tasks (`NULL`) are never pruned |
114
+ | `experiments` | `experiments` | `completedAt` | Time since completion, running experiments are never pruned |
115
+ | `notifications` | `notifications` | `createdAt` | Notification age |
116
+ | `harness` | `sessions` | `createdAt` | Session record age |
117
+ | `schedules` | `triggers` | `actual_fire_at` | Fire-history age (epoch-ms column) |
116
118
 
117
119
  > **Note:**
118
120
  >
119
121
  > - The memory `observational_memory` table has no timestamp anchor, so it can't be age-pruned and isn't a valid retention key.
120
122
  > - Experiments prune as whole units: an aged experiment's result rows are deleted together with it (results cascade with their parent), so a run is never left partially deleted. Retention doesn't have a separate `results` key.
123
+ > - `runOwnership` and `runFences` hold the run fencing records of durable agents, one small record per run in each. If the `runOwnership` `maxAge` is too short, a running execution can lose its run, but an execution that lost a run still can't write. A fence is retired only when its execution settles, so the fence of a run that crashed and was never recovered is never pruned.
121
124
  > - For `schedules`, the growth table is the fire history (`schedule_triggers`, one row per fire): schedule definitions are config and aren't pruned.
122
125
  > - On PostgreSQL, timestamp anchors use the timezone-aware mirror columns (for example `createdAtZ`, `completedAtZ`).
123
126
  > - DuckDB observability stores append-only events for all five signals. Its `spans` policy uses the event `timestamp` column rather than `startedAt`.
package/dist/index.cjs CHANGED
@@ -7310,10 +7310,10 @@ var MemorySpanner = class MemorySpanner extends _mastra_core_storage.MemoryStora
7310
7310
  };
7311
7311
  const { sql: preparedWhereSql, params: whereParams, types: whereTypes } = this.db.prepareWhereClause(filters, _mastra_core_storage.TABLE_MESSAGES);
7312
7312
  const metadataWhere = buildSpannerMessageMetadataFilter(metadataFilter);
7313
- const whereSql = [preparedWhereSql, ...metadataWhere.clauses].reduce((sql, clause) => {
7313
+ const whereSql = metadataWhere.clauses.reduce((sql, clause) => {
7314
7314
  if (!clause) return sql;
7315
7315
  return sql ? `${sql} AND ${clause}` : ` WHERE ${clause}`;
7316
- }, "");
7316
+ }, preparedWhereSql);
7317
7317
  Object.assign(whereParams, metadataWhere.params);
7318
7318
  if (perPage === 0 && (!include || include.length === 0)) return {
7319
7319
  messages: [],
@@ -12526,7 +12526,7 @@ var WorkflowsSpanner = class WorkflowsSpanner extends _mastra_core_storage.Workf
12526
12526
  }
12527
12527
  }
12528
12528
  /** Merges a step result and request-context delta into a snapshot inside an RW transaction. */
12529
- async updateWorkflowResults({ workflowName, runId, stepId, result, requestContext }) {
12529
+ async updateWorkflowResults({ workflowName, runId, stepId, result, requestContext, state }) {
12530
12530
  const table = quoteIdent(_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT, "table name");
12531
12531
  try {
12532
12532
  let mergedContext = {};
@@ -12562,6 +12562,7 @@ var WorkflowsSpanner = class WorkflowsSpanner extends _mastra_core_storage.Workf
12562
12562
  snapshot = typeof raw === "string" ? JSON.parse(raw) : raw;
12563
12563
  }
12564
12564
  snapshot.context[stepId] = result;
12565
+ if (state !== void 0) snapshot.context.__state = state;
12565
12566
  snapshot.requestContext = {
12566
12567
  ...snapshot.requestContext,
12567
12568
  ...requestContext
@@ -12608,6 +12609,7 @@ var WorkflowsSpanner = class WorkflowsSpanner extends _mastra_core_storage.Workf
12608
12609
  try {
12609
12610
  let updated;
12610
12611
  await this.db.runWithAbortRetry(() => this.database.runTransactionAsync(async (tx) => {
12612
+ updated = void 0;
12611
12613
  try {
12612
12614
  const [rows] = await tx.run({
12613
12615
  sql: `SELECT snapshot FROM ${table} WHERE workflow_name = @workflow_name AND run_id = @run_id`,