Skip to content

feat(labeler): admin emergency takedown and publisher-compromised actions (W9.6 PR-1) - #2026

Merged
ascorbic merged 2 commits into
feat/plugin-registry-labelling-servicefrom
feat/labeler-emergency-actions
Jul 13, 2026
Merged

ascorbic merged 2 commits into
feat/plugin-registry-labelling-servicefrom
feat/labeler-emergency-actions

Conversation

@ascorbic

@ascorbic ascorbic commented Jul 13, 2026 •

Copy link
Copy Markdown
Member

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) and publisher-compromised (on a DID), each through the W9.2 mutation guard as one atomic commitMutation batch: the signed label, a critical-severity operational event, and a deployment-alert outbox row (W11.3 drains it) all commit together, or none do.

Building on PR-0 (#2024) and W9.5 (#2023):

  • Admin-only, checked pre-effect. Every endpoint sets requiredRole: "admin" on its spec; guardMutation verifies 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 (no operator_actions, issued_labels, operational_events, or notification_outbox row). hasRole has no reviewer→admin path.
  • High-friction typed ceremony. The body carries two server-validated fields: subjectConfirmation (the release/package rkey, or the publisher DID's final segment — no fragile handle resolution) and intent (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 static CONFIRMATION_MISMATCH that never echoes the typed value. An issue-intent on a retract endpoint, or a takedown phrase for a compromise, is rejected.
  • No phantom alert. The event and outbox inserts gate on the label's in-batch existence (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, and assertIssuancePersisted returns 503 on both the proceed and replay paths. No "takedown issued" alert can ever fire for a takedown that never landed.
  • Retract restores the pre-takedown state. !takedown is admin-retractable (same ceremony, CONFIRM RETRACT); retraction issues a single neg:true label 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.
  • §10 holds: automation cannot negate an admin !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: !takedown and publisher-compromised already carry admin issuance modes at policyVersion 2026-07-10.experimental.3; the delta from W9.4's issue endpoint is purely the admin role 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 additive gateOnIssuedLabelActionKey that 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_key is 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:

  1. Retract with no active takedown succeeds as a no-op neg label 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.
  2. operator_actions.action is takedown / publisher-compromised for both issue and retract — direction lives in metadata.neg. This matches the ratified OperatorActionType set (no separate retract types), but an auditor filtering by action can't distinguish issue from retract without reading metadata. Flagging for audit-observability; changing it means new action-union members (touches the frozen operator-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

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm lint passes
  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • User-visible strings in the admin UI are wrapped for translation (if applicable). Do not include messages.po changes except in translation PRs — a workflow extracts catalogs on merge to main.
  • I have added a changeset (if this PR changes a published package)
  • New features link to an approved Discussion: RFC RFC: Decentralized Plugin Registry #694

i18n n/a — the labeler console is deliberately not localized (decision 2026-07-13). Changeset n/a — apps/labeler is a private, unpublished Worker app.

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Claude Code with Opus 4.8 (design, implementation, adversarial review, coordination)

Screenshots / test output

  • pnpm --filter @emdash-cms/labeler test: worker 507 pass (28 files; the console-mutation-api suite 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)
  • Typecheck (both projects) clean; console:build succeeds; lint: 0 diagnostics in apps/labeler

https://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.

…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
@github-actions github-actions Bot added review/needs-review No maintainer or bot review yet size/XL labels Jul 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Scope check

This 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.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 13, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-playground fa17f2b Jul 13 2026, 10:48 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 13, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-do fa17f2b Jul 13 2026, 10:46 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 13, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-cache fa17f2b Jul 13 2026, 10:48 PM

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: guardMutation runs hasRole(identity, "admin") before parseJsonBody/parseBody; hasRole has no reviewer→admin escalation for an admin requirement. 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 same db.batch, so the EXISTS sees the in-batch label; on signing suppression the event + outbox insert zero rows and assertIssuancePersisted 503s on both proceed and replay. Confirmed exactly-one-event across replay.
  • §10: The automated path rejects !takedown/publisher-compromised at validateAutomatedProposal (no automated mode in their subject rules) with the in-batch assertAutomatedNegationAllowed guard as backstop. Retract is a manual neg action, so the §10 guard is correctly bypassed.
  • Ceremony / T7: assertAdminIssuable runs before assertEmergencyConfirmation, so a subject-kind mismatch (e.g. publisher-compromised on a release) is a clean INVALID_BODY; a release URI confirmed with a DID segment fails CONFIRMATION_MISMATCH. Subject confirmation is derived from the URI (rkey / DID final segment), not echoed.
  • Idempotency: val/neg are server constants per endpoint; issue vs retract differ in neg and intent, so a key reused across directions yields IDEMPOTENCY_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: true v0.0.0 (no changeset needed); the labeler console is deliberately unlocalized by prior decision and uses logical Tailwind only — consistent with the existing LabelActionDialog.

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",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Suggested change
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.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@github-actions github-actions Bot added review/approved Approved; no new commits since and removed review/needs-review No maintainer or bot review yet labels Jul 13, 2026
@changeset-bot

changeset-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: fa17f2b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions Bot added review/needs-rereview New commits since the last review and removed review/approved Approved; no new commits since labels Jul 13, 2026
@ascorbic ascorbic added the bot:review Trigger an emdashbot code review on this PR label Jul 13, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and notification_outbox (console-mutation-api.test.ts, the rejects an unauthenticated caller with zero side effects (401) case). Previously it asserted status only.
  • Phantom-success gate (T1): commitMutation orders 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 — the gateOnIssuedLabelActionKey EXISTS-gate (joining issued_labels ⋈ issuance_actions ON idempotency_key) only ever matches this action's own label, and issuance_actions.idempotency_key is UNIQUE (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 by guardMutation before body parsing/signing/writes; assertAdminIssuable runs before assertEmergencyConfirmation so subject-kind confusion is a clean INVALID_BODY/CONFIRMATION_MISMATCH; val/neg/intent are server constants so issue-vs-retract reuse yields IDEMPOTENCY_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.

@github-actions github-actions Bot added review/approved Approved; no new commits since and removed review/needs-rereview New commits since the last review labels Jul 13, 2026
@ascorbic
ascorbic merged commit 6ce6ad5 into feat/plugin-registry-labelling-service Jul 13, 2026
18 of 22 checks passed
@ascorbic
ascorbic deleted the feat/labeler-emergency-actions branch July 13, 2026 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:review Trigger an emdashbot code review on this PR cla: signed review/approved Approved; no new commits since size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant