File size: 2,927 Bytes
52279ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
---
title: mbok_dev
emoji: 🔐
colorFrom: blue
colorTo: green
sdk: docker
pinned: false
---

# mbok_dev

Public gateway with Supabase authentication that dynamically loads the private ver20 application from `DLPO/habadashi` Space.

## Features

- Supabase email/password authentication
- Cookie-based session management
- Dynamic loading of private application code (source code not exposed in public repo)
- Role-based access control via profiles table

## Environment Variables (Set in HF Space Secrets)

- `SUPABASE_URL`: Your Supabase project URL
- `SUPABASE_KEY`: Your Supabase anon/service key
- `HF_TOKEN`: Hugging Face token with access to private `DLPO/habadashi` Space
- `OPENAI_KEY`: OpenAI API key (required by ver20)
- `CLIENTPOOL`: Client pool configuration (required by ver20)

## Architecture

1. User visits public Space
2. Bootstrap downloads ver20 from private `DLPO/habadashi` Space
3. User logs in with Supabase credentials
4. On successful login, ver20 Gradio app is mounted at `/app/`
5. User profile and organization info loaded from `profiles` table

## Startup Phase Logging

The application logs structured startup phases to help diagnose issues. Look for these phase markers in the logs:

### Expected Startup Sequence

1. `[STARTUP_META]` - Environment and configuration info
2. `[PHASE] bootstrap_start` - Begin downloading private app
3. `[PHASE] bootstrap_end success=true` - Private app downloaded
4. `[PHASE] supabase_init_start` - Initialize Supabase client
5. `[PHASE] supabase_init_end success=true` - Supabase ready
6. `[PHASE] fastapi_init_start/end` - FastAPI app created
7. `[PHASE] create_ui_start/end` - Login UI created
8. `[PHASE] import_ver20_start` - Import ver20 app
9. `[PHASE] import_ver20_end success=true` - Ver20 loaded
10. `[PHASE] mount_login_start/end` - Login UI mounted
11. `[PHASE] mount_app_start/end` - Ver20 app mounted
12. `[STARTUP_COMPLETE]` - All phases complete

### Health Check Endpoint

Once started, check the health endpoint:

```bash
curl https://DLPO-mbok-dev.hf.space/healthz
```

Expected response:
```json
{
  "ok": true,
  "ver20_loaded": true,
  "private_app_dir": "./private_app"
}
```

### Debugging Startup Failures

If the Space fails to start or restarts repeatedly:

1. **Check the last phase reached** in logs
2. **Look for `[ERROR]` and `[TRACEBACK]` markers** after the last phase
3. **Common failure points:**
   - `bootstrap_end success=false` - HF_TOKEN missing or invalid
   - `supabase_init_end success=false` - SUPABASE_URL/KEY missing
   - `import_ver20_end success=false` - Ver20 app.py structure issue
   - No phases after `mount_app_end` - Port binding or health check issue

### Request Logging

All HTTP requests are logged with:
- `[REQUEST]` - Incoming request (method, path)
- `[RESPONSE]` - Response status and duration

Example:
```
[REQUEST] method=GET path=/
[RESPONSE] method=GET path=/ status=307 duration=0.015s
```