{"record":{"id":"5643b86c7f3a237b","repo":"koala73/worldmonitor","slug":"recordpoolfilterstats-no-run-args-runid","errorCode":null,"errorMessage":"[_recordPoolFilterStats] no run ${args.runId}","messagePattern":"\\[_recordPoolFilterStats\\] no run (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"convex/broadcast/waveRuns.ts","lineNumber":466,"sourceCode":" * them for THIS run's pool selection remains useful even if the lease has\n * since rotated. Throws only if the run row itself is missing (a logic\n * bug in the caller, not a normal recovery scenario).\n */\nexport const _recordPoolFilterStats = internalMutation({\n  args: {\n    runId: v.string(),\n    excludeNonEnglish: v.boolean(),\n    eligiblePoolCount: v.number(),\n    excludedCount: v.number(),\n    excludedLocaleCounts: v.record(v.string(), v.number()),\n  },\n  handler: async (ctx, args) => {\n    const run = await ctx.db\n      .query(\"waveRuns\")\n      .withIndex(\"by_runId\", (q) => q.eq(\"runId\", args.runId))\n      .unique();\n    if (!run) {\n      throw new Error(`[_recordPoolFilterStats] no run ${args.runId}`);\n    }\n    await ctx.db.patch(run._id, {\n      excludeNonEnglish: args.excludeNonEnglish,\n      eligiblePoolCount: args.eligiblePoolCount,\n      excludedCount: args.excludedCount,\n      excludedLocaleCounts: args.excludedLocaleCounts,\n      updatedAt: Date.now(),\n    });\n    return { ok: true as const };\n  },\n});\n\n// ───────────────────────────────────────────────────────────────────────────\n// Pick phase\n// ───────────────────────────────────────────────────────────────────────────\n\n/**\n * Acquire the wave-run lease atomically. Refuses if:","sourceCodeStart":448,"sourceCodeEnd":484,"githubUrl":"https://github.com/koala73/worldmonitor/blob/ffec79ac339946fd2d24e85845da5755dcaa534b/convex/broadcast/waveRuns.ts#L448-L484","documentation":"Thrown by the _recordPoolFilterStats internal mutation when no waveRuns row matches the provided runId via the by_runId index with .unique(). Per its own docstring, this is NOT a normal recovery scenario — it indicates a logic bug in the caller (pickWaveAction), since the run row is created by _claimWaveRunLease before pool selection begins.","triggerScenarios":"pickWaveAction calls runMutation('_recordPoolFilterStats', {runId}) with a runId that was never claimed, was already discarded via discardWaveRun, or has a typo/transcription error. A race where the run was force-deleted between lease acquisition and stat recording.","commonSituations":"A developer modifies pickWaveAction and passes the wrong runId variable. The operator ran discardWaveRun while pickWaveAction was still executing. A test invokes _recordPoolFilterStats directly with a fabricated runId.","solutions":["Trace the runId in the calling action (pickWaveAction) back to the value returned by _claimWaveRunLease — they must be identical.","Check whether discardWaveRun or a manual DB delete removed the row mid-flight; if so, this throw is benign and the run should be treated as cancelled.","If calling from a test, first insert a waveRuns row with that runId, or call through _claimWaveRunLease to create one."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["In pickWaveAction, only call _recordPoolFilterStats with the runId returned by _claimWaveRunLease — never a derived or stale value.","Do not run discardWaveRun concurrently with an in-flight pickWaveAction.","In tests, insert a waveRuns row with the runId before calling _recordPoolFilterStats directly."],"tags":["convex","state-machine","wave-runs","logic-bug","internal-mutation"],"backgroundTag":null,"analyzedSha":"ffec79ac339946fd2d24e85845da5755dcaa534b","analyzedAt":"2026-08-12T11:24:56.012Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}