AutoResearchExam v1.1: run on Harbor main with any agent harness
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- README.md +80 -22
- are_protocol.md.j2 +24 -0
- tasks/act-tensor-sparse-panel-imputation-r2/environment/.dockerignore +1 -0
- tasks/act-tensor-sparse-panel-imputation-r2/environment/are-grader-ctx/Dockerfile +35 -0
- tasks/act-tensor-sparse-panel-imputation-r2/environment/are-grader-ctx/Dockerfile.are +53 -0
- tasks/act-tensor-sparse-panel-imputation-r2/environment/are-grader-ctx/are/drain.py +25 -0
- tasks/act-tensor-sparse-panel-imputation-r2/environment/are-grader-ctx/are/server.py +538 -0
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/compute_reward.py +0 -0
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/grader_core.py +0 -0
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/final/instance_00.npz +0 -0
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/final/instance_01.npz +0 -0
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/final/instance_02.npz +0 -0
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/final/instance_03.npz +0 -0
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/final/instance_04.npz +0 -0
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/final/instance_05.npz +0 -0
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/final/instance_06.npz +0 -0
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/final/instance_07.npz +0 -0
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/final/instance_08.npz +0 -0
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/final/instance_09.npz +0 -0
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/final/instance_10.npz +0 -0
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/final/instance_11.npz +0 -0
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/intermediate/instance_00.npz +0 -0
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/intermediate/instance_01.npz +0 -0
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/intermediate/instance_02.npz +0 -0
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/intermediate/instance_03.npz +0 -0
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/intermediate/instance_04.npz +0 -0
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/intermediate/instance_05.npz +0 -0
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/intermediate/instance_06.npz +0 -0
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/intermediate/instance_07.npz +0 -0
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/intermediate/instance_08.npz +0 -0
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/intermediate/instance_09.npz +0 -0
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/intermediate/instance_10.npz +0 -0
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/intermediate/instance_11.npz +0 -0
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/intermediate.sh +0 -0
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/requirements-verifier.txt +0 -0
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/requirements.txt +0 -0
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/run_candidate.py +0 -0
- tasks/{shortest-valid-ci-l2-ece/tests/intermediate.sh → act-tensor-sparse-panel-imputation-r2/environment/are-grader-ctx/test.sh} +3 -3
- tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/test_state.py +0 -0
- tasks/act-tensor-sparse-panel-imputation-r2/environment/docker-compose.yaml +76 -0
- tasks/act-tensor-sparse-panel-imputation-r2/task.toml +39 -25
- tasks/act-tensor-sparse-panel-imputation-r2/tests/Dockerfile +2 -35
- tasks/act-tensor-sparse-panel-imputation-r2/tests/finalize.py +59 -0
- tasks/act-tensor-sparse-panel-imputation-r2/tests/test.sh +1 -17
- tasks/activeprune-al-unlabeled-pool-pruning/environment/.dockerignore +1 -0
- tasks/activeprune-al-unlabeled-pool-pruning/environment/are-grader-ctx/Dockerfile +35 -0
- tasks/activeprune-al-unlabeled-pool-pruning/environment/are-grader-ctx/Dockerfile.are +53 -0
- tasks/activeprune-al-unlabeled-pool-pruning/{tests → environment/are-grader-ctx}/al_loop.py +0 -0
- tasks/activeprune-al-unlabeled-pool-pruning/environment/are-grader-ctx/are/drain.py +25 -0
- tasks/activeprune-al-unlabeled-pool-pruning/environment/are-grader-ctx/are/server.py +538 -0
README.md
CHANGED
|
@@ -12,6 +12,19 @@ tags:
|
|
| 12 |
# AutoResearchExam
|
| 13 |
|
| 14 |
This repository contains the 29 tasks from [AutoResearchExam](https://benchmarks.bespokelabs.ai/autoresearchexam/).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
<details>
|
| 17 |
<summary>View tasks by area →</summary>
|
|
@@ -99,36 +112,81 @@ This repository contains the 29 tasks from [AutoResearchExam](https://benchmarks
|
|
| 99 |
|
| 100 |
</details>
|
| 101 |
|
| 102 |
-
## Run
|
| 103 |
|
| 104 |
-
|
| 105 |
|
| 106 |
-
|
| 107 |
-
mkdir autoresearch-exam-run && cd autoresearch-exam-run
|
| 108 |
-
git clone https://github.com/bespokelabsai/AutoResearchExam-Terminus.git harness
|
| 109 |
-
cd harness
|
| 110 |
-
uv sync --python 3.12 --extra modal
|
| 111 |
-
uv run hf download bespokelabs/AutoResearchExam \
|
| 112 |
-
--repo-type dataset \
|
| 113 |
-
--local-dir ../hf-tasks
|
| 114 |
-
```
|
| 115 |
|
| 116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
```bash
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
--
|
| 122 |
-
--model
|
| 123 |
-
--
|
| 124 |
-
--plugin autoresearch-exam \
|
| 125 |
-
--pk max_iterations=1 \
|
| 126 |
-
--pk max_duration_seconds=3600
|
| 127 |
```
|
| 128 |
|
| 129 |
-
Use `--path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
|
| 131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
## Citation
|
| 134 |
|
|
|
|
| 12 |
# AutoResearchExam
|
| 13 |
|
| 14 |
This repository contains the 29 tasks from [AutoResearchExam](https://benchmarks.bespokelabs.ai/autoresearchexam/).
|
| 15 |
+
Version 1.1 runs natively on [Harbor](https://github.com/harbor-framework/harbor) with any
|
| 16 |
+
agent harness. Leaderboard scores come from the official harness on version 1.0. See
|
| 17 |
+
[Run](#run) for both.
|
| 18 |
+
|
| 19 |
+
## News
|
| 20 |
+
|
| 21 |
+
- **2026-10: v1.1.** Run AutoResearchExam with any agent harness using plain `harbor run`
|
| 22 |
+
on [Harbor](https://github.com/harbor-framework/harbor) main, without depending on any
|
| 23 |
+
custom harness. Same tasks, data and graders as v1.0. Leaderboard scores still come from
|
| 24 |
+
v1.0 with the official harness.
|
| 25 |
+
- **2026-09: v1.0.** Initial release with the official harness and leaderboard.
|
| 26 |
+
|
| 27 |
+
## Tasks by area
|
| 28 |
|
| 29 |
<details>
|
| 30 |
<summary>View tasks by area →</summary>
|
|
|
|
| 112 |
|
| 113 |
</details>
|
| 114 |
|
| 115 |
+
## Run
|
| 116 |
|
| 117 |
+
Each run has a 24 hour research budget, and the agent should keep working until it ends.
|
| 118 |
|
| 119 |
+
### With the official harness
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
+
The leaderboard uses the
|
| 122 |
+
[v1.0 tasks](https://github.com/bespokelabsai/AutoResearchExam/tree/v1.0) with the official
|
| 123 |
+
[AutoResearchExam-Terminus](https://github.com/bespokelabsai/AutoResearchExam-Terminus)
|
| 124 |
+
harness. To reproduce leaderboard scores, follow the instructions in that repository.
|
| 125 |
+
|
| 126 |
+
### With your own harness
|
| 127 |
+
|
| 128 |
+
The official harness keeps the agent working and submitting until the budget ends. With your
|
| 129 |
+
own harness, that is up to the agent. An agent can stop early, but then it scores lower,
|
| 130 |
+
because it did not follow the instruction to keep going.
|
| 131 |
+
|
| 132 |
+
Install [Harbor](https://github.com/harbor-framework/harbor), start Docker, and set up your
|
| 133 |
+
model provider's credentials. Then run any agent harness on a task:
|
| 134 |
|
| 135 |
```bash
|
| 136 |
+
git clone https://github.com/bespokelabsai/AutoResearchExam.git
|
| 137 |
+
harbor run \
|
| 138 |
+
--path AutoResearchExam/cpu-decoder-graph-executor \
|
| 139 |
+
--agent <agent> --model <model> --env docker \
|
| 140 |
+
--ak prompt_template_path=AutoResearchExam/are_protocol.md.j2
|
|
|
|
|
|
|
|
|
|
| 141 |
```
|
| 142 |
|
| 143 |
+
Use `--path AutoResearchExam` to run all tasks. `are_protocol.md.j2` adds the research protocol
|
| 144 |
+
after each task instruction: submit regularly, keep improving the solution, and keep going
|
| 145 |
+
until the run ends.
|
| 146 |
+
|
| 147 |
+
During the run, the agent can reach `api.openai.com` and `api.anthropic.com`. If your harness
|
| 148 |
+
uses another host, add `--allow-agent-host <host>`.
|
| 149 |
+
|
| 150 |
+
GPU tasks need an NVIDIA GPU and the NVIDIA Container Toolkit. Grading shares GPU 0 with the
|
| 151 |
+
agent by default. On a machine with a spare GPU, set `ARE_GRADER_GPU=1` to give grading its
|
| 152 |
+
own GPU.
|
| 153 |
+
|
| 154 |
+
## How autoresearch submissions and intermediate grading work
|
| 155 |
+
|
| 156 |
+
Each task runs the agent next to two grader containers.
|
| 157 |
+
|
| 158 |
+
- The agent submits with the `submit` tool of the `are` MCP server, or over HTTP at
|
| 159 |
+
`http://grader:8000/submit`. The first grader scores the submission on the public
|
| 160 |
+
validation split. The agent gets the score and grader output from the `result` tool.
|
| 161 |
+
- The second grader scores the same submission on the private test split. The agent cannot
|
| 162 |
+
reach it and never sees these scores.
|
| 163 |
+
- Grading does not pause the agent. The agent keeps working while a submission is graded.
|
| 164 |
+
Only one grade runs at a time, validation or test. A new submission is refused until the
|
| 165 |
+
previous one has its validation score.
|
| 166 |
+
- When the agent stops, the final workspace is graded too, unless it matches the last
|
| 167 |
+
submission.
|
| 168 |
+
|
| 169 |
+
## How scores can differ from v1.0
|
| 170 |
+
|
| 171 |
+
In v1.0, the official harness keeps the agent submitting for the full 24 hours. In v1.1, that
|
| 172 |
+
is your agent's responsibility.
|
| 173 |
+
|
| 174 |
+
In v1.0, grading paused the agent. Now the agent keeps working while a submission is
|
| 175 |
+
graded, so it has more working time. Because only one submission is graded at a time, an
|
| 176 |
+
agent cannot flood the grader.
|
| 177 |
+
|
| 178 |
+
Grading runs on the same machine as the agent and can compete with it for compute. A grader
|
| 179 |
+
uses as many cores as the task gives the agent, and the two graders never run at the same
|
| 180 |
+
time, so plan for about twice the cores each task requests.
|
| 181 |
+
|
| 182 |
+
## Scores
|
| 183 |
|
| 184 |
+
Each trial writes `verifier/reward.json`. Its `reward` is the private test score of the
|
| 185 |
+
submission with the best validation score. Its `auarc` uses each task's own score scale. To
|
| 186 |
+
put scores on the leaderboard scale, follow the
|
| 187 |
+
[scoring guide](https://github.com/bespokelabsai/AutoResearchExam-Terminus/blob/main/scripts/custom_harness.md)
|
| 188 |
+
to normalize scores and compute AUARC. Every submission's scores and times are in the
|
| 189 |
+
trial's `artifacts/var/lib/are/ledger.jsonl`.
|
| 190 |
|
| 191 |
## Citation
|
| 192 |
|
are_protocol.md.j2
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{{ instruction }}
|
| 2 |
+
|
| 3 |
+
## Autoresearch protocol
|
| 4 |
+
|
| 5 |
+
You will work on this task over a sequence of submissions. The task
|
| 6 |
+
instruction above remains the source of truth for what files may be changed
|
| 7 |
+
and what constitutes a good solution.
|
| 8 |
+
|
| 9 |
+
Submit your solution with the `submit` tool of the `are` MCP server whenever it
|
| 10 |
+
is ready. The grader grades a snapshot of your deliverable, and the `result`
|
| 11 |
+
tool returns the visible intermediate score and grader output once grading is
|
| 12 |
+
done. One submission is graded at a time. Then keep improving the solution and
|
| 13 |
+
submit again. Submit regularly as a way to checkpoint your progress.
|
| 14 |
+
|
| 15 |
+
If you cannot use MCP tools, the same actions are plain HTTP:
|
| 16 |
+
`POST http://grader:8000/submit?note=<short description>`, then
|
| 17 |
+
`GET http://grader:8000/result/<id>`.
|
| 18 |
+
|
| 19 |
+
Only use feedback returned by the grader.
|
| 20 |
+
|
| 21 |
+
**Do not stop. Keep going.** Continue autonomously until the harness stops
|
| 22 |
+
you. There is no point at which the task is finished: after every submission,
|
| 23 |
+
keep improving the solution and submit again. Do not stop to ask the user
|
| 24 |
+
whether you should continue.
|
tasks/act-tensor-sparse-panel-imputation-r2/environment/.dockerignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
are-grader-ctx
|
tasks/act-tensor-sparse-panel-imputation-r2/environment/are-grader-ctx/Dockerfile
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM --platform=linux/amd64 public.ecr.aws/docker/library/python:3.13-slim-bookworm@sha256:01f42367a0a94ad4bc17111776fd66e3500c1d87c15bbd6055b7371d39c124fb
|
| 2 |
+
|
| 3 |
+
ENTRYPOINT []
|
| 4 |
+
ENV PYTHONPATH=
|
| 5 |
+
ENV PYTHONSAFEPATH=1
|
| 6 |
+
ENV DEBIAN_FRONTEND=noninteractive \
|
| 7 |
+
PYTHONHASHSEED=0 \
|
| 8 |
+
PIP_NO_CACHE_DIR=1 \
|
| 9 |
+
PIP_DISABLE_PIP_VERSION_CHECK=1 \
|
| 10 |
+
OMP_NUM_THREADS=1 \
|
| 11 |
+
OPENBLAS_NUM_THREADS=1 \
|
| 12 |
+
MKL_NUM_THREADS=1 \
|
| 13 |
+
NUMEXPR_NUM_THREADS=1
|
| 14 |
+
|
| 15 |
+
RUN useradd --create-home --uid 1001 agent
|
| 16 |
+
|
| 17 |
+
COPY ./requirements.txt /tmp/requirements.txt
|
| 18 |
+
COPY ./requirements-verifier.txt /tmp/requirements-verifier.txt
|
| 19 |
+
RUN /usr/local/bin/python3 -m pip install --no-cache-dir \
|
| 20 |
+
-r /tmp/requirements.txt -r /tmp/requirements-verifier.txt \
|
| 21 |
+
&& rm /tmp/requirements.txt /tmp/requirements-verifier.txt
|
| 22 |
+
|
| 23 |
+
RUN mkdir -p /app/solution /logs/verifier
|
| 24 |
+
|
| 25 |
+
COPY . /tests
|
| 26 |
+
|
| 27 |
+
RUN chown -R root:root /tests \
|
| 28 |
+
&& chmod 700 /tests/hidden_data /tests/hidden_data/intermediate /tests/hidden_data/final \
|
| 29 |
+
&& chmod +x /tests/test.sh /tests/intermediate.sh \
|
| 30 |
+
&& find /tests -exec touch -d @1700000000 {} +
|
| 31 |
+
|
| 32 |
+
WORKDIR /tests
|
| 33 |
+
|
| 34 |
+
ENV HF_HUB_OFFLINE=1
|
| 35 |
+
ENV TRANSFORMERS_OFFLINE=1
|
tasks/act-tensor-sparse-panel-imputation-r2/environment/are-grader-ctx/Dockerfile.are
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM --platform=linux/amd64 public.ecr.aws/docker/library/python:3.13-slim-bookworm@sha256:01f42367a0a94ad4bc17111776fd66e3500c1d87c15bbd6055b7371d39c124fb
|
| 2 |
+
|
| 3 |
+
ENTRYPOINT []
|
| 4 |
+
ENV PYTHONPATH=
|
| 5 |
+
ENV PYTHONSAFEPATH=1
|
| 6 |
+
ENV DEBIAN_FRONTEND=noninteractive \
|
| 7 |
+
PYTHONHASHSEED=0 \
|
| 8 |
+
PIP_NO_CACHE_DIR=1 \
|
| 9 |
+
PIP_DISABLE_PIP_VERSION_CHECK=1 \
|
| 10 |
+
OMP_NUM_THREADS=1 \
|
| 11 |
+
OPENBLAS_NUM_THREADS=1 \
|
| 12 |
+
MKL_NUM_THREADS=1 \
|
| 13 |
+
NUMEXPR_NUM_THREADS=1
|
| 14 |
+
|
| 15 |
+
RUN useradd --create-home --uid 1001 agent
|
| 16 |
+
|
| 17 |
+
COPY ./requirements.txt /tmp/requirements.txt
|
| 18 |
+
COPY ./requirements-verifier.txt /tmp/requirements-verifier.txt
|
| 19 |
+
RUN /usr/local/bin/python3 -m pip install --no-cache-dir \
|
| 20 |
+
-r /tmp/requirements.txt -r /tmp/requirements-verifier.txt \
|
| 21 |
+
&& rm /tmp/requirements.txt /tmp/requirements-verifier.txt
|
| 22 |
+
|
| 23 |
+
RUN mkdir -p /app/solution /logs/verifier
|
| 24 |
+
|
| 25 |
+
COPY . /tests
|
| 26 |
+
|
| 27 |
+
RUN chown -R root:root /tests \
|
| 28 |
+
&& chmod 700 /tests/hidden_data /tests/hidden_data/intermediate /tests/hidden_data/final \
|
| 29 |
+
&& chmod +x /tests/test.sh /tests/intermediate.sh \
|
| 30 |
+
&& find /tests -exec touch -d @1700000000 {} +
|
| 31 |
+
|
| 32 |
+
WORKDIR /tests
|
| 33 |
+
|
| 34 |
+
ENV HF_HUB_OFFLINE=1
|
| 35 |
+
ENV TRANSFORMERS_OFFLINE=1
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
# ---- ARE 1.1 grader layer (appended to the task's own verifier Dockerfile) ----
|
| 39 |
+
ARG ARE_ROLE
|
| 40 |
+
# python.org images ship /usr/local/bin/python3; distro-python bases (kaggle GPU) lack
|
| 41 |
+
# ensurepip, so fall back to a pip-less venv filled by the base interpreter's pip.
|
| 42 |
+
RUN PY=$(command -v /usr/local/bin/python3 || command -v python3) \
|
| 43 |
+
&& if "$PY" -m venv /opt/are/venv; then \
|
| 44 |
+
/opt/are/venv/bin/pip install --no-cache-dir "fastmcp==2.14.7"; \
|
| 45 |
+
else rm -rf /opt/are/venv && "$PY" -m venv --without-pip /opt/are/venv \
|
| 46 |
+
&& "$PY" -m pip --python /opt/are/venv/bin/python install --no-cache-dir "fastmcp==2.14.7"; fi
|
| 47 |
+
COPY are/ /opt/are/
|
| 48 |
+
# The val grader, whose output reaches the agent, never holds the private grader or its
|
| 49 |
+
# data. The test grader keeps everything; nothing from it reaches the agent.
|
| 50 |
+
RUN rm -rf /tests/are /tests/Dockerfile.are \
|
| 51 |
+
&& if [ "$ARE_ROLE" = "val" ]; then rm -rf /tests/test.sh /tests/hidden_data/final; fi
|
| 52 |
+
ENV ARE_ROLE=$ARE_ROLE
|
| 53 |
+
CMD ["/opt/are/venv/bin/python", "/opt/are/server.py"]
|
tasks/act-tensor-sparse-panel-imputation-r2/environment/are-grader-ctx/are/drain.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Verifier collect hook, run after the agent stops.
|
| 2 |
+
|
| 3 |
+
Grades the final workspace as one last submission (unless it equals the last one),
|
| 4 |
+
then waits until every submission has both grades recorded.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import json
|
| 8 |
+
import time
|
| 9 |
+
import urllib.request
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
|
| 12 |
+
TOKEN = Path("/run/are-secret/token").read_text().strip()
|
| 13 |
+
H = {"x-are-token": TOKEN}
|
| 14 |
+
|
| 15 |
+
req = urllib.request.Request("http://localhost:8000/final", method="POST", headers=H)
|
| 16 |
+
with urllib.request.urlopen(req, timeout=120) as resp:
|
| 17 |
+
print("final:", json.loads(resp.read()), flush=True)
|
| 18 |
+
|
| 19 |
+
while True:
|
| 20 |
+
with urllib.request.urlopen(urllib.request.Request("http://localhost:8000/drain", headers=H), timeout=30) as resp:
|
| 21 |
+
state = json.loads(resp.read())
|
| 22 |
+
print(state, flush=True)
|
| 23 |
+
if state["val_pending"] == 0 and state["test_pending"] == 0:
|
| 24 |
+
break
|
| 25 |
+
time.sleep(5)
|
tasks/act-tensor-sparse-panel-imputation-r2/environment/are-grader-ctx/are/server.py
ADDED
|
@@ -0,0 +1,538 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""ARE 1.1 grader sidecar.
|
| 2 |
+
|
| 3 |
+
One image, two roles:
|
| 4 |
+
|
| 5 |
+
- ARE_ROLE=val ("grader" service). Reachable from the agent. Serves MCP tools and a
|
| 6 |
+
REST fallback. On submit it snapshots the shared deliverable volume, grades the
|
| 7 |
+
snapshot with the task's public grader (intermediate.sh), and returns only that
|
| 8 |
+
score. Every snapshot is also sent to the test grader; the hidden score goes to a
|
| 9 |
+
root-only ledger and never back to the agent.
|
| 10 |
+
- ARE_ROLE=test ("test-grader" service). On a private network that only the val
|
| 11 |
+
grader can reach. Grades snapshots with the task's private grader (test.sh).
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
from __future__ import annotations
|
| 15 |
+
|
| 16 |
+
import asyncio
|
| 17 |
+
import gzip
|
| 18 |
+
import hashlib
|
| 19 |
+
import io
|
| 20 |
+
import secrets
|
| 21 |
+
import json
|
| 22 |
+
import os
|
| 23 |
+
import queue
|
| 24 |
+
import shutil
|
| 25 |
+
import subprocess
|
| 26 |
+
import tarfile
|
| 27 |
+
import threading
|
| 28 |
+
import time
|
| 29 |
+
import urllib.request
|
| 30 |
+
from pathlib import Path
|
| 31 |
+
|
| 32 |
+
from fastmcp import FastMCP
|
| 33 |
+
from starlette.requests import Request
|
| 34 |
+
from starlette.responses import JSONResponse, Response
|
| 35 |
+
|
| 36 |
+
ROLE = os.environ.get("ARE_ROLE", "val")
|
| 37 |
+
PORT = int(os.environ.get("ARE_PORT", "8000"))
|
| 38 |
+
STATE = Path(os.environ.get("ARE_STATE_DIR", "/var/lib/are"))
|
| 39 |
+
ARTIFACT_PATHS = [p for p in os.environ.get("ARE_ARTIFACT_PATHS", "/app/output").split(":") if p]
|
| 40 |
+
# The shared deliverable volume. Its parent is root-only, so submitted code (which every
|
| 41 |
+
# task grader runs as the unprivileged agent user) cannot reach it to write back to the agent.
|
| 42 |
+
SUBMISSION_ROOT = Path(os.environ.get("ARE_SUBMISSION_ROOT", "/run/are-deliverable"))
|
| 43 |
+
AGENT_UID = int(os.environ.get("ARE_AGENT_UID", "1001"))
|
| 44 |
+
BUDGET_SEC = float(os.environ.get("ARE_BUDGET_SEC", "14400"))
|
| 45 |
+
GRADE_TIMEOUT_SEC = float(os.environ.get("ARE_GRADE_TIMEOUT_SEC", "1800"))
|
| 46 |
+
TEST_GRADER_URL = os.environ.get("ARE_TEST_GRADER_URL", "http://test-grader:8001")
|
| 47 |
+
FEEDBACK_TAIL = int(os.environ.get("ARE_FEEDBACK_TAIL_CHARS", "8192"))
|
| 48 |
+
SCRIPT = "/tests/intermediate.sh" if ROLE == "val" else "/tests/test.sh"
|
| 49 |
+
# Shared only by the two graders (a volume the agent's container never mounts). The test
|
| 50 |
+
# grader writes a fresh token at startup; every internal request must carry it, so the
|
| 51 |
+
# agent cannot reach the test grader or the internal endpoints even on a shared network.
|
| 52 |
+
TOKEN_FILE = Path(os.environ.get("ARE_TOKEN_FILE", "/run/are-secret/token"))
|
| 53 |
+
TOKEN = ""
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def _authorized(request: Request) -> bool:
|
| 57 |
+
"""Internal endpoints need the graders' token; an unset token never matches."""
|
| 58 |
+
return bool(TOKEN) and secrets.compare_digest(request.headers.get("x-are-token", ""), TOKEN)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def _net_isolation_available() -> bool:
|
| 62 |
+
try:
|
| 63 |
+
return subprocess.run(["unshare", "-n", "true"], capture_output=True, timeout=10).returncode == 0
|
| 64 |
+
except Exception:
|
| 65 |
+
return False
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
NET_ISOLATED = False # set at startup: grader scripts run in an empty network namespace
|
| 69 |
+
|
| 70 |
+
T0 = time.time()
|
| 71 |
+
_lock = threading.Lock()
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def _elapsed() -> float:
|
| 75 |
+
return round(time.time() - T0, 1)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def _ledger(event: dict) -> None:
|
| 79 |
+
event = {"t": _elapsed(), "wall": time.time(), **event}
|
| 80 |
+
for attempt in range(3):
|
| 81 |
+
try:
|
| 82 |
+
with _lock, open(STATE / "ledger.jsonl", "a") as fh:
|
| 83 |
+
fh.write(json.dumps(event) + "\n")
|
| 84 |
+
return
|
| 85 |
+
except OSError:
|
| 86 |
+
if attempt == 2:
|
| 87 |
+
raise
|
| 88 |
+
time.sleep(1)
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def _kill_grading_processes(proc: subprocess.Popen) -> None:
|
| 92 |
+
"""Kill everything a timed-out grade started, including processes that left its group."""
|
| 93 |
+
try:
|
| 94 |
+
os.killpg(proc.pid, 9)
|
| 95 |
+
except ProcessLookupError:
|
| 96 |
+
pass
|
| 97 |
+
_kill_other_processes()
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def _kill_other_processes() -> None:
|
| 101 |
+
"""Kill every process run by the agent user. Every task grader runs submitted code as
|
| 102 |
+
that user, so this stops all graded code (detached or not) and nothing else: the grader
|
| 103 |
+
server, the task's own grader and Harbor's hooks run as root."""
|
| 104 |
+
for entry in Path("/proc").iterdir():
|
| 105 |
+
if not entry.name.isdigit():
|
| 106 |
+
continue
|
| 107 |
+
try:
|
| 108 |
+
if entry.stat().st_uid == AGENT_UID:
|
| 109 |
+
os.kill(int(entry.name), 9)
|
| 110 |
+
except (ProcessLookupError, PermissionError, FileNotFoundError):
|
| 111 |
+
pass
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
# Places the agent user (who runs submitted code inside every task grader) can write.
|
| 115 |
+
_BASELINE: set[str] = set() # every path that existed when the grader started (its image)
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def _walk_one_fs(base: Path):
|
| 119 |
+
"""Every path under base on base's own filesystem (skips /proc, /sys and other mounts)."""
|
| 120 |
+
dev = base.stat().st_dev
|
| 121 |
+
for root, dirs, files in os.walk(base):
|
| 122 |
+
dirs[:] = [d for d in dirs if os.lstat(os.path.join(root, d)).st_dev == dev]
|
| 123 |
+
for name in dirs + files:
|
| 124 |
+
yield Path(root) / name
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def _all_paths() -> set[str]:
|
| 128 |
+
out = set()
|
| 129 |
+
for base in (Path("/"), Path("/dev/shm")):
|
| 130 |
+
if base.is_dir():
|
| 131 |
+
out.update(str(q) for q in _walk_one_fs(base))
|
| 132 |
+
return out
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def _protected(path: str) -> bool:
|
| 136 |
+
keep = [str(STATE), "/opt/are", str(TOKEN_FILE.parent)]
|
| 137 |
+
return any(path == k or path.startswith(k + "/") for k in keep)
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
def _fresh_state() -> None:
|
| 141 |
+
"""Start every grade from the grader image's own files, as ARE 1.0's fresh verifier
|
| 142 |
+
container did. The grader container lives for the whole run, so before each grade
|
| 143 |
+
stop anything an earlier grade left running and delete every file it created,
|
| 144 |
+
whoever wrote it. The deliverable volume and the token are separate mounts and are
|
| 145 |
+
never walked; the grader's own state is kept."""
|
| 146 |
+
_kill_other_processes()
|
| 147 |
+
# System V shared memory, semaphores and queues outlive processes; this server uses none.
|
| 148 |
+
subprocess.run(["ipcrm", "--all"], capture_output=True)
|
| 149 |
+
for path in sorted(_all_paths() - _BASELINE, key=lambda q: q.count("/"), reverse=True):
|
| 150 |
+
if _protected(path):
|
| 151 |
+
continue
|
| 152 |
+
try:
|
| 153 |
+
q = Path(path)
|
| 154 |
+
if q.is_dir() and not q.is_symlink():
|
| 155 |
+
shutil.rmtree(q, ignore_errors=True)
|
| 156 |
+
else:
|
| 157 |
+
q.unlink()
|
| 158 |
+
except OSError:
|
| 159 |
+
pass
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
def grade_snapshot(tar_bytes: bytes, tag: str) -> dict:
|
| 163 |
+
"""Extract a snapshot over the artifact paths and run this role's grader script."""
|
| 164 |
+
_fresh_state()
|
| 165 |
+
for path in ARTIFACT_PATHS:
|
| 166 |
+
p = Path(path)
|
| 167 |
+
if p.exists():
|
| 168 |
+
shutil.rmtree(p)
|
| 169 |
+
p.mkdir(parents=True)
|
| 170 |
+
with tarfile.open(fileobj=io.BytesIO(tar_bytes), mode="r:gz") as tf:
|
| 171 |
+
tf.extractall("/", filter="tar")
|
| 172 |
+
logs = Path("/logs/verifier")
|
| 173 |
+
if logs.exists():
|
| 174 |
+
shutil.rmtree(logs)
|
| 175 |
+
logs.mkdir(parents=True)
|
| 176 |
+
started = time.time()
|
| 177 |
+
# Submitted code runs with no network, as in ARE 1.0's verifier.
|
| 178 |
+
cmd = (["unshare", "-n"] if NET_ISOLATED else []) + ["bash", SCRIPT]
|
| 179 |
+
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True,
|
| 180 |
+
cwd="/tests", start_new_session=True)
|
| 181 |
+
try:
|
| 182 |
+
out, err = proc.communicate(timeout=GRADE_TIMEOUT_SEC)
|
| 183 |
+
error = None
|
| 184 |
+
except subprocess.TimeoutExpired:
|
| 185 |
+
_kill_grading_processes(proc)
|
| 186 |
+
out, err = proc.communicate()
|
| 187 |
+
error = f"grader timed out after {GRADE_TIMEOUT_SEC:.0f}s"
|
| 188 |
+
output = (out or "") + (err or "")
|
| 189 |
+
# Nothing a grade started may keep running after it, not even detached processes.
|
| 190 |
+
_kill_other_processes()
|
| 191 |
+
score = 0.0
|
| 192 |
+
reward_file = logs / "reward.txt"
|
| 193 |
+
if reward_file.exists():
|
| 194 |
+
try:
|
| 195 |
+
score = float(reward_file.read_text().strip() or 0)
|
| 196 |
+
except ValueError:
|
| 197 |
+
error = error or "unparseable reward"
|
| 198 |
+
metric = None
|
| 199 |
+
if (logs / "metric.json").exists():
|
| 200 |
+
try:
|
| 201 |
+
metric = json.loads((logs / "metric.json").read_text())
|
| 202 |
+
except ValueError:
|
| 203 |
+
pass
|
| 204 |
+
(STATE / "logs").mkdir(exist_ok=True)
|
| 205 |
+
(STATE / "logs" / f"{tag}.log").write_text(output)
|
| 206 |
+
return {
|
| 207 |
+
"score": score,
|
| 208 |
+
"metric": metric,
|
| 209 |
+
"error": error,
|
| 210 |
+
"net_isolated": NET_ISOLATED,
|
| 211 |
+
"seconds": round(time.time() - started, 1),
|
| 212 |
+
# What the agent sees, as in ARE 1.0: the grader's stdout tail (not stderr).
|
| 213 |
+
"output_tail": (out or "")[-FEEDBACK_TAIL:],
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
mcp = FastMCP("are")
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
# ---------------------------------------------------------------- test role
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
_grade_lock = threading.Lock()
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
def _grade_one_at_a_time(tar_bytes: bytes, tag: str) -> dict:
|
| 227 |
+
# A request that timed out on the caller's side may still be grading; the next one
|
| 228 |
+
# waits for it rather than sharing /app/output and /logs/verifier with it.
|
| 229 |
+
with _grade_lock:
|
| 230 |
+
return grade_snapshot(tar_bytes, tag)
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
if ROLE == "test":
|
| 234 |
+
|
| 235 |
+
@mcp.custom_route("/grade", methods=["POST"])
|
| 236 |
+
async def http_grade(request: Request) -> Response:
|
| 237 |
+
if not _authorized(request):
|
| 238 |
+
return JSONResponse({"error": "forbidden"}, status_code=403)
|
| 239 |
+
tag = request.query_params.get("tag", "x")
|
| 240 |
+
body = await request.body()
|
| 241 |
+
result = await asyncio.to_thread(_grade_one_at_a_time, body, f"{tag}-test")
|
| 242 |
+
return JSONResponse(result)
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
# ----------------------------------------------------------------- val role
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
class Board:
|
| 249 |
+
"""Submissions and their grading state. Hidden scores are never stored here."""
|
| 250 |
+
|
| 251 |
+
def __init__(self) -> None:
|
| 252 |
+
self.subs: dict[int, dict] = {}
|
| 253 |
+
self.val_q: queue.Queue[int] = queue.Queue()
|
| 254 |
+
self.next_id = 1
|
| 255 |
+
self.test_pending = 0
|
| 256 |
+
self.last_digest: str | None = None
|
| 257 |
+
|
| 258 |
+
def public(self, sid: int) -> dict:
|
| 259 |
+
s = self.subs[sid]
|
| 260 |
+
out = {k: s[k] for k in ("id", "note", "submitted_at_s", "status")}
|
| 261 |
+
if s["status"] == "graded":
|
| 262 |
+
v = s["val"]
|
| 263 |
+
out.update(
|
| 264 |
+
validation_score=v["score"],
|
| 265 |
+
error=v["error"],
|
| 266 |
+
grading_seconds=v["seconds"],
|
| 267 |
+
grader_output_tail=v["output_tail"],
|
| 268 |
+
)
|
| 269 |
+
return out
|
| 270 |
+
|
| 271 |
+
def best(self) -> dict | None:
|
| 272 |
+
graded = [s for s in self.subs.values() if s["status"] == "graded"]
|
| 273 |
+
if not graded:
|
| 274 |
+
return None
|
| 275 |
+
b = max(graded, key=lambda s: (s["val"]["score"], -s["id"]))
|
| 276 |
+
return {"id": b["id"], "validation_score": b["val"]["score"]}
|
| 277 |
+
|
| 278 |
+
|
| 279 |
+
board = Board()
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
def snapshot() -> bytes:
|
| 283 |
+
"""Deterministic tar.gz of the deliverable: same content, same bytes (gzip mtime 0)."""
|
| 284 |
+
raw = io.BytesIO()
|
| 285 |
+
with tarfile.open(fileobj=raw, mode="w") as tf:
|
| 286 |
+
for path in ARTIFACT_PATHS:
|
| 287 |
+
src = SUBMISSION_ROOT / path.lstrip("/")
|
| 288 |
+
tf.add(str(src), arcname=path.lstrip("/"))
|
| 289 |
+
out = io.BytesIO()
|
| 290 |
+
with gzip.GzipFile(fileobj=out, mode="wb", mtime=0) as gz:
|
| 291 |
+
gz.write(raw.getvalue())
|
| 292 |
+
return out.getvalue()
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
def do_submit(note: str, final: bool = False) -> dict:
|
| 296 |
+
with _lock:
|
| 297 |
+
pending = [s["id"] for s in board.subs.values() if s["status"] != "graded"]
|
| 298 |
+
if pending and not final:
|
| 299 |
+
return {
|
| 300 |
+
"error": f"Submission {pending[0]} is still being graded. One submission is "
|
| 301 |
+
f"graded at a time: check result({pending[0]}) and submit again "
|
| 302 |
+
"once it has its score.",
|
| 303 |
+
"pending_id": pending[0],
|
| 304 |
+
}
|
| 305 |
+
sid = board.next_id
|
| 306 |
+
board.next_id += 1
|
| 307 |
+
board.subs[sid] = {"id": sid, "note": note[:500], "submitted_at_s": _elapsed(),
|
| 308 |
+
"status": "queued"}
|
| 309 |
+
try:
|
| 310 |
+
data = snapshot()
|
| 311 |
+
digest = hashlib.sha256(data).hexdigest()
|
| 312 |
+
(STATE / "snapshots" / f"{sid:04d}.tar.gz").write_bytes(data)
|
| 313 |
+
_ledger({"event": "submitted", "id": sid, "note": note[:500], "bytes": len(data),
|
| 314 |
+
"sha256": digest, "final": final})
|
| 315 |
+
except Exception as exc:
|
| 316 |
+
with _lock:
|
| 317 |
+
board.subs.pop(sid, None) # release the slot; the id is not reused
|
| 318 |
+
return {"error": f"Could not snapshot the deliverable ({exc}). Nothing was submitted. "
|
| 319 |
+
"Make sure nothing is writing to it, then submit again."}
|
| 320 |
+
board.last_digest = digest
|
| 321 |
+
with _lock:
|
| 322 |
+
board.test_pending += 1
|
| 323 |
+
board.val_q.put(sid)
|
| 324 |
+
return {"id": sid, "status": "queued",
|
| 325 |
+
"hint": "Grading has started. Check result(id) for the validation score."}
|
| 326 |
+
|
| 327 |
+
|
| 328 |
+
def final_submit() -> dict:
|
| 329 |
+
"""After the agent stops: grade the final workspace unless it was already submitted."""
|
| 330 |
+
try:
|
| 331 |
+
data = snapshot()
|
| 332 |
+
except Exception as exc:
|
| 333 |
+
return {"error": f"final snapshot failed: {exc}"}
|
| 334 |
+
if board.subs and hashlib.sha256(data).hexdigest() == board.last_digest:
|
| 335 |
+
return {"skipped": "final workspace equals the last submission"}
|
| 336 |
+
return do_submit("final workspace (automatic)", final=True)
|
| 337 |
+
|
| 338 |
+
|
| 339 |
+
def grade_worker() -> None:
|
| 340 |
+
"""Grade each submission on val, then on test, one submission at a time.
|
| 341 |
+
|
| 342 |
+
The val score is published as soon as it is ready. The next submission's val grade
|
| 343 |
+
waits until this test grade is done, so the two graders never run at the same time.
|
| 344 |
+
"""
|
| 345 |
+
while True:
|
| 346 |
+
sid = board.val_q.get()
|
| 347 |
+
board.subs[sid]["status"] = "grading"
|
| 348 |
+
data = b""
|
| 349 |
+
try:
|
| 350 |
+
data = (STATE / "snapshots" / f"{sid:04d}.tar.gz").read_bytes()
|
| 351 |
+
res = grade_snapshot(data, f"{sid:04d}-val")
|
| 352 |
+
except Exception as exc:
|
| 353 |
+
res = {"score": 0.0, "metric": None, "error": f"grader failed: {exc}",
|
| 354 |
+
"net_isolated": NET_ISOLATED, "seconds": 0.0, "output_tail": ""}
|
| 355 |
+
board.subs[sid]["val"] = res
|
| 356 |
+
board.subs[sid]["status"] = "graded"
|
| 357 |
+
try:
|
| 358 |
+
_ledger({"event": "val", "id": sid, **{k: res[k] for k in ("score", "metric", "error", "seconds", "net_isolated")}})
|
| 359 |
+
except OSError as exc: # keep grading later submissions
|
| 360 |
+
print(f"ARE grader: ledger write failed for {sid}: {exc}", flush=True)
|
| 361 |
+
test_grade(sid, data)
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
def test_grade(sid: int, data: bytes) -> None:
|
| 365 |
+
try:
|
| 366 |
+
_test_grade(sid, data)
|
| 367 |
+
finally:
|
| 368 |
+
with _lock:
|
| 369 |
+
board.test_pending -= 1
|
| 370 |
+
|
| 371 |
+
|
| 372 |
+
def _test_grade(sid: int, data: bytes) -> None:
|
| 373 |
+
"""Send one snapshot to the test grader. A failed request is retried (the same snapshot
|
| 374 |
+
is graded again, so a retry can only recover the honest score); a request that ran
|
| 375 |
+
past its timeout is not, since the grade itself already took the full time."""
|
| 376 |
+
started = time.time()
|
| 377 |
+
for attempt in range(3):
|
| 378 |
+
try:
|
| 379 |
+
req = urllib.request.Request(
|
| 380 |
+
f"{TEST_GRADER_URL}/grade?tag={sid:04d}", data=data, method="POST",
|
| 381 |
+
headers={"x-are-token": TOKEN},
|
| 382 |
+
)
|
| 383 |
+
with urllib.request.urlopen(req, timeout=2 * GRADE_TIMEOUT_SEC + 300) as resp:
|
| 384 |
+
res = json.loads(resp.read())
|
| 385 |
+
break
|
| 386 |
+
except Exception as exc: # recorded, never shown to the agent
|
| 387 |
+
res = {"score": None, "metric": None, "error": f"test grader: {exc}",
|
| 388 |
+
"seconds": round(time.time() - started, 1)}
|
| 389 |
+
if attempt == 2 or isinstance(exc, TimeoutError) or isinstance(getattr(exc, "reason", None), TimeoutError):
|
| 390 |
+
break
|
| 391 |
+
time.sleep(5)
|
| 392 |
+
try:
|
| 393 |
+
_ledger({"event": "test", "id": sid, **{k: res.get(k) for k in ("score", "metric", "error", "seconds", "net_isolated")}})
|
| 394 |
+
except OSError as exc: # keep grading later submissions
|
| 395 |
+
print(f"ARE grader: ledger write failed for {sid}: {exc}", flush=True)
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
def with_time(out: dict) -> dict:
|
| 399 |
+
"""Wall-clock accounting on every reply, as the v1 harness gave each phase."""
|
| 400 |
+
out["total_budget_seconds"] = BUDGET_SEC
|
| 401 |
+
out["time_remaining_seconds"] = round(max(0.0, BUDGET_SEC - _elapsed()), 1)
|
| 402 |
+
return out
|
| 403 |
+
|
| 404 |
+
|
| 405 |
+
def status_dict() -> dict:
|
| 406 |
+
return {
|
| 407 |
+
"submissions": len(board.subs),
|
| 408 |
+
"queued_or_grading": sum(s["status"] != "graded" for s in board.subs.values()),
|
| 409 |
+
"best": board.best(),
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
def current_result(sid: int) -> dict:
|
| 414 |
+
return board.public(sid)
|
| 415 |
+
|
| 416 |
+
|
| 417 |
+
if ROLE == "val":
|
| 418 |
+
|
| 419 |
+
@mcp.tool
|
| 420 |
+
async def submit(note: str = "") -> dict:
|
| 421 |
+
"""Submit the current deliverable for grading.
|
| 422 |
+
|
| 423 |
+
Snapshots the deliverable directory right now (later edits do not affect this
|
| 424 |
+
submission) and starts grading it on the public validation split. Returns at
|
| 425 |
+
once with a submission id. One submission is graded at a time: check `result`
|
| 426 |
+
and submit again once the previous submission has its score. `note` is a short
|
| 427 |
+
description of what changed.
|
| 428 |
+
"""
|
| 429 |
+
return with_time(await asyncio.to_thread(do_submit, note))
|
| 430 |
+
|
| 431 |
+
@mcp.tool
|
| 432 |
+
async def result(id: int) -> dict:
|
| 433 |
+
"""The current state of a submission: queued, grading, or graded with its
|
| 434 |
+
validation score and grader output. Returns immediately."""
|
| 435 |
+
if id not in board.subs:
|
| 436 |
+
return {"error": f"unknown submission id {id}"}
|
| 437 |
+
return with_time(current_result(id))
|
| 438 |
+
|
| 439 |
+
@mcp.tool
|
| 440 |
+
async def status() -> dict:
|
| 441 |
+
"""Submission count, whether one is being graded, the best validation score,
|
| 442 |
+
and the time budget and time remaining."""
|
| 443 |
+
return with_time(status_dict())
|
| 444 |
+
|
| 445 |
+
@mcp.custom_route("/submit", methods=["POST"])
|
| 446 |
+
async def http_submit(request: Request) -> Response:
|
| 447 |
+
note = request.query_params.get("note", "")
|
| 448 |
+
return JSONResponse(with_time(await asyncio.to_thread(do_submit, note)))
|
| 449 |
+
|
| 450 |
+
@mcp.custom_route("/result/{sid}", methods=["GET"])
|
| 451 |
+
async def http_result(request: Request) -> Response:
|
| 452 |
+
sid = int(request.path_params["sid"])
|
| 453 |
+
if sid not in board.subs:
|
| 454 |
+
return JSONResponse({"error": f"unknown submission id {sid}"}, status_code=404)
|
| 455 |
+
return JSONResponse(with_time(current_result(sid)))
|
| 456 |
+
|
| 457 |
+
@mcp.custom_route("/status", methods=["GET"])
|
| 458 |
+
async def http_status(request: Request) -> Response:
|
| 459 |
+
return JSONResponse(with_time(status_dict()))
|
| 460 |
+
|
| 461 |
+
@mcp.custom_route("/final", methods=["POST"])
|
| 462 |
+
async def http_final(request: Request) -> Response:
|
| 463 |
+
if not _authorized(request):
|
| 464 |
+
return JSONResponse({"error": "forbidden"}, status_code=403)
|
| 465 |
+
# Collect hook, after the agent has stopped.
|
| 466 |
+
return JSONResponse(await asyncio.to_thread(final_submit))
|
| 467 |
+
|
| 468 |
+
@mcp.custom_route("/drain", methods=["GET"])
|
| 469 |
+
async def http_drain(request: Request) -> Response:
|
| 470 |
+
if not _authorized(request):
|
| 471 |
+
return JSONResponse({"error": "forbidden"}, status_code=403)
|
| 472 |
+
# Used by the verifier collect hook after the agent has stopped.
|
| 473 |
+
pending = sum(s["status"] != "graded" for s in board.subs.values())
|
| 474 |
+
return JSONResponse({"val_pending": pending, "test_pending": board.test_pending})
|
| 475 |
+
|
| 476 |
+
|
| 477 |
+
def _gpus() -> list[str]:
|
| 478 |
+
try:
|
| 479 |
+
out = subprocess.run(["nvidia-smi", "-L"], capture_output=True, text=True, timeout=20)
|
| 480 |
+
return [l for l in out.stdout.splitlines() if l.strip()]
|
| 481 |
+
except Exception:
|
| 482 |
+
return []
|
| 483 |
+
|
| 484 |
+
|
| 485 |
+
@mcp.custom_route("/health", methods=["GET"])
|
| 486 |
+
async def health(request: Request) -> Response:
|
| 487 |
+
return JSONResponse({"ok": True, "role": ROLE, "gpus": await asyncio.to_thread(_gpus)})
|
| 488 |
+
|
| 489 |
+
|
| 490 |
+
def _setup_token() -> None:
|
| 491 |
+
global TOKEN
|
| 492 |
+
if ROLE == "test":
|
| 493 |
+
TOKEN_FILE.parent.mkdir(parents=True, exist_ok=True)
|
| 494 |
+
os.chmod(TOKEN_FILE.parent, 0o700)
|
| 495 |
+
TOKEN = secrets.token_hex(32)
|
| 496 |
+
TOKEN_FILE.write_text(TOKEN)
|
| 497 |
+
os.chmod(TOKEN_FILE, 0o600)
|
| 498 |
+
else:
|
| 499 |
+
for _ in range(300): # the test grader is healthy before this one starts
|
| 500 |
+
if TOKEN_FILE.exists() and TOKEN_FILE.read_text().strip():
|
| 501 |
+
break
|
| 502 |
+
time.sleep(1)
|
| 503 |
+
TOKEN = TOKEN_FILE.read_text().strip()
|
| 504 |
+
if not TOKEN:
|
| 505 |
+
raise SystemExit("ARE: empty internal token; refusing to start")
|
| 506 |
+
|
| 507 |
+
|
| 508 |
+
def main() -> None:
|
| 509 |
+
global NET_ISOLATED
|
| 510 |
+
NET_ISOLATED = _net_isolation_available()
|
| 511 |
+
if not NET_ISOLATED:
|
| 512 |
+
# Graded code must never have a network path (for example back through /submit).
|
| 513 |
+
raise SystemExit("ARE grader: cannot run grades without network access "
|
| 514 |
+
"(needs `unshare -n`, i.e. CAP_SYS_ADMIN); refusing to start")
|
| 515 |
+
STATE.mkdir(parents=True, exist_ok=True)
|
| 516 |
+
_BASELINE.update(_all_paths())
|
| 517 |
+
_setup_token()
|
| 518 |
+
STATE.mkdir(parents=True, exist_ok=True)
|
| 519 |
+
os.chmod(STATE, 0o700)
|
| 520 |
+
(STATE / "snapshots").mkdir(exist_ok=True)
|
| 521 |
+
if ROLE == "val":
|
| 522 |
+
# The deliverable volume starts empty and root-owned; hand it to the agent user.
|
| 523 |
+
SUBMISSION_ROOT.mkdir(parents=True, exist_ok=True)
|
| 524 |
+
os.chmod(SUBMISSION_ROOT, 0o700)
|
| 525 |
+
for path in ARTIFACT_PATHS:
|
| 526 |
+
src = SUBMISSION_ROOT / path.lstrip("/")
|
| 527 |
+
src.mkdir(parents=True, exist_ok=True)
|
| 528 |
+
os.chown(src, AGENT_UID, AGENT_UID)
|
| 529 |
+
(STATE / "meta.json").write_text(json.dumps(
|
| 530 |
+
{"t0_wall": T0, "budget_seconds": BUDGET_SEC, "artifact_paths": ARTIFACT_PATHS}
|
| 531 |
+
))
|
| 532 |
+
threading.Thread(target=grade_worker, daemon=True).start()
|
| 533 |
+
mcp.run(transport="http", host="0.0.0.0", port=PORT, show_banner=False,
|
| 534 |
+
uvicorn_config={"timeout_keep_alive": 86400})
|
| 535 |
+
|
| 536 |
+
|
| 537 |
+
if __name__ == "__main__":
|
| 538 |
+
main()
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/compute_reward.py
RENAMED
|
File without changes
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/grader_core.py
RENAMED
|
File without changes
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/final/instance_00.npz
RENAMED
|
File without changes
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/final/instance_01.npz
RENAMED
|
File without changes
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/final/instance_02.npz
RENAMED
|
File without changes
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/final/instance_03.npz
RENAMED
|
File without changes
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/final/instance_04.npz
RENAMED
|
File without changes
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/final/instance_05.npz
RENAMED
|
File without changes
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/final/instance_06.npz
RENAMED
|
File without changes
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/final/instance_07.npz
RENAMED
|
File without changes
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/final/instance_08.npz
RENAMED
|
File without changes
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/final/instance_09.npz
RENAMED
|
File without changes
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/final/instance_10.npz
RENAMED
|
File without changes
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/final/instance_11.npz
RENAMED
|
File without changes
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/intermediate/instance_00.npz
RENAMED
|
File without changes
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/intermediate/instance_01.npz
RENAMED
|
File without changes
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/intermediate/instance_02.npz
RENAMED
|
File without changes
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/intermediate/instance_03.npz
RENAMED
|
File without changes
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/intermediate/instance_04.npz
RENAMED
|
File without changes
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/intermediate/instance_05.npz
RENAMED
|
File without changes
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/intermediate/instance_06.npz
RENAMED
|
File without changes
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/intermediate/instance_07.npz
RENAMED
|
File without changes
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/intermediate/instance_08.npz
RENAMED
|
File without changes
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/intermediate/instance_09.npz
RENAMED
|
File without changes
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/intermediate/instance_10.npz
RENAMED
|
File without changes
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/hidden_data/intermediate/instance_11.npz
RENAMED
|
File without changes
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/intermediate.sh
RENAMED
|
File without changes
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/requirements-verifier.txt
RENAMED
|
File without changes
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/requirements.txt
RENAMED
|
File without changes
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/run_candidate.py
RENAMED
|
File without changes
|
tasks/{shortest-valid-ci-l2-ece/tests/intermediate.sh → act-tensor-sparse-panel-imputation-r2/environment/are-grader-ctx/test.sh}
RENAMED
|
@@ -1,17 +1,17 @@
|
|
| 1 |
#!/bin/bash
|
| 2 |
set -u
|
| 3 |
|
|
|
|
|
|
|
| 4 |
mkdir -p /logs/verifier
|
| 5 |
chown root:root /logs/verifier 2>/dev/null || true
|
| 6 |
chmod 755 /logs/verifier 2>/dev/null || true
|
| 7 |
rm -f /logs/verifier/reward.txt /logs/verifier/ctrf.json /logs/verifier/metric.json
|
| 8 |
|
| 9 |
-
trap 'if [ ! -s /logs/verifier/reward.txt ]; then echo "0" > /logs/verifier/reward.txt; fi' EXIT
|
| 10 |
-
|
| 11 |
chmod -R go-rwx /tests
|
| 12 |
|
| 13 |
-
export GRADE_SPLIT=intermediate
|
| 14 |
cd /tests
|
|
|
|
| 15 |
/usr/local/bin/python3 -m pytest --ctrf /logs/verifier/ctrf.json /tests/test_state.py -rA
|
| 16 |
/usr/local/bin/python3 /tests/compute_reward.py
|
| 17 |
|
|
|
|
| 1 |
#!/bin/bash
|
| 2 |
set -u
|
| 3 |
|
| 4 |
+
trap 'if [ ! -s /logs/verifier/reward.txt ]; then mkdir -p /logs/verifier; printf "0\n" > /logs/verifier/reward.txt; fi' EXIT
|
| 5 |
+
|
| 6 |
mkdir -p /logs/verifier
|
| 7 |
chown root:root /logs/verifier 2>/dev/null || true
|
| 8 |
chmod 755 /logs/verifier 2>/dev/null || true
|
| 9 |
rm -f /logs/verifier/reward.txt /logs/verifier/ctrf.json /logs/verifier/metric.json
|
| 10 |
|
|
|
|
|
|
|
| 11 |
chmod -R go-rwx /tests
|
| 12 |
|
|
|
|
| 13 |
cd /tests
|
| 14 |
+
export GRADER_SPLIT=final
|
| 15 |
/usr/local/bin/python3 -m pytest --ctrf /logs/verifier/ctrf.json /tests/test_state.py -rA
|
| 16 |
/usr/local/bin/python3 /tests/compute_reward.py
|
| 17 |
|
tasks/act-tensor-sparse-panel-imputation-r2/{tests → environment/are-grader-ctx}/test_state.py
RENAMED
|
File without changes
|
tasks/act-tensor-sparse-panel-imputation-r2/environment/docker-compose.yaml
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ARE 1.1: grading lives in sidecars. Harbor configures `main` (build, limits, network).
|
| 2 |
+
services:
|
| 3 |
+
main:
|
| 4 |
+
depends_on:
|
| 5 |
+
grader:
|
| 6 |
+
condition: service_healthy
|
| 7 |
+
volumes:
|
| 8 |
+
- are-deliverable-0:/app/solution
|
| 9 |
+
|
| 10 |
+
grader:
|
| 11 |
+
build:
|
| 12 |
+
context: ./are-grader-ctx
|
| 13 |
+
dockerfile: Dockerfile.are
|
| 14 |
+
args:
|
| 15 |
+
ARE_ROLE: val
|
| 16 |
+
platform: linux/amd64
|
| 17 |
+
environment:
|
| 18 |
+
ARE_ROLE: val
|
| 19 |
+
ARE_PORT: "8000"
|
| 20 |
+
ARE_BUDGET_SEC: "86400"
|
| 21 |
+
ARE_ARTIFACT_PATHS: "/app/solution"
|
| 22 |
+
ARE_AGENT_UID: "1001"
|
| 23 |
+
ARE_GRADE_TIMEOUT_SEC: "1800"
|
| 24 |
+
volumes:
|
| 25 |
+
- are-deliverable-0:/run/are-deliverable/app/solution
|
| 26 |
+
- are-secret:/run/are-secret
|
| 27 |
+
expose:
|
| 28 |
+
- "8000"
|
| 29 |
+
cap_add: [SYS_ADMIN]
|
| 30 |
+
networks: [default, are-private]
|
| 31 |
+
cpus: 8
|
| 32 |
+
mem_limit: 14336m
|
| 33 |
+
depends_on:
|
| 34 |
+
test-grader:
|
| 35 |
+
condition: service_healthy
|
| 36 |
+
healthcheck:
|
| 37 |
+
test: ["CMD", "python3", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/health', timeout=2)"]
|
| 38 |
+
interval: 2s
|
| 39 |
+
timeout: 5s
|
| 40 |
+
retries: 60
|
| 41 |
+
start_period: 5s
|
| 42 |
+
|
| 43 |
+
test-grader:
|
| 44 |
+
build:
|
| 45 |
+
context: ./are-grader-ctx
|
| 46 |
+
dockerfile: Dockerfile.are
|
| 47 |
+
args:
|
| 48 |
+
ARE_ROLE: test
|
| 49 |
+
platform: linux/amd64
|
| 50 |
+
environment:
|
| 51 |
+
ARE_ROLE: test
|
| 52 |
+
ARE_PORT: "8001"
|
| 53 |
+
ARE_ARTIFACT_PATHS: "/app/solution"
|
| 54 |
+
ARE_GRADE_TIMEOUT_SEC: "1800"
|
| 55 |
+
expose:
|
| 56 |
+
- "8001"
|
| 57 |
+
volumes:
|
| 58 |
+
- are-secret:/run/are-secret
|
| 59 |
+
cap_add: [SYS_ADMIN]
|
| 60 |
+
networks: [are-private]
|
| 61 |
+
cpus: 8
|
| 62 |
+
mem_limit: 14336m
|
| 63 |
+
healthcheck:
|
| 64 |
+
test: ["CMD", "python3", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8001/health', timeout=2)"]
|
| 65 |
+
interval: 2s
|
| 66 |
+
timeout: 5s
|
| 67 |
+
retries: 60
|
| 68 |
+
start_period: 5s
|
| 69 |
+
|
| 70 |
+
volumes:
|
| 71 |
+
are-deliverable-0: {}
|
| 72 |
+
are-secret: {}
|
| 73 |
+
|
| 74 |
+
networks:
|
| 75 |
+
are-private:
|
| 76 |
+
internal: true
|
tasks/act-tensor-sparse-panel-imputation-r2/task.toml
CHANGED
|
@@ -1,57 +1,71 @@
|
|
| 1 |
schema_version = "1.4"
|
| 2 |
-
artifacts = [
|
|
|
|
|
|
|
| 3 |
|
| 4 |
[task]
|
| 5 |
name = "bespokelabs/act-tensor-sparse-panel-imputation-r2"
|
| 6 |
-
version = "1.
|
| 7 |
description = ""
|
| 8 |
-
keywords = [
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
[metadata]
|
| 13 |
category = "Machine Learning and AI"
|
| 14 |
subcategory = "Unsupervised and representation learning"
|
| 15 |
-
task_objective = [
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
expert_time_estimate_hours = 4.0
|
|
|
|
|
|
|
| 18 |
|
| 19 |
[verifier]
|
| 20 |
-
timeout_sec =
|
| 21 |
environment_mode = "separate"
|
| 22 |
-
collect = []
|
| 23 |
|
| 24 |
-
[verifier.
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
[verifier.environment]
|
| 27 |
network_mode = "no-network"
|
| 28 |
-
build_timeout_sec =
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
memory_mb = 14336
|
| 32 |
-
storage_mb = 153600
|
| 33 |
gpus = 0
|
| 34 |
-
mcp_servers = []
|
| 35 |
-
|
| 36 |
-
[verifier.environment.env]
|
| 37 |
|
| 38 |
[agent]
|
| 39 |
network_mode = "allowlist"
|
| 40 |
-
allowed_hosts = [
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
user = "agent"
|
| 43 |
|
| 44 |
[environment]
|
| 45 |
-
network_mode = "
|
| 46 |
-
allowed_hosts = [ "api.openai.com", "api.anthropic.com",]
|
| 47 |
build_timeout_sec = 3600.0
|
| 48 |
os = "linux"
|
| 49 |
cpus = 8
|
| 50 |
memory_mb = 14336
|
| 51 |
storage_mb = 153600
|
| 52 |
gpus = 0
|
| 53 |
-
mcp_servers = [
|
|
|
|
|
|
|
| 54 |
|
| 55 |
[environment.env]
|
| 56 |
-
|
| 57 |
-
[solution.env]
|
|
|
|
| 1 |
schema_version = "1.4"
|
| 2 |
+
artifacts = [
|
| 3 |
+
{ source = "/var/lib/are", service = "grader" },
|
| 4 |
+
]
|
| 5 |
|
| 6 |
[task]
|
| 7 |
name = "bespokelabs/act-tensor-sparse-panel-imputation-r2"
|
| 8 |
+
version = "1.1.0"
|
| 9 |
description = ""
|
| 10 |
+
keywords = [
|
| 11 |
+
"autoresearch",
|
| 12 |
+
"machine-learning",
|
| 13 |
+
"benchmark",
|
| 14 |
+
]
|
| 15 |
+
authors = [
|
| 16 |
+
{ name = "Bespoke Labs" },
|
| 17 |
+
]
|
| 18 |
|
| 19 |
[metadata]
|
| 20 |
category = "Machine Learning and AI"
|
| 21 |
subcategory = "Unsupervised and representation learning"
|
| 22 |
+
task_objective = [
|
| 23 |
+
"Implement",
|
| 24 |
+
"Optimize",
|
| 25 |
+
]
|
| 26 |
+
artifact_type = [
|
| 27 |
+
"Single script or program",
|
| 28 |
+
]
|
| 29 |
expert_time_estimate_hours = 4.0
|
| 30 |
+
are_version = "1.1"
|
| 31 |
+
budget_seconds = 86400
|
| 32 |
|
| 33 |
[verifier]
|
| 34 |
+
timeout_sec = 600.0
|
| 35 |
environment_mode = "separate"
|
|
|
|
| 36 |
|
| 37 |
+
[[verifier.collect]]
|
| 38 |
+
service = "grader"
|
| 39 |
+
command = "/opt/are/venv/bin/python /opt/are/drain.py"
|
| 40 |
+
timeout_sec = 3600.0
|
| 41 |
|
| 42 |
[verifier.environment]
|
| 43 |
network_mode = "no-network"
|
| 44 |
+
build_timeout_sec = 600.0
|
| 45 |
+
cpus = 1
|
| 46 |
+
memory_mb = 1024
|
|
|
|
|
|
|
| 47 |
gpus = 0
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
[agent]
|
| 50 |
network_mode = "allowlist"
|
| 51 |
+
allowed_hosts = [
|
| 52 |
+
"api.openai.com",
|
| 53 |
+
"api.anthropic.com",
|
| 54 |
+
"grader",
|
| 55 |
+
]
|
| 56 |
+
timeout_sec = 86400.0
|
| 57 |
user = "agent"
|
| 58 |
|
| 59 |
[environment]
|
| 60 |
+
network_mode = "public"
|
|
|
|
| 61 |
build_timeout_sec = 3600.0
|
| 62 |
os = "linux"
|
| 63 |
cpus = 8
|
| 64 |
memory_mb = 14336
|
| 65 |
storage_mb = 153600
|
| 66 |
gpus = 0
|
| 67 |
+
mcp_servers = [
|
| 68 |
+
{ name = "are", transport = "streamable-http", url = "http://grader:8000/mcp" },
|
| 69 |
+
]
|
| 70 |
|
| 71 |
[environment.env]
|
|
|
|
|
|
tasks/act-tensor-sparse-panel-imputation-r2/tests/Dockerfile
CHANGED
|
@@ -1,35 +1,2 @@
|
|
| 1 |
-
FROM
|
| 2 |
-
|
| 3 |
-
ENTRYPOINT []
|
| 4 |
-
ENV PYTHONPATH=
|
| 5 |
-
ENV PYTHONSAFEPATH=1
|
| 6 |
-
ENV DEBIAN_FRONTEND=noninteractive \
|
| 7 |
-
PYTHONHASHSEED=0 \
|
| 8 |
-
PIP_NO_CACHE_DIR=1 \
|
| 9 |
-
PIP_DISABLE_PIP_VERSION_CHECK=1 \
|
| 10 |
-
OMP_NUM_THREADS=1 \
|
| 11 |
-
OPENBLAS_NUM_THREADS=1 \
|
| 12 |
-
MKL_NUM_THREADS=1 \
|
| 13 |
-
NUMEXPR_NUM_THREADS=1
|
| 14 |
-
|
| 15 |
-
RUN useradd --create-home --uid 1001 agent
|
| 16 |
-
|
| 17 |
-
COPY ./requirements.txt /tmp/requirements.txt
|
| 18 |
-
COPY ./requirements-verifier.txt /tmp/requirements-verifier.txt
|
| 19 |
-
RUN /usr/local/bin/python3 -m pip install --no-cache-dir \
|
| 20 |
-
-r /tmp/requirements.txt -r /tmp/requirements-verifier.txt \
|
| 21 |
-
&& rm /tmp/requirements.txt /tmp/requirements-verifier.txt
|
| 22 |
-
|
| 23 |
-
RUN mkdir -p /app/solution /logs/verifier
|
| 24 |
-
|
| 25 |
-
COPY . /tests
|
| 26 |
-
|
| 27 |
-
RUN chown -R root:root /tests \
|
| 28 |
-
&& chmod 700 /tests/hidden_data /tests/hidden_data/intermediate /tests/hidden_data/final \
|
| 29 |
-
&& chmod +x /tests/test.sh /tests/intermediate.sh \
|
| 30 |
-
&& find /tests -exec touch -d @1700000000 {} +
|
| 31 |
-
|
| 32 |
-
WORKDIR /tests
|
| 33 |
-
|
| 34 |
-
ENV HF_HUB_OFFLINE=1
|
| 35 |
-
ENV TRANSFORMERS_OFFLINE=1
|
|
|
|
| 1 |
+
FROM python:3.12-slim
|
| 2 |
+
COPY . /tests/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tasks/act-tensor-sparse-panel-imputation-r2/tests/finalize.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Final verifier: score the run from the grader ledger.
|
| 2 |
+
|
| 3 |
+
reward hidden test score of the submission with the best validation score
|
| 4 |
+
(ties go to the earlier submission); 0 if nothing was submitted.
|
| 5 |
+
auarc area under the curve of that same quantity over the wall-clock budget,
|
| 6 |
+
using the time each validation score became available, divided by the
|
| 7 |
+
budget. 0 before the first graded submission.
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
import json
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
|
| 13 |
+
STATE = Path("/var/lib/are")
|
| 14 |
+
OUT = Path("/logs/verifier")
|
| 15 |
+
OUT.mkdir(parents=True, exist_ok=True)
|
| 16 |
+
|
| 17 |
+
meta = json.loads((STATE / "meta.json").read_text()) if (STATE / "meta.json").exists() else {}
|
| 18 |
+
budget = float(meta.get("budget_seconds") or 1.0)
|
| 19 |
+
|
| 20 |
+
subs: dict[int, dict] = {}
|
| 21 |
+
ledger = STATE / "ledger.jsonl"
|
| 22 |
+
for line in (ledger.read_text().splitlines() if ledger.exists() else []):
|
| 23 |
+
ev = json.loads(line)
|
| 24 |
+
s = subs.setdefault(ev["id"], {"id": ev["id"]})
|
| 25 |
+
if ev["event"] == "submitted":
|
| 26 |
+
s["submitted_t"] = ev["t"]
|
| 27 |
+
elif ev["event"] == "val":
|
| 28 |
+
s["val"] = ev["score"]
|
| 29 |
+
s["val_t"] = ev["t"]
|
| 30 |
+
elif ev["event"] == "test":
|
| 31 |
+
s["test"] = ev["score"]
|
| 32 |
+
|
| 33 |
+
graded = sorted((s for s in subs.values() if "val" in s), key=lambda s: s["val_t"])
|
| 34 |
+
|
| 35 |
+
# Step function of the hidden score of the best-validation pick over time.
|
| 36 |
+
auc, best, last_t, cur = 0.0, None, 0.0, 0.0
|
| 37 |
+
timeline = []
|
| 38 |
+
for s in graded:
|
| 39 |
+
t = min(s["val_t"], budget)
|
| 40 |
+
auc += cur * (t - last_t)
|
| 41 |
+
last_t = t
|
| 42 |
+
if best is None or s["val"] > best["val"] or (s["val"] == best["val"] and s["id"] < best["id"]):
|
| 43 |
+
best = s
|
| 44 |
+
cur = float(best.get("test") or 0.0)
|
| 45 |
+
timeline.append({"t": s["val_t"], "id": s["id"], "val": s["val"], "test": s.get("test"),
|
| 46 |
+
"pick": best["id"]})
|
| 47 |
+
auc += cur * (budget - last_t) if last_t < budget else 0.0
|
| 48 |
+
|
| 49 |
+
reward = {
|
| 50 |
+
"reward": float(best.get("test") or 0.0) if best else 0.0,
|
| 51 |
+
"auarc": auc / budget,
|
| 52 |
+
"best_val": float(best["val"]) if best else 0.0,
|
| 53 |
+
"n_submissions": float(len(subs)),
|
| 54 |
+
"n_test_graded": float(sum(s.get("test") is not None for s in subs.values())),
|
| 55 |
+
}
|
| 56 |
+
(OUT / "reward.json").write_text(json.dumps(reward))
|
| 57 |
+
(OUT / "timeline.json").write_text(json.dumps({"budget": budget, "selected": best and best["id"],
|
| 58 |
+
"submissions": timeline}, indent=1))
|
| 59 |
+
print(json.dumps(reward, indent=1))
|
tasks/act-tensor-sparse-panel-imputation-r2/tests/test.sh
CHANGED
|
@@ -1,18 +1,2 @@
|
|
| 1 |
#!/bin/bash
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
trap 'if [ ! -s /logs/verifier/reward.txt ]; then mkdir -p /logs/verifier; printf "0\n" > /logs/verifier/reward.txt; fi' EXIT
|
| 5 |
-
|
| 6 |
-
mkdir -p /logs/verifier
|
| 7 |
-
chown root:root /logs/verifier 2>/dev/null || true
|
| 8 |
-
chmod 755 /logs/verifier 2>/dev/null || true
|
| 9 |
-
rm -f /logs/verifier/reward.txt /logs/verifier/ctrf.json /logs/verifier/metric.json
|
| 10 |
-
|
| 11 |
-
chmod -R go-rwx /tests
|
| 12 |
-
|
| 13 |
-
cd /tests
|
| 14 |
-
export GRADER_SPLIT=final
|
| 15 |
-
/usr/local/bin/python3 -m pytest --ctrf /logs/verifier/ctrf.json /tests/test_state.py -rA
|
| 16 |
-
/usr/local/bin/python3 /tests/compute_reward.py
|
| 17 |
-
|
| 18 |
-
exit 0
|
|
|
|
| 1 |
#!/bin/bash
|
| 2 |
+
python3 /tests/finalize.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tasks/activeprune-al-unlabeled-pool-pruning/environment/.dockerignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
are-grader-ctx
|
tasks/activeprune-al-unlabeled-pool-pruning/environment/are-grader-ctx/Dockerfile
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM --platform=linux/amd64 public.ecr.aws/docker/library/python:3.13-slim-bookworm@sha256:01f42367a0a94ad4bc17111776fd66e3500c1d87c15bbd6055b7371d39c124fb
|
| 2 |
+
|
| 3 |
+
ENTRYPOINT []
|
| 4 |
+
ENV PYTHONPATH=
|
| 5 |
+
ENV PYTHONSAFEPATH=1
|
| 6 |
+
ENV DEBIAN_FRONTEND=noninteractive \
|
| 7 |
+
PYTHONHASHSEED=0 \
|
| 8 |
+
PIP_NO_CACHE_DIR=1 \
|
| 9 |
+
PIP_DISABLE_PIP_VERSION_CHECK=1 \
|
| 10 |
+
OMP_NUM_THREADS=1 \
|
| 11 |
+
OPENBLAS_NUM_THREADS=1 \
|
| 12 |
+
MKL_NUM_THREADS=1
|
| 13 |
+
|
| 14 |
+
RUN useradd --create-home --uid 1001 agent
|
| 15 |
+
|
| 16 |
+
COPY ./requirements.txt /tmp/requirements.txt
|
| 17 |
+
COPY ./requirements-verifier.txt /tmp/requirements-verifier.txt
|
| 18 |
+
RUN /usr/local/bin/python3 -m pip install --no-cache-dir \
|
| 19 |
+
-r /tmp/requirements.txt -r /tmp/requirements-verifier.txt \
|
| 20 |
+
&& rm /tmp/requirements.txt /tmp/requirements-verifier.txt
|
| 21 |
+
|
| 22 |
+
RUN mkdir -p /app/output /logs/verifier /grade_stage \
|
| 23 |
+
&& chmod 755 /tmp /var/tmp /dev/shm /home/agent
|
| 24 |
+
|
| 25 |
+
COPY . /tests
|
| 26 |
+
|
| 27 |
+
RUN chown -R root:root /tests \
|
| 28 |
+
&& chmod 700 /tests/hidden_data /tests/hidden_data/intermediate /tests/hidden_data/final \
|
| 29 |
+
&& chmod +x /tests/test.sh /tests/intermediate.sh \
|
| 30 |
+
&& find /tests -exec touch -d @1700000000 {} +
|
| 31 |
+
|
| 32 |
+
WORKDIR /tests
|
| 33 |
+
|
| 34 |
+
ENV HF_HUB_OFFLINE=1
|
| 35 |
+
ENV TRANSFORMERS_OFFLINE=1
|
tasks/activeprune-al-unlabeled-pool-pruning/environment/are-grader-ctx/Dockerfile.are
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM --platform=linux/amd64 public.ecr.aws/docker/library/python:3.13-slim-bookworm@sha256:01f42367a0a94ad4bc17111776fd66e3500c1d87c15bbd6055b7371d39c124fb
|
| 2 |
+
|
| 3 |
+
ENTRYPOINT []
|
| 4 |
+
ENV PYTHONPATH=
|
| 5 |
+
ENV PYTHONSAFEPATH=1
|
| 6 |
+
ENV DEBIAN_FRONTEND=noninteractive \
|
| 7 |
+
PYTHONHASHSEED=0 \
|
| 8 |
+
PIP_NO_CACHE_DIR=1 \
|
| 9 |
+
PIP_DISABLE_PIP_VERSION_CHECK=1 \
|
| 10 |
+
OMP_NUM_THREADS=1 \
|
| 11 |
+
OPENBLAS_NUM_THREADS=1 \
|
| 12 |
+
MKL_NUM_THREADS=1
|
| 13 |
+
|
| 14 |
+
RUN useradd --create-home --uid 1001 agent
|
| 15 |
+
|
| 16 |
+
COPY ./requirements.txt /tmp/requirements.txt
|
| 17 |
+
COPY ./requirements-verifier.txt /tmp/requirements-verifier.txt
|
| 18 |
+
RUN /usr/local/bin/python3 -m pip install --no-cache-dir \
|
| 19 |
+
-r /tmp/requirements.txt -r /tmp/requirements-verifier.txt \
|
| 20 |
+
&& rm /tmp/requirements.txt /tmp/requirements-verifier.txt
|
| 21 |
+
|
| 22 |
+
RUN mkdir -p /app/output /logs/verifier /grade_stage \
|
| 23 |
+
&& chmod 755 /tmp /var/tmp /dev/shm /home/agent
|
| 24 |
+
|
| 25 |
+
COPY . /tests
|
| 26 |
+
|
| 27 |
+
RUN chown -R root:root /tests \
|
| 28 |
+
&& chmod 700 /tests/hidden_data /tests/hidden_data/intermediate /tests/hidden_data/final \
|
| 29 |
+
&& chmod +x /tests/test.sh /tests/intermediate.sh \
|
| 30 |
+
&& find /tests -exec touch -d @1700000000 {} +
|
| 31 |
+
|
| 32 |
+
WORKDIR /tests
|
| 33 |
+
|
| 34 |
+
ENV HF_HUB_OFFLINE=1
|
| 35 |
+
ENV TRANSFORMERS_OFFLINE=1
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
# ---- ARE 1.1 grader layer (appended to the task's own verifier Dockerfile) ----
|
| 39 |
+
ARG ARE_ROLE
|
| 40 |
+
# python.org images ship /usr/local/bin/python3; distro-python bases (kaggle GPU) lack
|
| 41 |
+
# ensurepip, so fall back to a pip-less venv filled by the base interpreter's pip.
|
| 42 |
+
RUN PY=$(command -v /usr/local/bin/python3 || command -v python3) \
|
| 43 |
+
&& if "$PY" -m venv /opt/are/venv; then \
|
| 44 |
+
/opt/are/venv/bin/pip install --no-cache-dir "fastmcp==2.14.7"; \
|
| 45 |
+
else rm -rf /opt/are/venv && "$PY" -m venv --without-pip /opt/are/venv \
|
| 46 |
+
&& "$PY" -m pip --python /opt/are/venv/bin/python install --no-cache-dir "fastmcp==2.14.7"; fi
|
| 47 |
+
COPY are/ /opt/are/
|
| 48 |
+
# The val grader, whose output reaches the agent, never holds the private grader or its
|
| 49 |
+
# data. The test grader keeps everything; nothing from it reaches the agent.
|
| 50 |
+
RUN rm -rf /tests/are /tests/Dockerfile.are \
|
| 51 |
+
&& if [ "$ARE_ROLE" = "val" ]; then rm -rf /tests/test.sh /tests/hidden_data/final; fi
|
| 52 |
+
ENV ARE_ROLE=$ARE_ROLE
|
| 53 |
+
CMD ["/opt/are/venv/bin/python", "/opt/are/server.py"]
|
tasks/activeprune-al-unlabeled-pool-pruning/{tests → environment/are-grader-ctx}/al_loop.py
RENAMED
|
File without changes
|
tasks/activeprune-al-unlabeled-pool-pruning/environment/are-grader-ctx/are/drain.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Verifier collect hook, run after the agent stops.
|
| 2 |
+
|
| 3 |
+
Grades the final workspace as one last submission (unless it equals the last one),
|
| 4 |
+
then waits until every submission has both grades recorded.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import json
|
| 8 |
+
import time
|
| 9 |
+
import urllib.request
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
|
| 12 |
+
TOKEN = Path("/run/are-secret/token").read_text().strip()
|
| 13 |
+
H = {"x-are-token": TOKEN}
|
| 14 |
+
|
| 15 |
+
req = urllib.request.Request("http://localhost:8000/final", method="POST", headers=H)
|
| 16 |
+
with urllib.request.urlopen(req, timeout=120) as resp:
|
| 17 |
+
print("final:", json.loads(resp.read()), flush=True)
|
| 18 |
+
|
| 19 |
+
while True:
|
| 20 |
+
with urllib.request.urlopen(urllib.request.Request("http://localhost:8000/drain", headers=H), timeout=30) as resp:
|
| 21 |
+
state = json.loads(resp.read())
|
| 22 |
+
print(state, flush=True)
|
| 23 |
+
if state["val_pending"] == 0 and state["test_pending"] == 0:
|
| 24 |
+
break
|
| 25 |
+
time.sleep(5)
|
tasks/activeprune-al-unlabeled-pool-pruning/environment/are-grader-ctx/are/server.py
ADDED
|
@@ -0,0 +1,538 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""ARE 1.1 grader sidecar.
|
| 2 |
+
|
| 3 |
+
One image, two roles:
|
| 4 |
+
|
| 5 |
+
- ARE_ROLE=val ("grader" service). Reachable from the agent. Serves MCP tools and a
|
| 6 |
+
REST fallback. On submit it snapshots the shared deliverable volume, grades the
|
| 7 |
+
snapshot with the task's public grader (intermediate.sh), and returns only that
|
| 8 |
+
score. Every snapshot is also sent to the test grader; the hidden score goes to a
|
| 9 |
+
root-only ledger and never back to the agent.
|
| 10 |
+
- ARE_ROLE=test ("test-grader" service). On a private network that only the val
|
| 11 |
+
grader can reach. Grades snapshots with the task's private grader (test.sh).
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
from __future__ import annotations
|
| 15 |
+
|
| 16 |
+
import asyncio
|
| 17 |
+
import gzip
|
| 18 |
+
import hashlib
|
| 19 |
+
import io
|
| 20 |
+
import secrets
|
| 21 |
+
import json
|
| 22 |
+
import os
|
| 23 |
+
import queue
|
| 24 |
+
import shutil
|
| 25 |
+
import subprocess
|
| 26 |
+
import tarfile
|
| 27 |
+
import threading
|
| 28 |
+
import time
|
| 29 |
+
import urllib.request
|
| 30 |
+
from pathlib import Path
|
| 31 |
+
|
| 32 |
+
from fastmcp import FastMCP
|
| 33 |
+
from starlette.requests import Request
|
| 34 |
+
from starlette.responses import JSONResponse, Response
|
| 35 |
+
|
| 36 |
+
ROLE = os.environ.get("ARE_ROLE", "val")
|
| 37 |
+
PORT = int(os.environ.get("ARE_PORT", "8000"))
|
| 38 |
+
STATE = Path(os.environ.get("ARE_STATE_DIR", "/var/lib/are"))
|
| 39 |
+
ARTIFACT_PATHS = [p for p in os.environ.get("ARE_ARTIFACT_PATHS", "/app/output").split(":") if p]
|
| 40 |
+
# The shared deliverable volume. Its parent is root-only, so submitted code (which every
|
| 41 |
+
# task grader runs as the unprivileged agent user) cannot reach it to write back to the agent.
|
| 42 |
+
SUBMISSION_ROOT = Path(os.environ.get("ARE_SUBMISSION_ROOT", "/run/are-deliverable"))
|
| 43 |
+
AGENT_UID = int(os.environ.get("ARE_AGENT_UID", "1001"))
|
| 44 |
+
BUDGET_SEC = float(os.environ.get("ARE_BUDGET_SEC", "14400"))
|
| 45 |
+
GRADE_TIMEOUT_SEC = float(os.environ.get("ARE_GRADE_TIMEOUT_SEC", "1800"))
|
| 46 |
+
TEST_GRADER_URL = os.environ.get("ARE_TEST_GRADER_URL", "http://test-grader:8001")
|
| 47 |
+
FEEDBACK_TAIL = int(os.environ.get("ARE_FEEDBACK_TAIL_CHARS", "8192"))
|
| 48 |
+
SCRIPT = "/tests/intermediate.sh" if ROLE == "val" else "/tests/test.sh"
|
| 49 |
+
# Shared only by the two graders (a volume the agent's container never mounts). The test
|
| 50 |
+
# grader writes a fresh token at startup; every internal request must carry it, so the
|
| 51 |
+
# agent cannot reach the test grader or the internal endpoints even on a shared network.
|
| 52 |
+
TOKEN_FILE = Path(os.environ.get("ARE_TOKEN_FILE", "/run/are-secret/token"))
|
| 53 |
+
TOKEN = ""
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def _authorized(request: Request) -> bool:
|
| 57 |
+
"""Internal endpoints need the graders' token; an unset token never matches."""
|
| 58 |
+
return bool(TOKEN) and secrets.compare_digest(request.headers.get("x-are-token", ""), TOKEN)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def _net_isolation_available() -> bool:
|
| 62 |
+
try:
|
| 63 |
+
return subprocess.run(["unshare", "-n", "true"], capture_output=True, timeout=10).returncode == 0
|
| 64 |
+
except Exception:
|
| 65 |
+
return False
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
NET_ISOLATED = False # set at startup: grader scripts run in an empty network namespace
|
| 69 |
+
|
| 70 |
+
T0 = time.time()
|
| 71 |
+
_lock = threading.Lock()
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def _elapsed() -> float:
|
| 75 |
+
return round(time.time() - T0, 1)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def _ledger(event: dict) -> None:
|
| 79 |
+
event = {"t": _elapsed(), "wall": time.time(), **event}
|
| 80 |
+
for attempt in range(3):
|
| 81 |
+
try:
|
| 82 |
+
with _lock, open(STATE / "ledger.jsonl", "a") as fh:
|
| 83 |
+
fh.write(json.dumps(event) + "\n")
|
| 84 |
+
return
|
| 85 |
+
except OSError:
|
| 86 |
+
if attempt == 2:
|
| 87 |
+
raise
|
| 88 |
+
time.sleep(1)
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def _kill_grading_processes(proc: subprocess.Popen) -> None:
|
| 92 |
+
"""Kill everything a timed-out grade started, including processes that left its group."""
|
| 93 |
+
try:
|
| 94 |
+
os.killpg(proc.pid, 9)
|
| 95 |
+
except ProcessLookupError:
|
| 96 |
+
pass
|
| 97 |
+
_kill_other_processes()
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def _kill_other_processes() -> None:
|
| 101 |
+
"""Kill every process run by the agent user. Every task grader runs submitted code as
|
| 102 |
+
that user, so this stops all graded code (detached or not) and nothing else: the grader
|
| 103 |
+
server, the task's own grader and Harbor's hooks run as root."""
|
| 104 |
+
for entry in Path("/proc").iterdir():
|
| 105 |
+
if not entry.name.isdigit():
|
| 106 |
+
continue
|
| 107 |
+
try:
|
| 108 |
+
if entry.stat().st_uid == AGENT_UID:
|
| 109 |
+
os.kill(int(entry.name), 9)
|
| 110 |
+
except (ProcessLookupError, PermissionError, FileNotFoundError):
|
| 111 |
+
pass
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
# Places the agent user (who runs submitted code inside every task grader) can write.
|
| 115 |
+
_BASELINE: set[str] = set() # every path that existed when the grader started (its image)
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def _walk_one_fs(base: Path):
|
| 119 |
+
"""Every path under base on base's own filesystem (skips /proc, /sys and other mounts)."""
|
| 120 |
+
dev = base.stat().st_dev
|
| 121 |
+
for root, dirs, files in os.walk(base):
|
| 122 |
+
dirs[:] = [d for d in dirs if os.lstat(os.path.join(root, d)).st_dev == dev]
|
| 123 |
+
for name in dirs + files:
|
| 124 |
+
yield Path(root) / name
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def _all_paths() -> set[str]:
|
| 128 |
+
out = set()
|
| 129 |
+
for base in (Path("/"), Path("/dev/shm")):
|
| 130 |
+
if base.is_dir():
|
| 131 |
+
out.update(str(q) for q in _walk_one_fs(base))
|
| 132 |
+
return out
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def _protected(path: str) -> bool:
|
| 136 |
+
keep = [str(STATE), "/opt/are", str(TOKEN_FILE.parent)]
|
| 137 |
+
return any(path == k or path.startswith(k + "/") for k in keep)
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
def _fresh_state() -> None:
|
| 141 |
+
"""Start every grade from the grader image's own files, as ARE 1.0's fresh verifier
|
| 142 |
+
container did. The grader container lives for the whole run, so before each grade
|
| 143 |
+
stop anything an earlier grade left running and delete every file it created,
|
| 144 |
+
whoever wrote it. The deliverable volume and the token are separate mounts and are
|
| 145 |
+
never walked; the grader's own state is kept."""
|
| 146 |
+
_kill_other_processes()
|
| 147 |
+
# System V shared memory, semaphores and queues outlive processes; this server uses none.
|
| 148 |
+
subprocess.run(["ipcrm", "--all"], capture_output=True)
|
| 149 |
+
for path in sorted(_all_paths() - _BASELINE, key=lambda q: q.count("/"), reverse=True):
|
| 150 |
+
if _protected(path):
|
| 151 |
+
continue
|
| 152 |
+
try:
|
| 153 |
+
q = Path(path)
|
| 154 |
+
if q.is_dir() and not q.is_symlink():
|
| 155 |
+
shutil.rmtree(q, ignore_errors=True)
|
| 156 |
+
else:
|
| 157 |
+
q.unlink()
|
| 158 |
+
except OSError:
|
| 159 |
+
pass
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
def grade_snapshot(tar_bytes: bytes, tag: str) -> dict:
|
| 163 |
+
"""Extract a snapshot over the artifact paths and run this role's grader script."""
|
| 164 |
+
_fresh_state()
|
| 165 |
+
for path in ARTIFACT_PATHS:
|
| 166 |
+
p = Path(path)
|
| 167 |
+
if p.exists():
|
| 168 |
+
shutil.rmtree(p)
|
| 169 |
+
p.mkdir(parents=True)
|
| 170 |
+
with tarfile.open(fileobj=io.BytesIO(tar_bytes), mode="r:gz") as tf:
|
| 171 |
+
tf.extractall("/", filter="tar")
|
| 172 |
+
logs = Path("/logs/verifier")
|
| 173 |
+
if logs.exists():
|
| 174 |
+
shutil.rmtree(logs)
|
| 175 |
+
logs.mkdir(parents=True)
|
| 176 |
+
started = time.time()
|
| 177 |
+
# Submitted code runs with no network, as in ARE 1.0's verifier.
|
| 178 |
+
cmd = (["unshare", "-n"] if NET_ISOLATED else []) + ["bash", SCRIPT]
|
| 179 |
+
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True,
|
| 180 |
+
cwd="/tests", start_new_session=True)
|
| 181 |
+
try:
|
| 182 |
+
out, err = proc.communicate(timeout=GRADE_TIMEOUT_SEC)
|
| 183 |
+
error = None
|
| 184 |
+
except subprocess.TimeoutExpired:
|
| 185 |
+
_kill_grading_processes(proc)
|
| 186 |
+
out, err = proc.communicate()
|
| 187 |
+
error = f"grader timed out after {GRADE_TIMEOUT_SEC:.0f}s"
|
| 188 |
+
output = (out or "") + (err or "")
|
| 189 |
+
# Nothing a grade started may keep running after it, not even detached processes.
|
| 190 |
+
_kill_other_processes()
|
| 191 |
+
score = 0.0
|
| 192 |
+
reward_file = logs / "reward.txt"
|
| 193 |
+
if reward_file.exists():
|
| 194 |
+
try:
|
| 195 |
+
score = float(reward_file.read_text().strip() or 0)
|
| 196 |
+
except ValueError:
|
| 197 |
+
error = error or "unparseable reward"
|
| 198 |
+
metric = None
|
| 199 |
+
if (logs / "metric.json").exists():
|
| 200 |
+
try:
|
| 201 |
+
metric = json.loads((logs / "metric.json").read_text())
|
| 202 |
+
except ValueError:
|
| 203 |
+
pass
|
| 204 |
+
(STATE / "logs").mkdir(exist_ok=True)
|
| 205 |
+
(STATE / "logs" / f"{tag}.log").write_text(output)
|
| 206 |
+
return {
|
| 207 |
+
"score": score,
|
| 208 |
+
"metric": metric,
|
| 209 |
+
"error": error,
|
| 210 |
+
"net_isolated": NET_ISOLATED,
|
| 211 |
+
"seconds": round(time.time() - started, 1),
|
| 212 |
+
# What the agent sees, as in ARE 1.0: the grader's stdout tail (not stderr).
|
| 213 |
+
"output_tail": (out or "")[-FEEDBACK_TAIL:],
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
mcp = FastMCP("are")
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
# ---------------------------------------------------------------- test role
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
_grade_lock = threading.Lock()
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
def _grade_one_at_a_time(tar_bytes: bytes, tag: str) -> dict:
|
| 227 |
+
# A request that timed out on the caller's side may still be grading; the next one
|
| 228 |
+
# waits for it rather than sharing /app/output and /logs/verifier with it.
|
| 229 |
+
with _grade_lock:
|
| 230 |
+
return grade_snapshot(tar_bytes, tag)
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
if ROLE == "test":
|
| 234 |
+
|
| 235 |
+
@mcp.custom_route("/grade", methods=["POST"])
|
| 236 |
+
async def http_grade(request: Request) -> Response:
|
| 237 |
+
if not _authorized(request):
|
| 238 |
+
return JSONResponse({"error": "forbidden"}, status_code=403)
|
| 239 |
+
tag = request.query_params.get("tag", "x")
|
| 240 |
+
body = await request.body()
|
| 241 |
+
result = await asyncio.to_thread(_grade_one_at_a_time, body, f"{tag}-test")
|
| 242 |
+
return JSONResponse(result)
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
# ----------------------------------------------------------------- val role
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
class Board:
|
| 249 |
+
"""Submissions and their grading state. Hidden scores are never stored here."""
|
| 250 |
+
|
| 251 |
+
def __init__(self) -> None:
|
| 252 |
+
self.subs: dict[int, dict] = {}
|
| 253 |
+
self.val_q: queue.Queue[int] = queue.Queue()
|
| 254 |
+
self.next_id = 1
|
| 255 |
+
self.test_pending = 0
|
| 256 |
+
self.last_digest: str | None = None
|
| 257 |
+
|
| 258 |
+
def public(self, sid: int) -> dict:
|
| 259 |
+
s = self.subs[sid]
|
| 260 |
+
out = {k: s[k] for k in ("id", "note", "submitted_at_s", "status")}
|
| 261 |
+
if s["status"] == "graded":
|
| 262 |
+
v = s["val"]
|
| 263 |
+
out.update(
|
| 264 |
+
validation_score=v["score"],
|
| 265 |
+
error=v["error"],
|
| 266 |
+
grading_seconds=v["seconds"],
|
| 267 |
+
grader_output_tail=v["output_tail"],
|
| 268 |
+
)
|
| 269 |
+
return out
|
| 270 |
+
|
| 271 |
+
def best(self) -> dict | None:
|
| 272 |
+
graded = [s for s in self.subs.values() if s["status"] == "graded"]
|
| 273 |
+
if not graded:
|
| 274 |
+
return None
|
| 275 |
+
b = max(graded, key=lambda s: (s["val"]["score"], -s["id"]))
|
| 276 |
+
return {"id": b["id"], "validation_score": b["val"]["score"]}
|
| 277 |
+
|
| 278 |
+
|
| 279 |
+
board = Board()
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
def snapshot() -> bytes:
|
| 283 |
+
"""Deterministic tar.gz of the deliverable: same content, same bytes (gzip mtime 0)."""
|
| 284 |
+
raw = io.BytesIO()
|
| 285 |
+
with tarfile.open(fileobj=raw, mode="w") as tf:
|
| 286 |
+
for path in ARTIFACT_PATHS:
|
| 287 |
+
src = SUBMISSION_ROOT / path.lstrip("/")
|
| 288 |
+
tf.add(str(src), arcname=path.lstrip("/"))
|
| 289 |
+
out = io.BytesIO()
|
| 290 |
+
with gzip.GzipFile(fileobj=out, mode="wb", mtime=0) as gz:
|
| 291 |
+
gz.write(raw.getvalue())
|
| 292 |
+
return out.getvalue()
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
def do_submit(note: str, final: bool = False) -> dict:
|
| 296 |
+
with _lock:
|
| 297 |
+
pending = [s["id"] for s in board.subs.values() if s["status"] != "graded"]
|
| 298 |
+
if pending and not final:
|
| 299 |
+
return {
|
| 300 |
+
"error": f"Submission {pending[0]} is still being graded. One submission is "
|
| 301 |
+
f"graded at a time: check result({pending[0]}) and submit again "
|
| 302 |
+
"once it has its score.",
|
| 303 |
+
"pending_id": pending[0],
|
| 304 |
+
}
|
| 305 |
+
sid = board.next_id
|
| 306 |
+
board.next_id += 1
|
| 307 |
+
board.subs[sid] = {"id": sid, "note": note[:500], "submitted_at_s": _elapsed(),
|
| 308 |
+
"status": "queued"}
|
| 309 |
+
try:
|
| 310 |
+
data = snapshot()
|
| 311 |
+
digest = hashlib.sha256(data).hexdigest()
|
| 312 |
+
(STATE / "snapshots" / f"{sid:04d}.tar.gz").write_bytes(data)
|
| 313 |
+
_ledger({"event": "submitted", "id": sid, "note": note[:500], "bytes": len(data),
|
| 314 |
+
"sha256": digest, "final": final})
|
| 315 |
+
except Exception as exc:
|
| 316 |
+
with _lock:
|
| 317 |
+
board.subs.pop(sid, None) # release the slot; the id is not reused
|
| 318 |
+
return {"error": f"Could not snapshot the deliverable ({exc}). Nothing was submitted. "
|
| 319 |
+
"Make sure nothing is writing to it, then submit again."}
|
| 320 |
+
board.last_digest = digest
|
| 321 |
+
with _lock:
|
| 322 |
+
board.test_pending += 1
|
| 323 |
+
board.val_q.put(sid)
|
| 324 |
+
return {"id": sid, "status": "queued",
|
| 325 |
+
"hint": "Grading has started. Check result(id) for the validation score."}
|
| 326 |
+
|
| 327 |
+
|
| 328 |
+
def final_submit() -> dict:
|
| 329 |
+
"""After the agent stops: grade the final workspace unless it was already submitted."""
|
| 330 |
+
try:
|
| 331 |
+
data = snapshot()
|
| 332 |
+
except Exception as exc:
|
| 333 |
+
return {"error": f"final snapshot failed: {exc}"}
|
| 334 |
+
if board.subs and hashlib.sha256(data).hexdigest() == board.last_digest:
|
| 335 |
+
return {"skipped": "final workspace equals the last submission"}
|
| 336 |
+
return do_submit("final workspace (automatic)", final=True)
|
| 337 |
+
|
| 338 |
+
|
| 339 |
+
def grade_worker() -> None:
|
| 340 |
+
"""Grade each submission on val, then on test, one submission at a time.
|
| 341 |
+
|
| 342 |
+
The val score is published as soon as it is ready. The next submission's val grade
|
| 343 |
+
waits until this test grade is done, so the two graders never run at the same time.
|
| 344 |
+
"""
|
| 345 |
+
while True:
|
| 346 |
+
sid = board.val_q.get()
|
| 347 |
+
board.subs[sid]["status"] = "grading"
|
| 348 |
+
data = b""
|
| 349 |
+
try:
|
| 350 |
+
data = (STATE / "snapshots" / f"{sid:04d}.tar.gz").read_bytes()
|
| 351 |
+
res = grade_snapshot(data, f"{sid:04d}-val")
|
| 352 |
+
except Exception as exc:
|
| 353 |
+
res = {"score": 0.0, "metric": None, "error": f"grader failed: {exc}",
|
| 354 |
+
"net_isolated": NET_ISOLATED, "seconds": 0.0, "output_tail": ""}
|
| 355 |
+
board.subs[sid]["val"] = res
|
| 356 |
+
board.subs[sid]["status"] = "graded"
|
| 357 |
+
try:
|
| 358 |
+
_ledger({"event": "val", "id": sid, **{k: res[k] for k in ("score", "metric", "error", "seconds", "net_isolated")}})
|
| 359 |
+
except OSError as exc: # keep grading later submissions
|
| 360 |
+
print(f"ARE grader: ledger write failed for {sid}: {exc}", flush=True)
|
| 361 |
+
test_grade(sid, data)
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
def test_grade(sid: int, data: bytes) -> None:
|
| 365 |
+
try:
|
| 366 |
+
_test_grade(sid, data)
|
| 367 |
+
finally:
|
| 368 |
+
with _lock:
|
| 369 |
+
board.test_pending -= 1
|
| 370 |
+
|
| 371 |
+
|
| 372 |
+
def _test_grade(sid: int, data: bytes) -> None:
|
| 373 |
+
"""Send one snapshot to the test grader. A failed request is retried (the same snapshot
|
| 374 |
+
is graded again, so a retry can only recover the honest score); a request that ran
|
| 375 |
+
past its timeout is not, since the grade itself already took the full time."""
|
| 376 |
+
started = time.time()
|
| 377 |
+
for attempt in range(3):
|
| 378 |
+
try:
|
| 379 |
+
req = urllib.request.Request(
|
| 380 |
+
f"{TEST_GRADER_URL}/grade?tag={sid:04d}", data=data, method="POST",
|
| 381 |
+
headers={"x-are-token": TOKEN},
|
| 382 |
+
)
|
| 383 |
+
with urllib.request.urlopen(req, timeout=2 * GRADE_TIMEOUT_SEC + 300) as resp:
|
| 384 |
+
res = json.loads(resp.read())
|
| 385 |
+
break
|
| 386 |
+
except Exception as exc: # recorded, never shown to the agent
|
| 387 |
+
res = {"score": None, "metric": None, "error": f"test grader: {exc}",
|
| 388 |
+
"seconds": round(time.time() - started, 1)}
|
| 389 |
+
if attempt == 2 or isinstance(exc, TimeoutError) or isinstance(getattr(exc, "reason", None), TimeoutError):
|
| 390 |
+
break
|
| 391 |
+
time.sleep(5)
|
| 392 |
+
try:
|
| 393 |
+
_ledger({"event": "test", "id": sid, **{k: res.get(k) for k in ("score", "metric", "error", "seconds", "net_isolated")}})
|
| 394 |
+
except OSError as exc: # keep grading later submissions
|
| 395 |
+
print(f"ARE grader: ledger write failed for {sid}: {exc}", flush=True)
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
def with_time(out: dict) -> dict:
|
| 399 |
+
"""Wall-clock accounting on every reply, as the v1 harness gave each phase."""
|
| 400 |
+
out["total_budget_seconds"] = BUDGET_SEC
|
| 401 |
+
out["time_remaining_seconds"] = round(max(0.0, BUDGET_SEC - _elapsed()), 1)
|
| 402 |
+
return out
|
| 403 |
+
|
| 404 |
+
|
| 405 |
+
def status_dict() -> dict:
|
| 406 |
+
return {
|
| 407 |
+
"submissions": len(board.subs),
|
| 408 |
+
"queued_or_grading": sum(s["status"] != "graded" for s in board.subs.values()),
|
| 409 |
+
"best": board.best(),
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
def current_result(sid: int) -> dict:
|
| 414 |
+
return board.public(sid)
|
| 415 |
+
|
| 416 |
+
|
| 417 |
+
if ROLE == "val":
|
| 418 |
+
|
| 419 |
+
@mcp.tool
|
| 420 |
+
async def submit(note: str = "") -> dict:
|
| 421 |
+
"""Submit the current deliverable for grading.
|
| 422 |
+
|
| 423 |
+
Snapshots the deliverable directory right now (later edits do not affect this
|
| 424 |
+
submission) and starts grading it on the public validation split. Returns at
|
| 425 |
+
once with a submission id. One submission is graded at a time: check `result`
|
| 426 |
+
and submit again once the previous submission has its score. `note` is a short
|
| 427 |
+
description of what changed.
|
| 428 |
+
"""
|
| 429 |
+
return with_time(await asyncio.to_thread(do_submit, note))
|
| 430 |
+
|
| 431 |
+
@mcp.tool
|
| 432 |
+
async def result(id: int) -> dict:
|
| 433 |
+
"""The current state of a submission: queued, grading, or graded with its
|
| 434 |
+
validation score and grader output. Returns immediately."""
|
| 435 |
+
if id not in board.subs:
|
| 436 |
+
return {"error": f"unknown submission id {id}"}
|
| 437 |
+
return with_time(current_result(id))
|
| 438 |
+
|
| 439 |
+
@mcp.tool
|
| 440 |
+
async def status() -> dict:
|
| 441 |
+
"""Submission count, whether one is being graded, the best validation score,
|
| 442 |
+
and the time budget and time remaining."""
|
| 443 |
+
return with_time(status_dict())
|
| 444 |
+
|
| 445 |
+
@mcp.custom_route("/submit", methods=["POST"])
|
| 446 |
+
async def http_submit(request: Request) -> Response:
|
| 447 |
+
note = request.query_params.get("note", "")
|
| 448 |
+
return JSONResponse(with_time(await asyncio.to_thread(do_submit, note)))
|
| 449 |
+
|
| 450 |
+
@mcp.custom_route("/result/{sid}", methods=["GET"])
|
| 451 |
+
async def http_result(request: Request) -> Response:
|
| 452 |
+
sid = int(request.path_params["sid"])
|
| 453 |
+
if sid not in board.subs:
|
| 454 |
+
return JSONResponse({"error": f"unknown submission id {sid}"}, status_code=404)
|
| 455 |
+
return JSONResponse(with_time(current_result(sid)))
|
| 456 |
+
|
| 457 |
+
@mcp.custom_route("/status", methods=["GET"])
|
| 458 |
+
async def http_status(request: Request) -> Response:
|
| 459 |
+
return JSONResponse(with_time(status_dict()))
|
| 460 |
+
|
| 461 |
+
@mcp.custom_route("/final", methods=["POST"])
|
| 462 |
+
async def http_final(request: Request) -> Response:
|
| 463 |
+
if not _authorized(request):
|
| 464 |
+
return JSONResponse({"error": "forbidden"}, status_code=403)
|
| 465 |
+
# Collect hook, after the agent has stopped.
|
| 466 |
+
return JSONResponse(await asyncio.to_thread(final_submit))
|
| 467 |
+
|
| 468 |
+
@mcp.custom_route("/drain", methods=["GET"])
|
| 469 |
+
async def http_drain(request: Request) -> Response:
|
| 470 |
+
if not _authorized(request):
|
| 471 |
+
return JSONResponse({"error": "forbidden"}, status_code=403)
|
| 472 |
+
# Used by the verifier collect hook after the agent has stopped.
|
| 473 |
+
pending = sum(s["status"] != "graded" for s in board.subs.values())
|
| 474 |
+
return JSONResponse({"val_pending": pending, "test_pending": board.test_pending})
|
| 475 |
+
|
| 476 |
+
|
| 477 |
+
def _gpus() -> list[str]:
|
| 478 |
+
try:
|
| 479 |
+
out = subprocess.run(["nvidia-smi", "-L"], capture_output=True, text=True, timeout=20)
|
| 480 |
+
return [l for l in out.stdout.splitlines() if l.strip()]
|
| 481 |
+
except Exception:
|
| 482 |
+
return []
|
| 483 |
+
|
| 484 |
+
|
| 485 |
+
@mcp.custom_route("/health", methods=["GET"])
|
| 486 |
+
async def health(request: Request) -> Response:
|
| 487 |
+
return JSONResponse({"ok": True, "role": ROLE, "gpus": await asyncio.to_thread(_gpus)})
|
| 488 |
+
|
| 489 |
+
|
| 490 |
+
def _setup_token() -> None:
|
| 491 |
+
global TOKEN
|
| 492 |
+
if ROLE == "test":
|
| 493 |
+
TOKEN_FILE.parent.mkdir(parents=True, exist_ok=True)
|
| 494 |
+
os.chmod(TOKEN_FILE.parent, 0o700)
|
| 495 |
+
TOKEN = secrets.token_hex(32)
|
| 496 |
+
TOKEN_FILE.write_text(TOKEN)
|
| 497 |
+
os.chmod(TOKEN_FILE, 0o600)
|
| 498 |
+
else:
|
| 499 |
+
for _ in range(300): # the test grader is healthy before this one starts
|
| 500 |
+
if TOKEN_FILE.exists() and TOKEN_FILE.read_text().strip():
|
| 501 |
+
break
|
| 502 |
+
time.sleep(1)
|
| 503 |
+
TOKEN = TOKEN_FILE.read_text().strip()
|
| 504 |
+
if not TOKEN:
|
| 505 |
+
raise SystemExit("ARE: empty internal token; refusing to start")
|
| 506 |
+
|
| 507 |
+
|
| 508 |
+
def main() -> None:
|
| 509 |
+
global NET_ISOLATED
|
| 510 |
+
NET_ISOLATED = _net_isolation_available()
|
| 511 |
+
if not NET_ISOLATED:
|
| 512 |
+
# Graded code must never have a network path (for example back through /submit).
|
| 513 |
+
raise SystemExit("ARE grader: cannot run grades without network access "
|
| 514 |
+
"(needs `unshare -n`, i.e. CAP_SYS_ADMIN); refusing to start")
|
| 515 |
+
STATE.mkdir(parents=True, exist_ok=True)
|
| 516 |
+
_BASELINE.update(_all_paths())
|
| 517 |
+
_setup_token()
|
| 518 |
+
STATE.mkdir(parents=True, exist_ok=True)
|
| 519 |
+
os.chmod(STATE, 0o700)
|
| 520 |
+
(STATE / "snapshots").mkdir(exist_ok=True)
|
| 521 |
+
if ROLE == "val":
|
| 522 |
+
# The deliverable volume starts empty and root-owned; hand it to the agent user.
|
| 523 |
+
SUBMISSION_ROOT.mkdir(parents=True, exist_ok=True)
|
| 524 |
+
os.chmod(SUBMISSION_ROOT, 0o700)
|
| 525 |
+
for path in ARTIFACT_PATHS:
|
| 526 |
+
src = SUBMISSION_ROOT / path.lstrip("/")
|
| 527 |
+
src.mkdir(parents=True, exist_ok=True)
|
| 528 |
+
os.chown(src, AGENT_UID, AGENT_UID)
|
| 529 |
+
(STATE / "meta.json").write_text(json.dumps(
|
| 530 |
+
{"t0_wall": T0, "budget_seconds": BUDGET_SEC, "artifact_paths": ARTIFACT_PATHS}
|
| 531 |
+
))
|
| 532 |
+
threading.Thread(target=grade_worker, daemon=True).start()
|
| 533 |
+
mcp.run(transport="http", host="0.0.0.0", port=PORT, show_banner=False,
|
| 534 |
+
uvicorn_config={"timeout_keep_alive": 86400})
|
| 535 |
+
|
| 536 |
+
|
| 537 |
+
if __name__ == "__main__":
|
| 538 |
+
main()
|