feat: merge opus comfyui and login updates

This commit is contained in:
boos
2026-05-21 16:32:04 +02:00
parent c16479da7c
commit 9c84759498
105 changed files with 20160 additions and 1034 deletions
@@ -0,0 +1,45 @@
## ADDED Requirements
### Requirement: Cookie-authenticated reverse proxy at /comfy/*
The system SHALL mount a reverse proxy at `/comfy/*` that resolves the caller's `user_id` from the existing JWT cookie and forwards both HTTP and WebSocket traffic to that user's container.
#### Scenario: Anonymous request is rejected
- **WHEN** a request to `/comfy/` arrives without a valid JWT cookie
- **THEN** the proxy responds with HTTP 401 and does NOT touch the container pool
#### Scenario: Authenticated HTTP request reaches the right container
- **WHEN** user 7 requests `GET /comfy/api/object_info`
- **THEN** the proxy forwards the request body, query, and headers to `http://127.0.0.1:<port_for_user_7>/api/object_info` and streams the response back unchanged
#### Scenario: Authenticated WebSocket upgrade is proxied
- **WHEN** user 7's browser opens `wss://host/comfy/ws?clientId=abc`
- **THEN** the proxy upgrades the connection, opens a WS to `ws://127.0.0.1:<port_for_user_7>/ws?clientId=abc`, and pipes frames in both directions until either side closes
### Requirement: No URL rewriting of asset paths
The proxy SHALL forward request paths to the container with the `/comfy` prefix stripped and SHALL NOT rewrite response bodies.
#### Scenario: Asset path is preserved
- **WHEN** the browser requests `/comfy/extensions/core/foo.js`
- **THEN** the proxy forwards `/extensions/core/foo.js` to the container, and the response body is returned byte-for-byte
#### Scenario: ComfyUI's root-relative URLs work
- **WHEN** the container returns HTML referencing `/scripts/app.js`
- **THEN** the browser fetches `/comfy/scripts/app.js` (because the page was served under `/comfy/`) and the proxy resolves it correctly
### Requirement: Cold-start handling
If a request arrives while the user's container is `starting`, the proxy SHALL hold the request (up to 30 s) until the container reports `ready`, instead of returning 502.
#### Scenario: Request waits for cold start
- **WHEN** user 7's first request to `/comfy/` arrives and the container needs 12 s to start
- **THEN** the proxy waits for the readiness signal and forwards the request once the container is ready, returning a normal 200
#### Scenario: Cold-start timeout
- **WHEN** a container fails to become ready within 30 s
- **THEN** the proxy responds with HTTP 504 and the pool marks the container `failed` for the next idle scan
### Requirement: Last-used timestamp updated on every frame
Every HTTP request and WebSocket frame proxied to the container SHALL update `pool.containers[user_id].last_used_at = now`.
#### Scenario: Long-running WS keeps container alive
- **WHEN** a user holds a WS connection open for 90 minutes while exchanging frames every minute
- **THEN** the container is not reaped at the 60-minute mark