Skip to content

fix(labeler): reject an emergency retract with no active label (W9.6 follow-up) - #2029

Merged
ascorbic merged 1 commit into
feat/plugin-registry-labelling-servicefrom
feat/labeler-retract-guard
Jul 14, 2026
Merged

ascorbic merged 1 commit into
feat/plugin-registry-labelling-servicefrom
feat/labeler-retract-guard

Conversation

@ascorbic

@ascorbic ascorbic commented Jul 14, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

A small ratified hardening (2026-07-14) to the W9.6 emergency-action retract endpoints. Previously, retracting a !takedown or publisher-compromised label that wasn't in effect succeeded anyway — it signed a no-op neg:true label and emitted a high-severity operational event, returning 200 for a takedown that was never live. Now the retract endpoints pre-check that the target positive label is currently active and reject with 404 NO_ACTIVE_LABEL if it isn't — so no no-op negation is signed and no spurious alert fires.

  • assertRetractableLabel reads the same stream winner official clients see (getActiveLabelState) and rejects unless the winner for the target val exists and is active (non-negated, unexpired). The read passes cid: "" — every emergency label is cidRule: forbidden (URI-wide / DID, stored with cid NULL), so the URI-wide winner is always found regardless of subject kind.
  • Pure read, commits nothing on reject. The check runs after guardMutation's role gate (a reviewer still gets 403, never a 404 leaking label state) and after the typed-ceremony validation (a wrong confirmation still gets 400), but before createSigner / prepareManualLabelIssuance / commitMutation. An absent, already-negated, or expired label commits no operator_actions, issued_labels, operational_events, or notification_outbox row.

Handler-only change (console-mutation-api.ts + its test); the console isn't touched — a retract on a stale view surfaces a clean 404. Nothing frozen was touched.

This resolves one of four post-review decisions on the merged W9.6 (the other three — audit action shape, pause alerting, DLQ concurrent-loser accuracy — were ratified as leave-as-is; all four are recorded in the plan).

Adversarially reviewed by an independent Opus pass focused on the one dangerous failure mode — a false-positive rejection that would block a legitimate takedown undo. It proved, per subject kind, that cid: "" finds the active winner for release/package/publisher takedown and publisher-compromised (all store cid NULL), that the guard fires on both retract endpoints and can't be bypassed (replay only short-circuits an already-guarded action), and that ordering/zero-side-effects/no-info-leak all hold: no blockers. It closed the real coverage gap — the initial happy-path test only covered release/takedown, so it added the package/takedown, publisher/takedown, and publisher-compromised/DID issue→retract→200 round-trips, all folded in.

