An evaluation and reproduction harness integrating Sentry (runtime failure management for LLM agents) with the OpenCode CLI agent across SWE-bench Lite.
π Interactive Benchmark Dashboards:
- π Multi-Run DeepSeek Sentry Report (4 Iterations) β Pass@4: Sentry 75.0% vs Base 70.0%
- π¬ In-Depth Causal Analysis & Ablation Study β Analysis of intervened vs non-intervened tasks & anomaly decomposition
- π₯οΈ Live DeepSeek Sentry Dashboard (Latest Run)
- π Raw JSON DeepSeek Sentry Metrics
- ποΈ Local Gemma Sentry Dashboard (Host GPU Run) β Sentry 65.0% vs Base 55.0%
- Architecture & Workflow
- Empirical Results Summary
- Setup & Installation
- Running Benchmarks
- Model & Provider Configurations
- Known Issues & Best Practices
βββββββββββββββββββββββββββββββββββββββ
β SWE-bench Lite Task β
ββββββββββββββββββββ¬βββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Workspace (workspaces/<instance_id>) β
β - Cloned target repo at base commit β
β - opencode.json ("permission": {"websearch": "deny", "webfetch": "deny"}) β
ββββββββββββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββββ΄βββββββββββββββββββββββ
β β
[Base Evaluation] [Sentry Evaluation]
β β
βΌ βΌ
OpenCode CLI Session OpenCode CLI Session
(runs prompt in loop) (step-by-step streaming)
β β
β βΌ
β Sentry Sidecar Monitor
β - Sliding Window W=5
β - Check interval (every 5 steps)
β - Immediate check on tool errors
β β
β βββββββββββββββββββ΄ββββββββββββββββββ
β β β
β [No Failure] [Failure]
β β β
β βΌ βΌ
β Continue Turn Abort turn & inject
β RescuePrompt guidance
β β
βΌ βΌ
Outputs & Summary Diff Outputs, Diff & Lessons
- OpenCode Adapter (
benchmarks/opencode_adapter.py): Wrapsopencode run --pure --format json, captures streaming tool calls, errors, reasoning, and token usage. - Sentry Runner (
benchmarks/swebench_runner.py): Integrates Sentry'sSentryRunner, observe steps, triggers detection, and feeds rescue prompts back into the session. - Batch Evaluation (
benchmarks/run_batch_benchmark.py): Iterates through 10 benchmark tasks in both Base and Sentry modes with incremental state persistence.
Full multi-iteration comparative benchmark evaluating OpenCode with DeepSeek Flash (crazyrouter/deepseek-flash) supervised by Sentry with DeepSeek Flash across 4 independent runs on 20 SWE-bench Lite tasks (Seed 42).
All Sentry supervisor tokens are treated as billed API costs and included in total token metrics.
π Explore Multi-Run Results:
- π Open Multi-Iteration Aggregate Report (4 Runs) β Pass@4: Sentry 75.0% vs Base 70.0%
- π₯οΈ Open Live Dashboard (Latest Run)
- π¦ Download Machine-Readable Multi-Iteration Summary (JSON)
| Benchmark Run | Base Resolved | Sentry Resolved | Sentry Checks (Evaluations) | Sentry Interventions (Rate) | Base Steps | Sentry Steps (Ξ) | Base Billed Tokens | Sentry Billed Tokens (Ξ)* |
|---|---|---|---|---|---|---|---|---|
| Iteration 1 | 9 / 20 (45.0%) | 9 / 20 (45.0%) | 146 checks | 11 (7.5%) across 9 tasks | 596 | 634 (+6.4%) | 11.73M | 12.83M (+9.4%) |
| Iteration 2 | 10 / 20 (50.0%) | 12 / 20 (60.0%) | 160 checks | 9 (5.6%) across 8 tasks | 612 | 638 (+4.2%) | 13.02M | 12.92M (-0.7%) |
| Iteration 3 | 12 / 20 (60.0%) | 12 / 20 (60.0%) | 162 checks | 11 (6.8%) across 9 tasks | 597 | 650 (+8.9%) | 11.04M | 12.29M (+11.3%) |
| Iteration 4 | 11 / 20 (55.0%) | 13 / 20 (65.0%) | 139 checks | 15 (10.8%) across 12 tasks | 681 | 569 (-16.4%) | 12.80M | 11.61M (-9.3%) |
| Total / Pass@4 | 14 / 20 (70.0%) | 15 / 20 (75.0%) | 607 checks | 46 interventions (7.6%) | β | β | 48.59M | 49.65M (+2.2%) |
* Note: Sentry billed tokens include 100% of the Sentry LLM runtime supervisor API calls.
- Higher Ceiling (Pass@4 = 75.0% vs 70.0%): Sentry resolved 15 out of 20 tasks in at least one run (including
django-14667which Base failed across all 4 runs). - Consistent Outperformance in Complex Runs: Sentry achieved a +10% absolute boost in resolved rate in both Iteration 2 (60% vs 50%) and Iteration 4 (65% vs 55%).
- Execution Efficiency in Iteration 4: Under identical 1200s timeouts, Sentry slashed execution steps by -16.4% and net token consumption by -9.3%, proving that early intervention and rescue prompts curb unproductive model loops even when paying for supervisor API calls.
- Active Failure Detection (46 Interventions across 607 Sentry Checks = 7.6% Intervention Rate): Sentry performed 607 automated evaluations (triggered every 5 steps and on environment errors). In 92.4% of checks, the supervisor correctly confirmed normal progress (
no_failure), while in 46 instances (7.6%) it stepped in to abort non-progress loops, path probing outside/app/workspace, and planning stalls with targeted RescuePrompts. - Causal Validation & Zero-Interference Control Group: On tasks with 0 interventions across all 4 runs (16 task sessions), Base and Sentry exhibited strictly identical Pass Rates (81.3% vs 81.3%) and identical average step counts (14.4 vs 14.3 steps), proving that passive monitoring incurs zero behavioral drift. Read the full π¬ Causal Analysis Report.
Full comparative benchmark evaluating OpenCode with DeepSeek Flash (crazyrouter/deepseek-flash, variant: high) against the Sentry Runtime Supervisor (google/gemma-4-e4b on LM Studio) across 20 randomly sampled SWE-bench Lite tasks (Seed 42).
π Explore Full Results:
| Metric | Base (No Sentry) | Sentry (with Gemma-4 Supervisor) | Delta / Impact |
|---|---|---|---|
| Resolved Tasks (SWE-bench) | 11 / 20 (55.0%) | 13 / 20 (65.0%) | π +10.0% (+18.2% relative) |
| FAIL_TO_PASS Tests Passed | 17 / 27 (63.0%) | 21 / 27 (77.8%) | π― +4 additional test cases fixed |
| Total Billed Tokens | 13,459,341 tok | 11,785,777 tok | π° -1,673,564 tokens saved (-12.4%) |
| Total Execution Steps | 691 steps | 615 steps | β‘ -76 steps reduced (-11.0%) |
| Sentry Interventions | β | 14 interventions across 11 tasks | π‘οΈ 0 false positive terminations |
All patches evaluated in-container against hidden SWE-bench ground-truth test suites (FAIL_TO_PASS and PASS_TO_PASS regression suites):
| Task ID | Repo | Steps (B / S) | Billed Tokens (B / S) | Token Savings | Interv | FAIL_TO_PASS (B / S) | PASS_TO_PASS (B / S) | Resolved (Base / Sentry) |
|---|---|---|---|---|---|---|---|---|
django__django-11099 |
django/django |
9 / 7 | 92,188 / 32,078 | -65.2% | 1 | 3/3 / 3/3 | 19/19 / 19/19 | β Resolved / β Resolved |
django__django-11133 |
django/django |
24 / 21 | 338,210 / 305,627 | -9.6% | 1 | 1/1 / 1/1 | 64/64 / 64/64 | β Resolved / β Resolved |
django__django-11179 |
django/django |
19 / 24 | 265,087 / 320,602 | +20.9% | 1 | 1/1 / 1/1 | 40/40 / 40/40 | β Resolved / β Resolved |
django__django-11999 |
django/django |
35 / 40 | 897,933 / 865,818 | -3.6% | 0 | 1/1 / 1/1 | 30/30 / 30/30 | β Resolved / β Resolved |
django__django-12113 |
django/django |
47 / 41 | 1,154,012 / 946,285 | -18.0% | 2 | 0/1 / 1/1 | 0/0 / 0/0 | β Failed / π RESOLVED (Sentry WIN) |
django__django-12284 |
django/django |
54 / 35 | 1,222,044 / 639,769 | -47.6% | 2 | 1/1 / 1/1 | 31/31 / 31/31 | β Resolved / β Resolved |
django__django-12308 |
django/django |
37 / 16 | 603,322 / 131,554 | -78.2% | 1 | 0/2 / 2/2 | 0/20 / 20/20 | β Failed / π RESOLVED (Sentry WIN) |
django__django-12747 |
django/django |
15 / 32 | 130,853 / 646,377 | +393.9% | 1 | 3/3 / 3/3 | 49/49 / 49/49 | β Resolved / β Resolved |
django__django-13710 |
django/django |
31 / 22 | 471,086 / 326,557 | -30.7% | 1 | 1/1 / 1/1 | 62/62 / 62/62 | β Resolved / β Resolved |
django__django-13768 |
django/django |
25 / 16 | 322,225 / 224,657 | -30.3% | 1 | 1/1 / 1/1 | 18/18 / 18/18 | β Resolved / β Resolved |
django__django-14017 |
django/django |
49 / 40 | 1,010,641 / 896,580 | -11.3% | 1 | 2/2 / 2/2 | 147/147 / 147/147 | β Resolved / β Resolved |
django__django-14667 |
django/django |
31 / 60 | 635,528 / 1,310,117 | +106.1% | 0 | 0/1 / 0/1 | 0/29 / 0/29 | β Failed / β Failed |
django__django-16816 |
django/django |
60 / 60 | 1,304,577 / 1,465,282 | +12.3% | 0 | 0/2 / 1/2 (50%) | 0/123 / 0/123 | β Failed / |
pytest-dev__pytest-7220 |
pytest-dev/pytest |
44 / 29 | 981,522 / 421,050 | -57.1% | 0 | 0/1 / 0/1 | 0/11 / 0/11 | β Failed / β Failed |
sphinx-doc__sphinx-7975 |
sphinx-doc/sphinx |
39 / 26 | 739,093 / 494,239 | -33.1% | 1 | 0/1 / 0/1 | 0/7 / 0/7 | β Failed / β Failed |
sympy__sympy-11870 |
sympy/sympy |
60 / 34 | 1,810,024 / 996,748 | -44.9% | 1 | 0/1 / 0/1 | 1/58 / 1/58 | β Failed / β Failed |
sympy__sympy-13177 |
sympy/sympy |
25 / 15 | 345,937 / 200,526 | -42.0% | 0 | 1/2 (50%) / 1/2 (50%) | 0/76 / 0/76 | |
sympy__sympy-15011 |
sympy/sympy |
22 / 29 | 254,943 / 480,159 | +88.3% | 0 | 1/1 / 1/1 | 53/53 / 53/53 | β Resolved / β Resolved |
sympy__sympy-15308 |
sympy/sympy |
33 / 35 | 294,249 / 465,221 | +58.1% | 0 | 0/1 / 0/1 | 0/120 / 0/120 | β Failed / β Failed |
sympy__sympy-22005 |
sympy/sympy |
32 / 33 | 585,867 / 616,531 | +5.2% | 0 | 1/1 / 1/1 | 2/2 / 2/2 | β Resolved / β Resolved |
| TOTALS (20 TASKS) | β | 691 / 615 (-11.0%) | 13.46M / 11.79M | -12.4% (-1.67M) | 14 | 17/27 / 21/27 | 478/488 / 498/508 | Base: 11/20 (55%) / Sentry: 13/20 (65%) |
- Higher Task Success Rate (+10% Absolute):
- Sentry successfully diagnosed and corrected critical planning stalls in
django__django-12113anddjango__django-12308, allowing OpenCode to produce 100% passing patches where the baseline failed completely.
- Sentry successfully diagnosed and corrected critical planning stalls in
- Substantial Net Cost & Token Reduction (-12.4%):
- On tasks with deep reasoning exploration (
django__django-12308,pytest-dev__pytest-7220,django__django-11099,sympy__sympy-11870), Sentry eliminated non-productive cyclic searches, reducing billed tokens by up to -78.2%.
- On tasks with deep reasoning exploration (
- Execution Efficiency (-11.0% Steps):
- Sentry reduced cumulative interaction steps from 691 down to 615 across the 20 tasks, steering the agent away from timeout boundaries (max 60 steps).
- Zero Cloud Inference Cost for Supervisor:
- The Sentry runtime monitor ran 100% locally on host GPU via LM Studio (
google/gemma-4-e4b), adding $0.00 in API expenses while supervising the agent.
- The Sentry runtime monitor ran 100% locally on host GPU via LM Studio (
- Strict Isolation & Security:
- Every single task was evaluated in an isolated Docker container mounting an anonymous
/app/workspacewith an iptables Default-Deny network whitelist.
- Every single task was evaluated in an isolated Docker container mounting an anonymous
You can run the entire benchmark suite in a pre-configured Docker container with Python 3.11, Node.js 20, OpenCode CLI, git, pytest, and all testing tools preinstalled without touching your host machine:
./run_in_docker.sh build./run_in_docker.sh single psf__requests-2317./run_in_docker.sh batch# Evaluate a single task against hidden test_patch
./run_in_docker.sh eval psf__requests-2317
# Evaluate all task runs in a batch output directory
./run_in_docker.sh eval-batch outputs/batch_deepseek_flash./run_in_docker.sh shellAll patches, execution logs, and HTML reports are automatically written to ./outputs, ./reports, and ./workspaces on your host via Docker volume mounts. Local LM Studio on your host is automatically reachable via host.docker.internal:1234.
- Python 3.10 or 3.11
- OpenCode CLI installed (
npm install -g opencode-aior via homebrew) - Git and Docker (optional, for isolated environments)
- LM Studio / vLLM / Ollama (for local Sentry judge) OR an API key
git clone https://github.com/LHCWN/Sentry-Opencode-Bench.git
cd Sentry-Opencode-Bench
python3.11 -m venv .venv
source .venv/bin/activate
pip install -e .
pip install datasets pyyaml requestsGOOGLE_GENERATIVE_AI_API_KEY="your-gemini-key" \
PYTHONPATH=. .venv/bin/python benchmarks/swebench_runner.py \
--instance-id "psf__requests-2317" \
--opencode-model "google/gemini-3.5-flash-lite" \
--no-sentryGOOGLE_GENERATIVE_AI_API_KEY="your-gemini-key" \
PYTHONPATH=. .venv/bin/python benchmarks/swebench_runner.py \
--instance-id "psf__requests-2317" \
--opencode-model "google/gemini-3.5-flash-lite" \
--config "configs/providers/lmstudio.yaml" \
--check-interval 5 \
--check-on-errorGOOGLE_GENERATIVE_AI_API_KEY="your-gemini-key" \
PYTHONPATH=. .venv/bin/python benchmarks/run_batch_benchmark.py \
--model "google/gemini-3.5-flash-lite" \
--sentry-config "configs/providers/lmstudio.yaml" \
--max-steps 25Results are saved incrementally to outputs/batch_benchmark/results.json.
Configured to point to any OpenAI-compatible local runner (LM Studio, vLLM, Ollama, llama.cpp):
api:
provider: openai_compatible
model: google/gemma-4-e4b
base_url: http://127.0.0.1:1234/v1
api_key_env: null
json_mode: prompt
timeout: 120.0
max_retries: 0
model:
model: google/gemma-4-e4b
temperature: 0.0
max_tokens: 1536
structured_outputs: true
task_agent:
temperature: 0.7
max_tokens: 1024
structured_outputs: falseExport the environment variable before running:
export OPENROUTER_API_KEY="sk-or-v1-..."And pass --opencode-model "openrouter/deepseek/deepseek-chat".
Export the environment variable:
export GOOGLE_GENERATIVE_AI_API_KEY="AQ.Ab..."And pass --opencode-model "google/gemini-3.5-flash-lite".
- Original Sentry paper behavior: In the paper, Sentry calls the LLM detector on every single interaction cycle.
-
Problem: When using local models or API endpoints, calling the detector every turn creates huge latency (15β20s per check), quickly consumes API rate limits, and multiplies false positive interventions (
$1 - (0.95)^{20} \approx 64%$ ). -
Solution: We introduced
--check-interval 5and--check-on-error True:- Routine successful steps (
read,grep,editwithok=True) are observed silently (observe_step) to keep Sentry's sliding window intact. - Sentry's heavy LLM detector is triggered only every 5 steps, or immediately upon tool errors (
ok=False, non-zero exit codes, tool crashes).
- Routine successful steps (
- Google AI Studio Free Tier: Strict cap of 500 requests per day. Running 5β6 complex tasks will exhaust this quota. In production, use a paid Tier 1 key or a self-hosted model.
- OpenRouter Free Tier (
:free): Hard cap of 50 requests per day. Paid models (deepseek/deepseek-chat) cost fractions of a cent and do not have this daily restriction. - OpenCode Cloud Free Tier: Shared global capacity; frequently hits
Free usage limit reached (HTTP 429). Always configure a custom provider or local model.
- When evaluating long trajectories, Sentry's sliding window prompt can exceed 4,096 tokens.
- If LM Studio is configured with a 2k/4k context window, it will return
HTTP 400 Bad RequestorModelOutputTruncatedError. - Recommendation: Set LM Studio's context length (
n_ctx) to 8,192 or 16,384 tokens for the judge model (google/gemma-4-e4bor similar).
- Many local models (such as Gemma, Qwen, or LLaMA) wrap JSON responses in
```json ... ```markdown fences despite instructions. - Sentry includes automated code fence stripping in
Sentry/clients.pyandSentry/_structured.pyto prevent JSON parsing crashes.
- In each prepared repository,
opencode.jsonis generated with:This guarantees that benchmarks remain clean and the agent cannot search for patches online.{ "permission": { "websearch": "deny", "webfetch": "deny" } }
-
Why did tasks show ~1.5M - 3M tokens?
OpenCode streams per-step token usage via
step_finish:{"tokens": {"input": 45000, "output": 150, "total": 45150}}Because LLM conversational agents send the entire conversation history up to step$k$ as the prompt prefix on step$k$ , summingtokens.totalacross all$N$ steps calculates the cumulative tokens billed by the API provider ($\sum_{k=1}^N \text{input}_k$ ). -
Session Net Tokens (True Context Window):
- The actual conversation context size at the end of a session is represented by
last_step_inputormax_context_window(~20,000β80,000 tokens). - The total text generated by the model across all turns is
total_generated(~1,500β4,000 tokens). - The net unique tokens across the session is
$\approx \text{final_input} + \text{total_generated}$ .
- The actual conversation context size at the end of a session is represented by
- Both metrics are now explicitly tracked in
summary.jsonascumulative_tokens(billing perspective) andsession_net_tokens(context perspective).
To ensure benchmarks run safely without polluting the host or global Python/Node environments:
PIP_REQUIRE_VIRTUALENV=true: Agents are strictly forbidden from installing packages into the host/system Python (ERROR: Could not find an activated virtualenv).PIP_NO_INDEX=true: Prevents agents from downloading untracked external packages from PyPI over the network.PYTHONNOUSERSITE=1: Prevents agents from installing to or reading packages from~/.local/lib/pythonX.Y/site-packages.NPM_CONFIG_GLOBAL=false: Blocks global npm package installations.external_directory: "deny": OpenCode strictly blocks any tool execution or file reads outside the designatedworkspaces/<instance_id>folder.
When transferring the repo to another machine or running with alternative models:
# Re-run only tasks that previously failed (errored or stopped with 0 steps)
python benchmarks/run_batch_benchmark.py \
--model "openrouter/deepseek/deepseek-chat" \
--sentry-config "configs/providers/vllm.yaml" \
--rerun-failed
# Force re-run all 10 tasks from scratch
python benchmarks/run_batch_benchmark.py \
--model "openrouter/deepseek/deepseek-chat" \
--sentry-config "configs/providers/vllm.yaml" \
--forceThis repository is licensed under the MIT License.
{ "$schema": "https://opencode.ai/config.json", "provider": { "cloudflare": { "name": "Cloudflare Workers AI", "npm": "@ai-sdk/openai-compatible", "options": { "baseURL": "https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/ai/v1", "apiKey": "<CF_API_TOKEN>" }, "models": { "@cf/meta/llama-3.3-70b-instruct-fp8-fast": { "name": "Llama 3.3 70B Fast", "limit": { "context": 65536, "output": 4096 } } } } } }