Skip to content

feat(labeler): admin pause/resume of automated issuance (W9.6 PR-2) - #2027

Merged
ascorbic merged 1 commit into
feat/plugin-registry-labelling-servicefrom
feat/labeler-pause-resume
Jul 13, 2026
Merged

ascorbic merged 1 commit into
feat/plugin-registry-labelling-servicefrom
feat/labeler-pause-resume

Conversation

@ascorbic

@ascorbic ascorbic commented Jul 13, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

W9.6 PR-2 — the admin-only pause/resume of automated issuance, the operator surface for the global ingestion kill-switch. PR-0 (#2024) built the mechanism (the automation_state singleton, the fail-closed isAutomationPaused read, and the discovery-consumer enforcement); this PR wires the endpoints, status read, and console control that drive it.

  • Two endpoints through the mutation guard: POST /admin/api/automation/pause and /resume, both requiredRole: "admin". The effect flips automation_state.paused (buildAutomationPauseUpdate) and emits an ungated operational event — automation-paused (severity high) or automation-resumed (info) — committed with the audit row in one commitMutation batch. No label is issued, so there's no phantom-label risk and assertIssuancePersisted doesn't apply. A reason is required (it folds into the idempotency fingerprint); no confirmation ceremony — pause/resume is reversible and low-blast-radius, unlike a takedown.
  • The kill-switch stays ingestion-only and fail-closed (ratified): enforcement lives in the discovery consumer, never the signing layer, so manual/admin issuance — including an emergency !takedown — stays available while automation is paused. resume clears paused_reason to NULL. No auto-resume timer; resume is an explicit audited action.
  • Status read now reports automationPaused, pausedReason, and pausedSince (a direct singleton read added to the existing status Promise.all), degrading in the safe direction on error like its siblings.
  • Console: an admin-gated pause/resume control on the dashboard showing Active/Paused with a reason input, danger token when paused, RTL-safe logical Tailwind, plain English (unlocalized). Admin visibility is cosmetic via /whoami; the server is authoritative.

End-to-end proof: the payoff test drives the real processDiscoveryMessage on the same DB — hit the pause endpoint, and the consumer retries an ingestion create (no subject created); resume, and it processes to a subject + pending run. This proves the operator endpoint actually drives the gate PR-0 built, not a stubbed flag.

OperatorActionType already reserved pause-issuance / resume-issuance; operational-events.ts already reserved the event types. Nothing frozen was touched.

Adversarially reviewed by an independent Opus pass targeting authz-before-effect, the end-to-end gate drive, fail-closed preservation, singleton integrity under concurrent pause/resume, and a body-injection surface (paused derives from the route, never the wire — POSTing {paused:false} to /pause still pauses): no blockers, no test fixes needed. Two informational notes, neither worth a guard: a missing singleton row (a broken-migration state) makes the status card read "Active" while the consumer still fails closed and retries everything (cosmetic, safe direction); and pausedSince reflects the most recent pause under the event-per-action model.

Stacked on the integration branch (W9.5 + PR-0 + PR-1 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 520 pass (28 files; new pause/resume happy-path, per-endpoint reviewer-403/unauth-401 zero-side-effect, replay/409/re-pause, and the end-to-end consumer-gate proof), console 29 pass (new AutomationControl test)
  • 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-pause-resume. Updated automatically when the playground redeploys.

Two admin-only endpoints toggle the global ingestion kill-switch
through the mutation guard: the effect flips automation_state.paused
and emits an ungated operational event (automation-paused high /
automation-resumed info) with the audit row in one batch. System status
now reports the paused state, reason, and since; the console dashboard
gains an admin-gated pause/resume control. Enforcement already lives in
the discovery consumer (PR-0) — this wires the operator surface that
drives it, proven end to end (pause endpoint -> consumer retries ->
resume -> processes).

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

changeset-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 93170bb

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/XL labels Jul 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Scope check

This PR changes 678 lines across 10 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

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 93170bb Jul 13 2026, 11:11 PM

@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 93170bb Jul 13 2026, 11:11 PM

@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 93170bb Jul 13 2026, 11:12 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 judgment

This is the right change, solving the right problem, in a way that fits the labeler's architecture. W9.6 PR-0 built the kill-switch mechanism (automation_state singleton, fail-closed isAutomationPaused, discovery-consumer enforcement); PR-2 wires the operator surface that drives it — two admin-gated endpoints through the existing mutation guard, a status-card read, and a console control. It deliberately mirrors the established emergency-action pattern (runEmergencyAction) but correctly diverges where the semantics differ: no label is issued, so there's no confirmation ceremony, no assertIssuancePersisted, and the operational event is ungated (not label-gated). The kill-switch stays ingestion-only — enforcement lives in processDiscoveryMessage, never the signing layer — so manual/admin issuance (including !takedown) stays available while paused. That's a sound, spec-aligned design.

What I checked

  • Authz before effect: runAutomationToggle runs guardMutation (role gate + idempotency lookup) before any state UPDATE or event INSERT; the replay path returns the stored descriptor with no side effects. The per-endpoint tests (reviewer→403, unauth→401) verify zero side effects on operator_actions, operational_events, and automation_state.paused. Server is authoritative; the console isAdmin flag is cosmetic.
  • Idempotency/fingerprint: parseBody: () => ({}) ignores the wire body entirely, so paused derives from the route, not the body — POSTing {paused:false} to /pause still pauses (the adversarial note in the description holds). The fingerprint is over {action, reason} only; same key + same reason → replay, same key + different reason → 409, both covered by tests.
  • Atomicity: the audit row, automation_state UPDATE, and event INSERT go in one commitMutation batch; a key-race conflict rolls the effect back with the audit insert. No orphan event/state without an audit row. resume clears paused_reason to NULL. A re-pause while paused is a harmless re-write with its own audit row + event (tested).
  • Status read: readAutomationState is a direct singleton read added to the existing Promise.all; paused !== 1 (incl. missing row) reads "Active", matching the consumer's fail-closed posture only in the not-paused direction. pausedSince = updated_at is correct while paused (only pause/resume touch updated_at).
  • Console: AutomationControl mints the idempotency key per dialog open and reuses it across retries (correct replay semantics), gates the toggle behind isAdmin, uses logical (RTL-safe) Tailwind, and Kumo components. Invalidates system-status on success.
  • End-to-end proof: the payoff test drives the real processDiscoveryMessage on the same D1 — pause → consumer retries (no subject); resume → consumer acks and creates subject + pending run. This genuinely proves the endpoint drives PR-0's gate.
  • Conventions: SQL is parameterized throughout (no interpolation); no content tables touched (no locale filter needed); OperatorActionType (pause-issuance/resume-issuance) and OperationalEventType (automation-paused/automation-resumed) were already reserved. Changeset is n/a (private unpublished Worker); i18n is an explicitly documented decision (2026-07-13) not to localize the labeler console.

Conclusion

The implementation is clean, well-tested, and consistent with the established patterns. Fail-closed behavior is preserved and the gate drive is proven end-to-end. I have one non-blocking design observation (below) about notification delivery. Two items the description pre-acknowledges are fine as-is: the missing-singleton-row cosmetic discrepancy (status reads "Active" while the consumer fails closed — only in a broken-migration state, safe direction) and pausedSince reflecting the most recent pause (event-per-action model).

paused,
reason: ctx.reason,
cts: ctx.now.toISOString(),
};

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] runAutomationToggle records an automation-paused/automation-resumed row in operational_events but, unlike runEmergencyAction (which enqueues a notification_outbox row to the deployment-alert channel at line ~915), it stages no outbox row. Today that's benign — no outbox delivery worker is wired yet, so nothing is delivered regardless — but when delivery lands, a takedown/compromise will page the on-call channel while a kill-switch activation (severity high, an incident-response action) will be audit-only. If the intent is that pausing ingestion during an incident should also alert the deployment channel, consider staging an outbox row here for consistency; if audit-log/console visibility is deliberately sufficient for a reversible operator action, this is fine as-is. Flagging only as a product question, 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.

