Skip to content

Commit 7d7e663

Browse files
committed
docs: add Option C WebWorker implementation progress summary
- Document all 5 phases and 16 tasks completed - Note current issue: iframe can't connect to localhost:5173 - List all files modified/created - Provide reproduction steps and investigation checklist for next session
1 parent 61d164b commit 7d7e663

1 file changed

Lines changed: 105 additions & 0 deletions

File tree

‎AGENTS.md‎

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,108 @@ Steps to re-enable:
5454
`vector` base class, giving a performance boost for vector-heavy programs.
5555

5656
5. **Rebuild vpython.zip** — `npm run zip` in wmWVPRunner, then `do_build.sh`.
57+
58+
## Option C (WebWorker) Implementation — Issue #1 Fix (In Progress)
59+
60+
**Status:** Code complete and committed (14 commits), but runtime integration broken. Iframe at `localhost:5173` refuses to connect from Flask parent.
61+
62+
### What Was Done
63+
64+
Implemented Option C architecture from wmWVPRunner/ISSUES.md to resolve Issue #1 (rate() inside user functions causing SyntaxError). Full 5-phase implementation across 16 tasks:
65+
66+
**Phase 1 (Tasks 1-3):** Worker skeleton
67+
- Created `src/lib/workers/pyodide-worker.js` — Pyodide initialization on worker thread
68+
- Added `initializeWorker()` helper to `src/lib/utils/utils.js` with proper resource cleanup
69+
- Fixed code quality issues: event listener memory leaks, timeout race conditions
70+
- Refactored `src/routes/+page.svelte` runMe() to use worker instead of direct runPythonAsync
71+
- Removed regex substitution array (no longer needed)
72+
73+
**Phase 2 (Tasks 4-6):** rate() synchronization
74+
- Created `vpython/_worker_bridge.py` — Python module that wraps rate() and graphics calls
75+
- Implemented Atomics.wait/notify synchronization pattern
76+
- Added frame timing handler on main thread
77+
- Code changes committed; manual testing ready (but blocked by iframe connection issue)
78+
79+
**Phase 3 (Tasks 7-9):** Graphics proxy bridge
80+
- Added graphics object registry and proxy system
81+
- Wired sphere(), box(), cylinder(), pyramid(), cone(), torus(), helix(), ring(), vertex(), compound(), curve()
82+
- Graphics calls proxied through SharedArrayBuffer
83+
84+
**Phase 4 (Tasks 10-11):** I/O redirection
85+
- WorkerStdout/WorkerStderr classes redirect print() and errors to main thread
86+
- stdout/stderr handlers already in place from skeleton
87+
88+
**Phase 5 (Tasks 12-16):** Deployment & documentation
89+
- Created comprehensive test scenarios document (TEST_SCENARIOS.md)
90+
- Created implementation notes (IMPLEMENTATION_NOTES.md) with architecture, deployment checklist, known limitations
91+
- Added COOP/COEP header configuration for SharedArrayBuffer support
92+
- Fixed variable shadowing and const reassignment errors
93+
- Build system verified working (npm run build passes)
94+
95+
**All code committed to wmWVPRunner main branch (14 commits total).**
96+
97+
### Current Problem
98+
99+
**"localhost refuses to connect" in iframe — Vite dev server not reachable from Flask**
100+
101+
**Symptoms:**
102+
- Flask app loads at `http://localhost:8080` ✓
103+
- Vite dev server running at `http://localhost:5173` ✓
104+
- Direct browser access to `http://localhost:5173` works ✓
105+
- Iframe src="http://localhost:5173/" in Flask page → "localhost refuses to connect" ✗
106+
- No console logs from wmWVPRunner appear in browser (suggests iframe never loads)
107+
108+
**Setup:**
109+
- SSH from laptop to intelmini with `-L 8080:localhost:8080 -L 5173:localhost:5173` port forwarding
110+
- Flask + datastore running in tmux pane 1
111+
- Vite dev server running in tmux pane 2
112+
- Both report ready, but iframe can't reach Vite
113+
114+
**Recent changes that might be related:**
115+
- Added COOP/COEP headers to Flask (in flaskHost/src/__init__.py) — required for SharedArrayBuffer
116+
- Added Vite plugin to set COOP/COEP headers (in wmWVPRunner/vite.config.js)
117+
- Added check for SharedArrayBuffer availability and helpful error message
118+
- Added detailed console logging to track postMessage flow
119+
120+
### What Needs Investigation on Next Machine
121+
122+
1. **Verify Vite is serving with correct headers** — run curl to check if COOP/COEP headers are actually being sent
123+
2. **Check browser console logs** — See if detailed logging we added (prefixed with `[wmWVPRunner]`) appears
124+
3. **Verify network requests** — DevTools Network tab should show iframe request to localhost:5173
125+
4. **Check origin mismatch** — Flask sends postMessage from `localhost:8080`, wmWVPRunner needs to accept that origin
126+
5. **Test iframe in isolation** — Open wmWVPRunner directly at localhost:5173 to confirm it works
127+
128+
### Key Files Modified
129+
130+
**wmWVPRunner:**
131+
- `src/routes/+page.svelte` — Main runner page, refactored to use worker
132+
- `src/lib/workers/pyodide-worker.js` — New worker entry point
133+
- `src/lib/utils/utils.js` — Worker initialization helper
134+
- `vpython/_worker_bridge.py` — New worker bridge module
135+
- `vpython/__init__.py` — Conditional worker imports
136+
- `vite.config.js` — Vite plugin for COOP/COEP headers (newly created)
137+
- `svelte.config.js` — Documentation of header requirements
138+
- `IMPLEMENTATION_NOTES.md` — New comprehensive docs
139+
- `TEST_SCENARIOS.md` — New test documentation
140+
141+
**flaskHost:**
142+
- `src/__init__.py` — Added COOP/COEP headers via after_request handler
143+
144+
### Git State
145+
146+
**wmWVPRunner repo:**
147+
- 14 commits ahead of origin/main (all pushed)
148+
- Working tree clean
149+
- Latest commits: dec2d1f (debug logging), b69c777 (ready message delay), 4383618 (SharedArrayBuffer check)
150+
151+
**flaskHost repo:**
152+
- 1 commit ahead of origin/main (COOP/COEP headers)
153+
154+
### To Pick Up on Another Machine
155+
156+
1. `git pull origin main` in both wmWVPRunner and flaskHost
157+
2. In wmWVPRunner: `npm install && npm run dev`
158+
3. In flaskHost: `make serve` (or docker compose)
159+
4. Open DevTools and check console for `[wmWVPRunner]` logs
160+
5. Investigate why iframe can't reach localhost:5173 (network tab, headers, origin checks)
161+
6. Once iframe loads, manual tests are ready to go (see TEST_SCENARIOS.md)

0 commit comments

Comments
 (0)