{"record":{"id":"dc1e90e3d7732b91","repo":"koala73/worldmonitor","slug":"finalizewaverun-no-run-runid","errorCode":null,"errorMessage":"[_finalizeWaveRun] no run ${runId}","messagePattern":"\\[_finalizeWaveRun\\] no run (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"convex/broadcast/waveRuns.ts","lineNumber":1409,"sourceCode":" *   - waveRuns.status MUST be 'broadcast-created' (or 'sent' for idempotency\n *     on a duplicate finalize — returns no-op success without re-advancing\n *     the tier)\n *   - broadcastRampConfig.pendingRunId MUST === runId\n *\n * Without these, two concurrent finalizes could both advance currentTier\n * (skipping a wave's worth of progress) AND both clear the lease.\n */\nexport const _finalizeWaveRun = internalMutation({\n  args: {\n    runId: v.string(),\n    sentAt: v.number(),\n  },\n  handler: async (ctx, { runId, sentAt }) => {\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(`[_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      );","sourceCodeStart":1391,"sourceCodeEnd":1427,"githubUrl":"https://github.com/koala73/worldmonitor/blob/eeab0a219fce0f02a00603b532dbae9041b934ac/convex/broadcast/waveRuns.ts#L1391-L1427","documentation":"Internal invariant guard in _finalizeWaveRun: no waveRuns row exists for the supplied runId. The tier advance and lease clear cannot proceed because the run record is missing — a caller logic bug, or the row was deleted mid-finalize.","triggerScenarios":"Thrown at convex/broadcast/waveRuns.ts:1409 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the runId passed by finalizeWaveAction matches the claimed run","Manually reconcile ramp tier state (the wave was sent; check Resend) before restarting the ramp"],"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"}