fix(maintenance): list each prompt the Pair repair kept (#550)

The job counted its protected prompts but listed none, so Protected 2 opened
an empty group. The apply now returns one row per kept prompt with the
review's reasons, in its order ("Prompt 7: kept, pairs disagree on category:
Adult, asian"), and the job keeps them all for the report.
This commit is contained in:
Vito Sansevero
2026-10-31 17:27:00 -07:00
parent d4508c9997
commit 0504e67fd3
6 changed files with 132 additions and 4 deletions
+24 -2
View File
@@ -304,6 +304,25 @@ def _protected_detail(result, key):
return "Kept: pairs disagree on tags"
def _kept(results):
"""One row per kept prompt, its review reasons without "Kept: " (#550)."""
rows = []
for result in results:
classes = set(_protected_classes(result))
if classes:
rows.append(
{
"prompt_id": result["id"],
"reasons": [
_protected_detail(result, key).removeprefix("Kept: ")
for key in DETAIL_ORDER
if key in classes
],
}
)
return rows
def _details(results, targets):
rows = []
for key in DETAIL_ORDER:
@@ -398,8 +417,10 @@ def _fill_tags(conn, fills, expected):
def apply_pair_metadata(conn, fingerprint, targets):
"""Apply the reviewed fills on ``conn`` (inside BEGIN IMMEDIATE).
Returns ``{changed, categories, tag_sets, rows}``; ``rows`` lists every
filled prompt (``{prompt_id, category?, tags?}``), never capped.
Returns ``{changed, categories, tag_sets, rows, kept}``; ``rows`` lists
every filled prompt (``{prompt_id, category?, tags?}``) and ``kept`` every
prompt the plan keeps (``{prompt_id, reasons}``, in the review's wording
and order), both never capped.
"""
results, current = _state(conn)
if current != fingerprint or _targets(results) != targets:
@@ -427,4 +448,5 @@ def apply_pair_metadata(conn, fingerprint, targets):
"categories": len(categories),
"tag_sets": len(tags),
"rows": rows,
"kept": _kept(results),
}