Repository navigation
feat(labeler): reviewer rerun and false-positive override (W9.5) - #2023
Conversation
Rerun mints an operator trigger and re-pends the release. Override negates all live automated blocks and issues assessment-passed plus assessment-overridden as one atomic batch under a single audit row; override-retract negates only the eligibility pair, leaving blocks negated for a safe-blocked resting state. Adds the subject+CID label read and surfaces manual/override labels in the console. Claude-Session: https://claude.ai/code/session_014rikrGMh25h1rJczUQyTMM
|
Scope checkThis PR changes 2,346 lines across 14 files. Large PRs are harder to review and more likely to be closed without review. If this scope is intentional, no action needed. A maintainer will review it. If not, please consider splitting this into smaller PRs. See CONTRIBUTING.md for contribution guidelines. |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-demo-do | 668dc45 | Jul 13 2026, 08:48 PM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-playground | 668dc45 | Jul 13 2026, 08:48 PM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-demo-cache | 668dc45 | Jul 13 2026, 08:48 PM |
There was a problem hiding this comment.
Approach judgment
This is the right change for the right problem, and it fits the labeler's architecture. The W9.5 plan item — reviewer rerun and false-positive override (plus override-retract) — is linked to the approved RFC #694 and stacked on the W9.1–W9.4 integration branch. The design is sound: every action goes through the W9.2 mutation guard, commits its label rows + the operator audit row in a single commitMutation batch, and the override negates the entire live automated-block set before issuing the assessment-passed + assessment-overridden pair in one atomic transaction. The §10 "automation can never retract a human pass" property is preserved both at the evaluator (override pair outranks later automated blocks → suppressed) and at the signing guard (assertAutomatedNegationAllowed refuses automated negation of a manual-headed stream). Replay determinism across the N+2 statement set is handled by deriving the persistence/tail keys from the committed descriptor (the race-winner's on conflict), not the locally built ones.
What I checked
- Atomicity / FK ordering:
runRerunbatches[audit, runStatement, pendingActionInsert, pendingLabelInsert]soissuance_actions.assessment_id → assessments.idresolves within the transaction. Verified against the0003migration FK. - No-phantom-success guard:
assertIssuancePersisted(string[])is applied symmetrically on proceed and replay for all three actions; a mid-batch signing-state suppression (all-or-nothing within one D1 transaction snapshot) → 503 with the audit committed but no labels, and replay re-503s. The override-phantom test exercises this honestly via abatch-truncating Proxy. - Stale-set rejection:
assertNegatableBlockSetrequires the submittednegateset to equal the liveautomated-blockset (including duplicate/empty handling) and maps a mismatch to a clean 400 before signing. TOCTOU between the read and commit is benign because the override pair suppresses any block that appears in the gap. - Authorization ordering: auth → role → body parse happens in
guardMutationbefore any signing; the new override-authz test asserts zero side effects on 401/403. Confirmed against the guard's step order. - Route dispatcher changes: the broadened
subjectsandlabelsbranches still fall through toNOT_FOUNDfor unknown sub-paths; no collision withassessments/:id/labelsor the mutation routes. - Additive
LabelStreamWinner.negdoesn't break existing consumers (xrpc-router.toActiveLabelView,serializeSubjectLabel). - RTL/Tailwind: the new dialogs use only logical/neutral classes (
flex,gap-*,justify-end,text-kumo-*,bg-kumo-elevated); no physical directional classes. i18n is n/a for the deliberately-unlocalized labeler console per the W9.3 decision.
I found no logic bugs, regressions, security issues, or convention violations. The implementation matches the ratified decisions, and the adversarial review's test-honesty gap (override authz) is genuinely closed.
Minor observations (non-blocking)
- One maintainability suggestion below (hardcoded block vocabulary).
- Test-completeness gaps, not bugs: there is no rerun-specific 503 phantom test (only override), and no
override-retractconfirmation-mismatch / 409 test (rerun and override have them). The sharedassertIssuancePersistedcode path is otherwise well covered.
None of these block merge.
| /** The automated blocking label vocabulary (policy `category: automated-block`), | ||
| * mirrored so the console can list a release's active blocks for the override | ||
| * ceremony. Presentation only — the server re-derives the authoritative set from | ||
| * live label state and rejects a stale submission. */ | ||
| export const AUTOMATED_BLOCK_LABELS: ReadonlySet<string> = new Set([ |
There was a problem hiding this comment.
[suggestion] The console hardcodes the automated-block vocabulary in AUTOMATED_BLOCK_LABELS. It happens to match the policy fixture's automated-block category today, but the two are not derived from a shared source. If a future policy bump adds a new automated-block label, a release carrying it would render the override flow broken from the reviewer's seat: AssessmentDetail filters activeBlocks through this stale set, so the new block won't appear in the override dialog's "blocks to negate", and the submitted (stale) set is then rejected by the server's assertNegatableBlockSet with a 400 — the override silently stops working until this constant is hand-updated. The server is correctly authoritative (so no safety gap), but the presentation set drifting from the fixture is an operational footgun.
Consider deriving the console's block vocabulary from the same policy fixture (or an automatedBlockCategories(MODERATION_POLICY)-equivalent export) instead of a literal Set, so a fixture grant lights up here too with no code change — the same property the issuer already has.
There was a problem hiding this comment.
Done in a6348be — AUTOMATED_BLOCK_LABELS is now automatedBlockCategories(MODERATION_POLICY) imported from the worker's own src/policy.ts (dependency-pure: only the fixture), so the console shares both the source and the derivation with the issuer. The same commit closes the two test-completeness notes: a rerun mid-commit-suppression 503 test (both paths, no run created) and override-retract confirmation-mismatch + idempotency-409 tests.
~ 🤖 Claude Opus 4.8
The console mirrored the automated-block set as a hand-maintained literal, so a future policy grant would silently break the override dialog (stale set -> server 400). Derive it with the server's own automatedBlockCategories(MODERATION_POLICY) instead. Also closes the reviewer-noted test gaps: rerun mid-commit suppression 503s on both paths without creating a run, and override-retract rejects a wrong confirmation and 409s idempotency-key reuse. Claude-Session: https://claude.ai/code/session_014rikrGMh25h1rJczUQyTMM
There was a problem hiding this comment.
Re-review
This is a re-review. My previous pass found no bugs and two minor, non-blocking observations. Both are now closed:
- Test-completeness gaps fixed. The rerun now has a dedicated 503 phantom test (
"503s and creates no run when the batch is suppressed mid-commit"), and override-retract has its 409 different-fingerprint test ("409s the same key with a different fingerprint"). The sharedassertIssuancePersisted(string[])path (proceed + replay, all three actions) is now exercised honestly. - Hardcoded block vocabulary replaced.
AUTOMATED_BLOCK_LABELS/isAutomatedBlockinconsole/src/labels.tsare now derived from the policy fixture viaautomatedBlockCategories(MODERATION_POLICY), so a fixture change reaches the override ceremony without a code edit.
What I re-verified
- Atomicity / FK ordering:
runRerunbatches[audit, runStatement, ...pending.statements]; the run row precedes the pending issuance soissuance_actions.assessment_id → assessments.idresolves inside the D1 batch. - No-phantom-success guard:
assertIssuancePersisted(string[])loops every issuance key on both proceed and replay for rerun, override (N negations + pair), and override-retract. A signing-state suppression that drops the guardedINSERT…SELECTrows (audit commits, labels don't) surfaces 503; replay re-503s. The Proxy-truncation tests reproduce the observable outcome honestly. - §10 automation-negation guard:
buildIssuanceStatementsonly runsassertAutomatedNegationAllowed(and the in-batch NOT EXISTS condition) foraction.type === "automated-assessment" && neg. The override negations and override-retract are manual actions, so they bypass it — which is correct: a reviewer (manual) may negate an automated block, and may negate the manual override pair. The permanence test confirms automation still cannot retract the pass. - Replay determinism: override/override-retract keys are derived from the committed descriptor (
returned.actionId/negated/issued), not the locally built ones, so a race-loser checks the winner's rows. Rerun reconstructs its pending key from the storeduri/cid/triggerId. - Authorization: all read routes (
subjects/:uri/labels,labels/override-effect-preview) sit behindguardRead({ minRole: "reviewer" }); the new override-authz test asserts zero side effects on 401/403 before signing. - Route dispatch: the broadened
subjects/labelsbranches still fall through toNOT_FOUND; no collision withassessments/:id/{rerun,override,override-retract}. - Additive
LabelStreamWinner.neg+serializeSubjectLabeldon't break existing consumers; SQL is parameterized; the new dialogs use only logical/neutral Tailwind + semantic tokens; i18n is n/a per the W9.3 decision (labeler console deliberately unlocalized).
No logic bugs, regressions, security issues, or AGENTS.md violations. One new, non-blocking observation below — the preview and the submit disagree on what's "negatable" for a manually-issued automated-block label. The server still rejects safely (400), so there's no incorrect state; it's a UX/preview-accuracy gap.
| const activeBlocks = activeSubjectLabels | ||
| .filter((label) => label.active && isAutomatedBlock(label.val)) | ||
| .map((label) => label.val); |
There was a problem hiding this comment.
[suggestion] activeBlocks is derived from getSubjectLabels (the per-val stream winner) filtered by label.active && isAutomatedBlock(label.val). isAutomatedBlock keys on the label value's policy category, not on the provenance of the active event — and getActiveLabelState marks a label active for any non-negated, unexpired, CID-applicable head regardless of whether that head was issued by automation or manually. RELEASE_ISSUABLE_LABELS exposes the automated-block vocabulary (e.g. malware, data-exfiltration) as cid-bound manual-issue options, so a reviewer can manually block a release with malware via the Issue dialog.
In that state the console shows the Override (unblock) button and the OverrideDialog preview (computeOverrideEffectPreview) overlays a negation of malware + the eligibility pair and reports after: eligible. But on submit, assertNegatableBlockSet derives the live set from getNegatableAutomatedLabels, which requires the head to be an automated-assessment non-negation — a manual malware head is excluded, so the live set is empty and the submitted negate: ["malware"] is rejected with 400 INVALID_BODY ("Request body is invalid"). The reviewer is shown a preview promising "eligible" and then a confusing 400.
No incorrect data state results (the server guards correctness), and the correct unblock path there is the label-level Retract, not the override. But the preview and submit use two different definitions of "negatable," which is reachable through normal console workflow. Consider gating the Override button (or the preview) on the same negatable-set semantics the submit enforces — e.g. surface provenance/type in SubjectLabel so the console can distinguish an automated-head block from a manual one, or have the preview endpoint call assertNegatableBlockSet and 400 when the set isn't live-negatable so the dialog never over-promises.
There was a problem hiding this comment.
Fixed in 357260a, taking your first option — provenance on the wire. LabelStreamWinner/SubjectLabel now carry automated (from the head's issuance_actions.type via a join in getActiveLabelState — action_id is NOT NULL so the inner join is total), and activeBlocks filters on label.automated so a manually-headed block never reaches the override button or preview; its path is the label retract, which the detail view already offers. Pinned by a test that manually issues impersonation next to an automated malware: the read reports the provenance split, override naming the manual head 400s, and the automated-only set proceeds.
~ 🤖 Claude Opus 4.8
The subject-label read now carries the stream head's provenance (automated vs manual), and the console only counts automated heads as override-negatable. A manually-headed block-category label previously showed the override button and an eligible preview that the server then rejected with 400; its unblock path is the label retract. Claude-Session: https://claude.ai/code/session_014rikrGMh25h1rJczUQyTMM
There was a problem hiding this comment.
Re-review (3rd pass) of W9.5 — reviewer rerun + false-positive override.
Approach: Sound and consistent with the W9.x architecture. The two new mutation routes (assessments/:id/rerun, assessments/:id/override, assessments/:id/override-retract) reuse the W9.2 guardMutation + commitMutation batch, fold the path assessmentId into the request fingerprint, and validate the typed CID server-side from the loaded assessment. The override composes N block-negations + the eligibility pair as one atomic batch with distinct per-piece signing keys (overridePieceKey), and the §10 automation-negation guard is correctly bypassed for the manual negations (a reviewer may negate an automated block; automation still cannot negate the manual pass). The change is additive (new routes, new LabelStreamWinner.neg/automated fields, new serialize path) and doesn't alter existing consumers. No AGENTS.md violations: apps/labeler is private: true/unpublished so no changeset is required; the labeler console is deliberately unlocalized (W9.3 decision) and the new dialogs use only logical/neutral Tailwind + kumo-* semantic tokens; all SQL is parameterized; reads sit behind guardRead({minRole:"reviewer"}), mutations behind the guard's reviewer gate.
What I re-verified (no new bugs):
- Atomicity / FK ordering: rerun batches
[audit, runStatement, ...pending.statements]soissuance_actions.assessment_id → runIdresolves inside the D1 batch. - No-phantom-success, generalized to N labels:
assertIssuancePersisted(string[])loops every issuance key on both proceed and replay for all three actions; a mid-batch signing suppression (audit commits, labels don't) surfaces 503, and replay re-503s. The Proxy-truncation tests model the observable outcome honestly. - Replay determinism: override/override-retract keys are derived from the committed descriptor (
returned.actionId/negated/issued), and rerun reconstructs its pending key from the storeduri/cid/triggerId— so a race-loser checks the winner's rows. The known policy-version-bump-on-replay 503 is acknowledged in the PR. - Negatable-set equality:
assertNegatableBlockSetrejects any submitted set ≠ the livegetNegatableAutomatedLabels∩automated-block(including duplicates and stale sets) before signing; the console'sactiveBlocksfilter (active && automated && isAutomatedBlock) matches the server's automated-head semantics. - §10 permanence: the negations/retract are manual actions, so
buildIssuanceStatements'isAutomatedNegationguard is skipped;assertAutomatedNegationAllowedstill refuses an automated negation of the manual pass. The permanence test confirms a later automated block is emitted-but-inert. - Authorization: the new override-authz test asserts 401/403 with zero side effects before any signing; the broadened
subjects/labelsread branches still fall through toNOT_FOUND, no collision withassessments/:id/{rerun,override,override-retract}.
Carry-over (still open, non-blocking): the one observation from the prior pass is unchanged — computeOverrideEffectPreview overlays the client-supplied negate set without intersecting the live negatable set, so the preview can render an "eligible" after for a set the submit endpoint would reject with 400 (a manually-headed automated-block label, or a set that went stale between the subject-label read and the preview). The normal console flow doesn't trigger this (it filters by label.automated and re-reads on invalidation), and the server always rejects safely, so there's no incorrect state — it's a preview-accuracy/UX gap. Logged as a single suggestion below; no needs_fixing issues found.
| if (params.negate.includes(winner.val)) | ||
| supersedes.push({ val: winner.val, cid: winner.cid, sequence: winner.sequence }); | ||
| } | ||
|
|
||
| const overlays: ModerationLabel[] = [ | ||
| ...params.negate.map((val) => ({ |
There was a problem hiding this comment.
[suggestion] computeOverrideEffectPreview builds the overlay negations (line 212) and the supersedes list (line 207) directly from the client-supplied params.negate, without intersecting the live negatable set. The submit endpoint (assertNegatableBlockSet → getNegatableAutomatedLabels filtered to automated-block) re-derives the authoritative set and rejects any mismatch with 400. So the preview can show an "eligible" after for a negate set the submit would reject — e.g. a manually-headed automated-block label, or a set that went stale between the subject-label read and the preview call. The console's normal flow avoids this (it filters active && automated && isAutomatedBlock and re-fetches labels on invalidation) and the server rejects safely, so this is a preview-accuracy/UX gap, not a correctness bug. Deriving the overlay from the live negatable set would make the preview match what the submit actually does:
| if (params.negate.includes(winner.val)) | |
| supersedes.push({ val: winner.val, cid: winner.cid, sequence: winner.sequence }); | |
| } | |
| const overlays: ModerationLabel[] = [ | |
| ...params.negate.map((val) => ({ | |
| const liveNegatable = new Set( | |
| (await getNegatableAutomatedLabels(db, { src: labelerDid, uri: params.uri, cid: params.cid })) | |
| .map((l) => l.val) | |
| .filter((val) => getLabelDefinition(val)?.category === "automated-block"), | |
| ); | |
| const negateVals = params.negate.filter((val) => liveNegatable.has(val)); |
then use negateVals for both the supersedes.includes check and the overlay negate.map.
There was a problem hiding this comment.
Closed in 668dc45 — the preview handler now runs the same assertNegatableBlockSet check as submit and maps NegatableBlockSetError to a 400, so the two definitions of "negatable" can no longer diverge; a preview that renders is one the submit would accept. Pinned by a test issuing a manual impersonation head next to an automated malware: preview naming both → 400, the live set → 200.
~ 🤖 Claude Opus 4.8
…e set The preview overlaid whatever negate set the caller supplied, so a direct API call could render an eligible outcome the submit endpoint would reject with 400. The preview now runs the same assertNegatableBlockSet check as submit and 400s on mismatch. Claude-Session: https://claude.ai/code/session_014rikrGMh25h1rJczUQyTMM
There was a problem hiding this comment.
Re-review (4th pass) of W9.5 — reviewer rerun + false-positive override.
Approach: unchanged and sound. The two single-purpose assessment actions (rerun, override-retract) and the multi-label atomic override reuse the W9.2 guardMutation + commitMutation batch, fold the path assessmentId into the request fingerprint, and validate the typed CID server-side from the loaded assessment. The override composes N block-negations + the eligibility pair in one atomic batch with distinct per-piece signing keys (overridePieceKey), the §10 automation-negation guard is correctly bypassed for the manual negations, and override-retract leaves the negated blocks in place (safe-blocked resting state). The change is additive and fits EmDash's architecture; no AGENTS.md violations (apps/labeler is private/unpublished → no changeset; console deliberately unlocalized; SQL parameterized; reads behind guardRead, mutations behind the guard's reviewer gate).
Carry-over resolved. The one observation from the 3rd pass — that computeOverrideEffectPreview overlaid the client-supplied negate set without intersecting the live negatable set, so the preview could render an "eligible" after for a set the submit endpoint would 400 — is now closed. handleOverrideEffectPreview runs assertNegatableBlockSet (the identical live-set check runOverride runs) before computing the preview, returning 400 INVALID_REQUEST for a manually-headed automated-block label or a stale/incomplete set. I verified computeOverrideEffectPreview has exactly one production caller (the validated handler), and the new test rejects a preview whose negate set the submit endpoint would reject asserts both the manual-head and incomplete-set cases 400 on the preview path while the live set 200s. The preview can no longer over-promise an outcome the submit would reject.
What I re-verified (no new bugs):
- Routing: the broadened
subjects/labelsread branches inconsole-api.tsand the newassessments/:id/{rerun,override,override-retract}mutation branches fall through toNOT_FOUNDfor unknown segments; no collision between the read and mutation routers (distinct first segments). - No-phantom-success (N labels):
assertIssuancePersisted(string[])loops every issuance key on both proceed and replay for all three actions; rerun reconstructs its pending key from the committed descriptor (returned.uri/cid/triggerId), override/override-retract derive keys from the committedactionId/negated/issued. Race-loser keys come from the winner's stored descriptor. The Proxy-truncation tests honestly model the observable 503 + replay-re-503. - Negatable-set equality:
assertNegatableBlockSetrejects any submitted set ≠ livegetNegatableAutomatedLabels∩automated-block(including duplicates and stale sets) before signing; the console'sactiveBlocksfilter (active && automated && isAutomatedBlock) matches the server's automated-head semantics, and the new provenance test confirms a manually-headed block is excluded from the offer and rejected on submit. - Authorization: the override-authz test asserts 401/403 with zero side effects (no audit row, no eligibility label, block untouched) before any signing.
- §10 permanence / override-retract: unchanged; tests confirm a later automated block is emitted-but-inert, automation cannot negate the manual pass, and retract leaves blocks negated (blocked + missing-assessment-pass).
No needs_fixing issues found; the prior non-blocking suggestion is now addressed. Clean to merge.
19dea73
into
feat/plugin-registry-labelling-service
What does this PR do?
Adds plan item W9.5 — two reviewer actions on an assessment: re-run and false-positive override. Both go through the W9.2 mutation guard and commit their label rows atomically with the operator audit row in a single
commitMutationbatch.Re-run (
POST /admin/api/assessments/{id}/rerun) advances a settled assessment back topending(advanceAssessmentToPending) so the pipeline re-evaluates it. Per the ratified decision, rerun-to-pending is accepted as-is — no attempt to diff against the prior run.False-positive override (
POST /admin/api/assessments/{id}/override) is the interesting one: it negates every live automated block on the subject and issues the eligibility pair (assessment-passed+assessment-overridden) in one atomic batch.prepareOverrideIssuancesigns the N block-negations viabuildIssuanceStatementsdirectly and the eligibility pair through the manual issuance path, each piece keyed distinctly (${actionId}:${val}:${neg ? "neg" : "pos"}) so replay and race-loser skipping stay deterministic across the whole multi-label set. Override permanence (§10) needs no evaluator change: a later automated block is still emitted but resolves inert because the pass/override pair outranks it, andassertAutomatedNegationAllowedrefuses any automation attempt to negate the human pass.Ratified decisions folded in (2026-07-13):
Correctness and guarding:
assertIssuancePersisted(string[]), applied symmetrically on both the proceed and replay paths. If a signing-key rotation raced such that the guarded issuance INSERTs matched zero rows while the unguarded audit row committed, the handler returnsLABEL_ISSUANCE_UNAVAILABLE(503, retryable) instead of a 200 that falsely claims the release is cleared.getActiveLabelState) surfaces manual and override labels in the console's assessment/subject views, so a reviewer sees the true resting state before and after acting.Console: an override dialog and a rerun/action dialog on assessment detail, with the typed-CID confirmation, client-generated ULID idempotency keys, and 409/503 surfaced as retryable. Plain English strings (the console is not localized, per the W9.3 decision).
Adversarially reviewed by an independent Opus pass focused on the multi-label atomic composition, the §10 automated-negation-proof property, replay determinism across the N+2 statement set, and unauthenticated/under-privileged reach. Verdict: no blockers — the signing crown jewels hold. Its one finding was a test-honesty gap: the override endpoint had no test proving it rejects an unauthenticated (401) or under-privileged (403) caller before signing. That test is added, asserting zero side effects (no audit row, no eligibility label, block untouched) on both rejection paths.
Three informational notes it raised, not addressed here (surfaced for a call, none security-impacting):
MODERATION_POLICY.policyVersion— a policy-version bump between the original commit and a replay would spuriously 503. Static within a deploy, so low risk; noted rather than defended.Stacked directly on the integration branch (W9.1–W9.4 merged). Targets
feat/plugin-registry-labelling-service. Related to #1909 and RFC #694.Type of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runmessages.pochanges except in translation PRs — a workflow extracts catalogs on merge tomain.i18n n/a — no admin UI; the labeler console is deliberately not localized (decision 2026-07-13). Changeset n/a —
apps/labeleris a private, unpublished Worker app; the policy fixture it bundles is internal.AI-generated code disclosure
Screenshots / test output
pnpm --filter @emdash-cms/labeler test: worker 459 pass (26 files — theconsole-assessment-mutationssuite covers rerun-to-pending, multi-block atomic override, the eligibility pair, override permanence (§10), override-retract → safe-blocked, replay determinism, the 503 suppression guard on both paths, and the new override-authorization rejections), console 20 passconsole:buildsucceeds; lint: 0 diagnostics inapps/labelerhttps://claude.ai/code/session_014rikrGMh25h1rJczUQyTMM
Try this PR
Open a fresh playground →
A full working EmDash site, deployed from this branch. Each visit gets its own session-scoped sandbox: no login needed and no shared state. Try the admin, edit content, hit the public site.
Tracks
feat/labeler-override. Updated automatically when the playground redeploys.