@mastra/pg 1.11.0-alpha.0 → 1.11.1-alpha.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,48 @@
1
1
  # @mastra/pg
2
2
 
3
+ ## 1.11.1-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixed scheduler performance and correctness issues that could cause excessive Postgres CPU and noisy failed runs. ([#16805](https://github.com/mastra-ai/mastra/pull/16805))
8
+ - Added missing indexes on the schedules tables that the tick loop polls every 10 seconds: `(status, next_fire_at)` on `mastra_schedules` and `(schedule_id, actual_fire_at)` on `mastra_schedule_triggers`. Without these the scheduler performed a full sequential scan on every tick.
9
+ - The scheduler tick loop is now only started when at least one workflow declares a schedule (or `scheduler.enabled` is set explicitly), so deployments without scheduled workflows no longer poll the database at all.
10
+ - The scheduler now validates that a schedule's target workflow is still registered before firing it. Schedules whose target workflow has been removed from the Mastra config are skipped for a short grace window and then deleted, so stale rows stop producing failed workflow runs forever.
11
+ - The scheduler is now lazily initialized inside `startWorkers()`. Accessing `mastra.scheduler` before `startWorkers()` runs throws a descriptive error instead of returning a half-initialized instance.
12
+
13
+ - Updated dependencies [[`27fd1b7`](https://github.com/mastra-ai/mastra/commit/27fd1b79ac62eb7694f92587eb7d1be05b59be01), [`a702009`](https://github.com/mastra-ai/mastra/commit/a702009d3cfaa745120f501e21c783ed4d6a3072), [`8534d79`](https://github.com/mastra-ai/mastra/commit/8534d791fa1cb70fe1c19e2604c4b63cc10dd051), [`c78f8cd`](https://github.com/mastra-ai/mastra/commit/c78f8cd6222a86e6c60ae5210b6929ad5221b6fb), [`e146aad`](https://github.com/mastra-ai/mastra/commit/e146aadbba66c410ba0e74bac4c50135495cb8dd), [`1a0ec78`](https://github.com/mastra-ai/mastra/commit/1a0ec789a26cae443744e9abbd62ed6ee676af39), [`d52b6fe`](https://github.com/mastra-ai/mastra/commit/d52b6fe1c56853eb38864baae0bbfa75cc739ccb)]:
14
+ - @mastra/core@1.36.0-alpha.10
15
+
16
+ ## 1.11.0
17
+
18
+ ### Minor Changes
19
+
20
+ - Added favorites support to storage adapters so callers can favorite/unfavorite stored agents and skills, query favorite state alongside list results, and filter listings by visibility. ([#16580](https://github.com/mastra-ai/mastra/pull/16580))
21
+
22
+ **Example**
23
+
24
+ ```ts
25
+ const storage = new LibSQLStore({
26
+ /* config */
27
+ });
28
+ const favorites = await storage.getStore('favorites');
29
+
30
+ await favorites?.favorite({
31
+ userId: 'user-1',
32
+ entityType: 'agent',
33
+ entityId: 'agent-42',
34
+ });
35
+ ```
36
+
37
+ ### Patch Changes
38
+
39
+ - Fixed a workspace PATCH bug: omitted config fields in a PATCH no longer overwrite previously-persisted values with `undefined`. ([#16580](https://github.com/mastra-ai/mastra/pull/16580))
40
+
41
+ - Bumped `@mastra/core` peer dependency floor to `>=1.34.0-0` so the new `@mastra/core/storage/domains/favorites` subpath is available. Older `@mastra/core` versions don't ship the `FavoritesStorage` base class these adapters now extend. ([#16580](https://github.com/mastra-ai/mastra/pull/16580))
42
+
43
+ - Updated dependencies [[`b661349`](https://github.com/mastra-ai/mastra/commit/b661349281514691db78941a9044e6e4f1cde7a7), [`816b974`](https://github.com/mastra-ai/mastra/commit/816b974b424e4a1bfae3af30cc41263b6f1c0344), [`271c044`](https://github.com/mastra-ai/mastra/commit/271c044f6b79ff38cfa3409f4385fbd26a0f3185), [`bad08e9`](https://github.com/mastra-ai/mastra/commit/bad08e99c5291884c3ac76743c78c74f53a302c2), [`816b974`](https://github.com/mastra-ai/mastra/commit/816b974b424e4a1bfae3af30cc41263b6f1c0344), [`b32ba5f`](https://github.com/mastra-ai/mastra/commit/b32ba5fde524b46a4ff1bdf38e30d62a2bb29b04), [`75c7c38`](https://github.com/mastra-ai/mastra/commit/75c7c38a4e9af9821931539dd339f57fcc6414e3)]:
44
+ - @mastra/core@1.35.0
45
+
3
46
  ## 1.11.0-alpha.0
4
47
 
5
48
  ### Minor Changes
@@ -3,7 +3,7 @@ name: mastra-pg
3
3
  description: Documentation for @mastra/pg. Use when working with @mastra/pg APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/pg"
6
- version: "1.11.0-alpha.0"
6
+ version: "1.11.1-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.11.0-alpha.0",
2
+ "version": "1.11.1-alpha.0",
3
3
  "package": "@mastra/pg",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -130,7 +130,7 @@ Resource-scoped working memory requires specific storage adapters that support t
130
130
 
131
131
  ## Custom templates
132
132
 
133
- Templates guide the agent on what information to track and update in working memory. While a default template is used if none is provided, you'll typically want to define a custom template tailored to your agent's specific use case to ensure it remembers the most relevant information.
133
+ Templates guide the agent on what information to track and update in working memory. While a default template is used if none is provided, you'll typically want to define a custom template tailored to your agent's specific use case to ensure it remembers the most relevant information. For threads shared by multiple users, see [Multi-user threads](https://mastra.ai/docs/memory/multi-user-threads).
134
134
 
135
135
  Here's an example of a custom template. In this example the agent will store the users name, location, timezone, etc as soon as the user sends a message containing any of the info:
136
136
 
package/dist/index.cjs CHANGED
@@ -11758,18 +11758,22 @@ function rowToTrigger(row) {
11758
11758
  if (metadata !== void 0) trigger.metadata = metadata;
11759
11759
  return trigger;
11760
11760
  }
11761
- var SchedulesPG = class extends storage.SchedulesStorage {
11761
+ var SchedulesPG = class _SchedulesPG extends storage.SchedulesStorage {
11762
11762
  #db;
11763
11763
  #client;
11764
11764
  #schema;
11765
+ #skipDefaultIndexes;
11766
+ #indexes;
11765
11767
  /** Tables managed by this domain */
11766
11768
  static MANAGED_TABLES = [storage.TABLE_SCHEDULES, storage.TABLE_SCHEDULE_TRIGGERS];
11767
11769
  constructor(config) {
11768
11770
  super();
11769
- const { client, schemaName, skipDefaultIndexes } = resolvePgConfig(config);
11771
+ const { client, schemaName, skipDefaultIndexes, indexes } = resolvePgConfig(config);
11770
11772
  this.#client = client;
11771
11773
  this.#db = new PgDB({ client, schemaName, skipDefaultIndexes });
11772
11774
  this.#schema = schemaName || "public";
11775
+ this.#skipDefaultIndexes = skipDefaultIndexes;
11776
+ this.#indexes = indexes?.filter((idx) => _SchedulesPG.MANAGED_TABLES.includes(idx.table));
11773
11777
  }
11774
11778
  async init() {
11775
11779
  await this.#db.createTable({
@@ -11780,22 +11784,79 @@ var SchedulesPG = class extends storage.SchedulesStorage {
11780
11784
  tableName: storage.TABLE_SCHEDULE_TRIGGERS,
11781
11785
  schema: storage.TABLE_SCHEMAS[storage.TABLE_SCHEDULE_TRIGGERS]
11782
11786
  });
11787
+ await this.createDefaultIndexes();
11788
+ await this.createCustomIndexes();
11783
11789
  }
11784
- static getExportDDL(schemaName) {
11790
+ /**
11791
+ * Returns default index definitions for the schedules domain.
11792
+ * @param schemaPrefix - Prefix for index names (e.g. "my_schema_" or "")
11793
+ */
11794
+ static getDefaultIndexDefs(schemaPrefix) {
11785
11795
  return [
11796
+ {
11797
+ name: `${schemaPrefix}idx_mastra_schedules_status_next_fire`,
11798
+ table: storage.TABLE_SCHEDULES,
11799
+ columns: ["status", "next_fire_at"]
11800
+ },
11801
+ {
11802
+ name: `${schemaPrefix}idx_mastra_schedule_triggers_schedule_fire`,
11803
+ table: storage.TABLE_SCHEDULE_TRIGGERS,
11804
+ columns: ["schedule_id", "actual_fire_at DESC"]
11805
+ }
11806
+ ];
11807
+ }
11808
+ getDefaultIndexDefinitions() {
11809
+ const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
11810
+ return _SchedulesPG.getDefaultIndexDefs(schemaPrefix);
11811
+ }
11812
+ async createDefaultIndexes() {
11813
+ if (this.#skipDefaultIndexes) {
11814
+ return;
11815
+ }
11816
+ for (const indexDef of this.getDefaultIndexDefinitions()) {
11817
+ try {
11818
+ await this.#db.createIndex(indexDef);
11819
+ } catch (error) {
11820
+ this.logger?.warn?.(`Failed to create index ${indexDef.name}:`, error);
11821
+ }
11822
+ }
11823
+ }
11824
+ async createCustomIndexes() {
11825
+ if (!this.#indexes || this.#indexes.length === 0) {
11826
+ return;
11827
+ }
11828
+ for (const indexDef of this.#indexes) {
11829
+ try {
11830
+ await this.#db.createIndex(indexDef);
11831
+ } catch (error) {
11832
+ this.logger?.warn?.(`Failed to create custom index ${indexDef.name}:`, error);
11833
+ }
11834
+ }
11835
+ }
11836
+ static getExportDDL(schemaName) {
11837
+ const statements = [];
11838
+ const parsedSchema = schemaName ? utils.parseSqlIdentifier(schemaName, "schema name") : "";
11839
+ const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
11840
+ statements.push(
11786
11841
  generateTableSQL({
11787
11842
  tableName: storage.TABLE_SCHEDULES,
11788
11843
  schema: storage.TABLE_SCHEMAS[storage.TABLE_SCHEDULES],
11789
11844
  schemaName,
11790
11845
  includeAllConstraints: true
11791
- }),
11846
+ })
11847
+ );
11848
+ statements.push(
11792
11849
  generateTableSQL({
11793
11850
  tableName: storage.TABLE_SCHEDULE_TRIGGERS,
11794
11851
  schema: storage.TABLE_SCHEMAS[storage.TABLE_SCHEDULE_TRIGGERS],
11795
11852
  schemaName,
11796
11853
  includeAllConstraints: true
11797
11854
  })
11798
- ];
11855
+ );
11856
+ for (const idx of _SchedulesPG.getDefaultIndexDefs(schemaPrefix)) {
11857
+ statements.push(generateIndexSQL(idx, schemaName));
11858
+ }
11859
+ return statements;
11799
11860
  }
11800
11861
  async dangerouslyClearAll() {
11801
11862
  await this.#db.clearTable({ tableName: storage.TABLE_SCHEDULE_TRIGGERS });