Repository navigation
feat(admin): queue and backlog signal for registry records pending review - #8349
Conversation
…view Since #8337 registry review fails safe: an unparseable verdict, an out-of-contract verdict, or a failed model call (an Anthropic outage, or a deployment with no ANTHROPIC_API_KEY) leaves community brands and properties pending instead of publishing them. The moderator Slack channel was the only queue, so a provider outage could build a backlog behind a message nobody re-read. - `registry_review_queue` (migration 627) records every outcome that leaves a decision for a human. Edit rows carry the revision #8337 fixed — revision N restores the state before edit N. - `/admin/registry-review` plus `/api/admin/registry-review/*`: the queue (record, revision, submitter, verdict/reason, age), approve / reject / revert, each recorded with the moderator identity. - Backlog signal (count + oldest age) in the admin view, in a daily digest to the moderator channel, and as the `registry-review-queue-drained` operational diagnostic. Closes #8338
…ueue `issueDomainClaim` parks a bare `hosted_properties` row — empty adagents.json, a claim token, no creator and no revision — at `review_status = 'pending'` while a publisher proves origin control. The queue read `review_status` alone, so that row appeared as a community submission: approving it would have published an empty document as the publisher's own, and rejecting it would have deleted an in-flight claim and stranded its token. A pending row is a submission only when somebody submitted it. Both real paths leave a submitter — `createCommunityProperty` and `createDiscoveredBrand` write revision 1, `enhanceProperty` sets `created_by_user_id` — and a claim row has neither. The listing, the backlog count, the action guard and the diagnostic now all read that one predicate from `registry-review-queue-db.ts`.
Addresses the security, code and internal-tooling reviews of the queue. Correctness of the actions: - A revert is a decision about the record, not about one row. An inconclusive verdict bans nobody and leaves the record editable, so one member can stack edits 5, 6 and 7 and leave three open items. Restoring revision 5 undoes all three — and "reverting" item 7 afterwards would have put 5 and 6 straight back, emptied the queue and zeroed the backlog. Revert now rolls back to the earliest open revision and closes every item it covered. - Claiming is no longer resolving. The claim takes `claimed_at` / `claimed_by_user_id`; only a completed action writes `resolved_at`. A crash between the two now leaves the item in the queue instead of marking it reverted by a revert that never ran. Stale claims expire. - Approve and reject carry the `review_status = 'pending'` predicate into the write (`onlyIfPending`). The prior read-then-write let a review that finished in between turn "reject a pending submission" into "delete a live registry record". - `rollbackProperty` refuses authoritative and pending records, as `rollbackBrand` already did. A queued revert target can outlive the record's community status. - Record decisions close only `new_record` items, never a flagged edit the moderator never saw. - A malicious edit with no revision to revert to now queues with a null revision and no revert action, instead of vanishing from the queue while Slack says a human is needed. Usability of the view: - The queue returns the submitted record (brand fields and manifest, or adagents.json), capped and rendered in a collapsible block. A pending record is hidden from the public viewer, so this was the one thing a moderator could not see before approving it. Read from the row, not from a revision snapshot, which for a property carries its claim and verification tokens. - The page paginates and says "showing N of M"; a failed load no longer leaves stale backlog tiles standing. - The moderator channel distinguishes a published record from a kept edit, and says when a revert covered stacked edits. - A suspicious new record now reports that it was published anyway. The operational diagnostic is one aggregate violation reading the same backlog as the page and the digest, rather than one per stale item: the outage it exists to catch is exactly when per-item findings would bury the billing and directory violations the report is opened for.
…in SQL Second round of review findings. - **Stacked edits are one row.** The queue collapsed three flagged edits on a record into three rows with their own buttons, which invited a moderator to keep edit 7 and then revert edit 5 — discarding the edit they had just kept, with no row left to say so. The listing now returns one row per record, carrying the earliest open revision and a count of what it stands for, and both actions are record-scoped. - **The revert's resolve set comes from the rollback.** It was computed from a list read beforehand, so an edit landing in that window stayed open holding a revert target that now restores the vandalism. The rollback returns the revision it created; every open edit below it is closed in one statement. That also removes a filter that could never exclude anything. - **The claim is honoured at resolve time.** `resolveRegistryReviewItem` refuses when somebody else holds the item, so a lapsed hold cannot write one moderator's verdict over another's. - **Vandalism nobody could undo is `dismissed`, not `approved`.** An edit with no revision to restore has no revert; recording "keep" as an approval would put a moderator's name behind content they only failed to roll back. - The confirm dialog and the success message say what the server actually does — which revision was restored, and how many queued edits the decision closed. - Releasing a claim can no longer turn an intended 409 into a 500, and a failed queue write after a successful rollback no longer reports the rollback as failed. - `/api/properties/hosted/:domain/rollback` maps the new authoritative and pending refusals to 403 instead of 500.
…s target Third round of review findings, all on the collapsed flagged-edit row. - **The card showed one edit's evidence and asked for a verdict on all of them.** Land a benign edit first and the payload second and the row rendered the harmless summary over a "keep" button that approved both. The payload now carries every covered edit — revision, submitter, summary, verdict, reason — and the page renders them all. - **An edit reviewed after a revert named a poisoned revert target.** The review is asynchronous, so its queue row can land after a moderator already rolled the record back; revision N then snapshots the pre-revert state and "undo edit N" would put the vandalism straight back. `recordRegistryReviewOutcome` drops the revert target when a rollback has landed above the revision, and the revert path re-checks before acting. - **Keeping now honours a live claim**, all-or-nothing, and 409s. A revert is a fact about the record, so it may close items others hold; keeping is a decision *not* to act and can race one that does, which would have recorded "kept" over a rollback in flight. The page disables the buttons on a row somebody else is working. - **The backlog counts decisions, not rows**, so the header, the pager, the digest and the diagnostic all report the number the queue actually lists. "Load more" is driven by whether the last page came back full. - Dropped `resolveRegistryReviewItem`, which no longer had a caller. - `api-key-widget-containment` mocks the new admin router, as it does every other one.
Last two findings from the security review. - Two moderators on one record could both clear the route's pre-check — reviews for edits 4 and 5 race, so items can arrive out of revision order — and the loser's rollback would then restore a revision above the winner's, putting the undone edits back. The check moves inside `rollbackBrand` / `rollbackProperty` behind the row lock as an opt-in `onlyIfNoRollbackSince`, so the pre-check is the friendly error and the transaction is the boundary. The loser now gets a 409. - An item the revert refuses could only be cleared as `approved`, putting a moderator's name behind vandalism that was in fact already undone. Keeping now consults the same predicate and records `dismissed`. - A covered edit with no revision rendered as "revision 0", because `Number(null)` is 0.
There was a problem hiding this comment.
Ladon verdict: Approve
Approve — registry-review moderation queue (adcp#8338).
Checked the reviewer's findings against the decision table top-down:
- Row 1 (critical/high): no findings. ✓ clear
- Row 2 (gated_paths): gated_paths is false — does not fire.
- Row 3 (deleted high-risk path): all high-risk reasons are (added) or (modified); no deletions.
- Row 4 (medium data-loss/schema/infra): no medium findings.
- Row 5 (high-risk modified + medium): no medium findings, so does not fire despite modified high-risk files.
- Row 6 (sticky escalate): no prior decision.
- Row 7 (no-auto-approve team): no team match.
- Row 8 (3+ medium): zero medium findings.
- Row 9: falls through → approve.
Reviewer verified intended fail-safe control flow: pending guard travels into the write (onlyIfPending), revert targets re-checked under row lock (onlyIfNoRollbackSince) bounded by the rollback's own revision, all HTML sinks use textContent, property rollback guards mirror editCommunityProperty with 403 mapping in http.ts. Migration 627 is new (added). Change is server/admin-only with no static/schemas/source or published-surface touch, so no changeset is correctly required — no AdCP spec drift, oneOf, released-artifact, or governance-precedent concerns apply. high_risk is true but driven entirely by new files and contract-preserving modifications with no medium-or-higher findings, which per the flag guidance is normal scaffolding, not an escalation trigger.
Closes #8338.
Since #8337 the registry reviewer fails safe: an unparseable verdict, an out-of-contract verdict, or a failed model call — an Anthropic outage, or a deployment with no
ANTHROPIC_API_KEY— resolves toneeds_human_review, which approves nothing and reverts nothing. That is the right posture. What it left behind was a queue with no list: the moderator Slack channel was the only record, so an outage could build a backlog of invisible pending records behind a message nobody re-read.The queue
registry_review_queue(migration 627) is written byregistry-review.tson every outcome that leaves a decision for a human — an inconclusive verdict either way, plus amaliciousverdict whose delete or revert failed. The enqueue never throws: the Slack post is still the faster signal and must not be lost to a missing table.Two shapes of work sit in it, with different sources of truth on purpose:
review_status = 'pending'is authoritative; the queue table only supplies the verdict, reason and age. A record that went pending with no review row at all — the review never fired — therefore still lists, with "no verdict recorded".revision_numberis the revision a revert restores.A pending row is only a submission when somebody submitted it.
issueDomainClaimparks a barehosted_propertiesrow — emptyadagents.json, a claim token, no creator, no revision — atreview_status = 'pending'while a publisher proves origin control. Publishing that would push an empty document as the publisher's own; rejecting it would strand their token. Both real submission paths leave a submitter (createCommunityPropertyandcreateDiscoveredBrandwrite revision 1,enhancePropertysetscreated_by_user_id), and the listing, the backlog count and the action guard all read that one predicate.The view
/admin/registry-review, admin-only, next to the other registry moderation queues. Each row carries the record, the revision, the submitter, the verdict and reason, the age — and the submitted record itself, because a pending community record is hidden from the public viewer, so this is the only place a moderator can read what they are about to publish. It comes from the live row rather than a revision snapshot: a property revision snapshot is the whole row, including its claim and verification tokens.Each decision is recorded against the moderator in the queue row and posted back to the moderator channel so two people don't work the same card.
A record is one decision, not one per edit. An inconclusive verdict bans nobody and leaves the record editable, so one member can stack edits 5, 6 and 7 and leave three open items. Restoring revision 5 undoes all three — so three rows with their own buttons would let a moderator keep edit 7 and then revert edit 5, silently discarding the edit they just kept. The queue collapses them into one row carrying the earliest open revision, a count, and every edit the decision covers: landing a benign edit first and the payload second must not render as a harmless card.
Revert respects #8337's fixed revision semantics. Undoing edit N restores revision N; the target comes from the stored items, never from the request body. What the revert closes is computed from the revision the rollback itself created, not from a list read beforehand — an edit landing in that window is also undone by the rollback, and leaving it open would leave a revert target that now restores the vandalism. The review is asynchronous, so an item can also be written after a revert;
recordRegistryReviewOutcomedrops the revert target when a rollback has already landed above that revision, and the revert path re-checks before acting.Claiming is not resolving. The claim writes
claimed_at/claimed_by_user_id; only a completed action writesresolved_at. A crash between the two leaves the item in the queue, in the backlog and in the diagnostic, rather than marking it reverted by a revert that never ran — the "live vandalism closed as handled" failure the module's own header warns about. Stale claims are reclaimable after five minutes. A revert may close items others hold, because a completed rollback is a fact about the record; keeping may not, because it is a decision not to act and can race one that does.The pending guard travels into the write.
approveandrejectpassonlyIfPending, which appendsAND review_status = 'pending'to the statement. Reading the status and then deleting has a window — reachable in exactly the slow-review situation this feature exists for — in which "reject a pending submission" becomes "delete a live registry record". The option defaults off, so every existing caller is unchanged.Moderation is attributable or it does not happen. All routes are
requireGlobalAdmin; mutations additionally refuse the staticADMIN_API_KEYand any key-authenticated session, matching/api/brands/discovered/:domain/rollback. Reads stay open to the admin key so ops polling can watch the backlog. Vandalism a moderator could only fail to undo is recorded asdismissed, notapproved.The backlog signal
Count and oldest age, in three places with three audiences. All three read the same aggregate, which counts decisions — the rows the queue lists — so they cannot disagree with each other or with the page.
registry-review-digest, a daily post to the moderator channel once the oldest item passes 12h — the same cadence and threshold as the brand-logo and community-mirror digests. It carries counts, ages and a fixed link and nothing else: per-record detail is submitter- and model-authored and belongs on the page, not in a line the room reads as platform copy.registry-review-queue-drained, an integrity invariant for the operator already reading/api/admin/integrity/checkduring an incident. One aggregate violation, not one per item — the outage this exists to catch is exactly when per-item findings would bury the billing and directory violations that report is opened for. Severitywarning.Also fixed on the way
rollbackPropertynow refuses authoritative and pending records, asrollbackBrandalready did. A queued revert target can outlive the record's community status: a flagged edit can sit for weeks while the real publisher claims the domain and publishes their ownadagents.json. This tightens the pre-existing/api/properties/hosted/:domain/rollbacktoo, which now maps the refusal to 403 rather than 500.maliciousedit with no revision to revert to used to do nothing and tell nobody — Slack said a human was needed and the queue would have shown nothing. It now queues with a null revision and "Mark handled" as its only action.suspiciousnew record is published with only a log line; the moderator thread now says so (Record approved, flagged as suspicious) instead of showing a warning verdict with no action.Tests
All new tests fail if the corresponding behaviour is removed.
server/tests/unit/registry-review-queue-enqueue.test.ts— 12 cases: every fail-safe outcome enqueues, every finished one does not, the revision an edit carries, the revision-less edit, and the Slack post surviving a queue-write failure.server/tests/unit/admin-registry-review-routes.test.ts— 30 cases: authz (unauthenticated, non-admin, static admin key, tenant key), each action, the pending guard and its race, claim/release, stacked-edit reverts, the stale revert target, the claim conflict on keep, and the revert ignoring a client-supplied revision.server/tests/integration/registry-review-queue.test.ts— 24 cases against Postgres: the partial-index upsert and its age clock, thereview_status-driven listing, the domain-claim exclusion, the submitted content and its absent secrets, the collapse and its covered edits, claim semantics and stale reclaim, the revision-bounded resolve, conditional writes, the property rollback guard, the backlog aggregate, and the diagnostic's SQL.server/tests/unit/registry-review-digest.test.ts— 7 cases on when the digest fires and what it may contain.server/tests/unit/integrity/invariants.test.ts— 6 new cases for the aggregate invariant.Verified end to end against a real server and Postgres as well as in tests. No changeset — server/admin-only, and
scripts/check-changeset-protocol-scope.cjsagrees.Notes for review
registry_review_queueand itsschema_migrationsrow before re-running.needs_human_reviewbecause the model never ran, so the right resolution for most of them is "run it again now the provider is back", not forty hand judgements. Filed as Re-run registry review from the moderation queue, and drain an outage backlog automatically #8348, along with why bulk-approve is the wrong answer to the same pressure — it is the fix(registry): bind the registry-review verdict to the submitter and fail safe #8337 fail-open with extra steps./admin/bans; the queue's actions are about records.security-reviewer,code-reviewerandinternal-tools-strategistagents before opening and after each round of fixes. Every finding is fixed above or answered in these notes.Open workspace in Conductor