From 882589555b5e5a099e1c7c538306820818250cb2 Mon Sep 17 00:00:00 2001 From: Niels Rogge Date: Mon, 23 Nov 2026 13:25:24 +0000 Subject: [PATCH] Tell curation agents the exact existing-row field_diff Scheduled add-evals rejects an existing-row update unless field_diff equals the server-computed diff, but the skill never gave the format and the error never showed the expected value, so the in-job retry repeated the mistake: 13 rejections on 12 papers in 30 days. Return the computed diff in the rejection and document the {"field": {"before", "after"}} shape with an example. Co-Authored-By: Claude Opus 5.5 --- .agents/skills/remote-paper-curation/SKILL.md | 19 ++++- .../codex_curation_callback_service.py | 5 +- .../curation/test_codex_callback_service.py | 79 +++++++++++++++++++ 3 files changed, 101 insertions(+), 2 deletions(-) diff --git a/.agents/skills/remote-paper-curation/SKILL.md b/.agents/skills/remote-paper-curation/SKILL.md index ad2002117..ddc0182e6 100644 --- a/.agents/skills/remote-paper-curation/SKILL.md +++ b/.agents/skills/remote-paper-curation/SKILL.md @@ -216,7 +216,24 @@ write a JSON payload containing `evaluations` (each has this job's `paper_id`) and submit it with `python3 jobs/curation_api.py apply payload.json`. Always include `evaluation_removals`, `validation_evidence`, and `benchmark_gaps` arrays. Updating an existing row requires its exact context -`before_state`, a field-level diff, and primary-paper evidence. Duplicate +`before_state`, a field-level diff, and primary-paper evidence. The server +recomputes the diff between the stored row and the row you submit in +`evaluations`, and `field_diff` must equal it exactly: one key per changed +top-level field, each `{"before": , "after": }`, +with whole values (all of `metrics`, not one metric). Fields you leave +unchanged must be copied verbatim from `before_state`, or they become part of +the diff. To correct one score: + +```json +{"evaluation_id": 38506, "before_state": {...}, + "field_diff": {"metrics": {"before": {"Dice": 0.95}, "after": {"Dice": 0.948}}}, + "evidence": [{"source_url": "...", "table": "Table 2", "snippet": "..."}]} +``` + +If the apply is rejected with `expected field_diff for evaluation `, the +message contains the diff the server computed. Either use it as `field_diff` +or fix the submitted row so it no longer changes fields you did not mean to +change. Duplicate consolidation additionally requires every matched row ID and the canonical-row selection reason. Remove an invalid row only with its full before-state and unambiguous primary-paper evidence. diff --git a/backend/services/codex_curation_callback_service.py b/backend/services/codex_curation_callback_service.py index dd2cc65f9..f20ddc285 100644 --- a/backend/services/codex_curation_callback_service.py +++ b/backend/services/codex_curation_callback_service.py @@ -2,6 +2,7 @@ from __future__ import annotations +import json import math import re from datetime import UTC, datetime @@ -2004,7 +2005,9 @@ def _validate_scheduled_policy( audit["field_diff"] = supplied_diff if audit.get("field_diff") != changes or not audit.get("evidence"): raise ValueError( - "Evaluation update requires the exact field diff and primary evidence" + "Evaluation update requires the exact field diff and primary " + f"evidence; expected field_diff for evaluation {canonical.id}: " + f"{json.dumps(changes, sort_keys=True, default=str)}" ) if len(matches) > 1: duplicate_ids = sorted( diff --git a/backend/tests/curation/test_codex_callback_service.py b/backend/tests/curation/test_codex_callback_service.py index 996b9baaf..a26e4a1ce 100644 --- a/backend/tests/curation/test_codex_callback_service.py +++ b/backend/tests/curation/test_codex_callback_service.py @@ -1259,6 +1259,85 @@ def query(self, model): } +def test_scheduled_existing_row_diff_mismatch_reports_the_expected_diff(): + from backend.models.database import Evaluation, Metric, Paper, TaskDataset + + paper = SimpleNamespace( + id=42, + source="arxiv", + source_url=None, + arxiv_id="2601.00001", + ) + existing = _stored_evaluation( + methodology=None, + metrics={"GenEval Score": 0.9}, + source_url="https://paperswithcode.co/paper/2601.00001", + external_source_url="https://paperswithcode.co/paper/2601.00001", + ) + + class Query: + def __init__(self, model): + self.model = model + + def join(self, *_args): + return self + + def filter(self, *_args): + return self + + def one_or_none(self): + if self.model is TaskDataset: + return SimpleNamespace(supports_harness=False) + return None + + def all(self): + if self.model is Metric: + return [SimpleNamespace(name="GenEval Score", scale="0-1")] + if self.model is Evaluation: + return [existing] + return [] + + class Database: + def get(self, model, _key): + return paper if model is Paper else None + + def query(self, model): + return Query(model) + + audit = { + "evaluation_id": existing.id, + "before_state": CodexCurationCallbackService._evaluation_state(existing), + "field_diff": {"metrics": {"GenEval Score": {"before": 0.9, "after": 0.91}}}, + "evidence": [{"source_url": "https://arxiv.org/abs/2601.00001"}], + } + proposed = _evaluation(model_name="Existing Model") + proposed.metrics = {"GenEval Score": 0.91} + body = ApplyMutationRequest( + evaluations=[proposed], + validation_evidence=[audit], + score_evidence=[_score_evidence(source_value=91)], + ) + + with pytest.raises(ValueError) as error: + _scheduled_policy( + _service(Database(), SimpleNamespace()), + SimpleNamespace( + kind="add-evals", + paper_id=42, + trigger="hf-daily-cron", + trace_status="preapply_stored", + ), + body, + ) + + assert str(error.value) == ( + "Evaluation update requires the exact field diff and primary evidence; " + f"expected field_diff for evaluation {existing.id}: " + '{"metrics": {"after": {"GenEval Score": 0.91}, ' + '"before": {"GenEval Score": 0.9}}}' + ) + + def test_scheduled_evaluation_rejects_multiple_models_per_leaderboard(): from backend.models.database import Paper