{"record":{"id":"3fca6b7aacfb69e4","repo":"koala73/worldmonitor","slug":"finalizewaverun-run-runid-missing-broadcasti","errorCode":null,"errorMessage":"[_finalizeWaveRun] run ${runId} missing broadcastId/segmentId","messagePattern":"\\[_finalizeWaveRun\\] run (.+?) missing broadcastId/segmentId","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"convex/broadcast/waveRuns.ts","lineNumber":1425,"sourceCode":"      .withIndex(\"by_runId\", (q) => q.eq(\"runId\", runId))\n      .unique();\n    if (!run) throw new Error(`[_finalizeWaveRun] no run ${runId}`);\n\n    // Status check FIRST — broadcastId presence is downstream of being in\n    // broadcast-created status. Checking presence before status would mask\n    // a wrong-status caller behind a misleading \"missing broadcastId\" error.\n    if (run.status === \"sent\") {\n      // Idempotent: a duplicate finalize on an already-sent run is a no-op,\n      // not an error. Don't re-advance the tier.\n      return { ok: true as const, alreadySent: true as const, advancedToTier: undefined };\n    }\n    if (run.status !== \"broadcast-created\") {\n      throw new Error(\n        `[_finalizeWaveRun] run ${runId} is ${run.status}, expected broadcast-created`,\n      );\n    }\n    if (!run.broadcastId || !run.segmentId) {\n      throw new Error(\n        `[_finalizeWaveRun] run ${runId} missing broadcastId/segmentId`,\n      );\n    }\n\n    const config = await ctx.db\n      .query(\"broadcastRampConfig\")\n      .withIndex(\"by_key\", (q) => q.eq(\"key\", \"current\"))\n      .unique();\n    if (!config) throw new Error(\"[_finalizeWaveRun] no broadcastRampConfig\");\n    if (config.pendingRunId !== runId) {\n      throw new Error(\n        `[_finalizeWaveRun] lost lease: expected ${runId}, found ${config.pendingRunId ?? \"<cleared>\"}. ` +\n        `Refusing to advance tier — operator force-released the lease, or another run took over.`,\n      );\n    }\n\n    const now = Date.now();\n    const nextTier = config.currentTier + 1;","sourceCodeStart":1407,"sourceCodeEnd":1443,"githubUrl":"https://github.com/koala73/worldmonitor/blob/eeab0a219fce0f02a00603b532dbae9041b934ac/convex/broadcast/waveRuns.ts#L1407-L1443","documentation":"State guard in _finalizeWaveRun: the run is in 'broadcast-created' status but its row lacks broadcastId and/or segmentId. Finalize must record what was sent, so it refuses to advance the tier with incomplete send metadata; reaching here means the status transitioned without the ids being persisted.","triggerScenarios":"Thrown at convex/broadcast/waveRuns.ts:1425 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Look up the broadcast and segment in the Resend dashboard and recover the run's missing ids via the documented recovery flow","Audit _markBroadcastCreated and _markPickComplete to ensure the ids are always persisted with the status transition"],"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"}