{"record":{"id":"0893360575495369","repo":"TencentCloud/TencentDB-Agent-Memory","slug":"internal-error","errorCode":"internal_error","errorMessage":"default user key not created","messagePattern":"default user key not created","errorType":"error_code","errorClass":"MetadataError","httpStatus":null,"severity":"error","filePath":"MemoryCore/src/metadata/service/metadata-service.ts","lineNumber":485,"sourceCode":"    const externalId = input.external_id?.trim();\n    if (externalId) {\n      return { ...input, auth_provider: authProvider, external_id: externalId };\n    }\n    const userId = input.user_id ?? generateId(ID_PREFIX.user);\n    return { ...input, auth_provider: authProvider, user_id: userId, external_id: userId };\n  }\n\n  private async createUserWithType(input: CreateUserInput, userType: UserType): Promise<CreateUserApiResult> {\n    const resolved = this.resolveCreateUserInput(input);\n    await this.assertUserQuota();\n    const user = await this.store.createUser({\n      ...resolved,\n      password: null,\n      user_type: userType,\n    });\n    const defaultKey = await this.store.getDefaultUserKey(user.user_id);\n    if (!defaultKey) {\n      throw new MetadataError(\"internal_error\", \"default user key not created\");\n    }\n    return {\n      user_id: user.user_id,\n      user_type: user.user_type,\n      created_at: user.created_at,\n      default_user_key: defaultKey.key_value,\n    };\n  }\n\n  async getUserForCaller(userId: string, ctx: V3AuthContext): Promise<UserPublic> {\n    const user = await this.getUserById(userId);\n    if (!user || !canViewUser(user, ctx)) {\n      throw new MetadataError(\"user_not_found\", `user not found: ${userId}`);\n    }\n    return toPublicUser(user, ctx);\n  }\n\n  async getUserById(userId: string): Promise<UserEntity | null> {","sourceCodeStart":467,"sourceCodeEnd":503,"githubUrl":"https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/3efcd317b84146d6a08518ac0f7ee7c8a8d200ec/MemoryCore/src/metadata/service/metadata-service.ts#L467-L503","documentation":"Internal invariant error (code 'internal_error'): after createUserWithType persisted a user, the default user key that the store should have created alongside it is missing (store.getDefaultUserKey returned null). This indicates the store failed to persist the default key despite creating the user, i.e. an unexpected broken state, not a caller mistake.","triggerScenarios":"Calling any user-creation path (createNormalUser, createNormalUserWithKey, createUserWithType, created callback) where the store creates the user row but the default user key record is absent when read back.","commonSituations":"Misconfigured or partially-implemented custom store backend that skips default-key insertion; transaction/partial-failure bugs in the storage layer; version mismatch between service and store implementations.","solutions":["Verify/fix the store implementation so user creation atomically inserts the default user key","Check for storage-layer errors swallowed earlier in the create path (logs, transactions)","Report as a bug if using the built-in store; the caller cannot cause this via input"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const result = await svc.createNormalUser(input);\n} catch (e) {\n  if (e instanceof MetadataError && e.code === 'internal_error') {\n    // investigate store: default key missing after user insert\n  } else throw e;\n}","preventionTips":["Use the built-in store implementation or verify custom stores insert the default key with the user","Run integration tests that create a user and assert getDefaultUserKey returns a key","Keep service and store package versions compatible"],"tags":["internal","invariant","user-key","storage"],"backgroundTag":"internal-invariant-violated","analyzedSha":"3efcd317b84146d6a08518ac0f7ee7c8a8d200ec","analyzedAt":"2026-09-01T05:44:22.276Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}