Skip to content

feat(labeler): versioned policy resolver (W8.5) - #2004

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

ascorbic merged 1 commit into
feat/plugin-registry-labelling-servicefrom
feat/labeler-policy-resolver

Conversation

@ascorbic

Copy link
Copy Markdown
Member

What does this PR do?

Adds the labeler's versioned policy resolver — plan item W8.5, spec §9.9 steps 4–7. Replaces the orchestrator's stub resolvePolicyOutcome (marked "W7/W8 replace this with the real policy engine") with the real resolver in policy-resolver.ts, consuming validated NormalizedFinding[] (W8.1) under the versioned ModerationPolicy.

Resolution rules:

  • Source-aware blocking bar. deterministic/capability findings citing an automated-block category block at any severity — deterministic adapters only cite a block category when the condition definitively holds, so the category is the assertion. model/image findings block only at critical (spec step 5's bar for AI judgment). history findings never produce labels (plan W8.4: history may recommend review but cannot label).
  • assessment-passed issues whenever nothing blocks — including on warned outcomes. Spec: "An assessment may pass and warn at the same time." This is a behavioral fix over the stub, and it matters: clients gate installability on an active assessment-passed (feat(registry): enforce moderation labels in clients #1972), so warned-but-passing releases must carry it. A new supersession regression test pins the security-critical inverse — a blocking run negates a prior warned run's assessment-passed (the negation query has no category filter, so eligibility labels negate like descriptive ones; the test guards against a future "optimization" quietly changing that into an install-eligibility bypass).
  • Blocked outcomes still carry their warning labels (step 6 is unconditional). No assessment-passed.
  • Dedup + metadata: one label per category, severity = highest among citing findings; deterministic ordering (blocking → warnings → assessment-passed, first-citation order within groups).
  • Issuance filter: only labels whose policy subjectRules permit automated issuance on a release subject can be machine-proposed — a defensive layer on top of W8.1 validation.

No confidence thresholds are introduced — the spec doesn't define them; that's future policy-version material.

Reviewer note (pre-existing, out of scope): validateAutomatedProposal in service.ts (used by the standalone issueAutomatedAssessmentLabel path, not by finalize) requires critical severity for automated-block labels, which now disagrees with the resolver's spec-correct any-severity-deterministic rule. Nothing routes finalize through it today; flagged for a follow-up Discussion rather than changed here.

The orchestrator diff is exactly the stub + type deletion and the import swap; lifecycle steps 1–3/8–11 (staleness, retries, negation, persistence) are untouched. No migration, no lexicon change, no public-API change.

Reviewed with an opus adversarial pass that traced the warned→blocked supersession path end-to-end (no hole — and it drove the regression test that now pins it).

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

Admin i18n and changeset are n/a — this touches only apps/labeler, a private, unpublished Worker app (no admin UI, not on npm).

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Claude Code with Claude Fable 5 (design, review coordination, regression test), an Opus 4.8 subagent (adversarial review), and a Sonnet subagent (implementation)

Screenshots / test output

  • pnpm --filter @emdash-cms/labeler test: 274 pass (18 files) — 12 new resolver-matrix tests (source×severity×category blocking bars, history exclusion, pass+warn coexistence, blocked+warn, dedup/severity aggregation, issuance filter, ordering determinism) + 3 orchestrator tests (warned issues assessment-passed; blocked issues warnings without it; warned→blocked supersession negates the stale assessment-passed)
  • Typecheck clean; pnpm lint:json diagnostics unchanged at 19 (0 in apps/labeler)

Replace the orchestrator's stub resolvePolicyOutcome with the real
spec-§9.9 resolver in policy-resolver.ts. Deterministic/capability
findings citing an automated-block category block at any severity;
model/image findings block only at critical; history findings never
produce labels. Warning labels issue at any severity, including
alongside blocking labels. assessment-passed issues whenever nothing
blocks — including on warned outcomes, which install-eligibility
clients gate on. Labels dedupe per category with highest-severity
aggregation, ordered blocking → warnings → assessment-passed in
first-citation order, and only labels permitting automated release
issuance are ever machine-proposed.

Adds a supersession regression test pinning that a blocking run
negates a prior warned run's assessment-passed.
@changeset-bot

changeset-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 374106e

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

Copy link
Copy Markdown
Contributor

Scope check

This PR changes 591 lines across 4 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.

@github-actions github-actions Bot added cla: signed review/needs-review No maintainer or bot review yet labels Jul 13, 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-cache 374106e Jul 13 2026, 07:03 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 374106e Jul 13 2026, 07:03 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-do 374106e Jul 13 2026, 07:05 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.

This is the right change at the right place: it implements plan item W8.5 by replacing the orchestrator's stub resolvePolicyOutcome with a real, pure, versioned policy resolver in apps/labeler/src/policy-resolver.ts. Keeping the resolver stateless while the orchestrator continues to own persistence, negation, and staleness matches the labeler's architecture.

What I checked:

  • Source/severity blocking bar: deterministic/capability block at any severity; model/image only at critical; history is excluded. This matches the PR description and existing FindingSource types.
  • Warning + pass coexistence is correctly implemented: warned outcomes include both the warning label(s) and assessment-passed.
  • Blocked outcomes include warnings but not assessment-passed.
  • Dedup and severity aggregation are deterministic and first-citation ordered.
  • The defensive issuance filter (permitsAutomatedRelease) only permits labels that allow automated issuance on a release subject.
  • Supersession regression test correctly asserts that a subsequent blocking run negates the stale assessment-passed from a warned run.
  • No AGENTS.md violations: this touches only the private apps/labeler worker (no admin UI, no SQL, no i18n, no published package, no public API change).
  • Export move from orchestrator to resolver is safe: no other module imports the moved types.

I found no blocking issues. The one pre-existing divergence the author flagged—validateAutomatedProposal still requiring critical for automated-block labels while finalize bypasses it—is correctly left for a follow-up Discussion.

One minor test-gap suggestion: the resolver matrix covers deterministic, model, image, and history sources, but does not exercise the capability source that the description lists as blocking at any severity. Adding that test would pin the behavior explicitly.

}

describe("resolvePolicyOutcome: blocking", () => {
it("blocks on a deterministic finding at any severity", () => {

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 resolver matrix tests deterministic, model, image, and history sources, and the PR description explicitly calls out capability findings as blocking at any severity. Consider adding a capability analogue to the deterministic test so the spec-correct behavior is pinned, e.g.:

it("blocks on a capability finding at any severity", () => {
	const outcome = resolvePolicyOutcome(
		[finding({ source: "capability", category: "undeclared-access", severity: "low" })],
		MODERATION_POLICY,
	);
	expect(outcome.toState).toBe("blocked");
	expect(outcome.labels).toEqual([
		{ val: "undeclared-access", findingCategory: "undeclared-access", severity: "low" },
	]);
});

@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
@ascorbic
ascorbic merged commit e32710a into feat/plugin-registry-labelling-service Jul 13, 2026
12 checks passed
@ascorbic
ascorbic deleted the feat/labeler-policy-resolver branch July 13, 2026 07:09
@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/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant