Skip to content

feat(training-agent): admin suspend and resume for reporting webhook subscribers - #9199

Merged
bokelley merged 7 commits into
mainfrom
feat/training-reporting-subscriber-suspend
Nov 23, 2026
Merged

bokelley merged 7 commits into
mainfrom
feat/training-reporting-subscriber-suspend

Conversation

@bokelley

@bokelley bokelley commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A reporting webhook subscriber that stops accepting deliveries keeps every reporting notification on its account retrying. Each notification retries every 30-45 s until the SDK abandons it after 100 attempts, and every new notification starts again. The training agent's canary subscriber training-gcs-canary-20261011 has done this since 2026-10-25: 71 notifications abandoned, and steady error noise (see #9188).

Only the owning principal can turn a subscriber off today, through PUT /sales/reporting/notifications/:accountId, which is scoped to that principal. There is no operator override.

This route stands in for the long-term fix in the SDK, a per-subscriber retry budget and circuit breaker: adcontextprotocol/adcp-client#3780.

Change

New admin routes, behind the existing requireAuth + requireAdmin:

Route Does
GET /api/admin/training-agent/reporting/subscribers Lists every subscriber on the installation's accounts. Each entry has account_id, subscriber_id, active, url_host, event_types and recent_attempts: the outcome counts over the account's latest 200 webhook attempts, plus the last status, HTTP code and time.
POST /api/admin/training-agent/reporting/subscribers/:accountId/:subscriberId/suspend Clears the subscriber's active flag. The body needs { "reason": "..." } (5–500 chars).
POST .../resume Sets it again. Same body.

How suspension works. It uses only the pinned SDK's public APIs (@adcp/sdk 17.0.0-beta.35, @adcp/reporting-storage 0.3.0-beta.1). There is no raw SQL against SDK tables. Every write is a compare-and-set on the subscription set's generation, so it never overwrites a concurrent replacement by the owning principal, and it retries up to 3 times on conflict.

  • Suspend writes the stored set through the runtime's public subscription store. It reads with store.get and writes with store.replace({ expectedGeneration, nextGeneration, subscriptions }), changing only active. It must not go through runtime.replace: that revalidates every destination (DNS and reserved ranges), so a subscriber whose host stopped resolving, the main case for an admin stop, could never be turned off.
  • Resume goes through runtime.replace, so destinations are revalidated before delivery restarts. If a destination no longer validates, the route answers 422 subscription_set_invalid, and the owning principal must replace the set.

active is not part of the destination generation, so the generation and its proof both survive, and resuming needs no new challenge. In the pinned SDK, a suspended subscriber:

  • gets no new deliveries. emit resolves only active subscriptions.
  • stops burning attempts on pending notifications. On the next claim, a notification's frozen recipient for that subscriber is no longer addressed, so it settles as terminal and the activity projects (settleClaimRecipients) rather than retrying again.
  • gets no outbox retries. Live attempt authorization suppresses them as subscription_inactive, which is terminal.

Audit, intent first. Each valid request writes an attributed registry_audit_log row, training_reporting_subscriber_<suspend|resume>_requested, before anything changes. If that insert fails, the route answers 500 audit_write_failed ("Nothing was changed") and never calls the runtime. After the mutation it writes the result:

  • training_reporting_subscriber_suspended / _resumed (outcome applied or unchanged, changed, completed_at);
  • or ..._<verb>_failed (outcome not_found / subscription_set_invalid / unavailable, plus the error name and SQLSTATE).

A lost result row is logged and does not change the response, because the intent row already attributes the action.

Rows use workos_organization_id = 'system_training_agent' (following the system_brand_registry precedent) and resource_id = '<account>/<subscriber>'. Details carry the reason, timestamps, admin id and email, and the static-admin-key attribution (operator, key fingerprint, IP). The info log line carries the same fields except the email.

Responses:

  • Idempotent: 200 with changed: false when the subscriber is already in the requested state.
  • Unknown account or subscriber: 404 subscriber_not_found.
  • Bad ids: 400 invalid_id.
  • Missing or short reason: 400 reason_required.
  • Reporting disabled: 503 reporting_disabled; unavailable: 503 reporting_unavailable.

Not exposed: responses and logs carry identifiers and the destination host only, never the URL path, query or any credential. Failures are logged as an allowlisted error name and SQLSTATE only, never the raw error, because its message, stack or cause can carry URLs or backend values. Training-agent subscriptions are RFC 9421 only, so no credentials exist to leak. No existing admin page shows these subscribers.

The runbook (docs/runbooks/training-agent-gcs-reporting.md) gains a short "Suspending a subscriber" section with the commands.

No changeset: this is training-agent server code and an ops runbook, not the protocol package (.agents/playbook.md § Changesets).