Good product question, and I agree it's a decision rather than a defect — so I'm leaving it as-is (audit + console only) pending Matt's call rather than unilaterally deciding a pause should page on-call. The event stream already carries the high-severity automation-paused row, so W11.3 can alarm on it directly; staging a deployment-alert outbox row is a one-line addition if the answer is "a pause should page too." I'm batching this with two other alerting/audit-semantics questions from #2026 to put to Matt together once W9.6's PRs are all in, so the incident-notification policy is decided coherently rather than per-PR.

~ 🤖 Claude Opus 4.8

@github-actions github-actions Bot added review/awaiting-author Reviewed; waiting on the author to respond and removed review/needs-review No maintainer or bot review yet 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: approach judgment

This is the right change, solving the right problem, in a way that fits the labeler's architecture — unchanged since my prior pass. W9.6 PR-0 built the kill-switch mechanism (automation_state singleton, fail-closed isAutomationPaused, discovery-consumer enforcement); PR-2 wires the operator surface: two admin-gated endpoints through the existing mutation guard, a status-card read, and a console control. It mirrors runEmergencyAction but correctly diverges where the semantics differ — no label is issued, so no confirmation ceremony, no assertIssuancePersisted, and the operational event is ungated (not label-gated). The kill-switch stays ingestion-only (enforcement in processDiscoveryMessage, never the signing layer), so manual/admin issuance including !takedown stays available while paused. Sound and spec-aligned.

