Repository navigation
feat(labeler): admin emergency takedown and publisher-compromised actions (W9.6 PR-1) - #2026
Conversation
…ions (W9.6 PR-1) Four admin-only endpoints issue and retract !takedown (release, package, or publisher subject) and publisher-compromised (DID) through the mutation guard: a two-field typed ceremony (subject identifier + intent phrase, both server-validated pre-signing), the signed label, and the critical-severity operational event + deployment-alert outbox row committed in one batch. The event/outbox inserts gate on the issuance idempotency key (the numeric id gate is unknowable pre-commit) so a signing-suppressed batch alerts nothing; persistence is asserted on proceed and replay. Takedown retraction restores the pre-takedown computed state; no cascade to per-release labels. The console gains an admin-gated emergency actions card with the high-friction dialog, and the subject-label read serves bare-DID publisher subjects. Claude-Session: https://claude.ai/code/session_014rikrGMh25h1rJczUQyTMM
Scope checkThis PR changes 1,308 lines across 9 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-playground | fa17f2b | Jul 13 2026, 10:48 PM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-demo-do | fa17f2b | Jul 13 2026, 10:46 PM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-demo-cache | fa17f2b | Jul 13 2026, 10:48 PM |
There was a problem hiding this comment.
Approach
This is the right change for the right problem. W9.6 PR-1 adds four admin-only emergency endpoints (!takedown issue/retract on release/package/publisher, publisher-compromised issue/retract on a DID) layered cleanly onto the existing W9.2 mutation guard + prepareManualLabelIssuance path. The design choices are good: val/neg are server-fixed per endpoint (never read from the wire), authorization (requiredRole: "admin") is checked by guardMutation before body parsing/signing/writes, the two-field ceremony (subjectConfirmation + intent) is enforced in code with a static CONFIRMATION_MISMATCH that never echoes input, and both ceremony fields fold into the request fingerprint. The PR-0 correction (gating the event/outbox on issuance_actions.idempotency_key instead of the unknowable numeric id) is additive and correct — I confirmed issuance_actions.idempotency_key is UNIQUE (0001_init.sql) and equals ctx.actionId, so the gate can only match this action's own label.
What I checked
- Authz-before-effect:
guardMutationrunshasRole(identity, "admin")beforeparseJsonBody/parseBody;hasRolehas no reviewer→admin escalation for anadminrequirement. Reviewer→403 and unauthenticated→401 produce zero side effects (verified against the code and the per-endpoint zero-side-effect tests). - Phantom-success gate (T1): The
INSERT … SELECT … WHERE EXISTS (issued_labels ⋈ issuance_actions ON idempotency_key = ?)runs after the issuance statements in the samedb.batch, so the EXISTS sees the in-batch label; on signing suppression the event + outbox insert zero rows andassertIssuancePersisted503s on both proceed and replay. Confirmed exactly-one-event across replay. - §10: The automated path rejects
!takedown/publisher-compromisedatvalidateAutomatedProposal(noautomatedmode in their subject rules) with the in-batchassertAutomatedNegationAllowedguard as backstop. Retract is a manualnegaction, so the §10 guard is correctly bypassed. - Ceremony / T7:
assertAdminIssuableruns beforeassertEmergencyConfirmation, so a subject-kind mismatch (e.g.publisher-compromisedon a release) is a cleanINVALID_BODY; a release URI confirmed with a DID segment failsCONFIRMATION_MISMATCH. Subject confirmation is derived from the URI (rkey / DID final segment), not echoed. - Idempotency:
val/negare server constants per endpoint; issue vs retract differ innegandintent, so a key reused across directions yieldsIDEMPOTENCY_KEY_CONFLICT. The dialog mints a ULID per open and reuses it across retries. - SQL safety, FK ordering, changeset/i18n/RTL: All new SQL is parameterized; event INSERT precedes outbox INSERT (FK resolves); labeler is
private: truev0.0.0 (no changeset needed); the labeler console is deliberately unlocalized by prior decision and uses logical Tailwind only — consistent with the existingLabelActionDialog.
Conclusion
Clean, well-reasoned, and well-tested (24 new emergency tests + 6 dialog tests). I found no needs_fixing issues. The three suggestions below are the two non-blocking decisions the author already surfaced plus one minor test-coverage gap — none block merge.
| const eventInsert = buildOperationalEventInsert(deps.db, { | ||
| id: eventId, | ||
| eventType: EMERGENCY_EVENT_TYPE[action], | ||
| severity: neg ? "high" : "critical", |
There was a problem hiding this comment.
[suggestion] A retract with no active positive takedown/compromised label still succeeds: it issues a no-op neg:true label and emits a high-severity operational_events row plus a deployment-alert outbox row (line 902 sets severity: neg ? "high" : "critical" unconditionally). It fails safe (moves toward less restriction), but a stray "Retract" click on a publisher that was never taken down pages on-call with a high-severity emergency-takedown/publisher-compromised alert for a no-op — the test emits a high-severity operational event for a retract codifies this. You flagged this as decision #1; consider guarding retract on an active positive (404/409 otherwise) so a no-op can't manufacture a critical-adjacent alert.
| severity: neg ? "high" : "critical", | |
| severity: neg ? "high" : "critical", |
(or, more usefully, short-circuit runEmergencyAction for neg === true when no active positive exists for (src, uri, val) before building the batch.)
There was a problem hiding this comment.
Surfaced to Matt as a non-blocking semantics decision in the PR description (retract-with-nothing-active: idempotent no-op emitting an alert, vs guard with a 404/409). Fails safe either way; leaning toward adding the guard in a later PR once the alert plumbing is fuller, but deferring to his call rather than changing emergency-action semantics unilaterally here.
~ 🤖 Claude Opus 4.8
| ): Promise<Response> { | ||
| const val = EMERGENCY_VALUE[action]; | ||
| const spec: MutationSpec<EmergencyActionBody> = { | ||
| action, |
There was a problem hiding this comment.
[suggestion] operator_actions.action is takedown / publisher-compromised for both issue and retract (line 850); the direction lives only in metadata.neg (line 867). This matches the ratified OperatorActionType set, but an auditor filtering the audit log by action cannot tell an issuance from a retraction without parsing metadata_json. You flagged this as decision #2. If audit observability matters here, the cleanest fix is new action-union members (e.g. takedown-retract, publisher-compromised-retract), which touches the otherwise-frozen operator-actions.ts — so it's a deliberate tradeoff, not a defect.
There was a problem hiding this comment.
Also surfaced to Matt. Splitting issue/retract in the audit action column would add members to the OperatorActionType union in the frozen operator-actions.ts; direction is currently recoverable from metadata.neg. Left as-is pending his call on audit-observability vs touching that file.
~ 🤖 Claude Opus 4.8
| const subject = await getCurrentSubjectByUri(deps.db, uri); | ||
| if (!subject) throw new ReadGuardError("NOT_FOUND"); | ||
| cid = subject.cid; | ||
| if (parseSubjectKind(uri) === "publisher") { |
There was a problem hiding this comment.
[suggestion] The new publisher branch (lines 282–283) is a behavior change: a bare-DID subject with no ?cid= now returns 200 (empty or populated label state) instead of 404, so the console's publisher-labels query can resolve !takedown/publisher-compromised state for a publisher with no record row. This path is exercised indirectly by the UI but has no direct server-side test in console-api.test.ts (no publisher/DID-subject subject-labels case exists). The change is low-risk (getActiveLabelState treats cid: "" as applicable to cid IS NULL rows), but a focused test — e.g. issuing a publisher-compromised label then reading /admin/api/subjects/<DID>/labels and asserting the active winner — would lock in the new 200-vs-404 contract.
There was a problem hiding this comment.
Locked in with a direct test (fa17f2b): seeds a URI-wide publisher-compromised label (cid NULL) on a bare DID, reads /admin/api/subjects/<DID>/labels with no cid, and asserts the active winner — pinning the new 200-vs-404 contract server-side rather than only through the UI.
~ 🤖 Claude Opus 4.8
|
There was a problem hiding this comment.
Re-review of #2026 (I previously approved). The diff is unchanged since my prior pass, and the one test-symmetry suggestion I raised has been folded in.
Approach: Still the right change for the right problem — four admin-only emergency endpoints (!takedown issue/retract, publisher-compromised issue/retract) layered on the W9.2 guardMutation + prepareManualLabelIssuance path, with a two-field typed ceremony and a label-gated operational event + outbox row committed atomically.
What I re-verified on this pass:
- Test-symmetry gap closed: the unauthenticated test now asserts zero side effects across
operator_actions,issued_labels,operational_events, andnotification_outbox(console-mutation-api.test.ts, therejects an unauthenticated caller with zero side effects (401)case). Previously it asserted status only. - Phantom-success gate (T1):
commitMutationorders the batch as[operator_actions insert, ...effect], so the audit row precedes the issuance statements, the event INSERT, and the outbox INSERT. On an idempotency-key conflict the whole batch rolls back, so a race-loser commits no event/outbox row — thegateOnIssuedLabelActionKeyEXISTS-gate (joiningissued_labels ⋈ issuance_actions ON idempotency_key) only ever matches this action's own label, andissuance_actions.idempotency_keyisUNIQUE(0001_init.sql). No "takedown issued" alert can fire for a suppressed label. Confirmed. - Authz-before-effect, ceremony (T7), §10, idempotency, SQL safety: unchanged and still sound.
requiredRole: "admin"is checked byguardMutationbefore body parsing/signing/writes;assertAdminIssuableruns beforeassertEmergencyConfirmationso subject-kind confusion is a cleanINVALID_BODY/CONFIRMATION_MISMATCH;val/neg/intentare server constants so issue-vs-retract reuse yieldsIDEMPOTENCY_KEY_CONFLICT. All new SQL is parameterized.
No new needs_fixing issues. The two non-blocking decisions the author surfaced (retract-as-no-op still emitting a high-severity alert; operator_actions.action carrying direction only in metadata.neg) remain the author's explicit, pushed-back choices — I'm not reposting them. Clean, well-tested; the prior approval stands.
6ce6ad5
into
feat/plugin-registry-labelling-service
What does this PR do?
W9.6 PR-1 — the admin-only emergency actions. Four endpoints issue and retract
!takedown(on a release, package, or publisher subject) andpublisher-compromised(on a DID), each through the W9.2 mutation guard as one atomiccommitMutationbatch: the signed label, a critical-severity operational event, and adeployment-alertoutbox row (W11.3 drains it) all commit together, or none do.Building on PR-0 (#2024) and W9.5 (#2023):
requiredRole: "admin"on its spec;guardMutationverifies the Access identity and role before body parsing, signing, or any write. A reviewer gets 403 and an unauthenticated caller 401 with provably zero side effects (nooperator_actions,issued_labels,operational_events, ornotification_outboxrow).hasRolehas no reviewer→admin path.subjectConfirmation(the release/package rkey, or the publisher DID's final segment — no fragile handle resolution) andintent(a server-constant phrase bound per action and direction:CONFIRM TAKEDOWN/CONFIRM COMPROMISE/CONFIRM RETRACT). Both are validated before signing, both fold into the idempotency fingerprint, and the error is a staticCONFIRMATION_MISMATCHthat never echoes the typed value. An issue-intent on a retract endpoint, or a takedown phrase for a compromise, is rejected.WHERE EXISTS (issued_labels JOIN issuance_actions ON … WHERE idempotency_key = ?)), keyed on the issuance idempotency key — see the PR-0 correction below. If a signing-key rotation suppresses the label mid-batch, neither the event nor the outbox row inserts, andassertIssuancePersistedreturns 503 on both the proceed and replay paths. No "takedown issued" alert can ever fire for a takedown that never landed.!takedownis admin-retractable (same ceremony,CONFIRM RETRACT); retraction issues a singleneg:truelabel and re-exposes whatever automated blocks were live before — they were never negated, so nothing is re-issued and the evaluator resolves the subject to its real state (blocked, not redacted, not eligible). Publisher/package takedown is one URI-wide/DID label — no cascade to per-release labels, so there is no partial-application surface.!takedown— the automated path rejects the emergency vocabulary outright, with the in-batch guard as backstop.Console: an admin-only "Emergency actions" card on the subject/publisher view with the two-typed-field danger dialog (record takedown, publisher takedown, publisher-compromised — issue and retract, state-gated by the subject-label read with a "taken down" indicator). Admin visibility is cosmetic via
/whoami; the server is authoritative. Plain English strings (console unlocalized, W9.3 decision), RTL-safe logical Tailwind,role="alertdialog".No policy fixture change:
!takedownandpublisher-compromisedalready carryadminissuance modes atpolicyVersion 2026-07-10.experimental.3; the delta from W9.4's issue endpoint is purely theadminrole gate + ceremony + gated event/outbox.PR-0 correction (worth a look)
PR-0's phantom-success gate keyed on the numeric
issuance_actions.id, but the real issuance path lets D1 autoincrement that id in-batch — so it's unknowable to a handler and undrivable. This PR adds an additivegateOnIssuedLabelActionKeythat gates on the UNIQUE issuance idempotency key (= the operator action id, minted before commit) via a join to the label. PR-0's numeric gate and its five tests are untouched.issuance_actions.idempotency_keyis UNIQUE and equals this action's id, so the gate can only ever match this action's own label.Two decisions for a reviewer (non-blocking)
Surfaced by the independent adversarial pass; neither is a security issue (both fail safe), so I've left the behavior as-is pending your call:
neglabel and still emits a high-severity operational event + alert. It fails safe (moves toward less restriction), but a spurious critical-adjacent alert for a no-op is operational noise. Option: guard retract on an active positive and 404/409 otherwise. I lean toward adding the guard in PR-2/PR-3 once the DLQ/alert plumbing is fuller, but happy to do it here if you'd rather.operator_actions.actionistakedown/publisher-compromisedfor both issue and retract — direction lives inmetadata.neg. This matches the ratifiedOperatorActionTypeset (no separate retract types), but an auditor filtering byactioncan't distinguish issue from retract without reading metadata. Flagging for audit-observability; changing it means new action-union members (touches the frozenoperator-actions.ts).Adversarially reviewed by an independent Opus pass targeting authz-before-effect on all four endpoints, ceremony bypass, the T1 key-gate composition, subject-kind confusion (T7), retract resting state, §10, and replay-exactly-once: no blockers, crown jewels confirmed. Its one test-symmetry note (the 401 test asserted status only) is folded in — that test now asserts zero side effects too.
Stacked on the integration branch (W9.5 + PR-0 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 — the labeler console is deliberately not localized (decision 2026-07-13). Changeset n/a —
apps/labeleris a private, unpublished Worker app.AI-generated code disclosure
Screenshots / test output
pnpm --filter @emdash-cms/labeler test: worker 507 pass (28 files; theconsole-mutation-apisuite adds 24 emergency-action tests — per-endpoint reviewer/unauth zero-side-effect, admin-accepts, ceremony rejections, T1 phantom + replay-exactly-one-event, T7 subject confusion, retract resting state, §10), console 26 pass (6 new for the emergency dialog)console: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-emergency-actions. Updated automatically when the playground redeploys.