-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix(core): tenancy-scope datasets get and delete #18750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e791d3e
fix(core,server,client-js,stores): tenancy-scope datasets get and delete
NikAiyer a978dc7
chore: regenerate route metadata for new dataset tenancy query params
NikAiyer dd0dd10
fix(core,server,stores): tighten dataset tenancy — handle read gates,…
NikAiyer e2766d9
fix(core,server): close child-ID cross-dataset leak on Dataset handle
NikAiyer 0db24e0
fix(core): re-assert scope on experiment mutations + tighten ownershi…
NikAiyer b9c0bab
Merge branch 'main' into MASTRA-4438
NikAiyer 86955f4
Merge branch 'main' into MASTRA-4438
NikAiyer cb23c25
Merge branch 'main' into MASTRA-4438
NikAiyer bc92a74
Merge remote-tracking branch 'origin/main' into MASTRA-4438
NikAiyer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| --- | ||
| '@mastra/client-js': minor | ||
| '@mastra/server': patch | ||
| '@mastra/mongodb': patch | ||
| '@mastra/spanner': patch | ||
| '@mastra/core': patch | ||
| '@mastra/libsql': patch | ||
| '@mastra/mysql': patch | ||
| '@mastra/pg': patch | ||
| --- | ||
|
|
||
| Added optional tenancy arguments to `getDataset`, `updateDataset`, and `deleteDataset`. | ||
|
|
||
| You can now pass `organizationId` and `projectId` to scope dataset reads, updates, and deletes to a specific tenant. The server rejects the request with a 404 if the dataset id does not belong to that tenant, closing a cross-tenant read/delete gap. | ||
|
|
||
| **Example** | ||
|
|
||
| ```ts | ||
| // Before | ||
| await client.getDataset('abc123'); | ||
| await client.deleteDataset('abc123'); | ||
| await client.updateDataset({ id: 'abc123', name: 'renamed' }); | ||
|
|
||
| // After — scope to a tenant | ||
| await client.getDataset('abc123', { organizationId: 'org_a', projectId: 'proj_1' }); | ||
| await client.deleteDataset('abc123', { organizationId: 'org_a' }); | ||
| await client.updateDataset({ id: 'abc123', name: 'renamed', organizationId: 'org_a' }); | ||
| ``` | ||
|
|
||
| Related: [MASTRA-4438](https://linear.app/kepler-crm/issue/MASTRA-4438) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| --- | ||
| '@mastra/core': minor | ||
| '@mastra/client-js': patch | ||
| '@mastra/server': patch | ||
| '@mastra/mongodb': patch | ||
| '@mastra/spanner': patch | ||
| '@mastra/libsql': patch | ||
| '@mastra/mysql': patch | ||
| '@mastra/pg': patch | ||
| --- | ||
|
|
||
| Fixed a cross-tenant data-access issue on datasets by scoping `DatasetsManager.get` and `DatasetsManager.delete` to tenancy filters. | ||
|
|
||
| Previously `get({ id })` and `delete({ id })` looked up a dataset by its primary key alone. Any caller who knew a dataset id could read or delete it regardless of which `organizationId` / `projectId` it belonged to. This is now closed at the storage layer via a scoped SQL predicate (option (a) — no fetch-then-assert). | ||
|
|
||
| **What changed** | ||
|
|
||
| - `DatasetsManager.get` and `DatasetsManager.delete` accept optional `organizationId` and `projectId`. | ||
| - The tenancy is stashed on the returned `Dataset` handle and forwarded to every downstream storage call (`getDetails`, `update`, `addItem`, item batch ops, `startExperimentAsync`). | ||
| - The abstract storage contract (`getDatasetById`, `deleteDataset`) gained an optional `filters?: DatasetTenancyFilters` arg. | ||
| - Item-mutation inputs (`AddDatasetItemInput`, `UpdateDatasetItemInput`, `BatchInsertItemsInput`, `BatchDeleteItemsInput`) and `UpdateDatasetInput` accept optional `filters` for the internal existence check. | ||
|
|
||
| **Behavior** | ||
|
|
||
| - Omitting tenancy preserves the existing behavior (no predicate added) — fully backwards compatible. | ||
| - On tenancy mismatch, `get` throws NOT_FOUND (returns null at the storage layer) and `delete` is a silent no-op — matching how a missing id already behaves, so existence does not leak through error timing or messages. | ||
|
|
||
| **Example** | ||
|
|
||
| ```ts | ||
| // Before | ||
| const ds = await mastra.datasets.get({ id }); | ||
| await mastra.datasets.delete({ id }); | ||
|
|
||
| // After — scope to a tenant | ||
| const ds = await mastra.datasets.get({ id, organizationId, projectId }); | ||
| await mastra.datasets.delete({ id, organizationId, projectId }); | ||
| ``` | ||
|
|
||
| Related: [MASTRA-4438](https://linear.app/kepler-crm/issue/MASTRA-4438) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| --- | ||
| '@mastra/client-js': patch | ||
| '@mastra/server': patch | ||
| '@mastra/mongodb': patch | ||
| '@mastra/spanner': patch | ||
| '@mastra/core': patch | ||
| '@mastra/libsql': patch | ||
| '@mastra/mysql': patch | ||
| '@mastra/pg': patch | ||
| --- | ||
|
|
||
| Scoped `getDatasetById` and `deleteDataset` to tenancy filters when the caller passes `organizationId` / `projectId`. | ||
|
|
||
| The adapters now push the tenancy predicate into the SQL/query when the new optional `filters` argument is present. Legacy calls that omit tenancy are unchanged. On mismatch, `getDatasetById` returns `null` and `deleteDataset` is a silent no-op — the cascade delete (dataset items and versions) is gated by a scoped parent pre-check, so cross-tenant data is never touched. | ||
|
|
||
| Related: [MASTRA-4438](https://linear.app/kepler-crm/issue/MASTRA-4438) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| --- | ||
| '@mastra/server': minor | ||
| '@mastra/client-js': patch | ||
| '@mastra/mongodb': patch | ||
| '@mastra/spanner': patch | ||
| '@mastra/core': patch | ||
| '@mastra/libsql': patch | ||
| '@mastra/mysql': patch | ||
| '@mastra/pg': patch | ||
| --- | ||
|
|
||
| Added optional `organizationId` and `projectId` query parameters to the dataset routes. | ||
|
|
||
| `GET /datasets/:datasetId`, `PATCH /datasets/:datasetId`, and `DELETE /datasets/:datasetId` now accept optional tenancy query parameters. When provided, they are forwarded to `mastra.datasets.get` / `.delete` and the operation returns 404 if the dataset does not belong to the requested tenant. Requests that omit the query parameters keep their existing behavior. | ||
|
|
||
| **Example** | ||
|
|
||
| ``` | ||
| GET /datasets/abc123?organizationId=org_a&projectId=proj_1 | ||
| DELETE /datasets/abc123?organizationId=org_a | ||
| ``` | ||
|
|
||
| Related: [MASTRA-4438](https://linear.app/kepler-crm/issue/MASTRA-4438) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.