{"record":{"id":"90550cba5e323556","repo":"TencentCloud/TencentDB-Agent-Memory","slug":"team-limit-exceeded","errorCode":"team_limit_exceeded","errorMessage":"team limit ${limit} reached for instance ${this.instanceId} (current: ${count})","messagePattern":"team limit (.+?) reached for instance (.+?) \\(current: (.+?)\\)","errorType":"error_code","errorClass":"MetadataError","httpStatus":null,"severity":"error","filePath":"MemoryCore/src/metadata/service/metadata-service.ts","lineNumber":368,"sourceCode":"    const count = await this.store.countUsers();\n    const limit = this._configParams\n      ? await this._configParams.getEffectiveInt(\"quota\", \"max_users_per_instance\")\n      : this.quota.maxUsersPerInstance;\n    if (count >= limit) {\n      throw new MetadataError(\n        \"user_limit_exceeded\",\n        `user limit ${limit} reached for instance ${this.instanceId} (current: ${count})`,\n      );\n    }\n  }\n\n  private async assertTeamQuota(): Promise<void> {\n    const count = await this.store.countTeams();\n    const limit = this._configParams\n      ? await this._configParams.getEffectiveInt(\"quota\", \"max_teams_per_instance\")\n      : this.quota.maxTeamsPerInstance;\n    if (count >= limit) {\n      throw new MetadataError(\n        \"team_limit_exceeded\",\n        `team limit ${limit} reached for instance ${this.instanceId} (current: ${count})`,\n      );\n    }\n  }\n\n  // ============================================================\n  // User（含 user_key 生成/刷新）\n  // ============================================================\n  async initAdminUser(input: InitAdminInput): Promise<InitAdminResult> {\n    if ((await this.store.countUsers()) > 0) {\n      throw new MetadataError(\"already_initialized\", \"system already has users; init-admin requires empty database\");\n    }\n    if ((await this.store.countSystemAdmins()) > 0) {\n      throw new MetadataError(\"already_initialized\", \"system_admin already exists\");\n    }\n\n    // 核心操作：创建 admin 用户","sourceCodeStart":350,"sourceCodeEnd":386,"githubUrl":"https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/3efcd317b84146d6a08518ac0f7ee7c8a8d200ec/MemoryCore/src/metadata/service/metadata-service.ts#L350-L386","documentation":"MetadataError code 'team_limit_exceeded' is thrown by assertTeamQuota when a createTeam call would push the instance past max_teams_per_instance (ConfigParams effective value, or quota.maxTeamsPerInstance fallback). Same quota-guard pattern as the user limit but for teams.","triggerScenarios":"Calling createTeam when store.countTeams() >= limit.","commonSituations":"Automated team provisioning loops creating more teams than configured; ConfigParams silently overriding the code default quota; long-lived instances filling their team allocation.","solutions":["Delete obsolete teams to free quota slots","Raise quota.max_teams_per_instance in ConfigParams or quota.maxTeamsPerInstance in the service config","Check current team count against the limit in the error message before scheduling team creation"],"exampleFix":"// before\nconst cfg = { quota: { maxTeamsPerInstance: 5 } };\nawait svc.createTeam({ name: 'team6' }); // throws team_limit_exceeded\n// after\nawait configParams.set('quota', 'max_teams_per_instance', '50');\nawait svc.createTeam({ name: 'team6' }); // ok","handlingStrategy":"try-catch","validationCode":"const count = await store.countTeams();\nconst limit = configParams\n  ? await configParams.getEffectiveInt('quota', 'max_teams_per_instance')\n  : quota.maxTeamsPerInstance;\nif (count >= limit) return; // skip creation","typeGuard":null,"tryCatchPattern":"try {\n  await svc.createTeam(input);\n} catch (e) {\n  if (e instanceof MetadataError && e.code === 'team_limit_exceeded') {\n    // log and stop provisioning\n  } else throw e;\n}","preventionTips":["Pre-check team count before automated provisioning loops","Raise max_teams_per_instance before planned scale-out","Prune inactive teams periodically"],"tags":["quota","teams","limit-exceeded"],"backgroundTag":"quota-limit-exceeded","analyzedSha":"3efcd317b84146d6a08518ac0f7ee7c8a8d200ec","analyzedAt":"2026-09-01T05:44:22.276Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}