How brijeshvadalia/sql-debug-env works
1. This repository is a Dockerized, OpenEnv-compatible SQL debugging environment. The central product is a FastAPI service that runs SQL tasks against a seeded SQLite database and scores agent-submitted queries episode by episode.
2. The main runtime lives under server/. server/app.py is the HTTP entrypoint and exposes the environment API described in the README: /reset, /step, /evaluate, /hint, /curriculum, /leaderboard, /tasks, /stats, plus health and metadata endpoints. This is the boundary that agents and clients talk to.
3. server/environment.py is the core orchestration layer. It likely owns episode state, task selection, query execution, reward calculation, step counting, history tracking, and the transition from one observation to the next. This is where the “environment” semantics are implemented, not just raw request handling.
4. The database layer is intentionally self-contained. server/db/seed.sql defines the SQLite schema and initial data for customers, products, orders, order_items, and reviews. The README makes clear the database is in-memory or locally managed, so the environment has no external data-service dependency.
5. Task definitions are separated from execution logic in server/tasks/. This package appears to hold the eight task configurations: broken SQL, task descriptions, step limits, thresholds, and likely the metadata needed for curriculum and batch evaluation.
6. Grading is isolated in server/graders/. That boundary matters: task-specific correctness, partial credit, and performance-sensitive scoring are handled separately from the API and from the database seed. The README’s reward breakdown, query complexity, and performance metrics suggest graders compute deterministic scores and analysis from executed SQL and query plans.
7. models.py defines the shared typed contract for the environment. The README shows SQLAction, SQLObservation, and several nested analytics structures, so this file is the schema boundary between server, client, tests, and any external agent code.
8. client.py is the consumer-side SDK for interacting with the environment. It wraps the HTTP API into a Python interface for reset, step, and related calls, making the repo usable as both a service and a library for agent workflows.
9. inference.py is the evaluation/baseline runner. It connects an LLM client to the environment, submits SQL repairs, and measures performance across tasks. This is the main integration point with external model endpoints, but it is not required for the environment itself to run.
10. validate_submission.py is a submission-time contract checker. Together with openenv.yaml, Dockerfile, pyproject.toml, requirements.txt, and uv.lock, it forms the packaging and deployment layer that ensures the repo can be built reproducibly and exposed as an OpenEnv space.
11. The static UI is lightweight and auxiliary. server/homepage.html and static/tester.html provide a human-facing homepage and interactive tester, but they sit on top of the same API and do not contain the environment logic.
12. Tests are focused on environment behavior rather than frontend behavior. tests/test_environment.py and tests/conftest.py validate the server/environment contract, likely checking task resets, scoring, state transitions, and deterministic outputs.
13. From an architecture-diagram perspective, the key flow is: client or agent submits an action → FastAPI route in server/app.py → environment logic in server/environment.py → SQLite query execution against seeded data → grader computes reward and diagnostics → observation returned to the client. Optional branches include hinting, curriculum progression, and batch evaluation.
14. The important boundary in this repo is that all “world state” is inside the environment process: task state, episode history, scoring, and the database. External systems are only used by tooling around the environment, such as inference scripts or deployment platforms.
Main entry points: app.py API server · environment.py Environment · validate_submission.py Submission check · inference.py Baseline runner
Components 16
Runtime
Live environment service and its core execution path
- API server · HTTP boundary exposing the environment endpoints
server/app.py - Environment · Episode state, task flow, query execution, scoring, and observations
server/environment.py
Data & rules
Seeded database, tasks, and grading logic
- Seed DB · Customers, products, orders, items, and reviews seed data
server/db/seed.sql - Tasks · Task definitions, limits, thresholds, and curriculum metadata
server/tasks/__init__.py - Graders · Deterministic task scoring and SQL analysis boundaries
server/graders/__init__.py - Models · Shared request, response, and analytics schemas
models.py
Tooling
Client, evaluation, packaging, and submission support
- Client SDK · Convenience wrapper around the HTTP environment API
client.py - Baseline runner · Runs model-driven SQL repair against the environment
inference.py - Submission check · Verifies submission contract and packaging expectations
validate_submission.py - OpenEnv spec · Environment metadata for packaging and platform integration
openenv.yaml - Container build · Containerization entry for the service runtime
Dockerfile - Python deps · Reproducible dependency and lockfile set
pyproject.toml
UI & tests
Lightweight web UI and behavioral tests
- Homepage · Human-facing landing page for the service
server/homepage.html - Tester UI · Interactive browser tester layered on the API
static/tester.html - Env tests · Validates environment resets, scoring, and state transitions
tests/test_environment.py - Test setup · Shared fixtures for environment behavior tests
tests/conftest.py
Connections 16
- Client SDK → API server: calls API · Client submits reset, step, and related requests to the service
- API server → Environment: delegates · Routes HTTP actions into environment orchestration
- Environment → Seed DB: executes SQL · Runs agent queries against the seeded SQLite dataset
- Environment → Tasks: selects task · Loads task configuration and episode metadata
- Environment → Graders: scores · Computes reward and diagnostics for submitted SQL
- Environment → Models: uses schemas · Produces and consumes typed actions and observations
- API server → Models: serializes · HTTP layer exposes typed payloads to clients
- Baseline runner → Client SDK: uses SDK · Runner interacts with the environment through the client wrapper
- Baseline runner → API server: drives eval · Baseline evaluation ultimately exercises the API
- Submission check → OpenEnv spec: checks spec · Submission validation uses the OpenEnv contract metadata
- Submission check → Container build: verifies build · Ensures the packaged runtime can be built and shipped
- Submission check → Python deps: verifies deps · Checks reproducible dependency configuration
- Env tests → Environment: tests behavior · Exercises environment semantics and deterministic outcomes
- Env tests → Test setup: uses fixtures · Shares setup for environment state and test resources
- API server → Homepage: serves page · Exposes the lightweight homepage from the API service
- API server → Tester UI: serves UI · Provides the interactive tester as a thin client-facing layer