Skip to content

feat(client): observability events + cache hygiene API (closes #312, #355) - #358

Merged
gerchowl merged 4 commits into
devfrom
feature/312-355-cache-observability
May 7, 2026
Merged

gerchowl merged 4 commits into
devfrom
feature/312-355-cache-observability

Conversation

@gerchowl

@gerchowl gerchowl commented May 7, 2026

Copy link
Copy Markdown
Contributor

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

  • Per-index ETag: warm-cache uses `_get_with_etag`; cold start preserves `_get_json` shape for test compatibility (warm-path engages on second lifecycle).
  • Version-namespaced cache: `~/.cache/mat-vis/v0.6//...`. Upgrades across major.minor stop reading through orphan layouts — the bug bernhard hit in materials are missing from GPUOpen #281/Materials are missing from ambientCG #283.
  • Drop `latest/` aliasing: tag-pinned everywhere; falls back to `DEFAULT_TAG` when no explicit tag.
  • Orphan-layout detection at init: emits `cache_stale_detected` via `on_event` so reporters surface the cleanup recommendation.
  • `client.cache_check()`: JSON-serializable dict (`manifest_in_sync`, `indexes_in_sync`, `schema_version`, `pinned_tag`, `stale_layouts`, `stale_bytes`, `recommend`).
  • `client.cache_clear(stale_only=True)`: keeps current version's cache, removes only orphans.
  • CLI: `python -m mat_vis_client cache check [--json]` / `cache clear [--stale-only] [--yes]`.

Upgrade UX (lazy, not eager — by design)

The new version does NOT:

  • auto-delete the old cache (user data; could be GB)
  • auto-read through old layout (this IS the bug we're fixing)
  • eagerly re-fetch on init (would surprise CI runners)

It DOES:

  • write to the new versioned dir on first fetch
  • emit `cache_stale_detected` at init when orphans found
  • expose `cache_check()` for explicit query + `cache clear --stale-only` for cleanup

Files

  • `clients/python/src/mat_vis_client/progress.py` — new module: `ClientEvent`, `EventKind`, `OnEvent`, `silent_reporter`, `log_reporter`, `tty_reporter`, `mcp_reporter`
  • `clients/python/src/mat_vis_client/client.py` — `on_event` kwarg, `_emit` dispatcher, `_cache_read/write_etag_pair` generalised helpers, version-namespaced `_cache_scope`, `cache_check`, `cache_clear(stale_only=...)`, CLI subcommands
  • `clients/python/mat_vis_client_standalone.py` — signature parity (`on_event` kwarg, `cache_check` stub returning `unsupported-on-standalone`)
  • `clients/python/tests/test_progress_and_cache.py` — 17 new tests

Tests

  • 405 client tests (+17 new) green
  • 604 host tests green
  • standalone-drift gate green

References

  • mat-vis#312 (closed)
  • mat-vis#355 (closed)
  • mat-vis#287 (the silent `log.info` this PR replaces)
  • mat-vis#258 (manifest ETag pattern this generalises to indexes)
  • mat-vis#281 / Materials are missing from ambientCG #283 (bernhard's two false-report cycles surfaced as cache staleness; now structurally guarded)
  • 3-angle sub-agent spike — synthesized in conversation history

…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.
@github-actions github-actions Bot added area:testing Test infrastructure, BATS, pytest area:client Python/JS/Rust client packages labels May 7, 2026
…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).
@github-actions github-actions Bot added the area:workspace Workspace tooling, justfile, templates label May 7, 2026
gerchowl added 2 commits May 7, 2026 22:49
…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
gerchowl merged commit bd7f871 into dev May 7, 2026
5 checks passed
@gerchowl
gerchowl deleted the feature/312-355-cache-observability branch May 7, 2026 20:59
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:client Python/JS/Rust client packages area:testing Test infrastructure, BATS, pytest area:workspace Workspace tooling, justfile, templates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant