{"record":{"id":"7e143a0fd0a6f71d","repo":"TencentCloud/TencentDB-Agent-Memory","slug":"invalid-param-scope","errorCode":"invalid_param_scope","errorMessage":"module '${module}' param '${paramName}' is global-only, cannot set for user scope","messagePattern":"module '(.+?)' param '(.+?)' is global-only, cannot set for user scope","errorType":"error_code","errorClass":"MetadataError","httpStatus":null,"severity":"error","filePath":"MemoryCore/src/metadata/service/config-param-service.ts","lineNumber":159,"sourceCode":"    }\n    return num;\n  }\n\n  // ── 用户写入 ──\n\n  async setUserParam(userId: string, module: string, paramName: string, value: string): Promise<ConfigParamEntity> {\n    const moduleDef = getModuleDef(this.registry, module);\n    if (!moduleDef) {\n      throw new MetadataError(\"unknown_module\", `unknown module: ${module}`);\n    }\n\n    const paramDef = getParamDef(this.registry, module, paramName);\n    if (!paramDef) {\n      throw new MetadataError(\"invalid_param_key\", `unknown param: ${module}.${paramName}`);\n    }\n\n    if (!isUserWritable(this.registry, module, paramName)) {\n      throw new MetadataError(\"invalid_param_scope\", `module '${module}' param '${paramName}' is global-only, cannot set for user scope`);\n    }\n\n    this.validateParamValue(moduleDef, paramDef, value);\n\n    const result = await this.store.upsertConfigParam({\n      scope: \"user\",\n      user_id: userId,\n      module,\n      param_name: paramName,\n      param_value: value,\n      description: paramDef.description,\n    });\n\n    this.invalidateUserCache(userId, module);\n    return result;\n  }\n\n  // ── 配额 ──","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/3efcd317b84146d6a08518ac0f7ee7c8a8d200ec/MemoryCore/src/metadata/service/config-param-service.ts#L141-L177","documentation":"setUserParam checks isUserWritable to enforce scope rules. If the parameter is defined but does not include 'user' in its allowed_scopes (i.e. it is global-only), the service refuses user-scope writes with invalid_param_scope. Global parameters can only be changed at global scope.","triggerScenarios":"setUserParam(userId, module, paramName, value) where the ParamDef's allowed_scopes does not include 'user' — the param is meant to be configured only globally.","commonSituations":"Attempting per-user overrides of a system-wide setting (e.g. a global feature flag or quota), or copy-pasting a per-user config call for a param that is global-only by design.","solutions":["Set the parameter at global scope instead of user scope (use the global config update path).","Pick a different parameter that actually allows user scope (check allowed_scopes in the ParamDef).","If user-level overrides are genuinely needed, change the param definition to add 'user' to allowed_scopes in the registry.","Guard call sites: check isUserWritable(registry, module, paramName) before calling setUserParam."],"exampleFix":"// before\nawait svc.setUserParam(userId, \"system\", \"globalFlag\", \"1\"); // global-only\n// after — set globally instead\nawait svc.setGlobalParam(\"system\", \"globalFlag\", \"1\");","handlingStrategy":"validation","validationCode":"import { isUserWritable } from \"./registry\";\nif (!isUserWritable(registry, module, paramName)) {\n  throw new Error(`${module}.${paramName} is global-only; set it at global scope`);\n}\nawait svc.setUserParam(userId, module, paramName, value);","typeGuard":null,"tryCatchPattern":"try {\n  await svc.setUserParam(userId, module, paramName, value);\n} catch (e) {\n  if (e instanceof MetadataError && e.code === \"invalid_param_scope\") {\n    await svc.setGlobalParam(module, paramName, value); // fall back to global scope\n    return;\n  }\n  throw e;\n}","preventionTips":["Check allowed_scopes on the ParamDef before offering per-user editing in UIs.","Route global-only params to the global config path by design.","Re-verify scope flags after upgrading the registry definitions.","Hide global-only params from per-user settings screens."],"tags":["config","scope","authorization"],"backgroundTag":"invalid-param-scope","analyzedSha":"3efcd317b84146d6a08518ac0f7ee7c8a8d200ec","analyzedAt":"2026-09-01T05:44:22.276Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}