Skip to content

feat(registry): label-aware aggregator reads - #1965

Merged
ascorbic merged 4 commits into
feat/plugin-registry-labelling-servicefrom
feat/labeler-aggregator-reads
Jul 12, 2026
Merged

ascorbic merged 4 commits into
feat/plugin-registry-labelling-servicefrom
feat/labeler-aggregator-reads

Conversation

@ascorbic

@ascorbic ascorbic commented Jul 11, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Implements the aggregator's label-aware read path — W1.6 and W4.4–W4.6 from the labelling-service plan (#1909) — in three commits:

  • Accepted-labeler header parsing (@emdash-cms/registry-moderation): parseAcceptLabelersHeader / serializeContentLabelersHeader, RFC 8941 list grammar restricted to the forms the ATProto label spec uses, strict DID validation, first-occurrence ordering, union merge of repeated-DID redact flags, typed syntax errors.
  • Request-boundary policy (W4.4): handleXrpc resolves the policy once per request. Missing header → deployment defaults (every labelers row with trusted = 1, redact: true); explicitly empty → no accepted sources (no enforcement, no hydration); malformed → 400 InvalidRequest; requested DIDs without a labelers row are silently omitted. The response reports the sources actually considered via atproto-content-labelers, now correctly CORS-exposed (the previous expose-headers entry echoed the request header, which was meaningless). Also exports the package-scope and release-scope hard-block vocabulary from the shared moderation package, fixing the existing drift where the search SQL was missing publisher-compromised.
  • Enforcement + hydration (W4.5/W4.6): search and latest-release selection exclude hard-blocked subjects in parameterized SQL (CID-bound labels apply only to the subject's current CID; package/publisher blocks cascade to releases). All five read endpoints hydrate active labels from accepted sources onto views, batched per page (no N+1; 3–4 queries per request). Redaction: an accepted source with redact: true holding an active !takedown makes the subject indistinguishable from absence — 404 on getPackage/resolvePackage, omission in listReleases, and a 404 for a release list whose parent package is redacted (a 200-empty would leak existence). getLatestRelease skips the packages.latest_version fast path whenever an accepted policy is in force, since the pointer is not label-aware.

Adversarial review findings fixed pre-merge: a silent redaction bypass where the 64-label wire cap could truncate away the !takedown before the redaction decision (hydration now returns untruncated sets; the cap applies only at the view boundary, both regression-tested), and the listReleases existence leak above.

Decisions needing maintainer ratification (all flagged in review):

  1. Default policy: missing header resolves to trusted labelers with redact: true.
  2. Trust gates defaults only: an explicitly requested, configured-but-untrusted labeler is honored — persisted trusted is provenance, not request authorization (per the W0.3 audit).
  3. sync.getRecord intentionally serves records for redacted subjects (raw CAR bytes, publicly cached). Recommendation: keep — it is the sync/verification layer, the record remains available from the publisher's own PDS regardless, and consumers auditing labels need to fetch the subject record. Flagged by adversarial review as needing an explicit decision rather than an implicit passthrough.
  4. Read-path SQL enforcement is deliberately broader than evaluateReleaseModeration (documented in label-enforcement.ts): value/subject pairings the evaluator would reject still exclude, always in the over-hide direction. The evaluator remains the only eligibility engine; no positive-assessment requirement ships in this PR (shadow phase).

Implementation PRs target feat/plugin-registry-labelling-service per the umbrella PR. 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 is n/a — no UI changes. Changesets included for the two published packages that changed (@emdash-cms/registry-moderation ×2, @emdash-cms/registry-lexicons); the aggregator is private.

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Claude Code with Claude Fable 5 (design, review, fixes) and Sonnet/Opus subagents (implementation, adversarial review)

Screenshots / test output

  • pnpm --filter @emdash-cms/aggregator test: 15 files, 296 tests pass (41 header-parser tests, 7 request-policy contract tests, 24 enforcement/hydration/redaction tests incl. the truncation-bypass and existence-leak regressions)
  • pnpm --filter @emdash-cms/registry-moderation test: 114 pass; --filter @emdash-cms/registry-lexicons test: 14 pass
  • Typecheck clean; pnpm lint:quick 0 diagnostics; type-aware lint:json has no findings in any touched file
  • Query counts per read request under a non-empty policy: getPackage 3, listReleases 4, getLatestRelease 3, searchPackages ~3 — hydration is one batched query per page

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-aggregator-reads. Updated automatically when the playground redeploys.

ascorbic added 3 commits July 11, 2026 19:41
Adds parseAcceptLabelersHeader and serializeContentLabelersHeader to the
shared moderation package: RFC 8941 list parsing restricted to the forms
the ATProto label spec uses, strict DID validation, first-occurrence
ordering, union merging of repeated-DID redact flags, and typed syntax
errors. An empty header value means no accepted labelers; resolving a
missing header to deployment defaults stays with the caller.
…ndary

Parses atproto-accept-labelers once per request: a missing header resolves
to the deployment's trusted labelers with redact enabled, an empty header
accepts none, malformed syntax returns InvalidRequest, and requested DIDs
without a labelers row are omitted. The response reports the sources
actually considered via atproto-content-labelers, now correctly CORS-
exposed in place of the request header. Also exports the package-scope
and release-scope hard-block vocabulary from the shared moderation
package so SQL enforcement and the evaluator cannot drift.
Search and latest-release selection exclude subjects carrying hard-block
labels from the request's accepted sources, with CID-bound labels applying
only to the subject's current CID and package/publisher blocks cascading
to releases. Direct package reads and release lists return content with
hydrated labels; an accepted source with redact enabled turns an active
takedown into a response indistinguishable from absence, including for
the parent package of a release list. Redaction decisions always see the
full label set; the lexicon's 64-label cap applies only on the wire.
Latest-release selection skips the latest_version fast path whenever an
accepted policy is in force, since the pointer is not label-aware.
@changeset-bot

changeset-bot Bot commented Jul 11, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 968b719

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 21 packages
Name Type
@emdash-cms/registry-moderation Patch
@emdash-cms/registry-lexicons Patch
@emdash-cms/labeler Patch
@emdash-cms/admin Patch
@emdash-cms/plugin-cli Patch
@emdash-cms/registry-client Patch
emdash Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/do-demo-site Patch
@emdash-cms/do-solo-demo-site Patch
@emdash-cms/cloudflare Patch
@emdash-cms/sandbox-workerd Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
create-emdash Patch
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

Not sure what this means? Click here to learn what changesets are.

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

@github-actions

Copy link
Copy Markdown
Contributor

Scope check

This PR changes 1,840 lines across 20 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 review/needs-review No maintainer or bot review yet size/XL cla: signed labels Jul 11, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 11, 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 968b719 Jul 12 2026, 07:15 AM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 11, 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 968b719 Jul 12 2026, 07:16 AM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 11, 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 968b719 Jul 12 2026, 07:15 AM

@ascorbic ascorbic added the bot:review Trigger an emdashbot code review on this PR label Jul 11, 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.

I reviewed the label-aware aggregator read path introduced by this PR. Overall the approach is sound and matches the labelling-service plan: the request policy is resolved once before dispatch, enforcement SQL is parameterized and fail-closed, hydration is batched and untruncated until the view boundary, and the two pre-merge adversarial fixes (truncation bypass and parent-package existence leak) are correctly implemented. Test coverage looks broad.

I found two minor issues worth cleaning up: a stale/misleading docstring in views.ts that contradicts the deliberate untruncated-hydration design, and a subtle information-leak consideration in listReleases where an all-redacted page can still return a cursor. Neither is blocking, so I’m leaving this as comment.


Findings

  • [suggestion] apps/aggregator/src/routes/xrpc/views.ts:128-131

    The docstring says each hydrated subject is “individually capped by hydrateLabels”, but hydrateLabels deliberately returns untruncated sets so redaction decisions see every label. The cap is applied here in capLabels, after redaction has already been decided. Update the comment so future readers don’t assume hydration truncates.

    /** Caps a combined labels array at the lexicon's maxLength. A view's
     * labels are the union of multiple hydrated subjects (e.g. a release's own
     * URI plus its parent package and publisher DID). Hydration returns
     * untruncated per-subject sets so redaction decisions are made first;
     * this boundary cap trims only the final view array. */
    
  • [suggestion] apps/aggregator/src/routes/xrpc/listReleases.ts:149-152

    The cursor is derived from the last raw row before redaction filtering (hasMore && last), so a page where every release is redacted returns { releases: [], cursor: "..." }. That cursor lets a client infer that rows exist beyond the visible set, which somewhat undermines the “indistinguishable from absence” goal for redacted releases. If this is an acceptable trade-off (the alternative is either dropping later pages or doing extra server-side paging work), it should be explicitly documented in the handler comment; otherwise consider only emitting the cursor when at least one release survived.

@github-actions github-actions Bot added review/awaiting-author Reviewed; waiting on the author to respond overlap and removed review/needs-review No maintainer or bot review yet labels Jul 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Overlapping PRs

This PR modifies files that are also changed by other open PRs:

This may cause merge conflicts or duplicated work. A maintainer will coordinate.

@github-actions github-actions Bot added the review/needs-rereview New commits since the last review label Jul 12, 2026
@ascorbic

Copy link
Copy Markdown
Member Author

Both suggestions taken in 968b719: the stale capLabels docstring now describes the untruncated-hydration design, and the all-redacted-page cursor trade-off is documented at the cursor emission site — only emitting a cursor when a row survived would stop pagination early past legitimately visible later pages, and the sensitive case (package-level redaction) already 404s.

@github-actions github-actions Bot removed the review/awaiting-author Reviewed; waiting on the author to respond label Jul 12, 2026
@ascorbic
ascorbic merged commit 6133ac5 into feat/plugin-registry-labelling-service Jul 12, 2026
5 of 8 checks passed
@ascorbic
ascorbic deleted the feat/labeler-aggregator-reads branch July 12, 2026 07:13
@ascorbic ascorbic mentioned this pull request Jul 12, 2026
60 of 81 tasks
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/needs-rereview New commits since the last review size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant