TencentCloud/TencentDB-Agent-Memory · error
Generation log object key exceeds COS limit
Error message
Generation log object key exceeds COS limit
What it means
buildGenerationLogIdentity builds a COS object key embedding layer, timestamp, anchor memory id and log id, then enforces a hard 850-byte UTF-8 limit on the key because object stores (Tencent COS) cap key length. This guard throws when the composed key would exceed that limit.
Source
Thrown at MemoryCore/src/core/memory-generation-log/store.ts:45
}
function reverseTimestamp(timestampMs: number): string {
return String(MAX_TS - timestampMs).padStart(13, "0");
}
export function buildGenerationLogIdentity(
layer: MemoryGenerationLayer,
finishedAtMs: number,
anchorMemoryId?: string,
status: MemoryGenerationStatus = "succeeded",
): { generationId: string; logId: string; key: string } {
const generationId = `mg_${randomUUID().replace(/-/g, "")}`;
const anchor = safeId(anchorMemoryId ?? "none");
const suffix = generationId.slice(3, 19);
const logId = `mgl_${layer}_${status}_${finishedAtMs}_${anchor}_${suffix}`;
const { date, hour } = utcParts(finishedAtMs);
const key = `${ROOT}/layer=${layer}/date=${date}/hour=${hour}/${reverseTimestamp(finishedAtMs)}__mid=${anchor}__lid=${logId}.json`;
if (Buffer.byteLength(key, "utf8") > 850) throw new Error("Generation log object key exceeds COS limit");
return { generationId, logId, key };
}
export function buildPromptGenerationRef(
resolved: ResolvedMemoryPrompt | undefined,
layer: MemoryGenerationLayer,
): MemoryGenerationLog["prompt"] {
if (!resolved) {
return { memory_prompt_id: `builtin:${layer}`, version: 1, source: "system", prompt_sha256: "" };
}
return {
memory_prompt_id: resolved.memory_prompt_id,
version: resolved.version,
source: resolved.source,
prompt_sha256: createHash("sha256").update(resolved.prompt).digest("hex"),
};
}
View on GitHub (pinned to 3efcd317b8)
Solutions
- Pass a short, bounded anchorMemoryId (a real memory id) — the code already runs it through safeId, so check what safeId permits and pre-truncate/hash long identifiers before calling
- Hash or truncate the anchor (e.g. first 32 chars of a sha256) at the call site if the id is genuinely long
- Investigate why an oversized id reached this code path; the limit triggers only with pathological input
Example fix
// before
const key = buildGenerationLogIdentity({ layer: "l2", status: "ok", anchorMemoryId: longCompositeId });
// after
const anchor = createHash("sha256").update(longCompositeId).digest("hex").slice(0, 32);
const key = buildGenerationLogIdentity({ layer: "l2", status: "ok", anchorMemoryId: anchor }); Defensive patterns
Strategy: validation
Validate before calling
function safeAnchorId(id, max = 64) {
return Buffer.byteLength(String(id), "utf8") <= max ? id : createHash("sha256").update(String(id)).digest("hex").slice(0, 32);
} Type guard
function isBoundedAnchorId(id) {
return typeof id === "string" && id.length > 0 && Buffer.byteLength(id, "utf8") <= 64;
} Try / catch
try {
const identity = buildGenerationLogIdentity(args);
} catch (e) {
if (e.message.includes("exceeds COS limit")) {
logger.error("anchorMemoryId too long; hash/truncate before calling");
}
throw e;
} Prevention
- Always pass short memory ids (not URLs, text, or composite strings) as anchorMemoryId
- Hash long identifiers before using them as anchors
- Keep call-site helpers that normalize anchor ids in one place
When it happens
Trigger: Calling buildGenerationLogIdentity (directly or via l2Identity, l3Identity, generationIdentity) where the resulting key string exceeds 850 bytes — practically caused by an extremely long anchorMemoryId, since layer/date/hour/logId segments are fixed-length.
Common situations: anchorMemoryId is not a short id but a long URL, full text, or concatenated identifiers passed in as the anchor; passing raw uuid-ish strings plus extra prefixes; upstream refactor started passing a composite anchor string.
Related errors
- Invalid generation log key
- Invalid generation log cursor
- Invalid scoped storage key: ${JSON.stringify(key)}
- Path traversal rejected in scoped storage key: ${key}
- Storage key must be relative, got absolute: ${key}
AI-assisted analysis of TencentCloud/TencentDB-Agent-Memory@3efcd317b8 (2026-09-01).
Data as JSON: /api/errors/0f6bc63ca7632a0f.
Report an issue: GitHub.