Fix/episode cache bytes metric wiring#258
Open
huynna12 wants to merge 2 commits into
Open
Conversation
…es gauge Pi05DecomposedInference is the only production call site that constructs EpisodeCache (cache_level="episode"), but it never passed embodiment/model_id. EpisodeCache._emit_bytes_metric() is a no-op unless both are set, so tether_episode_cache_bytes_total (added in FastCrest#106, closes the tracking half of FastCrest#103) never actually emitted once episode mode was enabled. Reuse cuda_graphs_embodiment/cuda_graphs_model_id, already threaded into this same constructor for CUDA graph metrics, as the label values. Adds tests/test_episode_cache_production_wiring.py to cover the construction path end-to-end (mocked ORT sessions), which previously had no coverage.
insert() never checked whether (episode_id, lang_hash) already existed
in the cache. Re-inserting an existing key would:
- leak _total_bytes (old entry's bytes never subtracted before the
new entry's bytes were added), permanently inflating the
tether_episode_cache_bytes_total gauge from FastCrest#106
- potentially evict an unrelated LRU entry at capacity, since the
eviction check runs off len(_cache), which doesn't grow on replace
- inflate stats.episode_count, documented as "unique episodes seen"
Not reachable via the current production caller (predict_action_chunk
only calls insert() after a lookup() miss), but insert() is public API
on the class FastCrest#103 asked to make byte-accurate, so this closes that gap
directly rather than leaving it latent.
Adds three regression tests; confirmed each fails against the prior
implementation (assert 1032 == 516, episode_count 2 vs 1, evictions 1
vs 0) before passing with the fix.
Also drops two pre-existing unused imports (dataclasses.field,
tests/test_episode_cache_bytes.py's pytest) in the files touched here —
mechanical, zero behavior change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Closes the loop on #103. The requested tracking (
EpisodeCachebyte accounting +tether_episode_cache_bytes_totalPrometheus gauge) was already implemented in #106. This PR fixes two correctness gaps left in that implementation:Metric never emits in production. The only real call site,
Pi05DecomposedInference.__init__withcache_level="episode"(src/tether/runtime/pi05_decomposed_server.py:378), constructedEpisodeCachewithoutembodiment/model_id. SinceEpisodeCache._emit_bytes_metric()no-ops unless both are set, the gauge silently never emitted once episode mode was enabled. Fixed by reusingcuda_graphs_embodiment/cuda_graphs_model_id, already threaded into the same constructor for CUDA graph metrics.insert()double-counts bytes on a same-key re-insert. Callinginsert()twice for the same(episode_id, lang_hash)never backed out the old entry's bytes before adding the new ones - a permanent leak in_total_bytes(and therefore the gauge), a chance of evicting an unrelated LRU entry at capacity, and inflatedstats.episode_count("unique episodes seen"). Not reachable via today's only caller (which always checkslookup()first), butinsert()is public API on the exact class [Metrics] Track Episode Cache Memory Usage #103 asked to be byte-accurate, so it's fixed directly rather than left latent.Note:
cache_level="episode"isn't wired to anytether serveCLI flag yet, so this doesn't make the feature live today, it makes the byte-tracking and metric correct for when it becomes reachable.Type of Change
How Has This Been Tested?
pytest tests/passes locallytether doctorsanity checkOther: manual end-to-end script against the real (non-mocked)
classes, reproducible with:
pytest tests/test_episode_cache_bytes.py \ tests/test_episode_cache_production_wiring.py \ tests/test_episode_cache_utils.py \ tests/test_decomposed_server.py \ tests/test_cuda_graphs_integration.py \ tests/test_pi05_action_fast_path_integration.py -v # -> 51 passed, 1 skipped (CUDA-only test, expected without a GPU)Confirmed both new test groups fail against the pre-fix code before passing with it:
assert None == 'franka'(gap 1),assert 1032 == 516/ episode_count 2-vs-1 / evictions 1-vs-0 (gap 2).Also drove the real
Pi05DecomposedInferenceclass (mocked ORT session only - no real model export available here) throughcache_level="episode"and read the actual rendered Prometheus output:ruff checkclean on all touched files.Checklist