internal: admin endpoint to re-run auto-approval eval on parked review jobs (#1005)

## Summary
Adds `POST /api/internal/jobs/{job_id}/auto-approval-eval` (admin-only):
re-runs the auto-approval evaluator on a job parked at AWAITING_REVIEW.
The KaraokeHunt outreach batch runs with `made_for_you: true`
(stale-review exemption), which is also an enforcement blocker at
scoring time — this endpoint lets us lift the flag and re-evaluate so
confident jobs full-auto through review.

## Testing
- `test_internal_api.py::TestAutoApprovalEval` — outcome passthrough +
auth required; file green in full-collection run.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Administrators can manually re-run auto-approval evaluation for jobs
awaiting review.
- Jobs remain in review unless the evaluation is fully confident,
providing a fail-safe review process.

- **Bug Fixes**
- Improved batch job processing so an issue updating an optional job
setting no longer stops the remaining workflow.
- Prevented missing cached results from causing failures during
recanonicalization tasks.

- **Tests**
- Added coverage for authorized evaluation requests and unauthorized
access.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Andrew Beveridge ☄️andClaude Opus 4.8 authored and GitHub committed 2026-09-15 09:22:39 +00:00
1 parent 6800c14e57
commit 462f246768
5 files changed
+55 -5

No files matched your search

+19
View File
@@ -185,6 +185,25 @@ async def trigger_audio_worker(
)
@router.post("/jobs/{job_id}/auto-approval-eval")
async def trigger_auto_approval_eval(
job_id: str,
auth_data: Tuple[str, UserType, int] = Depends(require_admin)
):
"""
Re-run the auto-approval evaluation on a job parked at AWAITING_REVIEW
(admin only). Normally scoring runs from the screens/audio workers; this
endpoint lets an admin re-evaluate after conditions change (e.g. a batch
job's made_for_you enforcement blocker was lifted). Fail-safe: anything
short of fully confident leaves the job in review untouched.
"""
from backend.services.auto_approval.executor import maybe_auto_complete_review
logger.info(f"[job:{job_id}] admin auto-approval eval requested")
result = await maybe_auto_complete_review(job_id, trigger="admin_eval")
return {"job_id": job_id, **result}
@router.post("/workers/lyrics", response_model=WorkerResponse)
async def trigger_lyrics_worker(
request: WorkerRequest,
+23
View File
@@ -341,3 +341,26 @@ class TestWorkerIdempotency:
data = response.json()
assert data["status"] == "not_found"
class TestAutoApprovalEval:
"""POST /api/internal/jobs/{job_id}/auto-approval-eval — admin re-evaluation."""
def test_eval_calls_executor_and_returns_outcome(self, client):
with patch(
'backend.services.auto_approval.executor.maybe_auto_complete_review',
new=AsyncMock(return_value={"outcome": "auto_completed"}),
) as mock_eval:
response = client.post(
"/api/internal/jobs/test123/auto-approval-eval",
headers={"Authorization": "Bearer test-admin-token"},
)
assert response.status_code == 200
data = response.json()
assert data["job_id"] == "test123"
assert data["outcome"] == "auto_completed"
mock_eval.assert_awaited_once_with("test123", trigger="admin_eval")
def test_eval_requires_admin(self, client):
response = client.post("/api/internal/jobs/test123/auto-approval-eval")
assert response.status_code == 401
+1 -1
View File
@@ -1,6 +1,6 @@
[tool.poetry]
name = "karaoke-gen"
version = "0.225.6"
version = "0.225.7"
description = "Generate karaoke videos with synchronized lyrics. Handles the entire process from downloading audio and lyrics to creating the final video with title screens."
authors = ["Andrew Beveridge <andrew@beveridge.uk>"]
license = "MIT"
@@ -154,6 +154,8 @@ def main() -> int:
# --- 2. re-search corrected names (research + community-first fallbacks) ---
to_search = []
for k, d in decisions.items():
if k not in cache:
continue
if d["action"] == "research" or \
(d["action"] == "community-first" and not cache[k].get("recheck_v2", {}).get("available")):
if "search_v2" not in cache[k]:
@@ -195,10 +195,16 @@ def main() -> int:
job_id = job.get("job_id") or job.get("id")
entry["job_id"] = job_id
entry["submitted_at"] = now_iso()
# Exempt from stale-review auto-expiry immediately.
st, _ = api_post(f"/api/admin/jobs/{job_id}",
{"made_for_you": True}, args.token, method="PATCH")
entry["made_for_you_set"] = (st == 200)
# Exempt from stale-review auto-expiry immediately. A PATCH
# failure must not mask the successful job creation — record
# it so a later pass can re-flag.
try:
st, _ = api_post(f"/api/admin/jobs/{job_id}",
{"made_for_you": True}, args.token, method="PATCH")
entry["made_for_you_set"] = (st == 200)
except Exception as pe:
entry["made_for_you_set"] = False
entry["mfy_error"] = str(pe)[:200]
msg = (f"OK {a} – {t}: job {job_id} "
f"[{u['kind']}] mfy={'✅' if entry['made_for_you_set'] else '❌'}")
print(f" {msg}", flush=True)