mastra-ai/mastra · error

Factory workspace GitHub credential registration is no longe

Error message

Factory workspace GitHub credential registration is no longer active.

What it means

After workspace construction, `reconcileRegisteredWorkspace` verifies that the GitHub credential registration made during setup is still the one stored for the workspaceId. If the map entry was replaced or deleted while materializing, the workspace's credentials can no longer be trusted, so creation fails fast.

Source

Thrown at mastracode/factory/src/workspace.ts:517

            evicted = (await mastra?.removeWorkspace?.(workspaceId)) === true;
          } catch {
            // Preserve the credential-replacement error and retry on the next reuse.
          }
          try {
            await workspace.destroy();
            evicted = true;
          } catch {
            // The pending registration keeps the workspace quarantined if cleanup also fails.
          }
          if (evicted && githubTokenInjectors.get(workspaceId) === registered) {
            githubTokenInjectors.delete(workspaceId);
            constructedWorkspaces.delete(workspaceId);
          }
        }
        throw error;
      }
      if (registered && githubTokenInjectors.get(workspaceId) !== registered) {
        throw new Error('Factory workspace GitHub credential registration is no longer active.');
      }
      return workspace;
    };

    let existing: Workspace | undefined;
    try {
      existing = mastra?.getWorkspaceById(workspaceId) as Workspace | undefined;
    } catch {
      // Not registered yet.
      existing = undefined;
    }
    existing ??= constructedWorkspaces.get(workspaceId);
    if (existing) {
      existing.setToolsConfig(MASTRACODE_WORKSPACE_TOOLS);
      // A materialization kicked off by another caller may still be running.
      // Deliberately do NOT wait for it: a metadata-only resolution (thread
      // list, messages, activity) must not block on the clone/setup that lazy
      // materialization exists to avoid. Token reconciliation below no-ops

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Retry workspace creation — the conflicting registration will have settled
  2. Serialize workspace creation per workspaceId (avoid building the same factory concurrently)
  3. Check for duplicate session/workspace lifecycle events triggering parallel reconciliation
  4. Add logging on registerGithubTokenInjector to identify which path overwrote the registration
Defensive patterns

Strategy: retry

Validate before calling

const registered = await registerWorkspaceCredentials(workspaceId);
if (githubTokenInjectors.get(workspaceId) !== registered) {
  // another reconciliation overwrote registration — retry creation serially
  return createWorkspaceFactory(session, { lock: workspaceId });
}

Try / catch

try {
  const ws = await createWorkspaceFactory(session);
} catch (e) {
  if (e instanceof Error && e.message.includes('credential registration is no longer active')) {
    const ws = await createWorkspaceFactory(session); // retry after the race settles
  } else throw e;
}

Prevention

When it happens

Trigger: `createWorkspaceFactory` finishes constructing a workspace with a non-null `registered`, but `githubTokenInjectors.get(workspaceId)` returns a different registration object — another registration replaced it during construction.

Common situations: Two concurrent createWorkspaceFactory/reconciliation calls for the same workspaceId; a teardown/retirement of the workspace interleaved with creation; duplicate workspace factories built for one session.

Related errors


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