Not done here. Suspending the canary in production is Brian's call once this is deployed. This PR does not call the route against production.

Tests

server/tests/unit/training-reporting-subscriber-suspend.test.ts (15) runs against the real SDK runtime (createPersistentNotificationRuntime with the in-memory store):

  • suspend leaves the sibling and both proofs untouched;
  • resume runs no new prove, and both directions are idempotent;
  • not_found;
  • emit stops dispatching to the suspended subscriber and resumes after resume;
  • an outbox retry is suppressed as subscription_inactive, using a context captured from a real emit;
  • a destination that no longer validates: suspend still applies and stops dispatch with generation and proof intact, resume is refused with NotificationSubscriptionValidationError, then succeeds without re-proof once validation passes;
  • compare-and-set on both paths: suspend through the store and resume through the runtime each re-read on conflict, never overwrite an interleaved owner replace, and give up after 3 conflicts;
  • the runtime class's list only returns url_host, counts recent_attempts per subscriber, and resolves the owning principal.

server/tests/unit/admin-training-reporting-routes.test.ts (38):

  • auth on all three routes: 401 without credentials, 403 for a non-admin session, 403 for a WorkOS API key, 200 for the static admin key;
  • reason and id validation;
  • audit order: intent row, then mutation, then result row, both rows attributed;
  • intent-insert failure gives 500 with the runtime never called; a result-row failure keeps the 200/404/422/503;
  • 404, 422 and 503 each write the intent row plus a _failed row;
  • no raw error in any log: an error carrying password=hunter2, a URL and a nested SQLSTATE yields only error_name and database_code across runtime, intent, result and list failures;
  • no http(s):// anywhere in the list response.

The existing reporting route and startup tests still pass (82 in total across the 4 files). npm run typecheck passes.

Not covered here: the pending-claim settlement against PostgreSQL. The SDK guarantees it; it is described above and was verified against the pinned SDK source by the author and the reviewer.

Local hooks: the pre-commit hook (the full ~17-minute server suite) was skipped with --no-verify. The targeted files and typecheck were run instead, and CI is the gate. The advisory pre-push storyboard matrix was skipped (ADCP_SKIP_STORYBOARD_MATRIX=1).

🤖 Generated with Claude Code

bokelley and others added 3 commits November 23, 2026 20:53
…subscribers

A subscriber that stops accepting reporting webhooks keeps every
notification on its account retrying until the SDK abandons it, and only
the owning principal could turn it off. Add admin routes under
/api/admin/training-agent/reporting/subscribers to list subscribers with
recent attempt outcomes, and to suspend or resume one with a required
reason that lands in registry_audit_log.

Suspension flips the subscription's active flag through the notification
runtime with a compare-and-set on the set generation, so the destination
generation and proof survive and resume needs no new challenge. An
inactive subscriber gets no new emissions, its pending activities settle
it as terminal on their next claim, and outbox retries are suppressed.
Stands in for adcontextprotocol/adcp-client#3780.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Exercise setNotificationSubscriberActive against the SDK's in-memory
notification runtime (proof retained, dispatch and outbox-retry suppression,
compare-and-set) and the admin routes (auth, reason and id validation, audit
rows, error mapping, list redaction).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
aao-secretariat[bot]
aao-secretariat Bot previously approved these changes Nov 23, 2026

@aao-secretariat aao-secretariat 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.

Ladon verdict: Approve

Approve — admin suspend/resume for training-agent reporting webhook subscribers (server + runbook).

