fix(plugin): store channel self overrides in kv#2275
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (9)
🚧 Files skipped from review as they are similar to previous changes (7)
📝 WalkthroughWalkthroughAdds Cloudflare KV + cache-backed per-device channel self override helpers, plugs store-aware wrapper helpers into channel_self plugin routes, extends Postgres queries to accept an override channel id, integrates stored overrides into update flow gating by plugin version, and adds unit tests verifying KV vs Postgres routing. ChangesKV-backed per-device channel self overrides
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Merging this PR will not alter performance
Comparing Footnotes
|
55c50be to
b7a5a71
Compare
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
b7a5a71 to
04c1d86
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@supabase/functions/_backend/plugins/channel_self.ts`:
- Around line 156-166: deleteChannelSelfOverrideForDevice currently skips legacy
Postgres deletes when CHANNEL_SELF_STORE (KV) is enabled; update the function
signature to accept an options object (e.g., { cleanupLegacyPg = false }) and,
when KV is enabled but cleanupLegacyPg is true, call deleteChannelDevicePg(c,
appId, deviceId, drizzleClient) in addition to (or instead of)
deleteChannelSelfOverride so legacy channel_devices rows are removed; update all
migration-call sites (the vX.34.0+ migration branches referenced) to call
deleteChannelSelfOverrideForDevice(..., { cleanupLegacyPg: true }) so PG
overrides are cleaned up during migration.
In `@tests/channel-self-pg-client.unit.test.ts`:
- Around line 152-170: Change the two added tests to run concurrently: replace
the two it(...) calls named "uses replica and KV for old plugin reads when
channel self store is bound" and "uses replica and KV for old plugin writes when
channel self store is bound" with it.concurrent(...) so they execute in
parallel; keep the same test bodies (using createKvStore(), fetchPut(),
fetchPost(), and the same assertions against getPgClientMock,
getChannelDeviceOverridePgMock, upsertChannelDevicePgMock, and kv.get/kv.put)
but only change the test declaration to it.concurrent to follow repository
parallelization rules.
In `@tests/update-channel-self-store.unit.test.ts`:
- Around line 74-108: Change the new test case "passes KV-backed channel_self
override channel id into update lookup" from using it(...) to it.concurrent(...)
so it runs in parallel; locate the test in
tests/update-channel-self-store.unit.test.ts (the spec that imports updateWithPG
and asserts requestInfosPostgresMock was called) and replace the it(...)
invocation with it.concurrent(...), leaving the body, assertions, and references
to updateWithPG and requestInfosPostgresMock unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: da5c6d44-1d62-4bc9-832b-76eb65ec8ecf
📒 Files selected for processing (8)
supabase/functions/_backend/plugins/channel_self.tssupabase/functions/_backend/utils/cache.tssupabase/functions/_backend/utils/channelSelfStore.tssupabase/functions/_backend/utils/cloudflare.tssupabase/functions/_backend/utils/pg.tssupabase/functions/_backend/utils/update.tstests/channel-self-pg-client.unit.test.tstests/update-channel-self-store.unit.test.ts
ca1f971 to
ae6948a
Compare
ae6948a to
8c0789b
Compare
|



Summary (AI generated)
CHANNEL_SELF_STOREKV-backed channel self override store with local Cache API reads./channel_selfset/get/delete override state through KV when the binding is available./updatesto honor KV-backed channel self overrides by resolving the override channel from the read replica.CHANNEL_SELF_STOREis not bound.Motivation (AI generated)
Old devices still need server-side channel self overrides, but the hot channel self path should not rely on the primary database. Moving override state to replicated key-value storage keeps old plugin behavior working while allowing the new system to avoid primary database reads and writes.
Business Impact (AI generated)
This reduces primary database pressure on hot plugin endpoints and improves reliability for old devices during the transition to the replicated system. It keeps backward compatibility for customers who have not upgraded plugins yet while lowering operational risk on high-traffic paths.
Test Plan (AI generated)
bunx vitest run tests/channel-self-pg-client.unit.test.ts tests/update-channel-self-store.unit.test.tsbun lint:backendbunx eslint tests/channel-self-pg-client.unit.test.ts tests/update-channel-self-store.unit.test.tsbun typecheckgit diff --checkGenerated with AI
Summary by CodeRabbit
New Features
Bug Fixes
Tests