bugger.
All challenges/Pythonhardthe-lock-that-blocks-every-instance-v1
THE INVESTIGATION

The lock that blocks every instance

Unrelated objects wait for each other while each object still appears to cache correctly.

ConcurrencyCachingLifecycle

What’s going wrong

A cached asynchronous property uses one descriptor-wide queue. Independent instances are serialized, and a timing change can turn a later retry into a join of the wrong in-flight generation.

Input is an array of requests in nondecreasing integer at order. Each has instance (string), duration (positive integer), value (any JSON value), and ok (boolean). At time at, first settle all computations finishing at or before at. Success caches the first result for that instance permanently; failure caches nothing. A request for an uncached instance joins its pending computation or starts one immediately, completing at at+duration. A cached read responds immediately at the request time. Requests at the same timestamp are processed in array order. Print {responses:[{at,ok,value},...],computations}; failed values are null. Independent instances must overlap. Do not add real threads, sleeps or timers.

Expected behavior

Share work only within one instance, permit unrelated computations to overlap, retain falsey cached values, and allow retry after failure.

Reproduction

01 Independent instances overlap
[{"at":0,"instance":"a","duration":5,"value":"A","ok":true},{"at":0,"instance":"b","duration":2,"value":"B","ok":true}]
{"responses":[{"at":5,"ok":true,"value":"A"},{"at":2,"ok":true,"value":"B"}],"computations":2}
02 One instance shares pending result
[{"at":0,"instance":"a","duration":4,"value":"first","ok":true},{"at":1,"instance":"a","duration":9,"value":"ignored","ok":true}]
{"responses":[{"at":4,"ok":true,"value":"first"},{"at":4,"ok":true,"value":"first"}],"computations":1}
03 Cached read is immediate
[{"at":0,"instance":"a","duration":2,"value":0,"ok":true},{"at":3,"instance":"a","duration":8,"value":9,"ok":true}]
{"responses":[{"at":2,"ok":true,"value":0},{"at":3,"ok":true,"value":0}],"computations":1}

Before you begin

  • Event timelines
  • Caching
  • In-flight operations
  • Ownership

Need a nudge?

Reveal one investigation hint at a time. Try each clue before opening the next.

    The bug is intentional. Run the starter code to see it fail, then work toward a fix. Difficulty is provisional.
    Read-only preview
    Ready when you are
    Every fix starts with a failing test.

    Read the report, then sign in to start your investigation.