TencentCloud/TencentDB-Agent-Memory · error · MetadataError
internal_error
internal_error
Error message
default user key not created
What it means
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.
Source
Thrown at MemoryCore/src/metadata/service/metadata-service.ts:485
const externalId = input.external_id?.trim();
if (externalId) {
return { ...input, auth_provider: authProvider, external_id: externalId };
}
const userId = input.user_id ?? generateId(ID_PREFIX.user);
return { ...input, auth_provider: authProvider, user_id: userId, external_id: userId };
}
private async createUserWithType(input: CreateUserInput, userType: UserType): Promise<CreateUserApiResult> {
const resolved = this.resolveCreateUserInput(input);
await this.assertUserQuota();
const user = await this.store.createUser({
...resolved,
password: null,
user_type: userType,
});
const defaultKey = await this.store.getDefaultUserKey(user.user_id);
if (!defaultKey) {
throw new MetadataError("internal_error", "default user key not created");
}
return {
user_id: user.user_id,
user_type: user.user_type,
created_at: user.created_at,
default_user_key: defaultKey.key_value,
};
}
async getUserForCaller(userId: string, ctx: V3AuthContext): Promise<UserPublic> {
const user = await this.getUserById(userId);
if (!user || !canViewUser(user, ctx)) {
throw new MetadataError("user_not_found", `user not found: ${userId}`);
}
return toPublicUser(user, ctx);
}
async getUserById(userId: string): Promise<UserEntity | null> {View on GitHub (pinned to 3efcd317b8)
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
Defensive patterns
Strategy: try-catch
Try / catch
try {
const result = await svc.createNormalUser(input);
} catch (e) {
if (e instanceof MetadataError && e.code === 'internal_error') {
// investigate store: default key missing after user insert
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Generation log object key exceeds COS limit
- Invalid generation log key
- Invalid generation log cursor
- Invalid scoped storage key: ${JSON.stringify(key)}
- Path traversal rejected in scoped storage key: ${key}
AI-assisted analysis of TencentCloud/TencentDB-Agent-Memory@3efcd317b8 (2026-09-01).
Data as JSON: /api/errors/0893360575495369.
Report an issue: GitHub.