DEV Community

Cover image for Generate coding tasks. Prove the grader can catch a believable mistake.
Harish Kotra (he/him)
Harish Kotra (he/him)

Posted on AI-assisted

Generate coding tasks. Prove the grader can catch a believable mistake.

Coding Task Lab builds reproducible coding challenges from real repositories. Each challenge has a feature request, a reference implementation, and a grader. Before using a task to evaluate a coding agent, the lab checks that the reference passes, unchanged code fails the new requirements, and plausible wrong implementations fail a specific check.

The idea in one example

Both alias tasks receive --mode DEPLOY, but the alias points to a different choice than the canonical deploy value:

Contract Expected behavior What happens if you swap in the other reference?
Canonical choice wins Return deploy The collision check fails
Reject a conflicting alias Exit with code 2 The collision check fails

The two tasks share the same inputs. Each reference passes 11/11 checks on its own contract and 10/11 on the other. The swapped implementation still earns partial credit, but it does not solve the task. The grader tells you which rule it missed.

Quick start

Use Python 3.12+ and Git. The first run needs GitHub access to fetch Click unless you already have a verified checkout or snapshot. The local verifier does not require Docker or a model API key.

python3.12 -m venv .venv
.venv/bin/python -m pip install pytest==8.4.2
.venv/bin/python workspace.py
Enter fullscreen mode Exit fullscreen mode

Open http://127.0.0.1:8765 for the showcase. Choose Run the lab → New run → Local verifier → Start evaluation. Open a task and select Evidence to see what the wrong implementations got wrong. Export run downloads the task packages and the evidence for a completed run.

A source-only Git checkout starts without saved runs. The distributed submission archive includes the recorded sample. workspace.py --snapshot /path/to/click-source lets you use an offline source snapshot that matches the checked-in blob manifest.

Generate and validate from the terminal

# Pin the upstream checkout and generate the five tasks.
.venv/bin/python factory.py baseline
.venv/bin/python factory.py generate --out repro --run-log repro-run.json

# Run the packaged grader with the upstream pytest suite.
.venv/bin/python verify.py --dataset repro

# Test deliberate wrong patches and replay both alias policies.
.venv/bin/python factory.py audit --dataset repro --click-source .upstream/click/src/click
.venv/bin/python replay_alias.py --dataset repro
Enter fullscreen mode Exit fullscreen mode

To show reproducibility, generate again into repro-repeat and run diff -r repro repro-repeat. With identical inputs, the package files should match. To see a behavioral change, generate --seed 43 --out fresh: the unique-prefix contract requires one normalized character instead of the three required by seed 42.

.venv/bin/python factory.py generate --seed 43 --out fresh
diff -u repro/pallets__click-prefix-choice-42/instruction.md \
  fresh/pallets__click-prefix-choice-43/instruction.md
Enter fullscreen mode Exit fullscreen mode

Use a fresh output directory or a new seed when generating again. For the Docker version, start Docker with Compose and install Harbor in the same virtual environment:

.venv/bin/python -m pip install harbor==0.25.0
.venv/bin/python harbor_check.py --dataset repro
Enter fullscreen mode Exit fullscreen mode

Harbor builds the task images and runs the oracle (reference) and nop (unchanged) baselines. The job directories and aggregate baselines.json are saved under jobs/. The builds require access to GitHub, the base image registry, and Python package repositories.

Architecture

flowchart LR
    A["Clean checkout at a pinned Git commit"] --> B["Task generator"]
    C["Task rules or repository recipe + seed"] --> B
    B --> D["Harbor package: instructions, patches, tests, Dockerfile"]
    D --> E["Local pytest or Harbor in Docker"]
    D --> F["Deliberate wrong patches"]
    E --> G["Grading details and regression results"]
    F --> G
    G --> H["CLI reports, local workspace, and exports"]
Layer What it uses
Generation Python standard library (argparse, tomllib, difflib, random) and Git for commit checks and unified patches
Grading pytest 8.4.2, a test-result plugin, and explicit feature and regression test IDs
Container trials Harbor 0.25.0, Docker/Compose, and lightweight Bash entry points
Workspace Python ThreadingHTTPServer bound to localhost, with plain HTML, CSS, and JavaScript; no Node build step
Automation GitHub Actions regenerates the tasks twice, compares the output, and runs the Docker baselines
Optional benchmark Harbor Terminus-2 with a configured model provider; not used to generate the tasks or reported as a model solve rate

The Click factory checks the checkout’s origin, exact commit, and clean status before it generates patches. The Docker build checks out the same Click 8.3.1 commit. A representative package looks like this:

