{"record":{"id":"d9a2e7363fb5d2f2","repo":"TencentCloud/TencentDB-Agent-Memory","slug":"clearmemorycontent-requires-non-empty-teamid-and-a","errorCode":null,"errorMessage":"clearMemoryContent requires non-empty teamId and agentId","messagePattern":"clearMemoryContent requires non-empty teamId and agentId","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"MemoryCore/src/core/store/sqlite.ts","lineNumber":2743,"sourceCode":"      }\n    } catch (err) {\n      this.logger?.warn(`[sqlite] deleteL0BySession failed: ${err instanceof Error ? err.message : String(err)}`);\n      return 0;\n    }\n  }\n\n  /**\n   * 清空某个 (team, agent) 下的全部 L0 + L1 内容（含向量 / FTS 附属行）。\n   * 不动entity_* / meta_* 资产表 —— 资产 ID 与绑定关系完整保留。\n   *\n   * sqlite store 不落L2/L3 profile 行（profiles 表只存在于 TCVDB），\n   * 所以 profilesDeleted 恒为 0，L2/L3 文件由调用方走 StorageAdapter 清理。\n   */\n  clearMemoryContent(filter: MemoryContentClearFilter): MemoryContentClearResult {\n    const teamId = (filter?.teamId ?? \"\").trim();\n    const agentId = (filter?.agentId ?? \"\").trim();\n    if (!teamId || !agentId) {\n      throw new Error(\"clearMemoryContent requires non-empty teamId and agentId\");\n    }\n    const userId = filter.userId?.trim() || undefined;\n    const empty: MemoryContentClearResult = { l0Deleted: 0, l1Deleted: 0, profilesDeleted: 0 };\n    if (this.degraded) return empty;\n\n    // 参数绑定，禁止拼接。userId 可选 → 动态追加一段条件 + 一个参数。\n    const where = `team_id = ? AND agent_id = ?${userId ? \" AND user_id = ?\" : \"\"}`;\n    const params: string[] = userId ? [teamId, agentId, userId] : [teamId, agentId];\n\n    try {\n      const l0Ids = (this.db.prepare(\n        `SELECT record_id FROM l0_conversations WHERE ${where}`,\n      ).all(...params) as Array<{ record_id: string }>).map((r) => r.record_id);\n      const l1Ids = (this.db.prepare(\n        `SELECT record_id FROM l1_records WHERE ${where}`,\n      ).all(...params) as Array<{ record_id: string }>).map((r) => r.record_id);\n\n      if (l0Ids.length === 0 && l1Ids.length === 0) return empty;","sourceCodeStart":2725,"sourceCodeEnd":2761,"githubUrl":"https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/3efcd317b84146d6a08518ac0f7ee7c8a8d200ec/MemoryCore/src/core/store/sqlite.ts#L2725-L2761","documentation":"clearMemoryContent deletes L0/L1 memory content scoped by teamId and agentId, so both are mandatory; missing either would produce an over-broad or meaningless delete. The method trims both values and throws when either is empty.","triggerScenarios":"Calling VectorStore.clearMemoryContent(filter) where filter.teamId or filter.agentId is undefined, null, empty, or whitespace-only.","commonSituations":"Building the filter object dynamically where agentId comes from an unset field, a user-scoped clear path that forgot teamId, or passing null instead of a populated filter.","solutions":["Populate both filter.teamId and filter.agentId with non-empty trimmed strings before calling","Optionally include filter.userId to narrow the clear scope","Handle the degenerate degraded-store case (returns zeros) separately from this validation error"],"exampleFix":"// before\nstore.clearMemoryContent({ teamId: team?.id });\n// after\nif (!team?.id || !agent.id) throw new Error('teamId and agentId required');\nstore.clearMemoryContent({ teamId: team.id, agentId: agent.id });","handlingStrategy":"validation","validationCode":"function assertClearFilter(f) {\n  const teamId = (f?.teamId ?? '').trim();\n  const agentId = (f?.agentId ?? '').trim();\n  if (!teamId || !agentId) throw new Error('teamId and agentId required');\n  return { teamId, agentId };\n}\nstore.clearMemoryContent(assertClearFilter(filter));","typeGuard":"function isMemContentFilter(f): f is MemoryContentClearFilter & { teamId: string; agentId: string } {\n  return typeof f?.teamId === 'string' && f.teamId.trim() !== '' && typeof f?.agentId === 'string' && f.agentId.trim() !== '';\n}","tryCatchPattern":"try {\n  store.clearMemoryContent(filter);\n} catch (e) {\n  if (String(e.message).includes('non-empty teamId and agentId')) {\n    throw new ConfigError('Memory clear aborted: teamId/agentId missing in filter');\n  }\n  throw e;\n}","preventionTips":["Validate the filter object at the API boundary before it reaches the store","Keep teamId/agentId on a typed context object so they cannot be undefined","Never call destructive clears from paths where scope fields may be partial"],"tags":["validation","sqlite","data-deletion","guard"],"backgroundTag":"empty-required-parameter","analyzedSha":"3efcd317b84146d6a08518ac0f7ee7c8a8d200ec","analyzedAt":"2026-09-01T05:44:22.276Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}