tractor/ai/prompt-io/claude/20260406T172848Z_02b2ef1_pr...

1.6 KiB
Raw Blame History

Prompt

User asked to extend tests/test_resource_cache.py with a test that reproduces the edge case fixed in commit 02b2ef18 (per-key locking+user tracking in maybe_open_context()). The bug was originally triggered in pikers brokerd.kraken backend where the same acm_func was called with different kwargs, and the old global _Cache.users counter caused:

  • teardown skipped for one ctx_key bc another keys users kept the global count > 0
  • re-entry hitting assert not resources.get(ctx_key) during the teardown window

User requested a test that would fail under the old code and pass with the fix.

Response summary

Designed and implemented test_per_ctx_key_resource_lifecycle which verifies per-ctx_key resource isolation by:

  1. Holding resource 'a' open in a bg task
  2. Opening+closing resource 'b' (same acm_func, different kwargs) while 'a' is still alive
  3. Re-opening 'b' and asserting cache MISS — proving 'b' was torn down independently despite 'a' keeping its own user count > 0

With the old global counter, phase 3 would produce a stale cache HIT (leaked resource) or crash on the assert.

Also added a trivial acm_with_resource(resource_id) ACM helper at module level.

Files changed

  • tests/test_resource_cache.py — add acm_with_resource ACM + test_per_ctx_key_resource_lifecycle test fn

Human edits

None — committed as generated (pending user review).