Skip to content

Conversation

@fank
Copy link
Member

@fank fank commented Feb 2, 2026

Summary

This is the root cause of empty positions in recordings.

When using the memory storage backend, entities were only stored in the backend's internal map but NOT in EntityCache. State handlers use EntityCache.GetSoldier() to look up entities, causing all state updates to fail with "soldier X not found in cache".

Root Cause Analysis

  1. handleNewSoldier calls m.backend.AddSoldier() → stores in memory backend's map
  2. handleSoldierState calls s.deps.EntityCache.GetSoldier() → EntityCache is empty!
  3. Returns error "soldier not found in cache"
  4. Error was silently discarded (fixed in PR fix(dispatcher): log errors from buffered handlers #55)

Fix

Now entities are always cached in EntityCache regardless of storage backend:

// Always cache for state handler lookups
m.deps.EntityCache.AddSoldier(obj)

Test plan

  • All tests pass
  • Deploy and verify positions are now recorded

When using the memory backend, entities were only stored in the
backend's internal map but not in EntityCache. State handlers use
EntityCache to look up entities, causing all state updates to fail
with "soldier X not found in cache".

Now entities are always cached regardless of storage backend.

Also introduces HandlerService interface for better testability.
@fank fank force-pushed the fix/cache-entities-with-memory-backend branch from 59dadcc to 02355eb Compare February 2, 2026 14:38
@github-actions
Copy link

github-actions bot commented Feb 2, 2026

Merging this branch will increase overall coverage

Impacted Packages Coverage Δ 🤖
github.com/OCAP2/extension/v5/internal/worker 1.77% (+0.84%) 👍

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/OCAP2/extension/v5/internal/worker/dispatch.go 2.02% (+1.10%) 2080 (+14) 42 (+23) 2038 (-9) 👍
github.com/OCAP2/extension/v5/internal/worker/worker.go 0.94% (ø) 635 6 629

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/OCAP2/extension/v5/internal/worker/dispatch_test.go

@fank fank merged commit 98f283d into main Feb 2, 2026
3 checks passed
@fank fank deleted the fix/cache-entities-with-memory-backend branch February 2, 2026 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants