{"record":{"id":"f9fad5ed9c5b49da","repo":"koala73/worldmonitor","slug":"persistpickedbatch-chunk-too-large-contacts","errorCode":null,"errorMessage":"[_persistPickedBatch] chunk too large: ${contacts.length} > ${PERSIST_CHUNK_SIZE}","messagePattern":"\\[_persistPickedBatch\\] chunk too large: (.+?) > (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"convex/broadcast/waveRuns.ts","lineNumber":580,"sourceCode":"      createdAt: now,\n      updatedAt: now,\n    });\n    return { ok: true, runId: args.runId };\n  },\n});\n\n/**\n * Insert a chunk of picked-contact rows. Called repeatedly from\n * `pickWaveAction` to stay under Convex per-mutation write limits.\n */\nexport const _persistPickedBatch = internalMutation({\n  args: {\n    runId: v.string(),\n    contacts: v.array(v.string()), // normalizedEmails\n  },\n  handler: async (ctx, { runId, contacts }) => {\n    if (contacts.length > PERSIST_CHUNK_SIZE) {\n      throw new Error(\n        `[_persistPickedBatch] chunk too large: ${contacts.length} > ${PERSIST_CHUNK_SIZE}`,\n      );\n    }\n    const now = Date.now();\n    for (const email of contacts) {\n      await ctx.db.insert(\"wavePickedContacts\", {\n        runId,\n        normalizedEmail: email,\n        status: \"pending\",\n      });\n    }\n    // Bump updatedAt so the in-flight guard's lastActivityAt fallback sees fresh activity.\n    const run = await ctx.db\n      .query(\"waveRuns\")\n      .withIndex(\"by_runId\", (q) => q.eq(\"runId\", runId))\n      .unique();\n    if (run) await ctx.db.patch(run._id, { updatedAt: now });\n    return { inserted: contacts.length };","sourceCodeStart":562,"sourceCodeEnd":598,"githubUrl":"https://github.com/koala73/worldmonitor/blob/7d06c8633d256c18e38133030bc3613976a96ec9/convex/broadcast/waveRuns.ts#L562-L598","documentation":"Chunk-size guard in _persistPickedBatch: the caller passed more picked contacts than PERSIST_CHUNK_SIZE in one mutation. Chunking exists to stay under Convex per-mutation write limits; an oversized batch would exceed them, so it is rejected before any insert.","triggerScenarios":"Thrown at convex/broadcast/waveRuns.ts:564 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Split the batch into chunks of at most PERSIST_CHUNK_SIZE contacts before calling the mutation","Fix the batching loop in pickWaveAction so it never assembles an oversized chunk"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7d06c8633d256c18e38133030bc3613976a96ec9","analyzedAt":"2026-08-21T16:51:25.751Z","contentChangedAt":"2026-08-21T16:51:25.751Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}