repospace / FIX-DISASTER.md
2Btainment's picture
fix(preview): refuse unbuilt Vite/CRA shells instead of a white iframe
6ba0cb8 verified
|
Raw History Blame Contribute Delete
4.47 kB
# RepoSpace — FIX-DISASTER
**Date:** 2026-10-03 17:40 PT (Europe/Berlin)
**Space:** https://huggingface.co/spaces/2Btainment/repospace
**App:** https://2btainment-repospace.hf.space
**Verified runtime / Space commit:** `20df9002264cec9e184389a3d45c09b7fc4e2471`
**Local git fix commit:** `c46ea3a817864c68aedec3b9a70c1fff23cf0812`
**Stage when verified:** RUNNING (replica after this build; Python 3.12.15, Node 22.23.3)
## What users actually hit
The landing page was fine (dark Einswarm UI, `GET /` 200). The preview loop was not.
1. **Every Node repo died during `npm install`.** A 1024 MB `RLIMIT_AS` was applied to the sandbox. V8 aborts when it cannot reserve virtual address space, even if RSS is ~10 MB. Live log from `heroku/node-js-getting-started` on the previous revision:
`FATAL ERROR: NewSpace::EnsureCurrentCapacity Allocation failed - JavaScript heap out of memory`
then `RuntimeError: npm install failed with code -6` (SIGABRT).
Status went `failed`. The iframe never appeared.
2. **Many non-static repos showed the wrong page (or a blank shell).** Detection served the first nested `index.html` it found. `heroku/python-getting-started` (Django) was marked `running` / `static` because of `hello/templates/index.html`. The iframe returned HTTP 200 of the raw template (`{% extends "base.html" %}`), not the app. The same early check treated CRA/Vite `public/index.html` as a finished site, so the preview was an empty shell instead of `npm install` + build.
3. **False 429 on create after a restart.** SQLite rows left in `pending` / `building` / `running` still counted toward `MAX_CONCURRENT_SESSIONS` even when no process existed. `POST /api/sessions` mapped that to **429** `Too many concurrent sessions`. Status/log polls were already on a separate 600/min budget (previous commit); a 25-request burst on this build stayed **200**.
## Fix
- Do not set `RLIMIT_AS` unless `REPOSPACE_AS_MB` is at least 4096. Default is off. Wall-clock build/start timeouts still apply. CPU rlimit default is off so a live server is not SIGXCPU'd.
- Detect order: prebuilt `dist/` `build/` `out/` only, then `package.json`, then Python (including `manage.py`), then a real static `index.html`. Skip `templates/`, `public/` when a Node app exists, and HTML that contains `{%`, `{{`, or `<?php`.
- Python deps install into a per-session venv (`.repospace-venv`), not the control-plane interpreter. Django runs `migrate --noinput` then `runserver`.
- On startup, stale sqlite rows with no live process are marked `terminated`. Concurrency is counted from in-memory sessions.
- Image: Python 3.12 + Node 22. UI stops status/log polling once the session is `failed` or `terminated`.
- Space repo junk (committed `.venv`, `.pytest_cache`, `frontend/node_modules`) removed in the same upload so the Docker context is the app, not a virtualenv.
## What now works (live, this revision)
| Check | Result |
|---|---|
| `GET /` landing | 200, background `rgb(2,2,2)`, Einswarm dark/gold |
| `GET /api/health` | 200 `service=repospace` |
| `POST` `mdn/beginner-html-site-styled` | `pending` → `running` static |
| `GET /s/{id}/` static body | **HTTP 200**, `My test page` / **Mozilla is cool**, Python `SimpleHTTP` 3.12 |
| Visible iframe | Playwright: iframe 1372×707, body text starts "Mozilla is cool" |
| `POST` `heroku/node-js-getting-started` | `running` node; `npm install` added 345 packages; **HTTP 200** HTML titled "Node.js Getting Started on Heroku" (`X-Powered-By: Express`) |
| `POST` `shekhargulati/python-flask-docker-hello-world` | venv + pip + `flask run`; **HTTP 200** body `Flask inside Docker!!` |
| 25× `GET /api/sessions/{id}` | 25× 200, zero 429 |
| `GET .../logs` | 200 |
| `DELETE /api/sessions/{id}` | 200 `terminated`; following `GET /s/{id}/` **404** |
## Remaining limits
- No Firecracker, no Docker-in-Docker. Dockerfile-only repos still fail with an explicit unsupported error.
- Next.js full servers are still rejected on purpose (too heavy for this sandbox).
- Django/Flask apps that need Postgres, env secrets, or a Python newer than 3.12 will fail in the log; we do not pretend otherwise.
- cpu-basic, max 3 concurrent sessions, 15 min idle teardown, 60 min hard cap.
- One shared network namespace. Soft timeouts only; address-space cap is off so a huge install can still OOM the whole Space.
- Heroku Node sample warns `EBADENGINE` (wants npm 12; image has npm 10.9 with Node 22) but still installs and serves.