@@ -20,6 +20,10 @@ import { createCache, createLRUMemoryStore, DefaultStatefulContext, Namespace }
2020import { singleton } from "~/utils/singleton" ;
2121import type { TaskMetadataCache , TaskMetadataEntry } from "~/services/taskMetadataCache.server" ;
2222import { taskMetadataCacheInstance } from "~/services/taskMetadataCacheInstance.server" ;
23+ import {
24+ recordTaskMetaResolve ,
25+ type TaskMetaResolveSource ,
26+ } from "~/services/taskMetadataCacheTelemetry.server" ;
2327
2428// LRU cache for environment queue sizes to reduce Redis calls
2529const queueSizeCache = singleton ( "queueSizeCache" , ( ) => {
@@ -266,7 +270,10 @@ export class DefaultQueueManager implements QueueManager {
266270 slug : string
267271 ) : Promise < TaskMetadataEntry | null > {
268272 const cached = await this . taskMetaCache . getByWorker ( workerId , slug ) ;
269- if ( cached ) return cached ;
273+ if ( cached ) {
274+ recordTaskMetaResolve ( "locked" , "cache" ) ;
275+ return cached ;
276+ }
270277
271278 // Cache miss. Read the row from the replica first; if the replica comes
272279 // back empty, re-check the writer before concluding the task is missing.
@@ -277,11 +284,13 @@ export class DefaultQueueManager implements QueueManager {
277284 // registered. The writer read only runs on this rare miss-then-empty path,
278285 // never on the hot path.
279286 let row = await this . findLockedTaskRow ( this . replicaPrisma , workerId , environmentId , slug ) ;
287+ let source : TaskMetaResolveSource = "replica" ;
280288
281289 if ( ! row && this . replicaPrisma !== this . prisma ) {
282290 row = await this . findLockedTaskRow ( this . prisma , workerId , environmentId , slug ) ;
283291
284292 if ( row ) {
293+ source = "writer" ;
285294 logger . warn ( "Locked task metadata missing on replica but found on writer" , {
286295 workerId,
287296 environmentId,
@@ -290,7 +299,12 @@ export class DefaultQueueManager implements QueueManager {
290299 }
291300 }
292301
293- if ( ! row ) return null ;
302+ if ( ! row ) {
303+ recordTaskMetaResolve ( "locked" , "miss" ) ;
304+ return null ;
305+ }
306+
307+ recordTaskMetaResolve ( "locked" , source ) ;
294308
295309 const entry : TaskMetadataEntry = {
296310 slug,
@@ -336,14 +350,20 @@ export class DefaultQueueManager implements QueueManager {
336350 slug : string
337351 ) : Promise < TaskMetadataEntry | null > {
338352 const cached = await this . taskMetaCache . getCurrent ( environment . id , slug ) ;
339- if ( cached ) return cached ;
353+ if ( cached ) {
354+ recordTaskMetaResolve ( "current" , "cache" ) ;
355+ return cached ;
356+ }
340357
341358 // Cold cache: discover the current worker for the env. Replica is fine —
342359 // the adjacent BackgroundWorkerTask lookup below uses `replicaPrisma` too
343360 // (replica lag for "just deployed" is bounded the same way for both
344361 // queries; reading from the writer here would only widen the window).
345362 const worker = await findCurrentWorkerFromEnvironment ( environment , this . replicaPrisma ) ;
346- if ( ! worker ) return null ;
363+ if ( ! worker ) {
364+ recordTaskMetaResolve ( "current" , "miss" ) ;
365+ return null ;
366+ }
347367
348368 const row = await this . replicaPrisma . backgroundWorkerTask . findFirst ( {
349369 where : { workerId : worker . id , runtimeEnvironmentId : environment . id , slug } ,
@@ -354,7 +374,12 @@ export class DefaultQueueManager implements QueueManager {
354374 } ,
355375 } ) ;
356376
357- if ( ! row ) return null ;
377+ if ( ! row ) {
378+ recordTaskMetaResolve ( "current" , "miss" ) ;
379+ return null ;
380+ }
381+
382+ recordTaskMetaResolve ( "current" , "replica" ) ;
358383
359384 const entry : TaskMetadataEntry = {
360385 slug,
0 commit comments