What I re-verified

The diff is unchanged from the prior review; I re-traced each hunk against the runtime semantics in AGENTS.md:

  • Authz before effect: runAutomationToggle runs guardMutation (role gate + idempotency lookup) before any state UPDATE or event INSERT; replay returns the stored descriptor with no side effects. Per-endpoint tests verify zero side effects on operator_actions, operational_events, and automation_state.paused for reviewer→403 and unauth→401.
  • Idempotency/fingerprint: parseBody: () => ({}) ignores the wire body, so paused derives from the route (POSTing {paused:false} to /pause still pauses). Fingerprint is over {action, reason} only; same key+reason → replay, same key+different reason → 409 — both tested.
  • Atomicity: audit row + automation_state UPDATE + event INSERT go in one commitMutation batch; a key-race rolls the effect back with the audit insert. resume clears paused_reason to NULL. Re-pause while paused is a harmless idempotent re-write with its own audit row + event (tested).
  • Status read: readAutomationState is a parameterized singleton read added to the existing Promise.all; paused !== 1 (incl. missing row) reads "Active" — the pre-acknowledged cosmetic discrepancy in the safe direction (consumer still fails closed). pausedSince = updated_at is correct while paused (only pause/resume touch it). Note: on a hard D1 error (not a missing row) the status endpoint 500s like its count siblings do — consistent, not a regression.
  • Console: AutomationControl mints the idempotency key per dialog open and reuses it across retries, gates the toggle behind cosmetic isAdmin (server authoritative), uses Kumo components and logical (RTL-safe) Tailwind, and invalidates system-status on success. Stale-closure concerns are non-issues (dialog closes on success; submit requires a typed reason).
  • Dashboard: new whoami query drives cosmetic isAdmin, defaulting to false while loading/erroring so the toggle hides safely.
  • End-to-end proof: the payoff test drives the real processDiscoveryMessage on the same D1 — pause → consumer retries (no subject); resume → consumer acks and creates the subject. Genuinely proves the endpoint drives PR-0's gate.
  • Conventions: SQL is parameterized throughout; no content tables touched (no locale filter needed); reserved OperatorActionType/OperationalEventType reused, nothing frozen touched; the labeler console's no-Lingui posture matches existing components (e.g. AssessmentActionDialog's bare-English COPY), and is a documented decision; changeset n/a for a private unpublished Worker.

Conclusion

Clean, well-tested, and consistent with the established patterns. Fail-closed behavior is preserved and the gate drive is proven end-to-end. No new blocking or non-blocking findings.

One previously-noted design consideration remains open and is not reposted as a finding: the automation-paused/automation-resumed events are written to operational_events but, unlike emergency takedowns, get no notification_outbox row. I confirmed there is no outbox drain/delivery worker in apps/labeler/src today, so emergency alerts also sit undelivered — the automation omission is consistent with the current state and only becomes observable once a delivery worker is wired. Worth a deliberate decision then; not blocking now.

@github-actions github-actions Bot added review/approved Approved; no new commits since and removed review/awaiting-author Reviewed; waiting on the author to respond labels Jul 13, 2026
@ascorbic
ascorbic merged commit 05afa59 into feat/plugin-registry-labelling-service Jul 13, 2026
18 checks passed
@ascorbic
ascorbic deleted the feat/labeler-pause-resume branch July 13, 2026 23:19
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