{"record":{"id":"413d163f66644ce9","repo":"calcom/cal.diy","slug":"booking-reference-not-found-413d16","errorCode":null,"errorMessage":"Booking reference not found","messagePattern":"Booking reference not found","errorType":"http","errorClass":"HttpError","httpStatus":200,"severity":"warning","filePath":"apps/web/lib/daily-webhook/getBookingReference.ts","lineNumber":20,"sourceCode":"import { HttpError } from \"@calcom/lib/http-error\";\nimport logger from \"@calcom/lib/logger\";\nimport { safeStringify } from \"@calcom/lib/safeStringify\";\n\nconst log = logger.getSubLogger({ prefix: [\"daily-video-webhook-handler\"] });\n\nexport const getBookingReference = async (roomName: string) => {\n  const bookingReference = await BookingReferenceRepository.findDailyVideoReferenceByRoomName({ roomName });\n\n  if (!bookingReference || !bookingReference.bookingId) {\n    log.error(\n      \"bookingReference not found error:\",\n      safeStringify({\n        bookingReference,\n        roomName,\n      })\n    );\n\n    throw new HttpError({ message: \"Booking reference not found\", statusCode: 200 });\n  }\n\n  return bookingReference;\n};\n","sourceCodeStart":2,"sourceCodeEnd":25,"githubUrl":"https://github.com/calcom/cal.diy/blob/176037d0afbe572f870a3c702985e7cd83fe6c0c/apps/web/lib/daily-webhook/getBookingReference.ts#L2-L25","documentation":"Thrown by getBookingReference in the daily-webhook handler (HttpError) when no BookingReference is found for the roomName, or the reference has no bookingId. Notably the statusCode is 200 (not 404) — this is deliberate so the webhook responds success and Daily.co does not keep retrying for orphaned rooms. A log.error records the missing reference and roomName.","triggerScenarios":"A Daily.co webhook arrives for a roomName with no corresponding booking reference: room created outside the booking flow, reference already deleted, test/synthetic webhook, room naming mismatch.","commonSituations":"Ad-hoc rooms created in Daily without a booking, webhook delivered for a cancelled booking whose reference was cleaned up, roomName format change breaking the lookup, environment room/test room.","solutions":["Wrap the webhook handler so a missing reference is logged/monitored but returns 2xx (the handler already does this via statusCode 200) — do not convert it to an error response.","Alert on the rate of these 200-but-logged events to detect room/reference mismatches.","Ensure booking references are only deleted after all expected webhooks have been processed, and that roomName generation stays stable."],"exampleFix":"// before\nconst ref = await getBookingReference(roomName); // throws but returns 200\n\n// after\nlet ref;\ntry {\n  ref = await getBookingReference(roomName);\n} catch (e) {\n  // statusCode 200 is intentional — Daily will not retry\n  metrics.increment('daily.orphan_room', { roomName });\n  return Response.json({ ok: true, ignored: 'no reference' });\n}\nprocessReference(ref);","handlingStrategy":"try-catch","validationCode":"// Resolve reference defensively in the webhook handler\nlet ref;\ntry {\n  ref = await getBookingReference(roomName);\n} catch (e) {\n  metrics.increment('daily.orphan_room', { roomName });\n  return Response.json({ ok: true, ignored: 'no reference' });\n}\nawait processReference(ref);","typeGuard":"function isBookingReference(v: unknown): v is { bookingId: number } {\n  return !!v && typeof v === 'object' &&\n    typeof (v as any).bookingId === 'number';\n}","tryCatchPattern":"try {\n  const ref = await getBookingReference(roomName);\n  await processReference(ref);\n} catch (e) {\n  // statusCode is 200 by design — Daily will not retry\n  if (e instanceof HttpError && e.statusCode === 200) {\n    metrics.increment('daily.missing_reference', { roomName });\n    return Response.json({ ok: true, ignored: 'no reference' });\n  }\n  throw e;\n}","preventionTips":["Treat the 200 'not found' as an expected, monitored no-op — never convert it to an error response.","Alert on orphan-room rate to catch roomName/reference mismatches early.","Keep roomName generation stable and avoid deleting booking references before webhooks settle."],"tags":["booking","daily","webhook","video","booking-reference","idempotency"],"backgroundTag":null,"analyzedSha":"176037d0afbe572f870a3c702985e7cd83fe6c0c","analyzedAt":"2026-08-12T19:12:41.464Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}