{"record":{"id":"0e0a34ed5e3355db","repo":"paperclipai/paperclip","slug":"label-must-be-between-1-and-maximum-characte","errorCode":null,"errorMessage":"${label} must be between 1 and ${maximum} characters","messagePattern":"(.+?) must be between 1 and (.+?) characters","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/src/services/chat-sdk-state.ts","lineNumber":74,"sourceCode":"interface StateEnvelope {\n  kind: StateKind;\n  schemaVersion: typeof STATE_SCHEMA_VERSION;\n  value: unknown;\n}\n\nexport interface PaperclipChatSdkStateOptions extends ChatSdkStateScope {\n  maxValueBytes?: number;\n  now?: () => Date;\n  persistence: ChatSdkStatePersistence;\n}\n\nfunction assertBoundedIdentifier(\n  label: string,\n  value: string,\n  maximum: number,\n): void {\n  if (!value || value.length > maximum) {\n    throw new Error(`${label} must be between 1 and ${maximum} characters`);\n  }\n}\n\nfunction assertTtl(label: string, ttlMs: number): void {\n  if (!(Number.isFinite(ttlMs) && ttlMs > 0)) {\n    throw new Error(`${label} must be a positive finite number`);\n  }\n}\n\nfunction storageKey(kind: StateKind, logicalKey: string): string {\n  assertBoundedIdentifier(\n    \"Chat SDK state key\",\n    logicalKey,\n    MAX_LOGICAL_KEY_LENGTH,\n  );\n  const digest = createHash(\"sha256\").update(logicalKey).digest(\"hex\");\n  return `${kind}:${digest}`;\n}","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/paperclipai/paperclip/blob/01ad8584922b5d85292b1723cae71fa0d9b07a19/server/src/services/chat-sdk-state.ts#L56-L92","documentation":"assertBoundedIdentifier validates that a Chat SDK state identifier (label naming the field) is a non-empty string no longer than the given maximum. storageKey and constructors call it for keys, endpoint ids, and similar names. Empty or oversized identifiers would break namespacing or persistence bounds, so the adapter rejects them eagerly.","triggerScenarios":"Passing an empty string (''), undefined-as-string, or an identifier exceeding the configured maximum (e.g. a very long threadId, agentId, or state key) into a Chat SDK state API, constructor, or storageKey().","commonSituations":"Building state keys by concatenating user/session ids without length limits; storing full URLs or JSON blobs as keys; config where a tenant/org id is missing and defaults to ''.","solutions":["Trim and validate the identifier length before calling the API","Truncate or hash long identifiers before using them as state keys","Check upstream data sources for empty values and default or reject early"],"exampleFix":"// before\nawait state.set(userId, value);\n// after\nif (!userId || userId.length > 128) throw new Error(`bad userId: ${userId?.length}`);\nawait state.set(userId, value);","handlingStrategy":"validation","validationCode":"function validId(v: unknown, max: number): v is string { return typeof v === 'string' && v.length >= 1 && v.length <= max; }","typeGuard":"function isBoundedString(v: unknown, max = 256): v is string { return typeof v === 'string' && v.length > 0 && v.length <= max; }","tryCatchPattern":"try { await state.set(key, value); } catch (err) { if (/must be between 1 and .* characters/.test((err as Error).message)) { /* fix key, retry */ } else throw err; }","preventionTips":["Validate identifiers at system boundaries (webhooks, APIs) before use","Hash or truncate long composite keys","Never allow empty-string defaults for id fields"],"tags":["validation","identifier","argument-error"],"backgroundTag":"invalid-identifier-format","analyzedSha":"01ad8584922b5d85292b1723cae71fa0d9b07a19","analyzedAt":"2026-09-10T03:14:50.855Z","contentChangedAt":"2026-09-10T03:14:50.855Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}