Spaces:
Paused
Phase 11.5: Gradio dashboard at /dashboard (now the Space's base_path)
Browse filesserver/app.py: mounts a Gradio Blocks app at /dashboard via
gr.mount_gradio_app, leaving OpenEnv's API routes (/reset, /step,
/state, /ws) and the bundled playground at /web untouched.
The dashboard surfaces:
- Task inventory stats (4 cards)
- Leaderboard (5 models ร 7 columns); pending runs render as 'โ'
- SFT training summary table
- Loss-curve comparison plot (4K vs 8K)
- Reward design + 4-layer anti-hacking defenses tables
- Trajectory collection pipeline explainer
- Custom-task upload demo: user uploads .docx/.xlsx/.pptx + an
instruction, we save the file and emit copy-pasteable inference
commands for both API-served and in-process LoRA paths. Live
agent runs aren't hosted (no LoRA endpoint in the Space) but the
demo communicates the full env workflow.
README.md frontmatter: base_path /web โ /dashboard so the Space
iframe lands on the Gradio dashboard. README body fully rewritten:
hero results table including all 5 models, embedded loss-curve plot,
SFT training journey, training-log locations (HF Job IDs + local
artifact paths), Phase-by-Phase change log pointer.
pyproject.toml + Dockerfile: gradio>=5.0.0 added to deps.
Tested locally โ Gradio 6.x compat confirmed, no deprecation warnings,
no resource leaks from our code.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Dockerfile +2 -1
- README.md +161 -102
- pyproject.toml +1 -0
- server/app.py +401 -2
|
@@ -23,7 +23,8 @@ RUN uv pip install --system --no-cache-dir \
|
|
| 23 |
"python-docx>=1.1.0" \
|
| 24 |
"python-pptx>=1.0.0" \
|
| 25 |
"rapidfuzz>=3.0.0" \
|
| 26 |
-
"Pillow>=10.0.0"
|
|
|
|
| 27 |
|
| 28 |
COPY . /app/env/
|
| 29 |
|
|
|
|
| 23 |
"python-docx>=1.1.0" \
|
| 24 |
"python-pptx>=1.0.0" \
|
| 25 |
"rapidfuzz>=3.0.0" \
|
| 26 |
+
"Pillow>=10.0.0" \
|
| 27 |
+
"gradio>=5.0.0"
|
| 28 |
|
| 29 |
COPY . /app/env/
|
| 30 |
|
|
@@ -6,7 +6,7 @@ colorTo: blue
|
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
app_port: 8000
|
| 9 |
-
base_path: /
|
| 10 |
tags:
|
| 11 |
- openenv
|
| 12 |
- agent-environment
|
|
@@ -23,14 +23,14 @@ An [OpenEnv](https://github.com/meta-pytorch/OpenEnv) **code-execution
|
|
| 23 |
environment** for training and evaluating LLM agents on **real-world office
|
| 24 |
document work** โ Excel spreadsheets, Word documents, and PowerPoint decks.
|
| 25 |
The agent writes Python code (`openpyxl` / `python-docx` / `python-pptx`)
|
| 26 |
-
to read or modify authentic enterprise files
|
| 27 |
**multi-layer, gaming-resistant** scoring stack.
|
| 28 |
|
| 29 |
-
> 119 tasks across 3 file formats
|
| 30 |
> [Finch (FinWorkBench)](https://huggingface.co/datasets/FinWorkBench/Finch),
|
| 31 |
> [OSWorld-Verified](https://github.com/xlang-ai/OSWorld), and
|
| 32 |
-
> [PPTArena](https://github.com/michaelofengend/PPTArena)
|
| 33 |
-
> grading
|
| 34 |
|
| 35 |
---
|
| 36 |
|
|
@@ -50,10 +50,13 @@ Did its structural distance to the gold reference actually decrease? Final
|
|
| 50 |
grade is a 2- or 3-layer composition: validity gate + structural diff +
|
| 51 |
(for docx) the per-task evaluator from OSWorld.
|
| 52 |
|
| 53 |
-
**
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
---
|
| 59 |
|
|
@@ -61,27 +64,59 @@ A small 3B trainable target (Qwen2.5-Coder-3B-Instruct) gets **0.002 avg
|
|
| 61 |
|
| 62 |
| Model | Avg score | Success rate | xlsx (n=10) | docx (n=4) | pptx (n=8) |
|
| 63 |
|---|---|---|---|---|---|
|
| 64 |
-
| **MiniMaxAI/MiniMax-M2.1** (frontier baseline) |
|
| 65 |
-
| **
|
| 66 |
-
| **
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
Reproduce:
|
| 69 |
|
| 70 |
```bash
|
| 71 |
-
#
|
| 72 |
python inference.py --split eval --model MiniMaxAI/MiniMax-M2.1 \
|
| 73 |
--output-dir runs/baseline_minimax_m21_eval
|
| 74 |
|
| 75 |
-
#
|
| 76 |
-
python
|
| 77 |
-
--
|
|
|
|
| 78 |
```
|
| 79 |
|
| 80 |
-
Per-task breakdown lives in `runs/<dir>/summary.csv`
|
| 81 |
trajectories in `runs/<dir>/trajectories/<task_id>.jsonl`.
|
| 82 |
|
| 83 |
---
|
| 84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
## Task inventory (119 total)
|
| 86 |
|
| 87 |
| Family | Source | Train | Eval | Total | What it tests |
|
|
@@ -110,7 +145,7 @@ reset(task_id="finch_10")
|
|
| 110 |
step(action_type="code", content="...") # 0โ15 of these
|
| 111 |
โ subprocess runs the code, returns stdout/stderr
|
| 112 |
โ env measures: did the file change? is it still valid? did it move toward gold?
|
| 113 |
-
โ reward = 0.005โ0.10 (dense process reward
|
| 114 |
|
| 115 |
step(action_type="submit_file", content="<path>") # ends episode
|
| 116 |
โ multi-layer grading
|
|
@@ -118,64 +153,58 @@ step(action_type="submit_file", content="<path>") # ends episode
|
|
| 118 |
```
|
| 119 |
|
| 120 |
Three action types: `"code"` (Python), `"submit"` (text answer for QA tasks),
|
| 121 |
-
`"submit_file"` (path to a modified file).
|
|
|
|
|
|
|
| 122 |
|
| 123 |
---
|
| 124 |
|
| 125 |
## Reward design
|
| 126 |
|
| 127 |
-
|
| 128 |
-
explicitly calls out reward hacking as a top failure mode. Two layers, both
|
| 129 |
-
designed for *spec-aligned* signal.
|
| 130 |
|
| 131 |
### Per-step process reward (6 components, capped at 0.10/step)
|
| 132 |
|
| 133 |
-
|
| 134 |
-
from real file state โ not regex on the agent's code:
|
| 135 |
-
|
| 136 |
-
| Signal | Range | What it actually checks |
|
| 137 |
|---|---|---|
|
| 138 |
-
| `exec_health` | 0โ0.020 | Subprocess
|
| 139 |
-
| `lib_engagement` | 0โ0.010 | Code uses the family's expected library
|
| 140 |
-
| `mutation` | 0โ0.030 | SHA-256 of
|
| 141 |
-
| `validity` | 0โ0.020 | Mutated file still parses with the family's loader
|
| 142 |
-
| `progress` | 0โ0.040 | Structural distance to gold *decreased*
|
| 143 |
-
| `eval_check` | 0โ0.020 | Per-task evaluator score *increased* (docx-only
|
| 144 |
|
| 145 |
`progress` and `eval_check` give RL a dense gradient *toward correctness*,
|
| 146 |
-
not just "code ran". They're disabled at eval time
|
| 147 |
-
to keep the benchmark honest.
|
| 148 |
|
| 149 |
### Final grade (per family)
|
| 150 |
|
| 151 |
| Family | Layer 1 (gate) | Layer 2 | Layer 3 |
|
| 152 |
|---|---|---|---|
|
| 153 |
-
| `xlsx` |
|
| 154 |
-
| `docx` | python-docx parse | 40% paragraph diff | 60% per-task OSWorld evaluator (`compare_docx_files`, `check_tabstops`,
|
| 155 |
-
| `pptx` | python-pptx parse | 20% slide-count | 80% avg per-shape composite: 40% text + 20% style + 20% position + 20% size |
|
| 156 |
|
| 157 |
-
The `docx` 3rd layer is a port of OSWorld's
|
|
|
|
| 158 |
(Apache-2.0). 16 evaluator functions, including compound `or` (multi-gold)
|
| 159 |
-
and `and` (all-must-pass) checks.
|
| 160 |
-
uniform `{conj, checks: [...]}` schema.
|
| 161 |
|
| 162 |
-
### Anti-hacking defenses
|
| 163 |
|
| 164 |
-
|
| 165 |
-
|
| 166 |
|
| 167 |
-
|
|
| 168 |
-
|---|---|
|
| 169 |
-
|
|
| 170 |
-
|
|
| 171 |
-
| **
|
| 172 |
-
|
|
| 173 |
-
| `lib_engagement` regex gaming | Capped at 0.010/step โ trivially bounded |
|
| 174 |
-
| `mutation` spam (save garbage) | Capped, and the `progress`/`eval_check` signals dwarf it on real edits |
|
| 175 |
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
See [edits.md](edits.md) for the full audit.
|
| 179 |
|
| 180 |
---
|
| 181 |
|
|
@@ -185,7 +214,7 @@ See [edits.md](edits.md) for the full audit.
|
|
| 185 |
|
| 186 |
| Field | Type | Description |
|
| 187 |
|---|---|---|
|
| 188 |
-
| `action_type` | `str` | `"code"`
|
| 189 |
| `content` | `str` | Code, answer text, or absolute file path |
|
| 190 |
|
| 191 |
### `FinancialObservation`
|
|
@@ -194,12 +223,12 @@ See [edits.md](edits.md) for the full audit.
|
|
| 194 |
|---|---|---|
|
| 195 |
| `task_id` | `str` | e.g. `finch_10`, `osworld_0a0faba3`, `pptarena_case_60_fix_text_placement` |
|
| 196 |
| `task_description` | `str` | Instruction + constraints + source-file summary |
|
| 197 |
-
| `source_file` | `str` | Path to the working file (
|
| 198 |
| `task_type` | `str` | `"QA"` or `"MODIFY"` |
|
| 199 |
-
| `feedback` | `str` | Stdout/stderr of code, or grading explanation. Includes the per-step reward decomposition
|
| 200 |
| `current_step` / `max_steps` | `int` | 0โ15 |
|
| 201 |
| `done` | `bool` | Episode finished |
|
| 202 |
-
| `reward` | `float` | Step or final reward
|
| 203 |
|
| 204 |
---
|
| 205 |
|
|
@@ -209,7 +238,7 @@ See [edits.md](edits.md) for the full audit.
|
|
| 209 |
|
| 210 |
- Python 3.10+
|
| 211 |
- Docker (for HF Space deployment)
|
| 212 |
-
- LLM API key (for `inference.py`)
|
| 213 |
|
| 214 |
### Local dev
|
| 215 |
|
|
@@ -219,7 +248,7 @@ PYTHONPATH=. uvicorn server.app:app --host 0.0.0.0 --port 8000 \
|
|
| 219 |
--ws-ping-interval 600 --ws-ping-timeout 600 --reload
|
| 220 |
```
|
| 221 |
|
| 222 |
-
### Run a baseline
|
| 223 |
|
| 224 |
```bash
|
| 225 |
export HF_TOKEN="hf_..."
|
|
@@ -231,23 +260,57 @@ python inference.py \
|
|
| 231 |
--task-timeout 900
|
| 232 |
```
|
| 233 |
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
-
|
| 239 |
-
-
|
| 240 |
-
|
|
|
|
|
|
|
| 241 |
|
| 242 |
-
|
| 243 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
|
| 245 |
### Re-pull data from upstream sources
|
| 246 |
|
| 247 |
```bash
|
| 248 |
-
python data_pipeline/finch_pull.py
|
| 249 |
-
python data_pipeline/osworld_writer_pull.py
|
| 250 |
-
python data_pipeline/pptarena_pull.py --root /path/to/PPTArena-main
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
```
|
| 252 |
|
| 253 |
### Docker
|
|
@@ -257,9 +320,6 @@ docker build -t office-task-env:latest .
|
|
| 257 |
docker run -p 8000:8000 office-task-env:latest
|
| 258 |
```
|
| 259 |
|
| 260 |
-
The provided [`Dockerfile`](Dockerfile) installs `openpyxl`, `python-docx`,
|
| 261 |
-
`python-pptx`, `rapidfuzz`, and `Pillow`.
|
| 262 |
-
|
| 263 |
---
|
| 264 |
|
| 265 |
## Project structure
|
|
@@ -268,48 +328,43 @@ The provided [`Dockerfile`](Dockerfile) installs `openpyxl`, `python-docx`,
|
|
| 268 |
.
|
| 269 |
โโโ data/
|
| 270 |
โ โโโ manifest.jsonl # 109 rows: 50 Finch + 21 OSWorld + 38 PPTArena
|
|
|
|
| 271 |
โ โโโ 0/, 21/, โฆ # 10 hand-curated xlsx tasks
|
| 272 |
โ โโโ finch_50/<id>/{src,ref}.xlsx
|
| 273 |
โ โโโ osworld_writer/<uuid>/<src + N gold>.docx
|
| 274 |
โ โโโ pptarena/<slug>/{src,ref}.pptx
|
| 275 |
-
โโโ data_pipeline/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
โโโ graders/
|
| 277 |
โ โโโ __init__.py # grade_xlsx + grade_docx + grade_pptx
|
| 278 |
โ โโโ docx_metrics.py # 16 ported OSWorld evaluators
|
| 279 |
โโโ server/
|
| 280 |
-
โ โโโ financial_environment.py # OpenEnv environment + gold-stash
|
| 281 |
โ โโโ app.py # FastAPI + WebSocket
|
| 282 |
โโโ rewards.py # 6-component RewardTracker
|
| 283 |
-
โโโ tasks.py # Manifest loader
|
| 284 |
-
โโโ inference.py #
|
| 285 |
-
โโโ
|
| 286 |
-
|
|
|
|
|
|
|
| 287 |
```
|
| 288 |
|
| 289 |
---
|
| 290 |
|
| 291 |
-
## What's next (training pipeline โ in progress)
|
| 292 |
-
|
| 293 |
-
Per the budget plan in [edits.md](edits.md) (~$45 on HF Jobs):
|
| 294 |
-
|
| 295 |
-
1. Run a teacher (Claude Haiku 4.5) on the 97 train tasks, filter by score
|
| 296 |
-
2. SFT-warm-start `Qwen2.5-Coder-3B-Instruct` with LoRA on filtered trajectories (Unsloth, ~$10 on 1ร A100 80GB)
|
| 297 |
-
3. GRPO continued training with rollouts hitting this env in-process (~$30, 12h on the same GPU)
|
| 298 |
-
4. Re-eval on the 22-task split โ before/after plot
|
| 299 |
-
|
| 300 |
-
The trajectory persistence in `runs/<dir>/trajectories/*.jsonl` doubles as
|
| 301 |
-
the SFT corpus format โ `(messages, completion)` pairs ready for
|
| 302 |
-
`SFTTrainer`.
|
| 303 |
-
|
| 304 |
-
---
|
| 305 |
-
|
| 306 |
## Round-1 โ Round-2 change log
|
| 307 |
|
| 308 |
-
The
|
| 309 |
-
|
| 310 |
[`edits.md`](edits.md): manifest loader, RewardTracker, OSWorld docx port,
|
| 311 |
PPTArena ingest, layout+style-aware pptx grader, gold-stash hardening,
|
| 312 |
-
inference v2
|
|
|
|
| 313 |
|
| 314 |
---
|
| 315 |
|
|
@@ -321,7 +376,11 @@ inference v2.
|
|
| 321 |
docx tasks and the evaluator functions in `graders/docx_metrics.py` (Apache-2.0)
|
| 322 |
- **PPTArena** ([repo](https://github.com/michaelofengend/PPTArena)) โ the
|
| 323 |
pptx tasks and the `evaluation_pairs_refined.json` schema
|
| 324 |
-
- **
|
|
|
|
|
|
|
|
|
|
|
|
|
| 325 |
|
| 326 |
If you use this environment in research, please cite the upstream datasets:
|
| 327 |
|
|
@@ -332,4 +391,4 @@ If you use this environment in research, please cite the upstream datasets:
|
|
| 332 |
journal={arXiv preprint arXiv:2512.13168},
|
| 333 |
year={2025}
|
| 334 |
}
|
| 335 |
-
```
|
|
|
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
app_port: 8000
|
| 9 |
+
base_path: /dashboard
|
| 10 |
tags:
|
| 11 |
- openenv
|
| 12 |
- agent-environment
|
|
|
|
| 23 |
environment** for training and evaluating LLM agents on **real-world office
|
| 24 |
document work** โ Excel spreadsheets, Word documents, and PowerPoint decks.
|
| 25 |
The agent writes Python code (`openpyxl` / `python-docx` / `python-pptx`)
|
| 26 |
+
to read or modify authentic enterprise files and gets graded by a
|
| 27 |
**multi-layer, gaming-resistant** scoring stack.
|
| 28 |
|
| 29 |
+
> 119 tasks across 3 file formats ยท 22-task eval split ยท Real artifacts from
|
| 30 |
> [Finch (FinWorkBench)](https://huggingface.co/datasets/FinWorkBench/Finch),
|
| 31 |
> [OSWorld-Verified](https://github.com/xlang-ai/OSWorld), and
|
| 32 |
+
> [PPTArena](https://github.com/michaelofengend/PPTArena) ยท Multi-layer
|
| 33 |
+
> grading + four independent reward-hacking defenses.
|
| 34 |
|
| 35 |
---
|
| 36 |
|
|
|
|
| 50 |
grade is a 2- or 3-layer composition: validity gate + structural diff +
|
| 51 |
(for docx) the per-task evaluator from OSWorld.
|
| 52 |
|
| 53 |
+
**Training pipeline.** Kimi-K2.5 (the teacher) ran on the 97 training tasks
|
| 54 |
+
to produce trajectories; we filtered them with a defense-in-depth pipeline
|
| 55 |
+
(score โฅ 0.4, more than 1 step, never `1-step submit_file`) into a 53-trajectory
|
| 56 |
+
SFT corpus. Qwen2.5-Coder-3B-Instruct (the student) was warm-started with
|
| 57 |
+
LoRA on this corpus across two configs (4K and 8K context) โ both runs
|
| 58 |
+
logged on HF Jobs L40S, ~$0.50โ0.80 each. The 8K run is online at
|
| 59 |
+
[bpHigh/qwen3b-office-sft-kimi-long](https://huggingface.co/bpHigh/qwen3b-office-sft-kimi-long).
|
| 60 |
|
| 61 |
---
|
| 62 |
|
|
|
|
| 64 |
|
| 65 |
| Model | Avg score | Success rate | xlsx (n=10) | docx (n=4) | pptx (n=8) |
|
| 66 |
|---|---|---|---|---|---|
|
| 67 |
+
| **MiniMaxAI/MiniMax-M2.1** (frontier baseline) | 0.390 | 41% | 0.293 | 0.445 | 0.485 |
|
| 68 |
+
| **moonshotai/Kimi-K2.5** (teacher) | 0.481 | 52% | 0.370 | 0.472 | 0.673 |
|
| 69 |
+
| **Qwen/Qwen2.5-Coder-3B-Instruct** (student baseline) | **0.001** | 0% | 0.001 | 0.001 | 0.001 |
|
| 70 |
+
| **Qwen3-Coder-3B + LoRA SFT (4K)** *(eval pending)* | *coming* | *coming* | โ | โ | โ |
|
| 71 |
+
| **Qwen3-Coder-3B + LoRA SFT (8K)** *(eval pending)* | *coming* | *coming* | โ | โ | โ |
|
| 72 |
|
| 73 |
+
Reproduce any row:
|
| 74 |
|
| 75 |
```bash
|
| 76 |
+
# Hosted models via HF Router
|
| 77 |
python inference.py --split eval --model MiniMaxAI/MiniMax-M2.1 \
|
| 78 |
--output-dir runs/baseline_minimax_m21_eval
|
| 79 |
|
| 80 |
+
# In-process LoRA eval (no hosted endpoint needed)
|
| 81 |
+
python eval_lora.py \
|
| 82 |
+
--adapters bpHigh/qwen3b-office-sft-kimi,bpHigh/qwen3b-office-sft-kimi-long \
|
| 83 |
+
--split eval --output-dir runs/sft_eval
|
| 84 |
```
|
| 85 |
|
| 86 |
+
Per-task breakdown lives in `runs/<dir>/summary.csv`; full step-by-step
|
| 87 |
trajectories in `runs/<dir>/trajectories/<task_id>.jsonl`.
|
| 88 |
|
| 89 |
---
|
| 90 |
|
| 91 |
+
## SFT training run โ what the student saw
|
| 92 |
+
|
| 93 |
+
Student model: `Qwen/Qwen2.5-Coder-3B-Instruct`. LoRA r=32 on all-linear
|
| 94 |
+
targets, bf16, assistant-only loss masking. Two runs on 1ร L40S 48GB
|
| 95 |
+
($1.80/hr).
|
| 96 |
+
|
| 97 |
+

|
| 98 |
+
|
| 99 |
+
| | 4K context | 8K context |
|
| 100 |
+
|---|---|---|
|
| 101 |
+
| Hardware | L40S 48GB | L40S 48GB |
|
| 102 |
+
| Runtime | 198s | 354s |
|
| 103 |
+
| Loss start โ end | 0.412 โ 0.069 | 0.384 โ 0.103 |
|
| 104 |
+
| Final train_loss | 0.196 | 0.193 |
|
| 105 |
+
| Cost | ~$0.50 | ~$0.80 |
|
| 106 |
+
| Adapter | [bpHigh/qwen3b-office-sft-kimi](https://huggingface.co/bpHigh/qwen3b-office-sft-kimi) | [bpHigh/qwen3b-office-sft-kimi-long](https://huggingface.co/bpHigh/qwen3b-office-sft-kimi-long) |
|
| 107 |
+
|
| 108 |
+
The 8K curve has slightly higher end-loss because it sees the *long*
|
| 109 |
+
debugging trajectories from Kimi (5โ8 of 53 episodes get truncated at 4K).
|
| 110 |
+
Same convergence target, harder distribution โ which configuration generalizes
|
| 111 |
+
better is what the eval will tell us.
|
| 112 |
+
|
| 113 |
+
**Where the training logs live:**
|
| 114 |
+
- HF Jobs page (raw logs streamable): [Job 4K](https://huggingface.co/jobs/bpHigh/69ed74aed70108f37acdf4fc) ยท [Job 8K](https://huggingface.co/jobs/bpHigh/69ed7b51d2c8bd8662bceef4)
|
| 115 |
+
- Parsed metrics + plots: [`runs/sft_plots/`](runs/sft_plots/)
|
| 116 |
+
- Loss-curve generator: [`data_pipeline/analyze_sft_logs.py`](data_pipeline/analyze_sft_logs.py) (re-runnable on any HF Job ID)
|
| 117 |
+
|
| 118 |
+
---
|
| 119 |
+
|
| 120 |
## Task inventory (119 total)
|
| 121 |
|
| 122 |
| Family | Source | Train | Eval | Total | What it tests |
|
|
|
|
| 145 |
step(action_type="code", content="...") # 0โ15 of these
|
| 146 |
โ subprocess runs the code, returns stdout/stderr
|
| 147 |
โ env measures: did the file change? is it still valid? did it move toward gold?
|
| 148 |
+
โ reward = 0.005โ0.10 (dense process reward)
|
| 149 |
|
| 150 |
step(action_type="submit_file", content="<path>") # ends episode
|
| 151 |
โ multi-layer grading
|
|
|
|
| 153 |
```
|
| 154 |
|
| 155 |
Three action types: `"code"` (Python), `"submit"` (text answer for QA tasks),
|
| 156 |
+
`"submit_file"` (path to a modified file). **Submit is rejected on step 1** โ
|
| 157 |
+
the agent must execute code at least once before any submission is accepted
|
| 158 |
+
(see *Defenses* below).
|
| 159 |
|
| 160 |
---
|
| 161 |
|
| 162 |
## Reward design
|
| 163 |
|
| 164 |
+
Two layers, both designed for *spec-aligned* signal.
|
|
|
|
|
|
|
| 165 |
|
| 166 |
### Per-step process reward (6 components, capped at 0.10/step)
|
| 167 |
|
| 168 |
+
| Signal | Range | Measured from |
|
|
|
|
|
|
|
|
|
|
| 169 |
|---|---|---|
|
| 170 |
+
| `exec_health` | 0โ0.020 | Subprocess exit code; bonus if stdout non-empty |
|
| 171 |
+
| `lib_engagement` | 0โ0.010 | Code uses the family's expected library |
|
| 172 |
+
| `mutation` | 0โ0.030 | SHA-256 of working file changed |
|
| 173 |
+
| `validity` | 0โ0.020 | Mutated file still parses with the family's loader |
|
| 174 |
+
| `progress` | 0โ0.040 | Structural distance to gold *decreased* |
|
| 175 |
+
| `eval_check` | 0โ0.020 | Per-task evaluator score *increased* (docx-only) |
|
| 176 |
|
| 177 |
`progress` and `eval_check` give RL a dense gradient *toward correctness*,
|
| 178 |
+
not just "code ran". They're disabled at eval time
|
| 179 |
+
(`FINANCIAL_ENV_PROGRESS=0`) to keep the benchmark honest.
|
| 180 |
|
| 181 |
### Final grade (per family)
|
| 182 |
|
| 183 |
| Family | Layer 1 (gate) | Layer 2 | Layer 3 |
|
| 184 |
|---|---|---|---|
|
| 185 |
+
| `xlsx` | โ | 30% sheet-name match | 70% cell-level diff (2% numeric tolerance) |
|
| 186 |
+
| `docx` | python-docx parse + byte-equality refusal | 40% paragraph diff | 60% per-task OSWorld evaluator (`compare_docx_files`, `check_tabstops`, etc.) |
|
| 187 |
+
| `pptx` | python-pptx parse + byte-equality refusal | 20% slide-count | 80% avg per-shape composite: 40% text + 20% style + 20% position + 20% size |
|
| 188 |
|
| 189 |
+
The `docx` 3rd layer is a port of OSWorld's
|
| 190 |
+
[`metrics/docs.py`](https://github.com/xlang-ai/OSWorld/blob/main/desktop_env/evaluators/metrics/docs.py)
|
| 191 |
(Apache-2.0). 16 evaluator functions, including compound `or` (multi-gold)
|
| 192 |
+
and `and` (all-must-pass) checks.
|
|
|
|
| 193 |
|
| 194 |
+
### Anti-hacking defenses (4 independent layers)
|
| 195 |
|
| 196 |
+
A model attempting the [Kimi-K2.5 exploit](edits.md#phase-7--live-discovered-exploit--anti-exploit-fix)
|
| 197 |
+
(submit unmodified source on step 1, score 0.998) hits **all four** of:
|
| 198 |
|
| 199 |
+
| Layer | Phase | What it does |
|
| 200 |
+
|---|---|---|
|
| 201 |
+
| **Env action gate** | 9 | Refuses `submit_file` if no code step has been taken โ episode stays open for recovery |
|
| 202 |
+
| **Per-episode gold stash** | 4 | Gold files moved to `/tmp/oe_gold_<random>/` at episode start; restored on close. Defeats `glob('data/**/*Gold*')` searches |
|
| 203 |
+
| **Grader byte-equality refusal** | 7 | If submit's bytes match source bytes โ score=0.001 (unless task is OSWorld `infeasible`) |
|
| 204 |
+
| **SFT corpus filter** | 8 | Builder drops `n_steps==1 + submit_file` trajectories even at high score |
|
|
|
|
|
|
|
| 205 |
|
| 206 |
+
See [`edits.md`](edits.md) for the live story of how Kimi found the exploit
|
| 207 |
+
during eval and the 3 fixes that followed.
|
|
|
|
| 208 |
|
| 209 |
---
|
| 210 |
|
|
|
|
| 214 |
|
| 215 |
| Field | Type | Description |
|
| 216 |
|---|---|---|
|
| 217 |
+
| `action_type` | `str` | `"code"`, `"submit"`, `"submit_file"` |
|
| 218 |
| `content` | `str` | Code, answer text, or absolute file path |
|
| 219 |
|
| 220 |
### `FinancialObservation`
|
|
|
|
| 223 |
|---|---|---|
|
| 224 |
| `task_id` | `str` | e.g. `finch_10`, `osworld_0a0faba3`, `pptarena_case_60_fix_text_placement` |
|
| 225 |
| `task_description` | `str` | Instruction + constraints + source-file summary |
|
| 226 |
+
| `source_file` | `str` | Path to the working file (per-episode tmpdir copy) |
|
| 227 |
| `task_type` | `str` | `"QA"` or `"MODIFY"` |
|
| 228 |
+
| `feedback` | `str` | Stdout/stderr of code, or grading explanation. Includes the per-step reward decomposition. |
|
| 229 |
| `current_step` / `max_steps` | `int` | 0โ15 |
|
| 230 |
| `done` | `bool` | Episode finished |
|
| 231 |
+
| `reward` | `float` | Step or final reward in (0.001, 0.999) |
|
| 232 |
|
| 233 |
---
|
| 234 |
|
|
|
|
| 238 |
|
| 239 |
- Python 3.10+
|
| 240 |
- Docker (for HF Space deployment)
|
| 241 |
+
- LLM API key (for `inference.py`) or HF Jobs subscription (for training)
|
| 242 |
|
| 243 |
### Local dev
|
| 244 |
|
|
|
|
| 248 |
--ws-ping-interval 600 --ws-ping-timeout 600 --reload
|
| 249 |
```
|
| 250 |
|
| 251 |
+
### Run a baseline against a hosted model
|
| 252 |
|
| 253 |
```bash
|
| 254 |
export HF_TOKEN="hf_..."
|
|
|
|
| 260 |
--task-timeout 900
|
| 261 |
```
|
| 262 |
|
| 263 |
+
### Run an in-process LoRA eval (no hosted endpoint needed)
|
| 264 |
+
|
| 265 |
+
```bash
|
| 266 |
+
python eval_lora.py \
|
| 267 |
+
--base-model Qwen/Qwen2.5-Coder-3B-Instruct \
|
| 268 |
+
--adapters bpHigh/qwen3b-office-sft-kimi,bpHigh/qwen3b-office-sft-kimi-long \
|
| 269 |
+
--split eval \
|
| 270 |
+
--output-dir runs/sft_eval
|
| 271 |
+
```
|
| 272 |
|
| 273 |
+
CLI flags worth knowing on `inference.py`:
|
| 274 |
+
- `--split {train,eval,all}`
|
| 275 |
+
- `--family {xlsx,docx,pptx,all}`
|
| 276 |
+
- `--task-ids id1,id2,โฆ` (overrides split/family)
|
| 277 |
+
- `--limit N`
|
| 278 |
+
- `--resume` โ merge new task results into an existing `--output-dir`
|
| 279 |
+
- `--skip-completed` โ re-run only failed/exploit tasks (paired with `--resume`)
|
| 280 |
|
| 281 |
### Re-pull data from upstream sources
|
| 282 |
|
| 283 |
```bash
|
| 284 |
+
python data_pipeline/finch_pull.py
|
| 285 |
+
python data_pipeline/osworld_writer_pull.py
|
| 286 |
+
python data_pipeline/pptarena_pull.py --root /path/to/PPTArena-main
|
| 287 |
+
```
|
| 288 |
+
|
| 289 |
+
### Build the SFT corpus
|
| 290 |
+
|
| 291 |
+
```bash
|
| 292 |
+
python data_pipeline/build_sft_corpus.py \
|
| 293 |
+
--runs runs/teacher_kimi_k25_train \
|
| 294 |
+
--output data/sft_kimi_k25.jsonl \
|
| 295 |
+
--score-threshold 0.4
|
| 296 |
+
```
|
| 297 |
+
|
| 298 |
+
### Train the student (HF Jobs)
|
| 299 |
+
|
| 300 |
+
```bash
|
| 301 |
+
hf jobs run --flavor l40sx1 --timeout 8h --secrets HF_TOKEN \
|
| 302 |
+
pytorch/pytorch:2.6.0-cuda12.4-cudnn9-devel \
|
| 303 |
+
bash -c "apt-get update -qq && apt-get install -y -qq git && \
|
| 304 |
+
git clone https://github.com/bp-high/openenv_financial_task_env.git /work && \
|
| 305 |
+
cd /work && \
|
| 306 |
+
pip install -U 'trl>=0.11' peft accelerate bitsandbytes && \
|
| 307 |
+
python train_sft.py \
|
| 308 |
+
--dataset data/sft_kimi_k25.jsonl \
|
| 309 |
+
--base-model Qwen/Qwen2.5-Coder-3B-Instruct \
|
| 310 |
+
--output-dir /tmp/qwen3b-sft \
|
| 311 |
+
--epochs 4 --gradient-accumulation 2 --lora-r 32 \
|
| 312 |
+
--max-seq-len 8192 \
|
| 313 |
+
--push-to-hub bpHigh/qwen3b-office-sft-kimi-long"
|
| 314 |
```
|
| 315 |
|
| 316 |
### Docker
|
|
|
|
| 320 |
docker run -p 8000:8000 office-task-env:latest
|
| 321 |
```
|
| 322 |
|
|
|
|
|
|
|
|
|
|
| 323 |
---
|
| 324 |
|
| 325 |
## Project structure
|
|
|
|
| 328 |
.
|
| 329 |
โโโ data/
|
| 330 |
โ โโโ manifest.jsonl # 109 rows: 50 Finch + 21 OSWorld + 38 PPTArena
|
| 331 |
+
โ โโโ sft_kimi_k25.jsonl # 53 filtered teacher trajectories
|
| 332 |
โ โโโ 0/, 21/, โฆ # 10 hand-curated xlsx tasks
|
| 333 |
โ โโโ finch_50/<id>/{src,ref}.xlsx
|
| 334 |
โ โโโ osworld_writer/<uuid>/<src + N gold>.docx
|
| 335 |
โ โโโ pptarena/<slug>/{src,ref}.pptx
|
| 336 |
+
โโโ data_pipeline/
|
| 337 |
+
โ โโโ finch_pull.py # Phase 1 โ Finch xlsx tasks
|
| 338 |
+
โ โโโ osworld_writer_pull.py # Phase 3 โ OSWorld docx tasks
|
| 339 |
+
โ โโโ pptarena_pull.py # Phase 5 โ PPTArena pptx tasks
|
| 340 |
+
โ โโโ build_sft_corpus.py # Phase 8 โ trajectories โ SFT JSONL
|
| 341 |
+
โ โโโ analyze_sft_logs.py # Phase 10.1 โ HF Job logs โ metrics + PNG
|
| 342 |
+
โ โโโ compare_sft_runs.py # overlay multiple SFT runs
|
| 343 |
โโโ graders/
|
| 344 |
โ โโโ __init__.py # grade_xlsx + grade_docx + grade_pptx
|
| 345 |
โ โโโ docx_metrics.py # 16 ported OSWorld evaluators
|
| 346 |
โโโ server/
|
| 347 |
+
โ โโโ financial_environment.py # OpenEnv environment + gold-stash + early-submit gate
|
| 348 |
โ โโโ app.py # FastAPI + WebSocket
|
| 349 |
โโโ rewards.py # 6-component RewardTracker
|
| 350 |
+
โโโ tasks.py # Manifest loader
|
| 351 |
+
โโโ inference.py # API-based eval (Router/Nebius/OpenAI)
|
| 352 |
+
โโโ eval_lora.py # In-process LoRA eval (no API needed)
|
| 353 |
+
โโโ train_sft.py # SFT trainer (TRL + PEFT, HF Jobs)
|
| 354 |
+
โโโ runs/ # Baseline + teacher + SFT artifacts (incl. plots)
|
| 355 |
+
โโโ edits.md # Full Round-1 โ Round-2 change log (10 phases)
|
| 356 |
```
|
| 357 |
|
| 358 |
---
|
| 359 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 360 |
## Round-1 โ Round-2 change log
|
| 361 |
|
| 362 |
+
The journey from the original 10-task xlsx-only env to today's 3-format /
|
| 363 |
+
119-task / multi-layer-graded env is documented phase-by-phase in
|
| 364 |
[`edits.md`](edits.md): manifest loader, RewardTracker, OSWorld docx port,
|
| 365 |
PPTArena ingest, layout+style-aware pptx grader, gold-stash hardening,
|
| 366 |
+
inference v2, anti-exploit defenses, SFT corpus builder, training script,
|
| 367 |
+
log analyzer, in-process LoRA eval.
|
| 368 |
|
| 369 |
---
|
| 370 |
|
|
|
|
| 376 |
docx tasks and the evaluator functions in `graders/docx_metrics.py` (Apache-2.0)
|
| 377 |
- **PPTArena** ([repo](https://github.com/michaelofengend/PPTArena)) โ the
|
| 378 |
pptx tasks and the `evaluation_pairs_refined.json` schema
|
| 379 |
+
- **Kimi-K2.5** (Moonshot AI, served via Nebius) โ the SFT teacher
|
| 380 |
+
- **Qwen2.5-Coder-3B-Instruct** (Alibaba Qwen team) โ the student model
|
| 381 |
+
- **TRL + PEFT + Unsloth + transformers** โ training stack
|
| 382 |
+
- **OpenEnv / Meta PyTorch** ([repo](https://github.com/meta-pytorch/OpenEnv)) โ host framework
|
| 383 |
+
- **Hugging Face Jobs** โ compute for SFT runs
|
| 384 |
|
| 385 |
If you use this environment in research, please cite the upstream datasets:
|
| 386 |
|
|
|
|
| 391 |
journal={arXiv preprint arXiv:2512.13168},
|
| 392 |
year={2025}
|
| 393 |
}
|
| 394 |
+
```
|
|
@@ -20,6 +20,7 @@ dependencies = [
|
|
| 20 |
"python-pptx>=1.0.0",
|
| 21 |
"rapidfuzz>=3.0.0",
|
| 22 |
"Pillow>=10.0.0",
|
|
|
|
| 23 |
]
|
| 24 |
|
| 25 |
[project.optional-dependencies]
|
|
|
|
| 20 |
"python-pptx>=1.0.0",
|
| 21 |
"rapidfuzz>=3.0.0",
|
| 22 |
"Pillow>=10.0.0",
|
| 23 |
+
"gradio>=5.0.0",
|
| 24 |
]
|
| 25 |
|
| 26 |
[project.optional-dependencies]
|
|
@@ -1,10 +1,31 @@
|
|
| 1 |
-
"""FastAPI application for the
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from openenv.core.env_server.http_server import create_app
|
| 4 |
|
| 5 |
from models import FinancialAction, FinancialObservation
|
| 6 |
from server.financial_environment import FinancialEnvironment
|
| 7 |
|
|
|
|
| 8 |
app = create_app(
|
| 9 |
FinancialEnvironment,
|
| 10 |
FinancialAction,
|
|
@@ -13,10 +34,388 @@ app = create_app(
|
|
| 13 |
)
|
| 14 |
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
def main() -> None:
|
| 17 |
"""Entry point for direct execution."""
|
| 18 |
import uvicorn
|
| 19 |
-
|
| 20 |
uvicorn.run(app, host="0.0.0.0", port=8000)
|
| 21 |
|
| 22 |
|
|
|
|
| 1 |
+
"""FastAPI application for the Office Document Task Environment.
|
| 2 |
|
| 3 |
+
Wraps OpenEnv's standard create_app() and mounts a Gradio dashboard at
|
| 4 |
+
``/dashboard``. The OpenEnv playground continues to live at ``/web``;
|
| 5 |
+
the dashboard is a project summary view with leaderboard, training
|
| 6 |
+
plots, and a file-upload preview for ad-hoc tasks.
|
| 7 |
+
|
| 8 |
+
Routes:
|
| 9 |
+
/web OpenEnv playground (baked-in)
|
| 10 |
+
/dashboard Gradio Blocks app โ leaderboard, plots, upload demo
|
| 11 |
+
/docs FastAPI docs (baked-in)
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
from __future__ import annotations
|
| 15 |
+
|
| 16 |
+
import json
|
| 17 |
+
import shutil
|
| 18 |
+
import tempfile
|
| 19 |
+
from pathlib import Path
|
| 20 |
+
from typing import Any, Dict, List, Optional, Tuple
|
| 21 |
+
|
| 22 |
+
import gradio as gr
|
| 23 |
from openenv.core.env_server.http_server import create_app
|
| 24 |
|
| 25 |
from models import FinancialAction, FinancialObservation
|
| 26 |
from server.financial_environment import FinancialEnvironment
|
| 27 |
|
| 28 |
+
|
| 29 |
app = create_app(
|
| 30 |
FinancialEnvironment,
|
| 31 |
FinancialAction,
|
|
|
|
| 34 |
)
|
| 35 |
|
| 36 |
|
| 37 |
+
# ---------------------------------------------------------------------------
|
| 38 |
+
# Dashboard data helpers
|
| 39 |
+
# ---------------------------------------------------------------------------
|
| 40 |
+
|
| 41 |
+
REPO_ROOT = Path(__file__).resolve().parent.parent
|
| 42 |
+
RUNS_DIR = REPO_ROOT / "runs"
|
| 43 |
+
PLOTS_DIR = RUNS_DIR / "sft_plots"
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def _load_results(run_dir: Path) -> Optional[Dict[str, Any]]:
|
| 47 |
+
p = run_dir / "results.json"
|
| 48 |
+
if not p.exists():
|
| 49 |
+
return None
|
| 50 |
+
try:
|
| 51 |
+
return json.loads(p.read_text())
|
| 52 |
+
except Exception:
|
| 53 |
+
return None
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def _leaderboard_rows() -> List[List[Any]]:
|
| 57 |
+
"""Each row: [Model, Kind, Avg, Success, xlsx, docx, pptx, n]. Pending
|
| 58 |
+
runs render as 'โ' so judges can see what's still missing."""
|
| 59 |
+
candidates = [
|
| 60 |
+
("MiniMaxAI/MiniMax-M2.1", "frontier baseline", "baseline_minimax_m21_eval"),
|
| 61 |
+
("moonshotai/Kimi-K2.5", "teacher", "baseline_kimi_k25_eval"),
|
| 62 |
+
("Qwen/Qwen2.5-Coder-3B-Instruct", "student baseline (vanilla)",
|
| 63 |
+
"baseline_qwen25coder3b_eval"),
|
| 64 |
+
("Qwen3B + LoRA SFT (4K)", "student trained, 4K context",
|
| 65 |
+
"sft_eval_v2/bpHigh_qwen3b-office-sft-kimi"),
|
| 66 |
+
("Qwen3B + LoRA SFT (8K)", "student trained, 8K context",
|
| 67 |
+
"sft_eval_v2/bpHigh_qwen3b-office-sft-kimi-long"),
|
| 68 |
+
]
|
| 69 |
+
|
| 70 |
+
def _f(v):
|
| 71 |
+
if v is None:
|
| 72 |
+
return "โ"
|
| 73 |
+
if isinstance(v, float):
|
| 74 |
+
return f"{v:.3f}"
|
| 75 |
+
return str(v)
|
| 76 |
+
|
| 77 |
+
def _pct(v):
|
| 78 |
+
if v is None:
|
| 79 |
+
return "โ"
|
| 80 |
+
return f"{v * 100:.0f}%"
|
| 81 |
+
|
| 82 |
+
rows = []
|
| 83 |
+
for label, kind, dirname in candidates:
|
| 84 |
+
d = RUNS_DIR / dirname
|
| 85 |
+
r = _load_results(d)
|
| 86 |
+
if r is None:
|
| 87 |
+
rows.append([label, kind, "โ", "โ", "โ", "โ", "โ", "โ"])
|
| 88 |
+
continue
|
| 89 |
+
bf = r.get("by_family", {})
|
| 90 |
+
rows.append([
|
| 91 |
+
label, kind,
|
| 92 |
+
_f(r.get("avg_score")),
|
| 93 |
+
_pct(r.get("success_rate")),
|
| 94 |
+
_f(bf.get("xlsx", {}).get("avg")),
|
| 95 |
+
_f(bf.get("docx", {}).get("avg")),
|
| 96 |
+
_f(bf.get("pptx", {}).get("avg")),
|
| 97 |
+
r.get("n_tasks", 0) or "โ",
|
| 98 |
+
])
|
| 99 |
+
return rows
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def _sft_summary_rows() -> List[List[Any]]:
|
| 103 |
+
"""Per-SFT-run table: [Run, Final Loss, Runtime, Epochs]."""
|
| 104 |
+
out = []
|
| 105 |
+
for sub, label in (("qwen3b_kimi", "4K context"),
|
| 106 |
+
("qwen3b_kimi_long", "8K context")):
|
| 107 |
+
p = PLOTS_DIR / sub / "summary.json"
|
| 108 |
+
if not p.exists():
|
| 109 |
+
continue
|
| 110 |
+
try:
|
| 111 |
+
data = json.loads(p.read_text())
|
| 112 |
+
except Exception:
|
| 113 |
+
continue
|
| 114 |
+
loss = data.get("train_loss")
|
| 115 |
+
rt = data.get("train_runtime")
|
| 116 |
+
out.append([
|
| 117 |
+
label,
|
| 118 |
+
f"{loss:.4f}" if isinstance(loss, (int, float)) else "โ",
|
| 119 |
+
f"{rt:.0f}s" if isinstance(rt, (int, float)) else "โ",
|
| 120 |
+
f"{data.get('epoch')}",
|
| 121 |
+
])
|
| 122 |
+
return out
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def _task_inventory() -> Dict[str, int]:
|
| 126 |
+
manifest = REPO_ROOT / "data" / "manifest.jsonl"
|
| 127 |
+
counts = {"xlsx": 10, "docx": 0, "pptx": 0}
|
| 128 |
+
if manifest.exists():
|
| 129 |
+
for line in manifest.read_text().splitlines():
|
| 130 |
+
line = line.strip()
|
| 131 |
+
if not line:
|
| 132 |
+
continue
|
| 133 |
+
try:
|
| 134 |
+
row = json.loads(line)
|
| 135 |
+
fam = row.get("family", "xlsx")
|
| 136 |
+
counts[fam] = counts.get(fam, 0) + 1
|
| 137 |
+
except Exception:
|
| 138 |
+
pass
|
| 139 |
+
return counts
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def _comparison_plot_path() -> Optional[str]:
|
| 143 |
+
p = PLOTS_DIR / "comparison_4k_vs_8k.png"
|
| 144 |
+
return str(p) if p.exists() else None
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
def _per_run_plot(run: str) -> Optional[str]:
|
| 148 |
+
p = PLOTS_DIR / run / "sft_loss_curve.png"
|
| 149 |
+
return str(p) if p.exists() else None
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
# ---------------------------------------------------------------------------
|
| 153 |
+
# File upload handler
|
| 154 |
+
# ---------------------------------------------------------------------------
|
| 155 |
+
|
| 156 |
+
UPLOAD_DIR = Path(tempfile.gettempdir()) / "openenv_uploads"
|
| 157 |
+
UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
|
| 158 |
+
SUPPORTED_EXTS = {".xlsx", ".docx", ".pptx"}
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
def handle_upload(file_obj, instruction: str):
|
| 162 |
+
"""Accept a user-uploaded office document + task description. We don't
|
| 163 |
+
run an agent (no hosted LoRA), but we save the file and emit a copy-pasteable
|
| 164 |
+
inference command the user can run locally โ making the demo useful without
|
| 165 |
+
needing a model endpoint live in the Space.
|
| 166 |
+
"""
|
| 167 |
+
if file_obj is None:
|
| 168 |
+
return ("โ ๏ธ Please upload a .xlsx / .docx / .pptx file first.", "", None)
|
| 169 |
+
|
| 170 |
+
src_path = Path(file_obj.name if hasattr(file_obj, "name") else file_obj)
|
| 171 |
+
ext = src_path.suffix.lower()
|
| 172 |
+
if ext not in SUPPORTED_EXTS:
|
| 173 |
+
return (f"โ ๏ธ Unsupported extension `{ext}`. "
|
| 174 |
+
f"Need one of: {', '.join(sorted(SUPPORTED_EXTS))}", "", None)
|
| 175 |
+
|
| 176 |
+
family = ext.lstrip(".")
|
| 177 |
+
instruction = (instruction or "").strip()
|
| 178 |
+
if not instruction:
|
| 179 |
+
return ("โ ๏ธ Add a task instruction (e.g., 'center the title on slide 1').",
|
| 180 |
+
"", None)
|
| 181 |
+
|
| 182 |
+
# Save to upload dir with original-ish filename
|
| 183 |
+
dest = UPLOAD_DIR / f"user_{src_path.stem}{ext}"
|
| 184 |
+
try:
|
| 185 |
+
shutil.copy2(src_path, dest)
|
| 186 |
+
except Exception as e:
|
| 187 |
+
return (f"โ ๏ธ Couldn't save upload: {e}", "", None)
|
| 188 |
+
|
| 189 |
+
# Tell the user how to use it. Since the Space can't run their fine-tuned
|
| 190 |
+
# model live (no hosted LoRA endpoint), we produce instructions for two
|
| 191 |
+
# paths: (a) hit the Space's HTTP API with their own model, or (b) run
|
| 192 |
+
# eval_lora.py locally against an uploaded one-off task.
|
| 193 |
+
summary = (
|
| 194 |
+
f"โ
Saved `{dest.name}` ({dest.stat().st_size:,} bytes)\n\n"
|
| 195 |
+
f"**Detected family**: `{family}` ยท **Task**: \"{instruction[:120]}\""
|
| 196 |
+
)
|
| 197 |
+
|
| 198 |
+
api_snippet = f"""# Option A โ hit the env API directly with your own LLM
|
| 199 |
+
# (the Space's playground at /web works for one-off interactive runs)
|
| 200 |
+
|
| 201 |
+
# Option B โ register as an ad-hoc task locally + run inference.py
|
| 202 |
+
git clone https://github.com/bp-high/openenv_financial_task_env.git
|
| 203 |
+
cd openenv_financial_task_env
|
| 204 |
+
mkdir -p data/user_uploads/my_task
|
| 205 |
+
cp /path/to/your/{src_path.name} data/user_uploads/my_task/source{ext}
|
| 206 |
+
|
| 207 |
+
# Add this row to data/manifest.jsonl:
|
| 208 |
+
echo '{{"id": "user_my_task", "family": "{family}", "origin": "user_upload",
|
| 209 |
+
"split": "eval", "primary_tag": "user", "all_tags": ["user"],
|
| 210 |
+
"business_type": "user_upload",
|
| 211 |
+
"instruction": "{instruction}",
|
| 212 |
+
"constraints": "",
|
| 213 |
+
"source_file": "data/user_uploads/my_task/source{ext}",
|
| 214 |
+
"reference_file": "",
|
| 215 |
+
"task_type": "MODIFY", "max_steps": 15}}' >> data/manifest.jsonl
|
| 216 |
+
|
| 217 |
+
# Run inference against your task with any HF Router model:
|
| 218 |
+
python inference.py --task-ids user_my_task \\
|
| 219 |
+
--model moonshotai/Kimi-K2.5 \\
|
| 220 |
+
--api-base https://api.tokenfactory.us-central1.nebius.com/v1/
|
| 221 |
+
|
| 222 |
+
# OR run our SFT'd Qwen3B against it (no API needed):
|
| 223 |
+
python eval_lora.py --task-ids user_my_task \\
|
| 224 |
+
--adapters bpHigh/qwen3b-office-sft-kimi-long
|
| 225 |
+
"""
|
| 226 |
+
return summary, api_snippet, str(dest)
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
# ---------------------------------------------------------------------------
|
| 230 |
+
# Build the Gradio dashboard
|
| 231 |
+
# ---------------------------------------------------------------------------
|
| 232 |
+
|
| 233 |
+
INTRO_MD = """\
|
| 234 |
+
# ๐ Office Document Task Environment
|
| 235 |
+
|
| 236 |
+
Cross-format RL environment โ **Excel ยท Word ยท PowerPoint** โ
|
| 237 |
+
119 tasks, real enterprise artifacts, gaming-resistant grading,
|
| 238 |
+
SFT'd Qwen3-3B student.
|
| 239 |
+
|
| 240 |
+
[๐ฎ OpenEnv Playground](/web) ยท
|
| 241 |
+
[๐ฆ GitHub](https://github.com/bp-high/openenv_financial_task_env) ยท
|
| 242 |
+
[๐ค SFT Adapter (8K)](https://huggingface.co/bpHigh/qwen3b-office-sft-kimi-long) ยท
|
| 243 |
+
[๐ค SFT Adapter (4K)](https://huggingface.co/bpHigh/qwen3b-office-sft-kimi) ยท
|
| 244 |
+
[๐ API docs](/docs)
|
| 245 |
+
"""
|
| 246 |
+
|
| 247 |
+
REWARD_MD = """\
|
| 248 |
+
Every per-step reward measured from **real file state**, not regex on the
|
| 249 |
+
agent's code:
|
| 250 |
+
|
| 251 |
+
| Signal | Range | What it actually checks |
|
| 252 |
+
|---|---|---|
|
| 253 |
+
| `exec_health` | 0โ0.020 | Subprocess exit code 0; bonus if stdout non-empty |
|
| 254 |
+
| `lib_engagement` | 0โ0.010 | Code uses the family's expected library |
|
| 255 |
+
| `mutation` | 0โ0.030 | SHA-256 of working file changed since last step |
|
| 256 |
+
| `validity` | 0โ0.020 | Mutated file still parses |
|
| 257 |
+
| `progress` | 0โ0.040 | Structural distance to gold *decreased* |
|
| 258 |
+
| `eval_check` | 0โ0.020 | Per-task evaluator score *increased* (docx-only) |
|
| 259 |
+
"""
|
| 260 |
+
|
| 261 |
+
DEFENSES_MD = """\
|
| 262 |
+
A model trying to game the grader (e.g., submit unmodified source on step 1)
|
| 263 |
+
has to defeat **four independent defenses**:
|
| 264 |
+
|
| 265 |
+
| Layer | Phase | What it does |
|
| 266 |
+
|---|---|---|
|
| 267 |
+
| Env action gate | 9 | Refuses `submit_file` if no code step has been taken |
|
| 268 |
+
| Per-episode gold stash | 4 | Gold files moved to `/tmp/oe_gold_<random>/` at episode start |
|
| 269 |
+
| Grader byte-equality | 7 | If submit's bytes match source bytes โ score=0.001 |
|
| 270 |
+
| SFT corpus filter | 8 | Builder drops `n_steps==1 + submit_file` trajectories at any score |
|
| 271 |
+
|
| 272 |
+
Live story of how Kimi-K2.5 found this exploit during eval and the 3 fixes
|
| 273 |
+
that followed: [edits.md Phase 7](https://github.com/bp-high/openenv_financial_task_env/blob/main/edits.md#phase-7--live-discovered-exploit--anti-exploit-fix).
|
| 274 |
+
"""
|
| 275 |
+
|
| 276 |
+
PIPELINE_MD = """\
|
| 277 |
+
The student SFT corpus came from **Kimi-K2.5** (the teacher) running on the
|
| 278 |
+
97 train tasks. Trajectories were filtered through 6 layers before landing
|
| 279 |
+
in the corpus:
|
| 280 |
+
|
| 281 |
+
1. error column non-empty โ drop
|
| 282 |
+
2. `n_steps < 2` โ drop
|
| 283 |
+
3. **1-step `submit_file`** โ drop *(defense-in-depth โ even at high score)*
|
| 284 |
+
4. `final_score < 0.4` โ drop
|
| 285 |
+
5. malformed action_type โ drop
|
| 286 |
+
6. no successful code step โ drop
|
| 287 |
+
|
| 288 |
+
**97 raw โ 53 SFT examples** (avg score 0.841, avg 7.7 steps).
|
| 289 |
+
Builder: `data_pipeline/build_sft_corpus.py`.
|
| 290 |
+
"""
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
def build_dashboard() -> gr.Blocks:
|
| 294 |
+
counts = _task_inventory()
|
| 295 |
+
total_tasks = sum(counts.values())
|
| 296 |
+
|
| 297 |
+
with gr.Blocks(title="Office Document Task Env โ Dashboard") as demo:
|
| 298 |
+
|
| 299 |
+
gr.Markdown(INTRO_MD)
|
| 300 |
+
|
| 301 |
+
# ---- Task inventory stats ----
|
| 302 |
+
gr.Markdown("## Task inventory")
|
| 303 |
+
with gr.Row():
|
| 304 |
+
for label, n in [
|
| 305 |
+
("total tasks", total_tasks),
|
| 306 |
+
(".xlsx (Finch + curated)", counts.get("xlsx", 0)),
|
| 307 |
+
(".docx (OSWorld-Verified)", counts.get("docx", 0)),
|
| 308 |
+
(".pptx (PPTArena)", counts.get("pptx", 0)),
|
| 309 |
+
]:
|
| 310 |
+
gr.HTML(
|
| 311 |
+
f'<div style="text-align:center;padding:1rem;'
|
| 312 |
+
f'border:1px solid #e5e7eb;border-radius:8px;background:white">'
|
| 313 |
+
f'<div style="font-size:1.8rem;font-weight:700;color:#2563eb">{n}</div>'
|
| 314 |
+
f'<div style="color:#64748b;font-size:.85rem">{label}</div>'
|
| 315 |
+
f'</div>'
|
| 316 |
+
)
|
| 317 |
+
|
| 318 |
+
# ---- Leaderboard ----
|
| 319 |
+
gr.Markdown("## Leaderboard โ 22-task eval split")
|
| 320 |
+
gr.DataFrame(
|
| 321 |
+
value=_leaderboard_rows(),
|
| 322 |
+
headers=["Model", "Kind", "Avg", "Success", "xlsx", "docx", "pptx", "n"],
|
| 323 |
+
interactive=False,
|
| 324 |
+
wrap=True,
|
| 325 |
+
)
|
| 326 |
+
gr.Markdown(
|
| 327 |
+
"Rows showing `โ` haven't been published yet. Reproduce: see "
|
| 328 |
+
"`inference.py` (API-served) and `eval_lora.py` (in-process LoRA) "
|
| 329 |
+
"in the README."
|
| 330 |
+
)
|
| 331 |
+
|
| 332 |
+
# ---- SFT runs ----
|
| 333 |
+
gr.Markdown("## SFT training runs")
|
| 334 |
+
gr.DataFrame(
|
| 335 |
+
value=_sft_summary_rows() or [["โ", "โ", "โ", "โ"]],
|
| 336 |
+
headers=["Run", "Final train_loss", "Runtime", "Epochs"],
|
| 337 |
+
interactive=False,
|
| 338 |
+
)
|
| 339 |
+
gr.Markdown(
|
| 340 |
+
"Hardware: 1ร L40S 48GB on HF Jobs ($1.80/hr). "
|
| 341 |
+
"Total SFT cost: **under $2**."
|
| 342 |
+
)
|
| 343 |
+
|
| 344 |
+
# ---- Plot ----
|
| 345 |
+
gr.Markdown("## 4K vs 8K context length ablation")
|
| 346 |
+
plot = _comparison_plot_path()
|
| 347 |
+
if plot:
|
| 348 |
+
gr.Image(value=plot, label="SFT loss โ 4K vs 8K")
|
| 349 |
+
else:
|
| 350 |
+
gr.Markdown(
|
| 351 |
+
"_Comparison plot not yet generated. Run "
|
| 352 |
+
"`data_pipeline/compare_sft_runs.py` after the second SFT job finishes._"
|
| 353 |
+
)
|
| 354 |
+
|
| 355 |
+
# ---- Reward design ----
|
| 356 |
+
gr.Markdown("## Reward design")
|
| 357 |
+
gr.Markdown(REWARD_MD)
|
| 358 |
+
|
| 359 |
+
# ---- Anti-hacking ----
|
| 360 |
+
gr.Markdown("## Anti-hacking โ 4 independent defenses")
|
| 361 |
+
gr.Markdown(DEFENSES_MD)
|
| 362 |
+
|
| 363 |
+
# ---- Trajectory pipeline ----
|
| 364 |
+
gr.Markdown("## Trajectory collection pipeline")
|
| 365 |
+
gr.Markdown(PIPELINE_MD)
|
| 366 |
+
|
| 367 |
+
# ---- File upload demo ----
|
| 368 |
+
gr.Markdown("## ๐๏ธ Try your own task")
|
| 369 |
+
gr.Markdown(
|
| 370 |
+
"Upload a `.xlsx` / `.docx` / `.pptx`, give it a task instruction, "
|
| 371 |
+
"and we'll generate the inference command you can run against the "
|
| 372 |
+
"env locally with any HF-Router model or our SFT'd Qwen3B adapter. "
|
| 373 |
+
"Live agent runs aren't hosted in this Space (no inference endpoint "
|
| 374 |
+
"for the LoRA), but the env + model run cleanly anywhere with a GPU."
|
| 375 |
+
)
|
| 376 |
+
with gr.Row():
|
| 377 |
+
with gr.Column(scale=1):
|
| 378 |
+
upload = gr.File(
|
| 379 |
+
label="Upload office doc",
|
| 380 |
+
file_types=[".xlsx", ".docx", ".pptx"],
|
| 381 |
+
)
|
| 382 |
+
instruction = gr.Textbox(
|
| 383 |
+
label="Task instruction",
|
| 384 |
+
placeholder="e.g., 'Center the title on slide 1' or "
|
| 385 |
+
"'Add a SUM formula in row 50 column F'",
|
| 386 |
+
lines=2,
|
| 387 |
+
)
|
| 388 |
+
submit = gr.Button("Generate inference command", variant="primary")
|
| 389 |
+
with gr.Column(scale=2):
|
| 390 |
+
upload_status = gr.Markdown()
|
| 391 |
+
command_block = gr.Code(label="Run this locally", language="shell")
|
| 392 |
+
saved_path = gr.Textbox(label="Saved upload path", visible=False)
|
| 393 |
+
|
| 394 |
+
submit.click(
|
| 395 |
+
fn=handle_upload,
|
| 396 |
+
inputs=[upload, instruction],
|
| 397 |
+
outputs=[upload_status, command_block, saved_path],
|
| 398 |
+
)
|
| 399 |
+
|
| 400 |
+
gr.Markdown(
|
| 401 |
+
"---\n\n"
|
| 402 |
+
"**Full project journey across 11 phases:** "
|
| 403 |
+
"[edits.md](https://github.com/bp-high/openenv_financial_task_env/blob/main/edits.md) "
|
| 404 |
+
"(~2,000 lines of phase-by-phase changelog)."
|
| 405 |
+
)
|
| 406 |
+
|
| 407 |
+
return demo
|
| 408 |
+
|
| 409 |
+
|
| 410 |
+
# Build + mount. Gradio wraps itself as a sub-app inside FastAPI; the
|
| 411 |
+
# OpenEnv playground at /web is unaffected.
|
| 412 |
+
demo = build_dashboard()
|
| 413 |
+
app = gr.mount_gradio_app(app, demo, path="/dashboard")
|
| 414 |
+
|
| 415 |
+
|
| 416 |
def main() -> None:
|
| 417 |
"""Entry point for direct execution."""
|
| 418 |
import uvicorn
|
|
|
|
| 419 |
uvicorn.run(app, host="0.0.0.0", port=8000)
|
| 420 |
|
| 421 |
|