{"record":{"id":"2b34fd774d590c0b","repo":"koala73/worldmonitor","slug":"markbroadcastcreated-no-run-runid","errorCode":null,"errorMessage":"[_markBroadcastCreated] no run ${runId}","messagePattern":"\\[_markBroadcastCreated\\] no run (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"convex/broadcast/waveRuns.ts","lineNumber":1279,"sourceCode":" *\n * Without these guards, two concurrent finalizeWaveAction invocations\n * (e.g. operator-triggered resumeFinalizeWaveRun while the original is\n * mid-flight on a slow Resend response) could both call\n * createProLaunchBroadcast, both call _markBroadcastCreated, and overwrite\n * each other's broadcastId — leading to one of the two created Resend\n * broadcasts being orphaned + duplicate sends downstream.\n */\nexport const _markBroadcastCreated = internalMutation({\n  args: {\n    runId: v.string(),\n    broadcastId: v.string(),\n  },\n  handler: async (ctx, { runId, broadcastId }) => {\n    const run = await ctx.db\n      .query(\"waveRuns\")\n      .withIndex(\"by_runId\", (q) => q.eq(\"runId\", runId))\n      .unique();\n    if (!run) throw new Error(`[_markBroadcastCreated] no run ${runId}`);\n\n    // Idempotent: if already broadcast-created with the SAME broadcastId,\n    // treat as no-op success. Different broadcastId = a duplicate Resend\n    // broadcast was created — surface as failure so the caller can decide\n    // (typically: log, don't proceed to send the new duplicate).\n    if (run.status === \"broadcast-created\") {\n      if (run.broadcastId === broadcastId) {\n        return { ok: true as const, alreadyMarked: true as const };\n      }\n      return {\n        ok: false as const,\n        reason: \"duplicate-broadcast-detected\" as const,\n        existing: run.broadcastId,\n      };\n    }\n    if (run.status !== \"pushing\") {\n      return { ok: false as const, reason: `wrong-status-${run.status}` as const };\n    }","sourceCodeStart":1261,"sourceCodeEnd":1297,"githubUrl":"https://github.com/koala73/worldmonitor/blob/eeab0a219fce0f02a00603b532dbae9041b934ac/convex/broadcast/waveRuns.ts#L1261-L1297","documentation":"Internal invariant guard in _markBroadcastCreated: no waveRuns row exists for the supplied runId. The broadcastId cannot be recorded because the run record is missing — a caller logic bug, or the run row was deleted while finalize was mid-flight.","triggerScenarios":"Thrown at convex/broadcast/waveRuns.ts:1279 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the runId matches the one claimed at pick time","Investigate deletion of the waveRuns row (operator purge, retention job) and reconcile the orphaned Resend broadcast manually"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"eeab0a219fce0f02a00603b532dbae9041b934ac","analyzedAt":"2026-08-21T16:51:25.751Z","contentChangedAt":"2026-08-21T16:51:25.751Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}