pallets__click-alias-reject-conflict-42/
├── instruction.md
├── task.toml
├── environment/Dockerfile
├── solution/
│   ├── patch.diff
│   └── solve.sh
└── tests/
    ├── fail_to_pass.json       # new requirements
    ├── pass_to_pass.json       # existing behaviors to preserve
    ├── test_patch.diff
    ├── test.sh
    ├── grade.py
    ├── run_script.sh
    └── parser.py
Enter fullscreen mode Exit fullscreen mode

The grader applies the test patch and runs pytest. A failed regression check yields zero. Otherwise the reward is the fraction of passing feature checks; only 1.0 counts as solved. The focused wrong-patch audit is separate from the Docker baseline jobs. For the scoring internals, design choices, and trade-offs, see the technical blog.

What the tasks cover

Task Rule Mistake the tests catch
Prefix choice Accept unique normalized prefixes at the generated minimum length; exact matches win Accept the first of two ambiguous matches
Alias: canonical priority Keep the canonical choice on a collision Reject a valid canonical input
Alias: reject conflicts Reject collisions between different targets Accept the conflicting input
Config-first option Prefer CLI → config → environment → default and report the actual source Let the environment override a configured zero
Fallback group Send unknown words to a fallback without losing arguments or changing regular dispatch Override a command that resolves after normalization

Recorded results: For each of the two tested seeds, all five references scored 1.0, all five unchanged baselines scored 0.0, and all listed regressions passed in Docker. A separate focused audit caught 15/15 deliberate wrong patches per seed. These figures measure validator behavior on the tested tasks, not model performance or coverage of all possible mistakes. Raw results and videos are local submission artifacts, excluded from Git; the commands above regenerate the evidence.

Add a repository

Start with the MarkupSafe example:

.venv/bin/python portable.py recipes/markupsafe \
  --check output/portable/markupsafe-replay.json
Enter fullscreen mode Exit fullscreen mode
reference        5/5 checks   reward=1.00
no-change        0/5 checks   reward=0.00
believable-error 4/5 checks   reward=0.80
Enter fullscreen mode Exit fullscreen mode

The last implementation incorrectly escapes an already formatted value. You can see the behavior test in recipes/markupsafe/checks.py. To create another recipe:

  1. Copy the example recipe and set the GitHub owner/repo, full commit SHA, task slug, and upstream license in recipe.toml.
  2. Write instruction.md and checks.py. In the recipe, list the new pytest node IDs and the existing node IDs that must keep passing.
  3. Supply reference.py and an insertion anchor, or a solution.diff for a multi-file change. Describe one plausible wrong edit in [wrong_patch].
  4. Run portable.py against a trusted recipe. Use a custom Dockerfile and run_script.sh if the project needs a different setup from src/ imports and pytest under tests/. The runner must load the bundled parser and record the configured pytest IDs.

The current adapter targets Python/pytest GitHub repositories. A recipe author supplies the feature and expected behavior. The tooling packages changes and checks them against the repository; it does not discover requirements from a GitHub URL. Other languages need a verifier adapter.

Contribute

  1. Fork this repository on GitHub, then clone your fork and create a branch.
   git clone https://github.com/YOUR_HANDLE/YOUR_FORK.git coding-task-lab
   cd coding-task-lab
   git switch -c feature/new-task-recipe
Enter fullscreen mode Exit fullscreen mode
  1. Follow the quick start. Use factory.py and templates/ for Click task changes or portable.py and recipes/ for adding a repository.
  2. Include a good reference, an unchanged baseline, and a wrong implementation that fails for the reason you expect. Make sure existing tests still pass. Run the Docker baselines if the change touches package generation or the verifier.
  3. Open a pull request with the contract, the commands you ran, and a small before/after result. Commit source, recipes, and docs; keep generated tasks, logs, upstream checkouts, local credentials, and presentation files out of the PR.

Features worth adding

  • A second language adapter: start with one TypeScript repository and map Vitest results to the existing feature/regression result contract.
  • A test that one implementation isn’t special: make it easy to replay an independently written reference patch against the same task.
  • Clearer failure reports: put the failed rule, expected value, and actual value above the full pytest output.
  • A seed comparison view: distinguish a different acceptance rule from a renamed fixture and show the exact spec and test changes.
  • Benchmark reports by rule: when a provider is configured, report which requirements agents missed and distinguish solver failures from infrastructure errors.

Code & more: https://www.dailybuild.xyz/project/336-coding-task-lab

Top comments (0)