No blocking findings. The change adds admin-only routes and GCS reporting logic with no published protocol surface touched (no static/schemas/source/**, task defs, or normative docs/reference/**), so the omitted changeset is correct per the changeset-scope rule.

Checked against repo-specific gates:

  • Schema↔docs coherence: N/A — no schema changes.
  • Changeset scope: app/admin/operational-only PR, no changeset required.
  • Concurrency (gcs-reporting.ts:259-278): read-then-replace compare-and-set with expectedGeneration and 3-attempt conflict retry — concurrent owning-principal replace is not clobbered.
  • Auth/PII (training-reporting.ts): behind requireAuth+requireAdmin; logs/responses carry host only, no URL path/query/credentials; errors collapse to generic 503. No self-report-score REST route.
  • Audit: workos_organization_id='system_training_agent' is a plain VARCHAR sentinel following the system_brand_registry precedent; audit-write failure fails visibly (500 + log), not warn-only.
  • Operational readiness: listNotificationSubscribers bounded LIMIT 200, degrades cleanly on listActivity failure; admin-only bounded GET, not a worker/queue/billing path.
  • Tests: two 200+ line test files cover auth tiers, validation, idempotency, 404/422/503/500, and SDK emit/suppression.

high_risk is true but driven by one (added) route file and two (modified) route files with no medium-or-higher findings — presumed safe per the high-risk-flag guidance; not escalation-worthy on the flag alone. gated_paths is false. No no-auto-approve team match. No prior decision.

Non-blocking follow-up (noted, not a finding): recent_attempts uses one account-wide 200-attempt window per subscriber; a multi-subscriber account could crowd out a subscriber's view — non-issue for the single-canary reality.

No critical/high/medium findings, no escalation triggers → row 9 approve.

bokelley and others added 2 commits November 23, 2026 21:03
…, log no raw errors

Review follow-ups:
- Suspending writes the stored subscription set through the runtime's
  public store compare-and-set, changing only active. The runtime's
  replace revalidates every destination, so a subscriber whose host
  stopped resolving could never be turned off. Resume still goes through
  replace, so a destination is revalidated before delivery restarts.
- Record an attributed *_requested audit row before any change and a
  result or *_failed row after it, so no change exists without an audit
  row. Static-admin attribution is in every row and log line.
- Log only an allowlisted error name and SQLSTATE, never the raw error,
  whose message, stack or cause can carry URLs or backend values.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
aao-secretariat[bot]
aao-secretariat Bot previously approved these changes Nov 23, 2026

@aao-secretariat aao-secretariat 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.

Ladon verdict: Approve

Approve — subsequent pass on a prior clean approve, delta is clean.

This PR adds training-agent GCS reporting admin routes plus a runbook. The reviewer found no critical/high/medium findings in the delta. Walking the decision table:

  • Row 1 (critical/high): no such findings.
  • Row 2 (gated_paths unsatisfied): gated_paths is false — does not apply.
  • Row 3 (deletion in high-risk path): high_risk is true but all reasons are (modified)/(added); no (deleted). Does not apply.
  • Row 4 (medium + data-loss/schema/infra): no medium findings.
  • Row 5 (modified high-risk + medium): high-risk modified files present, but no medium finding to pair. Does not apply.
  • Row 6 (sticky escalate): prior decision was approve, not escalate.
  • Row 7 (no-auto-approve team): no team match.
  • Row 8 (≥3 medium): zero medium findings.
  • Row 9: approve.

Checked: no protocol-surface changes (training-agent server + ops runbook only), so no changeset required — consistent with reviewer's scope assessment. The intent-first audit restructure (fail-closed on logging failure, runtime never invoked), suspend-via-store.replace to bypass destination revalidation for dead hosts vs resume-via-runtime.replace, allowlisted errorFacts (error_name + SQLSTATE, no raw message/stack/URL), and CAS retry/not_found/unchanged/applied mapping are all covered by tests. High-risk flag is a heuristic here; the modifications preserve contract and the reviewer surfaced no concerns.

…ute tests

The test app parsed cookies without the app's CSRF middleware (CodeQL).
Mount csrfProtection as production does, send a valid double-submit pair
on cookie-session requests, and pin that a cookie POST without it is
refused before any audit row or runtime call.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@aao-secretariat aao-secretariat 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-approval: no reviewable delta since the prior approval; re-submitting after stale-review dismissal.

@bokelley
bokelley merged commit a77e9e2 into main Nov 23, 2026
128 of 130 checks passed
@bokelley
bokelley deleted the feat/training-reporting-subscriber-suspend branch November 23, 2026 23:03
KonstantinMirin added a commit to KonstantinMirin/adcp that referenced this pull request Nov 25, 2026
…, certification retry (adcontextprotocol#9196), release-audit changesets (adcontextprotocol#8879), reporting subscriber suspend and resume (adcontextprotocol#9199), inventory goal forecast refusal (adcontextprotocol#9206), enum hoisting annotations (adcontextprotocol#9167), format_option_ref (adcontextprotocol#8876), claim-priority indexes (adcontextprotocol#9219)

Two conflicts.

Resolution ledger:
- semantic: package.json `test` -> union: this branch's chain (the
  suites it added and the build-cache and git-env steps) plus main's
  test:build-schemas-hoist-enum-annotations and
  test:build-schemas-hoist-inside-definitions, after
  test:build-schemas-exit-status. Every script main's chain runs is in
  the merged chain. Dependencies auto-merged to main's versions.
- semantic: server/src/training-agent/gcs-reporting.ts imports -> union:
  this branch's narrow `@adcp/sdk/utils` import of canonicalize; main's
  randomUUID import and its added `@adcp/sdk/server` names. The rest of
  the file auto-merged.
- mechanical: package-lock.json -> main's (auto-merged; this branch
  does not change it).

Checks: npm ci on main's lockfile (SDK 17.0.0-beta.40), npm run
typecheck, and the pre-commit hook's full run.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants