Spaces:
Running
Running
Initial OpenEnv SQL debug environment
Browse files
README.md
CHANGED
|
@@ -1,242 +1,14 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: sql-debug-env
|
| 3 |
-
emoji: "🧪"
|
| 4 |
-
colorFrom: blue
|
| 5 |
-
colorTo: green
|
| 6 |
-
sdk: docker
|
| 7 |
-
pinned: false
|
| 8 |
-
---
|
| 9 |
-
|
| 10 |
# SQL Debug Environment (`sql-debug-env`)
|
| 11 |
|
| 12 |
-

|
| 13 |
-

|
| 14 |

|
| 15 |

|
| 16 |

|
| 17 |
-

|
| 20 |
-
|
| 21 |
-
**Deterministic OpenEnv benchmark for real SQL debugging workflows.**
|
| 22 |
-
|
| 23 |
-
**Quick links:** [Live Space](https://md896-sql-debug-env.hf.space) · [Swagger](https://md896-sql-debug-env.hf.space/docs) · [OpenAPI](https://md896-sql-debug-env.hf.space/openapi.json) · [GitHub](https://github.com/mdayan8/sql-debug-env)
|
| 24 |
-
|
| 25 |
-
An OpenEnv environment focused on a real engineering workflow: **SQL query debugging**.
|
| 26 |
-
Agents iterate on broken SQL using schema/error/sample inspection until they produce the expected result.
|
| 27 |
-
|
| 28 |
-
## Space Config
|
| 29 |
-
| Key | Value |
|
| 30 |
-
|---|---|
|
| 31 |
-
| `title` | `sql-debug-env` |
|
| 32 |
-
| `emoji` | `🧪` |
|
| 33 |
-
| `colorFrom` | `blue` |
|
| 34 |
-
| `colorTo` | `green` |
|
| 35 |
-
| `sdk` | `docker` |
|
| 36 |
-
| `pinned` | `false` |
|
| 37 |
-
|
| 38 |
-
## Abstract
|
| 39 |
-
This project implements a deterministic OpenEnv benchmark for SQL debugging. It includes three graded tasks (easy -> medium -> hard), typed action/observation/reward models, dense reward shaping, reproducible behavior, Docker deployment, and a baseline inference runner that emits strict structured logs.
|
| 40 |
-
|
| 41 |
-
## Why this matters
|
| 42 |
-
- SQL debugging is a daily task in analytics and backend teams.
|
| 43 |
-
- Deterministic graders allow fair model comparison.
|
| 44 |
-
- Dense reward shaping supports step-by-step agent learning.
|
| 45 |
-
- Fast local runtime enables quick iteration and validation.
|
| 46 |
-
|
| 47 |
-
## Core Components
|
| 48 |
-
- **API layer**: `server/main.py`
|
| 49 |
-
- **Environment engine**: `server/env.py`
|
| 50 |
-
- **Episode database**: `server/database.py` (in-memory SQLite)
|
| 51 |
-
- **Typed models**: `server/models.py`
|
| 52 |
-
- **Reward logic**: `server/reward.py`
|
| 53 |
-
- **Task + graders**: `server/tasks/`
|
| 54 |
-
- **Baseline runner**: `inference.py`
|
| 55 |
-
|
| 56 |
-
## Architecture
|
| 57 |
-
```mermaid
|
| 58 |
-
flowchart LR
|
| 59 |
-
agent[Agent Or Evaluator] --> api[FastAPI API Layer]
|
| 60 |
-
api --> env[SQLDebugEnv]
|
| 61 |
-
env --> db[InMemory SQLite DB]
|
| 62 |
-
env --> tasks[Task Registry easy medium hard]
|
| 63 |
-
tasks --> grader[Deterministic Grader]
|
| 64 |
-
env --> reward[Reward Engine]
|
| 65 |
-
grader --> reward
|
| 66 |
-
reward --> api
|
| 67 |
-
```
|
| 68 |
-
|
| 69 |
-
## API Surface
|
| 70 |
-
- `POST /reset`
|
| 71 |
-
- `POST /step`
|
| 72 |
-
- `GET /state`
|
| 73 |
-
- `GET /tasks`
|
| 74 |
-
- `GET /health`
|
| 75 |
-
- `GET /benchmark`
|
| 76 |
-
|
| 77 |
-
## API Docs
|
| 78 |
-
- Swagger UI: `http://localhost:7860/docs`
|
| 79 |
-
- ReDoc: `http://localhost:7860/redoc`
|
| 80 |
-
- OpenAPI: `http://localhost:7860/openapi.json`
|
| 81 |
-
|
| 82 |
-
## Action Space
|
| 83 |
-
| Action | Required fields | Purpose |
|
| 84 |
-
|---|---|---|
|
| 85 |
-
| `submit_query` | `query` | Submit SQL candidate for execution + grading |
|
| 86 |
-
| `inspect_schema` | none | Return schema metadata |
|
| 87 |
-
| `inspect_error` | none | Return last execution error details |
|
| 88 |
-
| `inspect_sample` | `table_name` | Return sample rows from table |
|
| 89 |
-
| `reset_query` | none | Reset current query to original broken query |
|
| 90 |
-
|
| 91 |
-
## Observation Space (high-level)
|
| 92 |
-
- Task context: `task_id`, `task_description`, `original_query`, `expected_description`
|
| 93 |
-
- Progress: `steps_taken`, `steps_remaining`, `current_score`
|
| 94 |
-
- Feedback: `last_action_type`, `last_query_result`, `schema_info`, `error_details`, `sample_rows`
|
| 95 |
-
- Episode status: `is_done`, `success`
|
| 96 |
-
|
| 97 |
-
## Reward Design
|
| 98 |
-
Reward is clamped to `[0.0, 1.0]` and combines:
|
| 99 |
-
- `correctness` (`0.0-0.6`)
|
| 100 |
-
- `efficiency` (`0.0-0.2`)
|
| 101 |
-
- `syntax_progress` (`0.0-0.1`)
|
| 102 |
-
- `schema_bonus` (`0.0-0.1`)
|
| 103 |
-
- `penalty` deduction magnitude (`0.0-0.2`)
|
| 104 |
-
|
| 105 |
-
## Task Suite
|
| 106 |
-
### Easy — `easy_syntax_fix`
|
| 107 |
-
Fix a misspelled SQL keyword and alias mismatch.
|
| 108 |
-
|
| 109 |
-
### Medium — `medium_logic_fix`
|
| 110 |
-
Fix join/filter placement and aggregation scope issues.
|
| 111 |
-
|
| 112 |
-
### Hard — `hard_multi_bug`
|
| 113 |
-
Fix multi-part bugs across correlation, date logic, and aggregation/window behavior.
|
| 114 |
-
|
| 115 |
-
## Repository Structure
|
| 116 |
-
```text
|
| 117 |
-
sql-debug-env/
|
| 118 |
-
├── Dockerfile
|
| 119 |
-
├── openenv.yaml
|
| 120 |
-
├── inference.py
|
| 121 |
-
├── README.md
|
| 122 |
-
├── requirements.txt
|
| 123 |
-
├── pyproject.toml
|
| 124 |
-
├── uv.lock
|
| 125 |
-
├── scripts/
|
| 126 |
-
│ └── benchmark_local.py
|
| 127 |
-
├── server/
|
| 128 |
-
│ ├── main.py
|
| 129 |
-
│ ├── env.py
|
| 130 |
-
│ ├── models.py
|
| 131 |
-
│ ├── database.py
|
| 132 |
-
│ ├── reward.py
|
| 133 |
-
│ └── tasks/
|
| 134 |
-
│ ├── base.py
|
| 135 |
-
│ ├── task_easy.py
|
| 136 |
-
│ ├── task_medium.py
|
| 137 |
-
│ └── task_hard.py
|
| 138 |
-
└── tests/
|
| 139 |
-
├── test_env.py
|
| 140 |
-
├── test_graders.py
|
| 141 |
-
└── test_reward.py
|
| 142 |
-
```
|
| 143 |
-
|
| 144 |
-
## Reliability and Benchmarking
|
| 145 |
-
### Verified local status
|
| 146 |
-
- `openenv validate --verbose`: PASS
|
| 147 |
-
- `python3 -m unittest discover -s tests -p "test_*.py"`: 10/10 PASS
|
| 148 |
-
- Docker smoke test: PASS (`/health`, `/tasks`, `/reset`, `/step`)
|
| 149 |
-
|
| 150 |
-
### Live benchmark endpoint
|
| 151 |
-
`GET /benchmark?runs=20` performs fresh timing each call.
|
| 152 |
-
|
| 153 |
-
Example:
|
| 154 |
-
```bash
|
| 155 |
-
curl "http://localhost:7860/benchmark?runs=20"
|
| 156 |
-
```
|
| 157 |
-
|
| 158 |
-
## Quick Start
|
| 159 |
-
### Local
|
| 160 |
-
```bash
|
| 161 |
-
pip install -r requirements.txt
|
| 162 |
-
uvicorn server.main:app --host 0.0.0.0 --port 7860
|
| 163 |
-
```
|
| 164 |
-
|
| 165 |
-
### Docker
|
| 166 |
-
```bash
|
| 167 |
-
docker build -t sql-debug-env .
|
| 168 |
-
docker run -p 7860:7860 sql-debug-env
|
| 169 |
-
```
|
| 170 |
-
|
| 171 |
-
### Smoke test
|
| 172 |
-
```bash
|
| 173 |
-
curl http://localhost:7860/health
|
| 174 |
-
curl http://localhost:7860/tasks
|
| 175 |
-
curl -X POST http://localhost:7860/reset -H "Content-Type: application/json" -d '{}'
|
| 176 |
-
curl -X POST http://localhost:7860/step -H "Content-Type: application/json" -d '{"action":{"action_type":"inspect_schema"}}'
|
| 177 |
-
curl "http://localhost:7860/benchmark?runs=20"
|
| 178 |
-
```
|
| 179 |
-
|
| 180 |
-
## Baseline Inference
|
| 181 |
-
```bash
|
| 182 |
-
export API_BASE_URL="https://api.openai.com/v1"
|
| 183 |
-
export MODEL_NAME="gpt-4o-mini"
|
| 184 |
-
export OPENAI_API_KEY="your-key"
|
| 185 |
-
export HF_TOKEN="$OPENAI_API_KEY"
|
| 186 |
-
export ENV_BASE_URL="http://localhost:7860"
|
| 187 |
-
export SEED="1"
|
| 188 |
-
python inference.py
|
| 189 |
-
```
|
| 190 |
-
|
| 191 |
-
## Hugging Face Spaces (Docker)
|
| 192 |
-
1. Create Docker Space.
|
| 193 |
-
2. Push this repository.
|
| 194 |
-
3. Ensure `openenv.yaml` has:
|
| 195 |
-
`api.base_url: "https://md896-sql-debug-env.hf.space"`
|
| 196 |
-
4. Verify:
|
| 197 |
-
```bash
|
| 198 |
-
curl https://md896-sql-debug-env.hf.space/health
|
| 199 |
-
curl -X POST https://md896-sql-debug-env.hf.space/reset -H "Content-Type: application/json" -d '{}'
|
| 200 |
-
curl https://md896-sql-debug-env.hf.space/docs
|
| 201 |
-
```
|
| 202 |
-
---
|
| 203 |
-
title: sql-debug-env
|
| 204 |
-
emoji: "🧪"
|
| 205 |
-
colorFrom: blue
|
| 206 |
-
colorTo: green
|
| 207 |
-
sdk: docker
|
| 208 |
-
pinned: false
|
| 209 |
-
---
|
| 210 |
-
|
| 211 |
-
# SQL Debug Environment (`sql-debug-env`)
|
| 212 |
-
|
| 213 |

|
| 214 |
-

|
| 215 |
-

|
| 216 |
-

|
| 217 |
-

|
| 218 |
-

|
| 219 |
-

|
| 220 |
-

|
| 221 |
|
| 222 |
An OpenEnv environment for a real task people do every day: **debugging SQL**. The agent gets a broken query, a live (in-memory) SQLite database, and a description of the expected output. It can inspect schema/errors/samples and submit fixed queries until it solves the task.
|
| 223 |
|
| 224 |
-
## Space Config
|
| 225 |
-
| Key | Value |
|
| 226 |
-
|---|---|
|
| 227 |
-
| `title` | `sql-debug-env` |
|
| 228 |
-
| `emoji` | `🧪` |
|
| 229 |
-
| `colorFrom` | `blue` |
|
| 230 |
-
| `colorTo` | `green` |
|
| 231 |
-
| `sdk` | `docker` |
|
| 232 |
-
| `pinned` | `false` |
|
| 233 |
-
|
| 234 |
-
## Why this project matters
|
| 235 |
-
- SQL debugging is a real operational task across analytics and backend teams.
|
| 236 |
-
- The environment is deterministic, fast, and local-first for reliable evaluation.
|
| 237 |
-
- Reward shaping gives useful partial progress signals instead of only pass/fail.
|
| 238 |
-
- The benchmark endpoint provides live runtime evidence for reviewers.
|
| 239 |
-
|
| 240 |
## What’s in this repo
|
| 241 |
- **FastAPI server**: `server/main.py` (endpoints: `/health`, `/tasks`, `/reset`, `/step`, `/state`)
|
| 242 |
- **Environment logic**: `server/env.py` + `server/database.py`
|
|
@@ -259,20 +31,6 @@ An OpenEnv environment for a real task people do every day: **debugging SQL**. T
|
|
| 259 |
- Docker-first deployment path (local and Hugging Face Spaces)
|
| 260 |
- Local benchmark endpoint for live latency checks (`/benchmark`)
|
| 261 |
|
| 262 |
-
## Architecture
|
| 263 |
-
```mermaid
|
| 264 |
-
flowchart LR
|
| 265 |
-
Client[Client Agent or Evaluator] --> API[FastAPI Server]
|
| 266 |
-
API --> Env[SQLDebugEnv]
|
| 267 |
-
Env --> DB[InMemory SQLite Episode DB]
|
| 268 |
-
Env --> Tasks[Task Set easy medium hard]
|
| 269 |
-
Env --> Reward[Reward Engine]
|
| 270 |
-
Tasks --> Grader[Deterministic Graders]
|
| 271 |
-
Grader --> Reward
|
| 272 |
-
Reward --> API
|
| 273 |
-
API --> Client
|
| 274 |
-
```
|
| 275 |
-
|
| 276 |
## API Docs (FastAPI Auto Docs)
|
| 277 |
Use these for interactive testing in browser:
|
| 278 |
|
|
@@ -280,35 +38,6 @@ Use these for interactive testing in browser:
|
|
| 280 |
- ReDoc: `http://localhost:7860/redoc`
|
| 281 |
- OpenAPI spec: `http://localhost:7860/openapi.json`
|
| 282 |
|
| 283 |
-
## Project Structure
|
| 284 |
-
```text
|
| 285 |
-
sql-debug-env/
|
| 286 |
-
├── Dockerfile
|
| 287 |
-
├── openenv.yaml
|
| 288 |
-
├── inference.py
|
| 289 |
-
├── README.md
|
| 290 |
-
├── requirements.txt
|
| 291 |
-
├── pyproject.toml
|
| 292 |
-
├── uv.lock
|
| 293 |
-
├── scripts/
|
| 294 |
-
│ └── benchmark_local.py
|
| 295 |
-
├── server/
|
| 296 |
-
│ ├── main.py
|
| 297 |
-
│ ├── env.py
|
| 298 |
-
│ ├── models.py
|
| 299 |
-
│ ├── database.py
|
| 300 |
-
│ ├── reward.py
|
| 301 |
-
│ └── tasks/
|
| 302 |
-
│ ├── base.py
|
| 303 |
-
│ ├── task_easy.py
|
| 304 |
-
│ ├── task_medium.py
|
| 305 |
-
│ └── task_hard.py
|
| 306 |
-
└── tests/
|
| 307 |
-
├── test_env.py
|
| 308 |
-
├── test_graders.py
|
| 309 |
-
└── test_reward.py
|
| 310 |
-
```
|
| 311 |
-
|
| 312 |
## Action Space
|
| 313 |
| Action | Required fields | Cost / reward effect |
|
| 314 |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# SQL Debug Environment (`sql-debug-env`)
|
| 2 |
|
|
|
|
|
|
|
| 3 |

|
| 4 |

|
| 5 |

|
| 6 |
+

|
| 7 |
+

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
An OpenEnv environment for a real task people do every day: **debugging SQL**. The agent gets a broken query, a live (in-memory) SQLite database, and a description of the expected output. It can inspect schema/errors/samples and submit fixed queries until it solves the task.
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
## What’s in this repo
|
| 13 |
- **FastAPI server**: `server/main.py` (endpoints: `/health`, `/tasks`, `/reset`, `/step`, `/state`)
|
| 14 |
- **Environment logic**: `server/env.py` + `server/database.py`
|
|
|
|
| 31 |
- Docker-first deployment path (local and Hugging Face Spaces)
|
| 32 |
- Local benchmark endpoint for live latency checks (`/benchmark`)
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
## API Docs (FastAPI Auto Docs)
|
| 35 |
Use these for interactive testing in browser:
|
| 36 |
|
|
|
|
| 38 |
- ReDoc: `http://localhost:7860/redoc`
|
| 39 |
- OpenAPI spec: `http://localhost:7860/openapi.json`
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
## Action Space
|
| 42 |
| Action | Required fields | Cost / reward effect |
|
| 43 |
|---|---|---|
|