Skip to content

fix(gateway): manual verify mirrors channel + contact from assistant when gateway is missing the row#30584

Merged
dvargasfuertes merged 1 commit into
mainfrom
apollo/verify-mirror-channel
May 13, 2026
Merged

fix(gateway): manual verify mirrors channel + contact from assistant when gateway is missing the row#30584
dvargasfuertes merged 1 commit into
mainfrom
apollo/verify-mirror-channel

Conversation

@vellum-apollo-bot
Copy link
Copy Markdown
Contributor

@vellum-apollo-bot vellum-apollo-bot Bot commented May 13, 2026

What

POST /v1/contact-channels/:id/verify 404'd on any contact channel that
lived in the assistant DB but not yet in the gateway DB — i.e. every
channel created before the dual-write was wired. Verify now backfills the
channel + its parent contact from the assistant DB into the gateway DB
before attempting the verify write.

Why

Gateway-security-migration window: assistant DB is present-day source of
truth, gateway DB is back-filled lazily as contacts are touched. Users
see channels in the assistant UI whose ids the gateway has never heard
of; the verify endpoint should fix-then-flip, not reject.

How

New private helper on ContactStore:

mirrorChannelFromAssistantIfMissing(channelId): Promise<boolean>
  • Returns true if the gateway already has the channel.
  • Otherwise reads channel + parent contact from the assistant DB via
    assistantDbQuery and inserts both into the gateway DB with
    INSERT ... ON CONFLICT DO NOTHING (idempotent, concurrent-safe).
  • Returns false (and emits a warn log) when the assistant channel
    references a missing contact — broken state, don't paper over it.

markChannelVerified now calls the helper first and returns null only
when neither DB has the channel.

Tests

10/10 pass on gateway/src/__tests__/contact-store-mark-channel-verified.test.ts:

  • Existing 6 cases continue to pass.
  • New: mirrors channel + contact from assistant DB when gateway empty,
    then verifies.
  • New: refuses to mirror when assistant channel references missing
    contact (returns null, nothing landed in gateway).
  • New: mirror is idempotent across successive calls (exactly one row
    each in contacts + contact_channels after N invocations).
  • New: gateway-present channel takes precedence over assistant copy (no
    mirror, no overwrite of an existing gateway contact).

Mock structure: per-test fakeAssistantDb keyed by id; assistantDbQuery
routes to channel/contact maps; assistantDbRun records calls for
inspection.

Locally:

  • gateway && bunx tsc --noEmit → clean
  • gateway && bunx eslint <touched> --max-warnings 0 → clean
  • gateway && bun test src/__tests__/contact-store-mark-channel-verified.test.ts
    → 10/10 pass
  • gateway/scripts/test.sh full suite → 124/124 test files pass

Related


Open in Devin Review

…DB when gateway is missing the row

POST /v1/contact-channels/:id/verify was 404ing on any channel that existed
in the assistant DB but not yet in the gateway DB — i.e. every channel
created before the dual-write was wired. ContactStore.markChannelVerified
now backfills the channel and its parent contact into the gateway DB from
the assistant DB before attempting the verify write.

- New private helper ContactStore.mirrorChannelFromAssistantIfMissing:
  reads the channel + parent contact from the assistant DB and inserts
  both into the gateway DB via INSERT ... ON CONFLICT DO NOTHING.
  Refuses to mirror (returns false) when the assistant channel references
  a missing contact (broken state, logs a warn).
- markChannelVerified now calls the mirror helper first; returns null
  only when neither DB has the channel.
- handleVerifyContactChannel doc comment updated to mention the backfill.
- Tests: 4 new cases (gateway-empty mirror+verify, orphan-channel refusal,
  mirror idempotency across calls, gateway-precedence when both sides
  hold the channel). 10/10 pass; 124 gateway test files green; tsc + lint
  clean.

The mirror direction (assistant → gateway, on read-miss) is the
migration-window pattern for gateway-native operations during the
gateway-security-migration: assistant DB is present-day source of truth,
gateway DB is back-filled lazily as contacts are touched.
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

@dvargasfuertes dvargasfuertes merged commit 841f598 into main May 13, 2026
14 checks passed
@dvargasfuertes dvargasfuertes deleted the apollo/verify-mirror-channel branch May 13, 2026 21:06
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.

1 participant