Session summary: fixed Space runtime port conflict (redacted)
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697# Session Summary: `elikoy/mapviewer` — Fix Runtime Port Conflict
**Date:** 2026-09-15 **User timezone:** Europe/Amsterdam **Starting state:** Space `elikoy/mapviewer` was in runtime error after a previous session pushed a new-tab refactor.
## 1. What was already done (carried-in context)
- Dataset `elikoy/mapviewer-data` is complete: `parcels.parquet` (43,754 × 16), `buildings.parquet` (43,667 × 5), raw provenance, and a staged `_space/` directory.- Garden band 50–500 m² → **27,037 parcels** (reference number).- Staged `_space/app.py` had already been refactored from a modal to a **new-tab map viewer**: - Per-row `View` link opens `/map/{pid}` in a new tab. - `build_map_page(pid)` returns a standalone Leaflet page with parcel + intersecting BAG buildings. - FastAPI route `/map/{pid}` registered **before** `mount_gradio_app`. - Entrypoint used `uvicorn.run(fast_app, host='0.0.0.0', port=7860)`.- Staged `_space/requirements.txt` included `fastapi` and `uvicorn`.- Previous verification job (`6aa9775b…`) timed out on Playwright table rendering due to job-sandbox Private Network Access (environmental, not an app bug).
## 2. This session
### 2.1 Inspected state- Live Space `elikoy/mapviewer` still ran the old modal `app.py`.- Direct `hf_fs_write` to Space returned **403 Forbidden** (OAuth token lacks Space write scope).- Used user-provided write token via `hf_jobs` secret `SPACE_TOKEN`.
### 2.2 Pushed new-tab version to Space- Job `6aa97a1a…` downloaded staged `_space/app.py` + `_space/requirements.txt` from `elikoy/mapviewer-data` and uploaded them to `elikoy/mapviewer`.- Space began rebuilding.
### 2.3 Diagnosed runtime error- Live probes returned **503 "Your space is in error"**.- Space run logs showed: ``` INFO: Started server process [1] INFO: Waiting for application startup. INFO: Application startup complete. ERROR: [Errno 98] error while attempting to bind on address ('0.0.0.0', 7860): [errno 98] address already in use ```- Root cause: `uvicorn.run(...)` in `app.py` conflicted with the Hugging Face Space runtime's own server process.
### 2.4 Fixed the port conflict- Edited staged `_space/app.py` in `elikoy/mapviewer-data`: - Removed `import uvicorn`. - Removed `if __name__ == '__main__': uvicorn.run(...)`. - Renamed `fast_app` → `app` and exposed the final ASGI app as top-level `app = ui.mount_gradio_app(app, demo, path='/')`.- Pushed the fixed `app.py` to the Space (job `6aa98e26…`).- Space began rebuilding; verification job `6aa98e2f…` started polling for readiness.
### 2.5 Factory reset- User initiated a factory reset on the Space to clear any stuck processes and rebuild cleanly from the latest commit.
## 3. Current state
| Item | Status ||---|---|| `_space/app.py` (dataset staging) | ✅ fixed: no `uvicorn.run`, exposes ASGI `app` || `_space/requirements.txt` | ✅ still includes `fastapi`, `uvicorn` (needed by Space runtime) || Space `elikoy/mapviewer` | 🔄 factory reset in progress / rebuilding || `/apply_filters` live verification | ⏳ pending || `/map/{pid}` live verification | ⏳ pending |
## 4. Next steps
1. Wait for the factory reset to complete (Space status should return 200).2. Verify `GET https://elikoy-mapviewer.hf.space/` returns the Gradio UI.3. Verify `gradio_client` call to `/apply_filters` returns **27,037** matches.4. Verify `GET https://elikoy-mapviewer.hf.space/map/35450425370000` returns 200 with Leaflet + parcel popup.5. Optional: browser smoke test of the new-tab View link.
## 5. Hard-won notes
- On HF Spaces, **do not call `uvicorn.run()` yourself**. Expose a top-level ASGI app named `app` and let the platform serve it.- When combining Gradio + FastAPI custom routes, use `app = gr.mount_gradio_app(app, demo, path='/')` and expose `app`.- Space writes with the session OAuth token return 403; use a user token with write access via `hf_jobs` secrets.- Space `/logs/run` is SSE-streaming; read with bounded `iter_content`, not `.read()` to EOF.- Job-sandbox Private Network Access can block Playwright/Gradio queue tests; verify with `gradio_client` and `requests` against the live Space instead.
## 6. Reference test commands
```pythonfrom gradio_client import Clientimport requests
space_url = 'https://elikoy-mapviewer.hf.space'
client = Client(space_url, httpx_kwargs={'timeout': 120})result = client.predict( 50, 500, 0, 1e12, 0, 100, 0, 1e9, [], [], None, None, 1200, 2026, False, [], 'Any', '', 25, api_name='/apply_filters')assert '27,037' in result[0]
r = requests.get(f'{space_url}/map/35450425370000', timeout=30)assert r.status_code == 200assert 'leaflet' in r.text.lower()```SESSION_2026-09-15_fix-port-conflict.mdAdded+97