Stacked on the integration branch (all W9.6 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 — no admin UI; the labeler console isn't localized (decision 2026-07-13), and this PR touches no console strings. Changeset n/a — apps/labeler is a private, unpublished Worker app. Bug fix on unreleased W9.6 code, so no Discussion needed beyond the existing RFC #694.

AI-generated code disclosure

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

Screenshots / test output

  • pnpm --filter @emdash-cms/labeler test: worker 546 pass (28 files; the emergency-retract-guard suite covers the active-label happy path for all four label/subject combinations, the no-active-label 404 with four-count zero-side-effect assertions on both retract endpoints, the already-retracted double-retract edge, and the 403-before-guard / 400-before-guard ordering), console 35 pass
  • Typecheck (both projects) clean; 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-retract-guard. Updated automatically when the playground redeploys.

A takedown/publisher-compromised retract now pre-checks that the target
positive label is currently in effect (getActiveLabelState winner exists
and active) before signing. An absent, already-negated, or expired label
is a 404 NO_ACTIVE_LABEL — no no-op negation is signed and no operational
event fires for a label that was never live. Pure read after the role and
ceremony gates, before any commit.

Claude-Session: https://claude.ai/code/session_014rikrGMh25h1rJczUQyTMM
@changeset-bot

changeset-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 1743746

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-review No maintainer or bot review yet size/L cla: signed labels Jul 14, 2026
@cloudflare-workers-and-pages

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 1743746 Jul 14 2026, 05:41 AM

@cloudflare-workers-and-pages

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 1743746 Jul 14 2026, 05:41 AM

@cloudflare-workers-and-pages

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 1743746 Jul 14 2026, 05:41 AM

@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, solving the right problem. The W9.6 emergency-retract endpoints previously signed a no-op neg:true label and emitted a high-severity operational event for a takedown that was never live, returning 200. Adding a pre-check that the target positive label is currently in effect before signing is a sound, minimal hardening that fits the existing guard-then-sign-then-commit shape of runEmergencyAction. The fix is correctly scoped to the two emergency retract endpoints (handler + tests only; nothing frozen touched), and the "TDD for bugs" convention is honored with a reproducing test for every subject/label combination.

What I checked

  • Guard semantics (assertRetractableLabel). It reads the same getActiveLabelState stream winner the console and XRPC clients see, keyed by (src = labelerDid, uri, cid: ""), and rejects unless winners.get(val) exists and .active is true. I verified against the implementation that active requires neg === 0, applicable (row.cid === null || row.cid === input.cid), and unexpired, and that the map's last-write-wins iteration yields the highest-sequence winner. The policy fixture confirms both !takedown and publisher-compromised are cidRule: forbidden on every subject kind they grant admin for, so emergency labels are always stored with cid NULL → cid: "" always matches via the row.cid === null branch. The !-prefixed val is stored verbatim and looked up verbatim. No false-positive-vs-console divergence: the guard reads through the same deps.db binding the console display uses.
  • Ordering / zero side effects. The guard runs after guardMutation (role gate → ceremony → assertAdminIssuable) and before createSigner/prepareManualLabelIssuance/commitMutation. A reviewer still gets 403 and a wrong ceremony/intent still gets 400 before the 404. On reject, no signer is created and no operator_actions/issued_labels/operational_events/notification_outbox row is written, and no deferred work is scheduled (the if (neg) read precedes deps.defer). Verified.
  • Replay path. guardMutation returns the stored descriptor for an already-committed action and short-circuits before assertRetractableLabel, so a legitimate replay of a successful retract returns 200 (not re-checked). A 404 never commits, so it cannot be replayed as success. Correct.
  • Error handling. NoActiveLabelError is added to the top-level instanceof chain in handleConsoleMutation; its { error: { code, message } } envelope with status 404 matches the sibling LabelMutationError/DeadLetterResolvedError shapes. Static message; the code (NO_ACTIVE_LABEL) leaks nothing an admin can't already see via the console read, and non-admins are 403'd first.
  • TOCTOU. The read and the commit are not atomic, but the only harmful direction (false reject blocking a legitimate undo) is bounded by reading the same binding/state the console shows; the opposite direction (label negates/expires between read and commit) merely signs a negation that becomes the new winner — pre-existing behavior, no regression. Concurrent double-retract behaves as before this PR.
  • Tests. New suite covers the active happy path for all four label/subject combinations (release+takedown, package+takedown, publisher+takedown, publisher+publisher-compromised), the no-active-label 404 on both retract endpoints with globalCounts before/after zero-side-effect assertions, the already-retracted double-retract → 404, and the 403-before-guard / 400-before-guard ordering. The previously-shared-DB-dependent "emits a high-severity event for a retract" test was correctly rewritten to issue its own takedown first (it would otherwise 404 under the new guard). Helpers (countRows, bodyError, globalCounts) are sound.
  • Conventions. Raw D1 with bound ? placeholders (no interpolation); apps/labeler is private: true v0.0.0 so changeset n/a is correct; no admin-UI strings so i18n n/a; no content-table/locale concerns apply. The trailing deadLetterRow reflow is an oxfmt pass on a file this PR already touches, not a drive-by on an unrelated file.

Conclusion

Clean, well-scoped, well-tested hardening with no logic bugs, regressions, security/authorization gaps, or convention violations found. The claim that cid: "" always finds the URI-wide emergency-label winner holds against the fixture and the getActiveLabelState implementation. Approving.

@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 14, 2026
@ascorbic
ascorbic merged commit 3792edf into feat/plugin-registry-labelling-service Jul 14, 2026
10 checks passed
@ascorbic
ascorbic deleted the feat/labeler-retract-guard branch July 14, 2026 05:52
@ascorbic ascorbic mentioned this pull request Jul 14, 2026
60 of 81 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: signed review/approved Approved; no new commits since size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant