Skip to content

Commit 0b31095

Browse files
anth-volkclaude
andcommitted
Fix worker templates: add pydantic to pip_install and add_local_file for simulation.py
Discovered during GA test app migration that all three worker image templates were missing pydantic in pip_install (simulation.py uses it at module level) and add_local_file for simulation.py (Modal only auto-mounts module-level imports). Also adds architecture validator checks and scaffold checklist items for both. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 097cd6d commit 0b31095

File tree

6 files changed

+27
-4
lines changed

6 files changed

+27
-4
lines changed

agents/dashboard/backend-builder.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,16 @@ Generate `backend/app.py`. Only `modal` at module level. Imports business logic
263263

264264
```python
265265
import modal
266+
from pathlib import Path
266267
from _image_setup import snapshot_models
267268

269+
_BACKEND_DIR = Path(__file__).parent
268270
app = modal.App("DASHBOARD_NAME-workers")
269271
image = (
270272
modal.Image.debian_slim(python_version="3.11")
271-
.pip_install("policyengine-us==LATEST_VERSION") # Pinned — looked up from PyPI in Step 1
273+
.pip_install("policyengine-us==LATEST_VERSION", "pydantic") # Pinned — looked up from PyPI in Step 1
272274
.run_function(snapshot_models)
275+
.add_local_file(str(_BACKEND_DIR / "simulation.py"), remote_path="/root/simulation.py")
273276
)
274277

275278
@app.function(image=image, cpu=8.0, memory=32768, timeout=3600)

agents/dashboard/dashboard-architecture-validator.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,18 @@ grep -n 'run_function' backend/app.py
133133
# Should find the snapshot call
134134
```
135135

136+
**app.py must include pydantic in pip_install (simulation.py uses it at module level):**
137+
```bash
138+
grep -n 'pydantic' backend/app.py
139+
# Should find "pydantic" in the .pip_install() call
140+
```
141+
142+
**app.py must include add_local_file for simulation.py (not auto-mounted):**
143+
```bash
144+
grep -n 'add_local_file.*simulation' backend/app.py
145+
# Should find the .add_local_file() call — Modal only auto-mounts module-level imports
146+
```
147+
136148
**simulation.py must have policyengine imports at module level (snapshotted):**
137149
```bash
138150
grep -n '^from policyengine\|^import policyengine' backend/simulation.py

agents/dashboard/dashboard-scaffold.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,8 @@ If either fails, fix before proceeding.
587587
- [ ] If custom-modal: `app.py` only imports `modal` at module level
588588
- [ ] If custom-modal: `simulation.py` has policyengine imports at module level (snapshotted)
589589
- [ ] If custom-modal: image uses `.run_function(snapshot_models)` for fast cold starts
590+
- [ ] If custom-modal: worker image `pip_install` includes `"pydantic"` (simulation.py uses it at module level)
591+
- [ ] If custom-modal: worker image uses `.add_local_file()` for `simulation.py` (not auto-mounted since it's imported inside function bodies)
590592
- [ ] If custom-modal: gateway is lightweight (no policyengine in its Modal image)
591593
- [ ] If custom-modal: gateway image explicitly includes `pydantic`
592594
- [ ] If custom-modal: workers have `cpu=8.0`, `memory=32768`, `timeout >= 3600`
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Pattern C (custom-modal) backend now uses three-file structure mirroring api-v2: _image_setup.py (snapshot), app.py (Modal decorators), simulation.py (pure logic). Adds .run_function() for fast cold starts, cpu=8.0/memory=32768 resource specs, and architecture validator check #6 for Modal backend structure.
1+
Pattern C (custom-modal) backend now uses three-file structure mirroring api-v2: _image_setup.py (snapshot), app.py (Modal decorators), simulation.py (pure logic). Adds .run_function() for fast cold starts, cpu=8.0/memory=32768 resource specs, explicit pydantic in worker pip_install, .add_local_file() for simulation.py mounting, and architecture validator check #6 for Modal backend structure.

commands/new-tool.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,16 @@ Create `backend/app.py` (worker app, only `modal` at module level):
212212

213213
```python
214214
import modal
215+
from pathlib import Path
215216
from _image_setup import snapshot_models
216217

218+
_BACKEND_DIR = Path(__file__).parent
217219
app = modal.App("TOOL_NAME-workers")
218220
image = (
219221
modal.Image.debian_slim(python_version="3.11")
220-
.pip_install("policyengine-us==LATEST_VERSION")
222+
.pip_install("policyengine-us==LATEST_VERSION", "pydantic")
221223
.run_function(snapshot_models)
224+
.add_local_file(str(_BACKEND_DIR / "simulation.py"), remote_path="/root/simulation.py")
222225
)
223226

224227
@app.function(image=image, cpu=8.0, memory=32768, timeout=3600)

skills/tools-and-apis/policyengine-interactive-tools-skill/SKILL.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,16 @@ Only `modal` at module level. Imports business logic **inside each function body
193193

194194
```python
195195
import modal
196+
from pathlib import Path
196197
from _image_setup import snapshot_models
197198

198199
app = modal.App("my-tool-workers")
200+
_BACKEND_DIR = Path(__file__).parent
199201
image = (
200202
modal.Image.debian_slim(python_version="3.11")
201-
.pip_install("policyengine-us==X.Y.Z") # Pin to latest — look up from PyPI
203+
.pip_install("policyengine-us==X.Y.Z", "pydantic") # Pin to latest — look up from PyPI
202204
.run_function(snapshot_models)
205+
.add_local_file(str(_BACKEND_DIR / "simulation.py"), remote_path="/root/simulation.py")
203206
)
204207

205208
@app.function(image=image, cpu=8.0, memory=32768, timeout=3600)

0 commit comments

Comments
 (0)