# Common Helper — `EngineFilenameSchema`

## Purpose

Self-describing `.engine` filename schema per D-C10-7. TensorRT engines are NOT portable across `(SM, JetPack, TRT, precision)` tuples; the filename schema makes mismatch instantly visible at takeoff load (F2) so refusing-to-deserialize-on-mismatch becomes trivial.

## Used By

- C7 — Inference Runtime (writes engines with this schema; reads them on `deserialize_engine`).
- C10 — Pre-flight Cache Provisioning (compiles engines via C7 with this schema; writes them to the cache root).

## Interface (sketch)

```
class EngineFilenameSchema:
    @staticmethod
    def build(model_name: str, sm: int, jetpack: str, trt: str, precision: str) -> str
    @staticmethod
    def parse(filename: str) -> EngineCacheKey
    @staticmethod
    def matches_host(filename: str, host_capabilities: HostCapabilities) -> bool
```

Filename format: `{model}__sm{SM}_jp{JP_dotted}_trt{TRT_dotted}_{precision}.engine`

Example: `ultravpr__sm87_jp6.2_trt10.3_fp16.engine`

```
EngineCacheKey:
  model_name:       string
  sm:               int               (e.g. 87 for Jetson Orin Nano Super)
  jetpack:          string            (e.g. "6.2")
  trt:              string            (e.g. "10.3")
  precision:        enum {fp16, int8, mixed}

HostCapabilities:
  current_sm:       int
  current_jetpack:  string
  current_trt:      string
```

## Implementation Notes

- Stateless; pure string parsing.
- `matches_host` returns true iff every tuple element matches exactly. F2 takeoff load uses this to decide which engines to deserialize and which to refuse.

## Caveats

- The dotted-version format must round-trip cleanly through filesystems (no `/` or `\` in dotted versions; safe).
- Adding a new tuple dimension (e.g., a per-binary `BUILD_*` flag combination) requires extending the schema AND every existing `.engine` filename. Versioning the schema itself is a Plan-phase carryforward if/when needed.
