VibecoderMcSwaggins commited on
Commit
e745675
·
2 Parent(s): e1ce419 89a1f34

Merge branch 'main' into dev

Browse files
Files changed (1) hide show
  1. BUGS-HF-SPACES-INTEGRATION.md +252 -0
BUGS-HF-SPACES-INTEGRATION.md ADDED
@@ -0,0 +1,252 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Bug Report: HuggingFace Spaces Frontend/Backend Integration
2
+
3
+ **Date**: 2025-12-12
4
+ **Auditor**: Claude Code
5
+ **Status**: Pre-deployment audit (UPDATED after URL verification)
6
+
7
+ ---
8
+
9
+ ## Executive Summary
10
+
11
+ Audit of the frontend/backend integration for HuggingFace Spaces deployment. After verifying against the **actual deployed Space URLs**, the core configuration is **CORRECT**. No P0/P1 blockers found. Minor P2/P3 improvements identified.
12
+
13
+ ### Actual Space URLs (Verified)
14
+ - **Frontend**: https://huggingface.co/spaces/VibecoderMcSwaggins/stroke-viewer-frontend
15
+ - Runtime URL: `https://vibecodermcswaggins-stroke-viewer-frontend.hf.space`
16
+ - **Backend**: https://huggingface.co/spaces/VibecoderMcSwaggins/stroke-deepisles-demo
17
+ - Runtime URL: `https://vibecodermcswaggins-stroke-deepisles-demo.hf.space`
18
+
19
+ ---
20
+
21
+ ## Configuration Verification (All PASS)
22
+
23
+ | Component | Configuration | Status | Evidence |
24
+ |-----------|--------------|--------|----------|
25
+ | CORS Regex | `r"https://.*stroke-viewer-frontend.*\.hf\.space"` | **PASS** | Matches `vibecodermcswaggins-stroke-viewer-frontend.hf.space` |
26
+ | Backend URL in Frontend | `VITE_API_URL=https://vibecodermcswaggins-stroke-deepisles-demo.hf.space` | **PASS** | Correctly points to backend |
27
+ | Built dist has production URL | `https://vibecodermcswaggins-stroke-deepisles-demo.hf.space` | **PASS** | Verified in `dist/assets/index-*.js` |
28
+ | Proxy headers | `--proxy-headers` in Dockerfile CMD | **PASS** | Ensures HTTPS URLs behind HF proxy |
29
+ | Port configuration | 7860 | **PASS** | Matches HF Spaces requirements |
30
+ | Results directory | `/tmp/stroke-results` | **PASS** | Writable on HF Spaces |
31
+ | Async job queue | Implemented | **PASS** | Avoids 60s gateway timeout |
32
+
33
+ ### CORS Regex Verification
34
+
35
+ ```python
36
+ # Test performed:
37
+ import re
38
+ frontend_url = 'https://vibecodermcswaggins-stroke-viewer-frontend.hf.space'
39
+ cors_regex = r'https://.*stroke-viewer-frontend.*\.hf\.space'
40
+ re.fullmatch(cors_regex, frontend_url) # Returns Match object - SUCCESS
41
+
42
+ # Also matches proxy/embed format:
43
+ proxy_url = 'https://vibecodermcswaggins--stroke-viewer-frontend--abc123.hf.space'
44
+ re.fullmatch(cors_regex, proxy_url) # Returns Match object - SUCCESS
45
+ ```
46
+
47
+ ---
48
+
49
+ ## P2 - MEDIUM PRIORITY (Non-blocking)
50
+
51
+ ### ISSUE-001: Hardcoded User in Production Config
52
+
53
+ **Severity**: P2 - MEDIUM
54
+ **Impact**: Forks/clones require manual configuration update
55
+ **Files**: `frontend/.env.production`, `frontend/dist/`
56
+
57
+ #### Problem
58
+
59
+ The production URL is hardcoded for a specific user:
60
+ ```
61
+ # frontend/.env.production
62
+ VITE_API_URL=https://vibecodermcswaggins-stroke-deepisles-demo.hf.space
63
+ ```
64
+
65
+ Anyone forking this repo must:
66
+ 1. Update `.env.production` with their backend URL
67
+ 2. Rebuild the frontend (`npm run build`)
68
+ 3. Re-deploy the dist folder
69
+
70
+ #### Recommendation (Optional)
71
+
72
+ Add a deployment note to `frontend/README.md`:
73
+ ```markdown
74
+ ## Fork Deployment
75
+
76
+ If you fork this repo, update `.env.production` before building:
77
+ \`\`\`
78
+ VITE_API_URL=https://{YOUR_USERNAME}-stroke-deepisles-demo.hf.space
79
+ \`\`\`
80
+ Then rebuild: `npm run build`
81
+ ```
82
+
83
+ ---
84
+
85
+ ### ISSUE-002: allow_credentials May Be Unnecessary
86
+
87
+ **Severity**: P2 - MEDIUM
88
+ **Impact**: More permissive than needed
89
+ **File**: `src/stroke_deepisles_demo/api/main.py:87`
90
+
91
+ #### Problem
92
+
93
+ ```python
94
+ app.add_middleware(
95
+ CORSMiddleware,
96
+ allow_origins=CORS_ORIGINS,
97
+ allow_origin_regex=r"https://.*stroke-viewer-frontend.*\.hf\.space",
98
+ allow_credentials=True, # <-- Is this needed?
99
+ allow_methods=["*"],
100
+ allow_headers=["*"],
101
+ )
102
+ ```
103
+
104
+ The frontend API client doesn't use credentials:
105
+ ```typescript
106
+ // frontend/src/api/client.ts - no credentials option in fetch calls
107
+ const response = await fetch(`${this.baseUrl}/api/cases`, { signal })
108
+ ```
109
+
110
+ #### Recommendation (Optional)
111
+
112
+ If credentials (cookies, auth headers) aren't needed, consider:
113
+ ```python
114
+ app.add_middleware(
115
+ CORSMiddleware,
116
+ allow_origins=CORS_ORIGINS,
117
+ allow_origin_regex=r"https://.*stroke-viewer-frontend.*\.hf\.space",
118
+ allow_credentials=False, # More restrictive
119
+ allow_methods=["GET", "POST"], # Only methods actually used
120
+ allow_headers=["Content-Type"], # Only headers actually needed
121
+ )
122
+ ```
123
+
124
+ This follows the principle of least privilege.
125
+
126
+ ---
127
+
128
+ ## P3 - LOW PRIORITY (Nice-to-have)
129
+
130
+ ### ISSUE-003: FRONTEND_ORIGIN Env Var Not Used
131
+
132
+ **Severity**: P3 - LOW
133
+ **Impact**: Works without it, but could be more explicit
134
+ **File**: `Dockerfile`, `src/stroke_deepisles_demo/api/main.py:72-78`
135
+
136
+ #### Problem
137
+
138
+ The code supports `FRONTEND_ORIGIN` environment variable:
139
+ ```python
140
+ FRONTEND_ORIGIN = os.environ.get("FRONTEND_ORIGIN", "")
141
+ if FRONTEND_ORIGIN:
142
+ CORS_ORIGINS.append(FRONTEND_ORIGIN)
143
+ ```
144
+
145
+ But it's not set in the Dockerfile. The regex fallback works, but explicit is better than implicit.
146
+
147
+ #### Recommendation (Optional)
148
+
149
+ Add to Dockerfile:
150
+ ```dockerfile
151
+ ENV FRONTEND_ORIGIN=https://vibecodermcswaggins-stroke-viewer-frontend.hf.space
152
+ ```
153
+
154
+ Or document that users can set it as a Space secret for more explicit configuration.
155
+
156
+ ---
157
+
158
+ ## P4 - INFO (No Action Required)
159
+
160
+ ### INFO-001: Static Space README Configuration
161
+
162
+ **Status**: CORRECT
163
+ **File**: `frontend/README.md`
164
+
165
+ The Static Space header is properly configured:
166
+ ```yaml
167
+ ---
168
+ title: Stroke Lesion Viewer
169
+ emoji: 🧠
170
+ sdk: static
171
+ app_file: dist/index.html
172
+ app_build_command: npm run build
173
+ nodejs_version: "20" # Required for Vite 7
174
+ ---
175
+ ```
176
+
177
+ ### INFO-002: Backend Dockerfile Configuration
178
+
179
+ **Status**: CORRECT
180
+ **File**: `Dockerfile`
181
+
182
+ All critical settings are present:
183
+ - `FROM isleschallenge/deepisles:latest` - Correct base image
184
+ - `USER user` - Non-root user (required by HF Spaces)
185
+ - `EXPOSE 7860` - Correct port
186
+ - `--proxy-headers` - Trusts X-Forwarded-Proto
187
+
188
+ ### INFO-003: Async Job Queue Pattern
189
+
190
+ **Status**: CORRECT
191
+ **Files**: `src/stroke_deepisles_demo/api/routes.py`, `frontend/src/hooks/useSegmentation.ts`
192
+
193
+ The implementation correctly handles HF Spaces' ~60s gateway timeout:
194
+ 1. POST `/api/segment` returns immediately with job ID (202 Accepted)
195
+ 2. Frontend polls GET `/api/jobs/{id}` every 2 seconds
196
+ 3. Progress updates shown via `ProgressIndicator`
197
+
198
+ ---
199
+
200
+ ## Pre-Deployment Checklist
201
+
202
+ Before going live, verify these items:
203
+
204
+ | Check | Status | Notes |
205
+ |-------|--------|-------|
206
+ | Frontend Space created | [ ] | `stroke-viewer-frontend` Static Space |
207
+ | Backend Space created | [ ] | `stroke-deepisles-demo` Docker Space |
208
+ | Backend Space has GPU | [ ] | T4 or better required for DeepISLES |
209
+ | Frontend built with production env | [x] | dist/ contains correct backend URL |
210
+ | CORS regex matches frontend URL | [x] | Verified via regex test |
211
+ | `--proxy-headers` in Dockerfile | [x] | Ensures HTTPS URLs |
212
+ | Port 7860 configured | [x] | Required by HF Spaces |
213
+ | Results dir in /tmp | [x] | `/tmp/stroke-results` |
214
+
215
+ ---
216
+
217
+ ## Runtime Testing Checklist
218
+
219
+ Once both Spaces are running:
220
+
221
+ | Test | Expected Result | How to Verify |
222
+ |------|-----------------|---------------|
223
+ | Frontend loads | Page renders without errors | Open frontend URL in browser |
224
+ | Backend health check | `{"status": "healthy", ...}` | `curl https://...-stroke-deepisles-demo.hf.space/health` |
225
+ | Cases endpoint | JSON array of case IDs | Check Network tab in DevTools |
226
+ | CORS on cases | No CORS error | Check Console tab in DevTools |
227
+ | Segmentation job created | 202 response with jobId | Click "Run Segmentation" |
228
+ | Progress polling | Progress updates in UI | Watch ProgressIndicator |
229
+ | Results displayed | NiiVue viewer shows volumes | Verify 3D rendering |
230
+ | Static file CORS | NIfTI files load without error | Check Network tab |
231
+
232
+ ---
233
+
234
+ ## Previously Fixed Issues (Reference)
235
+
236
+ These issues from earlier audits are correctly resolved:
237
+
238
+ | ID | Issue | Fix Applied |
239
+ |----|-------|-------------|
240
+ | 001 | CORS regex only matched proxy URL format | Fixed: `.*stroke-viewer-frontend.*` matches both |
241
+ | 002 | HTTP URLs returned behind HTTPS proxy | Fixed: `--proxy-headers` in uvicorn CMD |
242
+ | 003 | Gateway timeout on long inference | Fixed: Async job queue with polling |
243
+
244
+ ---
245
+
246
+ ## Sources
247
+
248
+ - [HuggingFace Static Spaces](https://huggingface.co/docs/hub/en/spaces-sdks-static)
249
+ - [HF Spaces URL Format](https://huggingface.co/docs/hub/spaces-embed)
250
+ - [FastAPI CORS Configuration](https://www.stackhawk.com/blog/configuring-cors-in-fastapi/)
251
+ - [Deploying FastAPI on HF Spaces](https://huggingface.co/blog/HemanthSai7/deploy-applications-on-huggingface-spaces)
252
+ - [HF Spaces Docker Docs](https://huggingface.co/docs/hub/spaces-sdks-docker)