mastra-ai/mastra · error

Workspace with id ${id} not found

Error message

Workspace with id ${id} not found

What it means

Thrown by MastraStorage's in-memory workspace domain when update() is called with an id that has no persisted workspace config. The store does a Map lookup on db.workspaces and fails fast rather than silently returning an unmodified record. It is a 'patch a nonexistent resource' error, analogous to a 404 on an HTTP PATCH.

Source

Thrown at packages/core/src/storage/domains/workspaces/inmemory.ts:88

    await this.createVersion({
      id: versionId,
      workspaceId: workspace.id,
      versionNumber: 1,
      ...snapshotConfig,
      changedFields: Object.keys(snapshotConfig),
      changeMessage: 'Initial version',
    });

    // Return the thin record
    return this.deepCopyConfig(newConfig);
  }

  async update(input: StorageUpdateWorkspaceInput): Promise<StorageWorkspaceType> {
    const { id, ...updates } = input;

    const existingConfig = this.db.workspaces.get(id);
    if (!existingConfig) {
      throw new Error(`Workspace with id ${id} not found`);
    }

    // Separate metadata fields from config fields
    const { authorId, activeVersionId, metadata, status, ...rawConfigFields } = updates;

    // Strip undefined keys so omitted PATCH fields don't overwrite persisted values
    const configFields: Record<string, unknown> = {};
    for (const [key, value] of Object.entries(rawConfigFields)) {
      if (value !== undefined) configFields[key] = value;
    }

    // Config field names from StorageWorkspaceSnapshotType
    const configFieldNames = [
      'name',
      'description',
      'filesystem',
      'sandbox',
      'mounts',

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Verify the id exists by calling getWorkspaceById(id) or list() before updating, and create it if missing
  2. Confirm you are using the same storage instance that holds the workspace (not a fresh InMemoryDomain instance)
  3. Check the id value for typos or copying the wrong entity's id (agent vs workspace)
  4. Persist durable workspaces in a real storage backend (LibSQL/Postgres/etc.) instead of in-memory if ids must survive restarts

Example fix

// before
await storage.workspaces.update({ id: workspaceId, name: 'Renamed' }); // throws if missing
// after
const existing = await storage.workspaces.getWorkspaceById(workspaceId);
if (!existing) {
  throw new Error(`Workspace ${workspaceId} does not exist; create it first`);
}
await storage.workspaces.update({ id: workspaceId, name: 'Renamed' });
Defensive patterns

Strategy: validation

Validate before calling

const existing = await storage.workspaces.getWorkspaceById(id);
if (!existing) throw new Error(`Workspace ${id} not found; create it before updating`);

Try / catch

try {
  await storage.workspaces.update({ id, ...updates });
} catch (err) {
  if (err instanceof Error && err.message === `Workspace with id ${id} not found`) {
    // create the workspace or surface a 404-style response
  } else throw err;
}

Prevention

When it happens

Trigger: Calling storage.workspaces.update({ id: 'nonexistent-id', name: 'x' }) (or any other field) when no workspace with that id was created in this storage instance; using an id from a different storage backend; referencing a workspace dropped by clear()/reset; using a stale id after process restart since the in-memory store is volatile.

Common situations: Hardcoded test ids that were never created; passing a workflow or agent id instead of a workspace id; two storage instances (e.g. unit test fixtures) each with their own in-memory Map; script creating the workspace in one process and updating it in another.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/e8253abc698a6e97. Report an issue: GitHub.