You are given a Python workflow that enriches transaction records by joining them against a preloaded product catalog.
The workflow is implemented as a class CatalogEnricher that:
Accepts a product catalog (dict-of-lists with keys pid, name, category, price) at construction time and builds a DataFrame from it
For each call to enrich, accepts a dict of transaction records (pid, qty, date) and joins them with the cached catalog
Computes a total column as qty * price
Returns only transactions where the pid exists in the catalog (inner join), sorted by total descending
Also computes a summary: the set of pid values in the transactions that are NOT in the catalog (anti-join), returned as a list
The class is designed to amortize expensive initialization (loading the product catalog into a DataFrame and building lookup structures) across many method calls.
Your Task
Port this workflow to Modal. The class-based design — where the product catalog is loaded once at construction and reused for every enrichment request — maps naturally to a stateful remote worker.
The original workflow is in workflow.py. Study the CatalogEnricher class and run_pipeline function carefully.
Required Output
Write /app/solution/modal_app.py. It must:
Define a module-level app object
Define a module-level Modal Function named run_case
run_caseremote invocation (case) accepts a dict with keys:
"catalog": dict-of-lists with keys pid (int), name (str), category (str), price (float)
"transactions": dict-of-lists with keys pid (int), qty (int), date (str)
Returns a dict with keys:
"enriched": list of dicts with keys pid, name, category, price, qty, date, total — sorted by total descending
"missing_pids": sorted list of pid integers that appeared in transactions but not in the catalog
The remote environment needs polars installed.
Capability contract
Expose the workflow as a single Modal remote function: define run_case as an @app.function so the harness can invoke it with run_case.remote(case).