Add atomic storage for user-verified agent registration

Merged
SI
1mo ago
+288-2

Agent registration needs a single winner when approval, polling, or revocation reaches different API instances. Add a service-role-only ciphertext compare-and-swap operation restricted to RecoupAgentRegistration; it preserves immutable bindings and cannot update expired or revoked state. Generic upserts can insert registrations but cannot overwrite them, preventing a delayed save from reverting an approval.

Add bounded cleanup of at most 100 expired registration families per call, with an issuer-specific partial expiry index. Cleanup preserves active artifacts, other issuers, and revocation tombstones. No new table, public grant, scheduler, or production feature is enabled.

Validation: all 44 isolated PostgreSQL tests pass, including concurrent transitions, stale-save and revocation races, immutable bindings, exact cleanup survivors, indexed batch lookup, and role permissions. All 244 API/OAuth tests pass with the updated migration fixture enabled, including two-instance PostgreSQL integration and ordinary PKCE compatibility; agent HTTP routing uses its in-memory fixture.

Apply this additive migration before enabling the companion API and chat registration feature. API/chat remain disabled by default; rollout and rollback are documented in the API PR. The isolated tests do not claim a full production Supabase migration replay.

Companion PRs: API #1052 and App #2249.