{"record":{"id":"63ccf85bf928c9bc","repo":"Hmbown/CodeWhale","slug":"import-exceeds-the-maxevents-tolocalestring-event-limit-pet","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/ios/Resources/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/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/pet/ios/Resources/pet-native.js#L2049-L2085","documentation":"This error is thrown by the Codewhale session importer when the number of events parsed from a session snapshot exceeds maxEvents, the configured cap on import size. The library throws early (before creating each event) to avoid unbounded memory growth during import. It is a hard guard, not a soft warning: the whole import aborts.","triggerScenarios":"Calling the Codewhale session import (the function containing the sourceEntries loop at pet/ios/Resources/pet-native.js:2067) with a session snapshot whose entry count meets or exceeds the maxEvents limit. Each entry that would push events.length to maxEvents triggers the throw.","commonSituations":"Importing a very long Codewhale session (hours-long agent runs with thousands of turns); re-importing an already-grown session; passing a too-small maxEvents option; accidentally importing a concatenated export containing several sessions.","solutions":["Increase the maxEvents option passed to the import call.","Split the session export into smaller chunks and import them separately.","Reduce imported content, e.g. filter out non-message entries before import.","Verify you are importing a single session, not a multi-session concatenation."],"exampleFix":"// before\nimportCodewhaleSession(snapshot); // default maxEvents\n// after\nimportCodewhaleSession(snapshot, { maxEvents: 100_000 });","handlingStrategy":"validation","validationCode":"const events = collectEvents(snapshot);\nif (events.length >= maxEvents) throw new Error(`Snapshot has ${events.length} events, over limit ${maxEvents}`);","typeGuard":"function isWithinEventLimit(count, maxEvents) {\n  return Number.isInteger(maxEvents) && count < maxEvents;\n}","tryCatchPattern":"try {\n  importCodewhaleSession(snapshot, { maxEvents });\n} catch (e) {\n  if (String(e.message).includes('event limit')) {\n    console.error(`Session too large: raise maxEvents or split the export (${e.message})`);\n  } else throw e;\n}","preventionTips":["Count entries in the snapshot before importing and size maxEvents accordingly.","Set maxEvents generously (or explicitly) rather than relying on defaults.","Split very long session exports at the source.","Never concatenate multiple sessions into one import."],"tags":["import","limit","events"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-22T16:17:23.217Z"}