{"record":{"id":"d49f24b4560e3590","repo":"paperclipai/paperclip","slug":"chat-sdk-kind-state-exceeds-the-this-maxvalue","errorCode":null,"errorMessage":"Chat SDK ${kind} state exceeds the ${this.maxValueBytes}-byte limit","messagePattern":"Chat SDK (.+?) state exceeds the (.+?)-byte limit","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/src/services/chat-sdk-state.ts","lineNumber":506,"sourceCode":"    return new Date(this.now().getTime() + ttlMs);\n  }\n\n  private envelope(kind: StateKind, value: unknown): StateEnvelope {\n    const envelope: StateEnvelope = {\n      kind,\n      schemaVersion: STATE_SCHEMA_VERSION,\n      value,\n    };\n    let serialized: string;\n    try {\n      serialized = JSON.stringify(envelope);\n    } catch (error) {\n      throw new Error(`Chat SDK ${kind} state is not JSON-serializable`, {\n        cause: error,\n      });\n    }\n    if (Buffer.byteLength(serialized) > this.maxValueBytes) {\n      throw new Error(\n        `Chat SDK ${kind} state exceeds the ${this.maxValueBytes}-byte limit`,\n      );\n    }\n    return envelope;\n  }\n\n  private async compareAndSet(\n    key: string,\n    expectedVersion: number | null,\n    kind: StateKind,\n    value: unknown,\n    expiresAt: Date | null,\n  ): Promise<boolean> {\n    return this.persistence.compareAndSet({\n      ...this.scope,\n      key,\n      expectedVersion,\n      expiresAt,","sourceCodeStart":488,"sourceCodeEnd":524,"githubUrl":"https://github.com/paperclipai/paperclip/blob/01ad8584922b5d85292b1723cae71fa0d9b07a19/server/src/services/chat-sdk-state.ts#L488-L524","documentation":"After serializing the state envelope, the adapter enforces a per-value byte budget (this.maxValueBytes). Values whose serialized JSON exceeds the limit are rejected to keep persistence records bounded. The message includes the kind and the configured byte limit.","triggerScenarios":"Storing very large payloads: long conversation transcripts, big arrays, embedded base64 blobs, or accumulated list/queue data whose JSON exceeds maxValueBytes.","commonSituations":"A transcript growing unbounded over a long session; embedding file contents or screenshots as base64 in state; a lowered maxValueBytes config after upgrading; many small writes that compound into one large record.","solutions":["Reduce payload size before storing: truncate, summarize, or store an external reference/pointer instead of the full data","Move large blobs to object storage and keep only a key in state","Raise maxValueBytes if the limit is genuinely too small (and verify backend record limits)"],"exampleFix":"// before\nawait state.set(kind, key, { transcript: allMessages }); // too large\n// after\nconst recent = allMessages.slice(-50);\nawait state.set(kind, key, { transcript: recent, truncated: allMessages.length - recent.length });","handlingStrategy":"validation","validationCode":"if (Buffer.byteLength(JSON.stringify(envelope)) > maxValueBytes) throw new Error('state too large before set');","typeGuard":null,"tryCatchPattern":"try { await state.set(kind, key, value); } catch (err) { if (/exceeds the .*-byte limit/.test((err as Error).message)) { value = truncate(value); return state.set(kind, key, value); } throw err; }","preventionTips":["Bound transcript/list growth before writing","Store large blobs externally, keep references in state","Pre-check serialized size for payloads near the limit"],"tags":["size-limit","serialization","payload"],"backgroundTag":"file-size-limit-exceeded","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"}