{"record":{"id":"055a56716a582bc2","repo":"Hmbown/CodeWhale","slug":"import-exceeds-the-maxevents-tolocalestring-event-limit","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":"crates/tui/src/tui/pet_watch/pet-native.js","lineNumber":2067,"sourceCode":"    }\n    const events = [];\n    const pending = new Map();\n    let seq = 0;\n    const originWall = orderOnly ? undefined : sourceEntries.map(e => parseTime(e.created_at)).find((n) => n !== undefined);\n    const agentId = 'parent';\n    const model = str(metadata.model);\n    const provider = str(metadata.model_provider);\n    const when = (entry, fallback) => {\n        if (orderOnly || originWall === undefined)\n            return { start: fallback, open: false };\n        const t = parseTime(entry.created_at);\n        if (t === undefined)\n            return { start: fallback, open: true };\n        return { start: t - originWall, open: false };\n    };\n    for (const entry of sourceEntries) {\n        if (events.length >= maxEvents)\n            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 = Array.isArray(message.content) ? message.content.map(obj) : [];\n        if (!blocks.length) {\n            const text = str(entry.text) ?? str(message.text);\n            if (text)\n                blocks.push({ type: role === 'user' ? 'text' : 'text', text });\n        }\n        if (!blocks.length)\n            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') {","sourceCodeStart":2049,"sourceCodeEnd":2085,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tui/pet_watch/pet-native.js#L2049-L2085","documentation":"Thrown during session import when the number of events derived from the session's journal entries/messages would exceed maxEvents, the configured cap for a single import. The check runs before converting each entry, aborting the whole import at the first entry that would overflow the limit. This protects the pet watch renderer from unbounded memory and event count.","triggerScenarios":"Importing a very large or long-running Codewhale session whose journal entries plus messages convert to more than maxEvents timeline events; the loop hits the cap while iterating sourceEntries.","commonSituations":"Importing weeks-old sessions with tens of thousands of entries; lowering maxEvents via configuration and then importing an old session; re-importing a session after repeated appends grow it past the limit.","solutions":["Split or truncate the session export so each import stays under the event limit.","Raise the maxEvents configuration if memory allows, then retry the import.","Import a narrower time range or prune the journal before export.","Pre-filter the session JSON to remove noise entries (e.g. deltas) before importing."],"exampleFix":"// before\nimportSession(hugeSession, { maxEvents: 1000 });\n// after\nimportSession(hugeSession, { maxEvents: 50000 });","handlingStrategy":"validation","validationCode":"if (session.journal.entries.length > maxEvents) throw new Error('Session too large to import under current limit');","typeGuard":null,"tryCatchPattern":"try { importSession(s, { maxEvents }); } catch (e) { if (e.message.startsWith('Import exceeds the')) retryWithHigherLimitOrChunk(s); else throw e; }","preventionTips":["Size-check the export before importing; estimate one event per entry.","Keep maxEvents generous (or Infinity where safe) for large sessions.","Chunk very old sessions into multiple imports.","Watch the event count while appending to long-lived sessions."],"tags":["import","limit","events"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-22T11:17:16.035Z"}