{"record":{"id":"fc16f720a7c6372a","repo":"Hmbown/CodeWhale","slug":"import-exceeds-the-maxevents-tolocalestring-event-limit-fc16f7","errorCode":null,"errorMessage":"Import exceeds the ${maxEvents.toLocaleString()} event limit.","messagePattern":"Import exceeds the (.+?) event limit\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"pet/src/core/codewhale.ts","lineNumber":184,"sourceCode":"  }\n\n  const events: WhaleEvent[] = [];\n  const pending = new Map<string, number>();\n  let seq = 0;\n  const originWall = orderOnly ? undefined : sourceEntries.map(e => parseTime(e.created_at)).find((n): n is number => n !== undefined);\n  const agentId = 'parent';\n  const model = str(metadata.model);\n  const provider = str(metadata.model_provider);\n\n  const when = (entry: Obj, fallback: number): { start: number; open: boolean } => {\n    if (orderOnly || originWall === undefined) return { start: fallback, open: false };\n    const t = parseTime(entry.created_at);\n    if (t === undefined) return { start: fallback, open: true };\n    return { start: t - originWall, open: false };\n  };\n\n  for (const entry of sourceEntries) {\n    if (events.length >= maxEvents) throw new Error(`Import exceeds the ${maxEvents.toLocaleString()} event limit.`);\n    const entryId = str(entry.id) ?? `${sessionId}/entry/${seq}`;\n    const message = obj(entry.message ?? (entry.kind === 'message' ? entry : {}));\n    const role = str(message.role) ?? (str(entry.kind) === 'user' ? 'user' : str(entry.kind) === 'assistant' ? 'assistant' : undefined);\n    const blocks: Obj[] = Array.isArray(message.content) ? message.content.map(obj) : [];\n    if (!blocks.length) {\n      const text = str(entry.text) ?? str(message.text);\n      if (text) blocks.push({ type: role === 'user' ? 'text' : 'text', text });\n    }\n    if (!blocks.length) continue;\n    const parentEventId = events.length ? events[events.length - 1]!.id : undefined;\n    for (const block of blocks) {\n      const t = when(entry, seq);\n      const idBase = `${entryId}/${seq}`;\n      const type = str(block.type) ?? 'text';\n      const raw = pointer('codewhale.session/v1', { sessionId, entryId, seq, blockType: type, toolUseId: block.id ?? block.tool_use_id });\n      if (type === 'tool_use' || type === 'server_tool_use') {\n        const tool = str(block.name) ?? 'tool';\n        const callId = str(block.id) ?? idBase;","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/pet/src/core/codewhale.ts#L166-L202","documentation":"During fromCodewhaleSession() entry conversion, each source entry emits one or more events; once the events array reaches maxEvents the import aborts with this error rather than silently truncating the session trace. The limit protects the analyzer from unbounded memory use on very large sessions.","triggerScenarios":"Importing a session document whose journal/messages expand to more than maxEvents trace events — e.g. a long-running session with thousands of tool calls, message blocks, and deltas, or calling trace() with a lowered maxEvents option on a moderately large session.","commonSituations":"Analyzing a multi-day session export, batching many sessions through one importer configured with a small cap, or a version change where entries now fan out into more events per journal entry.","solutions":["Increase the maxEvents option passed to trace()/fromCodewhaleSession for large sessions (mind memory cost).","Split or truncate the session export so each import stays within the limit.","Pre-filter journal entries (e.g. drop delta-heavy items) before import to reduce emitted event count.","Check whether a caller is passing an accidentally small maxEvents (e.g. 0 or a test value)."],"exampleFix":"// before\nconst trace = trace(bigSession); // default maxEvents\n// after\nconst trace = trace(bigSession, { maxEvents: 1_000_000 });","handlingStrategy":"try-catch","validationCode":"// rough pre-check: entries fan out to >=1 event each\nif (sourceEntries.length * 4 > maxEvents) console.warn(`${file} may exceed maxEvents=${maxEvents}`);","typeGuard":null,"tryCatchPattern":"try { trace = fromCodewhaleSession(doc, file, { maxEvents }); }\ncatch (e) {\n  const m = e.message.match(/exceeds the ([\\d,]+) event limit/);\n  if (m) { maxEvents = parseInt(m[1].replace(/,/g, ''), 10) * 2; return retry(); }\n  throw e;\n}","preventionTips":["Size maxEvents to the largest session you expect, with headroom.","Monitor event counts per import and alert before the cap.","Truncate or split very long sessions at export time."],"tags":["import","limit-exceeded","session"],"backgroundTag":"payload-too-large","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-22T11:17:16.035Z"}