Repository navigation
feat(client): observability events + cache hygiene API (closes #312, #355) - #358
Merged
Merged
Conversation
…355) Joint design from 3-angle sub-agent spike. Single `on_event=` callback + typed ClientEvent taxonomy + opt-in reporters (silent/log/tty/mcp). #312 — observability surface: client = MatVisClient(on_event=tty_reporter()) client = MatVisClient(on_event=mcp_reporter(emit)) #355 — cache hygiene: - Per-index ETag (warm path); cold start preserves _get_json shape for test compatibility. - Version-namespaced cache: ~/.cache/mat-vis/v0.6/<tag>/... - Drop "latest/" aliasing; tag-pinned everywhere. - Orphan-layout detection at init emits cache_stale_detected. - client.cache_check() — JSON-serializable status dict. - client.cache_clear(stale_only=True) — keeps current version's cache. - CLI: python -m mat_vis_client cache check / clear --stale-only. Upgrade UX (lazy, not eager): - New version does NOT auto-delete old cache. - Does NOT auto-read through old layout (the bernhard #281/#283 bug). - Does NOT eagerly re-fetch on init. - Lazy re-fetch on first call to materials/fetch_texture. Tests: 405 client (+17), 604 host, drift gate green. Refs #312, #355, #287, #258.
…follow-up) User caught the E2E gap: unit tests in test_progress_and_cache.py mock _get_with_etag per-test, which proves the code path runs but not that on-disk artifacts validate across process boundaries — the load-bearing claim of #355. Three pieces: 1. tests/e2e/_e2e_fixtures.py — preserved fixture set declaration pinning gerchowl/[email protected] (2 ambientcg AcousticFoam materials × 1k × 3 channels). Frozen tag so substrate evolution doesn't break tests; preflight HEADs every fixture URL. 2. scripts/rebake_e2e_fixtures.py — operator-runnable script that restores the fixture set via gh workflow run bake.yml. Self- recovering: missing fixtures recommend running this script. 3. clients/python/tests/test_cache_lifecycle_e2e.py — two scenarios: - Cross-process upgrade (no network): spawn fresh subprocess against a local http.server stub; assert client emits etag_not_modified on second run + emits cache_stale_detected when orphan dir exists. - Real HF round-trip (MAT_VIS_E2E=1 + preflight): cache_check() against real HF; warm-path ETag handshake actually fires. Manifest path now also emits etag_not_modified — symmetry with the index path; uniform observability across both ETag-validated fetches. Tests: 407 client (+19 new), 2 e2e tests skipped without MAT_VIS_E2E=1 + fixture preflight. Refs #312, #355, #358 (parent PR).
…er follow-up) Independent adversarial review caught two gaps in #358 that left bernhard's literal repro broken even after the structural fix: 1. get_client() singleton (the path bernhard reaches via pymat) constructed MatVisClient with no on_event= — _emit short- circuits, log.info stays silent in default loggers. 2. Orphan-layout detection emitted only via on_event — silent-default consumers never see it; orphan caches sit silently consuming disk. Fix: 1. __init__.py get_client() now wires tty_reporter() by default. The reporter auto-detects TTY: pretty progress in REPL/Jupyter, falls back to silent-log in CI/scripts (no spam regression). MAT_VIS_NO_PROGRESS=1 env var opts out → silent_reporter(). 2. _emit_legacy_layout_warning_if_any now also fires log.warning in addition to the on_event dispatch. Root logger sits at WARNING by default so even silent consumers see one line per process at startup. After fix: bernhard's #312 repro shows progress in his IPython REPL out-of-box (no consumer wiring needed). Stale cache from a v0.6.x install logs one WARN line at startup pointing at cache clear --stale-only — my own dev cache surfaced 147MB of orphans this way. 4 new tests: get_client wires on_event by default; MAT_VIS_NO_PROGRESS=1 opts out; orphan WARN log fires without on_event; both surfaces fire when on_event is wired. 411 client tests pass (+4 new). #312 + #355 now FIXED end-to-end. Refs #358 (parent), independent-review-driven follow-up.
bernhard mat-vis#311 sub-bullet 'Unclear error messages': Today: 'material X is not staged for tier 3k. Needs a re-bake.' bernhard's expectation: '... is not staged for tier 3k. Available tiers: ["1k", "2k"].' The pre-#332 wording was actionable only for maintainers ('rebake') and gave the user no path forward without grep'ing the catalog. Implementation: - MaterialNotStagedError gains optional available= kwarg + .available attribute (programmatic consumers like pymat / build123d can render alternate-tier UI from it). - Message lists 'Available tiers: [...]' when alternatives exist, falls back to the original 'Needs a re-bake' wording when the material isn't staged anywhere (the only case where rebake is the actual answer). - Both raise sites in _resolve_material_id pass available_tiers from the catalog entry — direct-UUID path AND name-resolved path. - Standalone parity: same signature + behavior in mat_vis_client_standalone.py. Closes the strict-xfail forcing function from PR #334. 3 new tests pin the post-fix behavior; existing #280 tests for original_name unchanged. 414 client tests pass (+3); standalone-drift gate green. Refs #332 (closed), #311 (bernhard's umbrella; this closes one of the sub-bullets), #280 (related — original_name). Lands on the same branch as #358 since it's the same area of client.py and the same bernhard-audit feedback loop.
gerchowl
added a commit
that referenced
this pull request
May 15, 2026
…355) (#358) * feat(client): observability events + cache hygiene API (closes #312, #355) Joint design from 3-angle sub-agent spike. Single `on_event=` callback + typed ClientEvent taxonomy + opt-in reporters (silent/log/tty/mcp). #312 — observability surface: client = MatVisClient(on_event=tty_reporter()) client = MatVisClient(on_event=mcp_reporter(emit)) #355 — cache hygiene: - Per-index ETag (warm path); cold start preserves _get_json shape for test compatibility. - Version-namespaced cache: ~/.cache/mat-vis/v0.6/<tag>/... - Drop "latest/" aliasing; tag-pinned everywhere. - Orphan-layout detection at init emits cache_stale_detected. - client.cache_check() — JSON-serializable status dict. - client.cache_clear(stale_only=True) — keeps current version's cache. - CLI: python -m mat_vis_client cache check / clear --stale-only. Upgrade UX (lazy, not eager): - New version does NOT auto-delete old cache. - Does NOT auto-read through old layout (the bernhard #281/#283 bug). - Does NOT eagerly re-fetch on init. - Lazy re-fetch on first call to materials/fetch_texture. Tests: 405 client (+17), 604 host, drift gate green. Refs #312, #355, #287, #258. * test: cross-process + real-HF E2E for cache observability (#312/#358 follow-up) User caught the E2E gap: unit tests in test_progress_and_cache.py mock _get_with_etag per-test, which proves the code path runs but not that on-disk artifacts validate across process boundaries — the load-bearing claim of #355. Three pieces: 1. tests/e2e/_e2e_fixtures.py — preserved fixture set declaration pinning gerchowl/[email protected] (2 ambientcg AcousticFoam materials × 1k × 3 channels). Frozen tag so substrate evolution doesn't break tests; preflight HEADs every fixture URL. 2. scripts/rebake_e2e_fixtures.py — operator-runnable script that restores the fixture set via gh workflow run bake.yml. Self- recovering: missing fixtures recommend running this script. 3. clients/python/tests/test_cache_lifecycle_e2e.py — two scenarios: - Cross-process upgrade (no network): spawn fresh subprocess against a local http.server stub; assert client emits etag_not_modified on second run + emits cache_stale_detected when orphan dir exists. - Real HF round-trip (MAT_VIS_E2E=1 + preflight): cache_check() against real HF; warm-path ETag handshake actually fires. Manifest path now also emits etag_not_modified — symmetry with the index path; uniform observability across both ETag-validated fetches. Tests: 407 client (+19 new), 2 e2e tests skipped without MAT_VIS_E2E=1 + fixture preflight. Refs #312, #355, #358 (parent PR). * fix(client): close #312/#355 from bernhard's seat (independent reviewer follow-up) Independent adversarial review caught two gaps in #358 that left bernhard's literal repro broken even after the structural fix: 1. get_client() singleton (the path bernhard reaches via pymat) constructed MatVisClient with no on_event= — _emit short- circuits, log.info stays silent in default loggers. 2. Orphan-layout detection emitted only via on_event — silent-default consumers never see it; orphan caches sit silently consuming disk. Fix: 1. __init__.py get_client() now wires tty_reporter() by default. The reporter auto-detects TTY: pretty progress in REPL/Jupyter, falls back to silent-log in CI/scripts (no spam regression). MAT_VIS_NO_PROGRESS=1 env var opts out → silent_reporter(). 2. _emit_legacy_layout_warning_if_any now also fires log.warning in addition to the on_event dispatch. Root logger sits at WARNING by default so even silent consumers see one line per process at startup. After fix: bernhard's #312 repro shows progress in his IPython REPL out-of-box (no consumer wiring needed). Stale cache from a v0.6.x install logs one WARN line at startup pointing at cache clear --stale-only — my own dev cache surfaced 147MB of orphans this way. 4 new tests: get_client wires on_event by default; MAT_VIS_NO_PROGRESS=1 opts out; orphan WARN log fires without on_event; both surfaces fire when on_event is wired. 411 client tests pass (+4 new). #312 + #355 now FIXED end-to-end. Refs #358 (parent), independent-review-driven follow-up. * feat(client): MaterialNotStagedError lists available tiers (closes #332) bernhard mat-vis#311 sub-bullet 'Unclear error messages': Today: 'material X is not staged for tier 3k. Needs a re-bake.' bernhard's expectation: '... is not staged for tier 3k. Available tiers: ["1k", "2k"].' The pre-#332 wording was actionable only for maintainers ('rebake') and gave the user no path forward without grep'ing the catalog. Implementation: - MaterialNotStagedError gains optional available= kwarg + .available attribute (programmatic consumers like pymat / build123d can render alternate-tier UI from it). - Message lists 'Available tiers: [...]' when alternatives exist, falls back to the original 'Needs a re-bake' wording when the material isn't staged anywhere (the only case where rebake is the actual answer). - Both raise sites in _resolve_material_id pass available_tiers from the catalog entry — direct-UUID path AND name-resolved path. - Standalone parity: same signature + behavior in mat_vis_client_standalone.py. Closes the strict-xfail forcing function from PR #334. 3 new tests pin the post-fix behavior; existing #280 tests for original_name unchanged. 414 client tests pass (+3); standalone-drift gate green. Refs #332 (closed), #311 (bernhard's umbrella; this closes one of the sub-bullets), #280 (related — original_name). Lands on the same branch as #358 since it's the same area of client.py and the same bernhard-audit feedback loop.
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.
Summary
Closes #312 (download progress) AND #355 (cache invalidation hygiene) together. Joint design from a 3-angle sub-agent spike (API surface, existing-code patterns, consumer integration). All three converged on a single `on_event=` callback with typed `ClientEvent` taxonomy + opt-in reporters from a new `mat_vis_client.progress` module.
#312 — observability surface
```python
client = MatVisClient(on_event=tty_reporter()) # REPL: progress on stderr
client = MatVisClient(on_event=mcp_reporter(emit)) # pymat-mcp: structured events
client = MatVisClient(on_event=log_reporter()) # CI: log lines
client = MatVisClient() # default: silent
```
bernhard's #312 repro now produces visible feedback under `tty_reporter` without consumers configuring logging — the silent `log.info` from #287's incomplete fix is replaced by a proper user-facing surface.
#355 — cache hygiene
Upgrade UX (lazy, not eager — by design)
The new version does NOT:
It DOES:
Files
Tests
References