Skip to content

fix(api): JWT notifications auth + builtin kill-switch revert - #2805

Open
riderx wants to merge 6 commits into
mainfrom
cursor/dbd197d2
Open

fix(api): JWT notifications auth + builtin kill-switch revert#2805
riderx wants to merge 6 commits into
mainfrom
cursor/dbd197d2

Conversation

@riderx

@riderx riderx commented Jul 31, 2026

Copy link
Copy Markdown
Member

Summary (AI generated)

  • Switch notification manage routes from middlewareKey to middlewareAuth so the dashboard JWT can call /notifications/update-check (and related routes) without Invalid apikey.
  • Fix channel built-in kill-switch: when a device is still on an OTA bundle and the channel points at built-in, /updates now returns success { version: "builtin" } with no error/kind, so the plugin can reset to the store binary.
  • Devices already on built-in still get already_on_builtin + kind: up_to_date.

Motivation (AI generated)

A customer enabling silent push after reverting a channel to built-in hit two bugs:

  1. Dashboard sends JWT, but notification routes only accepted Capgo API keys.
  2. /updates always returned already_on_builtin + kind: up_to_date for built-in channels, so the plugin never entered its version == "builtin" reset path.

Business Impact (AI generated)

Restores silent background update push from the console and the intended emergency rollback / kill-switch (channel → built-in).

Test Plan (AI generated)

  • Call /notifications/update-check from the dashboard while logged in (JWT) and confirm it queues without Invalid apikey.
  • Call the same endpoint with a Capgo API key and confirm it still works.
  • Point a channel at built-in while a device runs an OTA bundle; confirm /updates returns { "version": "builtin" } without error/kind.
  • Device already on built-in still receives already_on_builtin / up_to_date.
  • bunx vitest run tests/native-notifications-api.unit.test.ts
  • Related updates tests covering builtin kill-switch.

Generated with AI


Note

Medium Risk
Touches authenticated notification APIs and changes /updates success vs error semantics for built-in channels, which affects emergency rollbacks and console push-update flows.

Overview
Notification management routes now use middlewareAuth instead of middlewareKey, so the dashboard can call endpoints like /notifications/update-check with a session JWT while Capgo API keys still work.

Built-in channel kill-switch on /updates is fixed for plugin ≥ 6.2.0: after plugin_parser rewrites version_name "builtin" to version_build, the server treats version_name === version_build as already on the store binary (already_on_builtin / up_to_date). Devices still running an OTA bundle get a success { version: "builtin" } with no error or kind, plus stats, so the plugin can reset to the store binary.

Tests cover the new builtin responses, mock middlewareAuth for notifications, and align countDevices expectations with a platform/options filter object.

Reviewed by Cursor Bugbot for commit a8e30a7. Bugbot is set up for automated code reviews on this repo. Configure here.

Management notification routes used API-key-only middleware, so the dashboard Bearer session failed with Invalid apikey when queuing silent update checks after promoting builtin.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 1 minute

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d4514069-ed87-48c1-b81f-fa9a8cf7be66

📥 Commits

Reviewing files that changed from the base of the PR and between b5a9950 and a8e30a7.

📒 Files selected for processing (5)
  • supabase/functions/_backend/plugin_runtime/utils/update.ts
  • supabase/functions/_backend/public/notifications/index.ts
  • tests/native-notifications-api.unit.test.ts
  • tests/private-analytics-validation.unit.test.ts
  • tests/updates.test.ts

Comment @coderabbitai help to get the list of available commands.

@codspeed-hq

codspeed-hq Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 43 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing cursor/dbd197d2 (a8e30a7) with main (b5a9950)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Co-authored-by: Cursor <cursoragent@cursor.com>
@riderx

riderx commented Jul 31, 2026

Copy link
Copy Markdown
Member Author

Superseded by #2807, which includes this JWT/middlewareAuth fix plus the channel built-in kill-switch /updates behavior the same customer report needs.

@riderx riderx closed this Jul 31, 2026
Devices on an OTA bundle with a channel pointed at builtin need a success
{ version: 'builtin' } response (no error/kind) so the plugin can reset.
Already-on-builtin stays on the dedicated already_on_builtin path.

Co-authored-by: Cursor <cursoragent@cursor.com>
@riderx riderx reopened this Jul 31, 2026
@riderx riderx changed the title fix(notifications): accept dashboard JWT for silent update pushes fix(api): JWT notifications auth + builtin kill-switch revert Jul 31, 2026
plugin_parser maps version_name "builtin" to version_build, so compare
version_name === version_build for the store-binary up-to-date case.

Co-authored-by: Cursor <cursoragent@cursor.com>
riderx and others added 2 commits July 31, 2026 05:13
Main changed countDevices to take a platform/updatedAt options object;
update the private analytics unit expectation so merge CI stays green.

Co-authored-by: Cursor <cursoragent@cursor.com>
@sonarqubecloud

Copy link
Copy Markdown

@riderx
riderx marked this pull request as ready for review July 31, 2026 02:34

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a8e30a7. Configure here.

return updateError200(c, 'already_on_builtin', 'Already on builtin')
}
else {
return updateError200(c, 'already_on_builtin', 'Already on builtin', {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Matching OTA semver skips kill-switch

Medium Severity

For a built-in channel, already_on_builtin is returned when version_name === version_build. A device can still be running an OTA bundle while both fields report the same semver (common when bundle and native versions align). The kill-switch then returns already_on_builtin instead of { version: "builtin" }, so the plugin may not reset to the store binary.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit a8e30a7. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Risk: high. Cursor Bugbot did not complete successfully (skipped) and left one unresolved medium finding on the builtin kill-switch path; this PR also changes notification auth and /updates semantics above the low-risk approval threshold. Human review is needed before merge.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver External

@cursor
cursor Bot requested review from Dalanir and WcaleNieWolny July 31, 2026 02:36

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Risk: high. Cursor Bugbot skipped as a check and left one unresolved medium finding on the builtin kill-switch path; this PR also changes notification auth and /updates semantics above the medium approval threshold. Human review is needed; reviewers were assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

2 issues found across 5 files

Confidence score: 2/5

  • In supabase/functions/_backend/plugin_runtime/utils/update.ts, awaiting sendStatsAndDevice before returning the kill-switch/reset payload can cause the response to never be sent if that side effect fails, leaving devices stuck on OTA instead of rolling back to native — make stats/device reporting non-blocking or isolate failures so the reset response is always returned.
  • In supabase/functions/_backend/plugin_runtime/utils/update.ts, the kill-switch condition version_name === version_build can misclassify devices that are still on an OTA bundle when semver matches the native build, which can trigger incorrect reset behavior and state tracking — tighten the check with an explicit runtime/source-of-version signal before deciding rollback state.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="supabase/functions/_backend/plugin_runtime/utils/update.ts">

<violation number="1" location="supabase/functions/_backend/plugin_runtime/utils/update.ts:671">
P2: The kill-switch check `version_name === version_build` can also match a device that is still running an OTA bundle whose semver happens to equal the native build version (a common case when bundle and native versions are kept in sync). In that scenario the endpoint returns `already_on_builtin` instead of `{ version: 'builtin' }`, so the plugin never enters its reset-to-store-binary path even though the channel has reverted to built-in. Consider distinguishing “on OTA bundle” vs “on native binary” using a signal other than semver equality (e.g. whether a bundle id/version is actually installed) before short-circuiting to `already_on_builtin`.</violation>

<violation number="2" location="supabase/functions/_backend/plugin_runtime/utils/update.ts:675">
P1: Devices can remain on the OTA bundle when the stats/device side effect fails, because the awaited `sendStatsAndDevice` rejects before the reset response is sent. The kill-switch response is the mechanism that tells the plugin to restore the store binary, so this telemetry write should be best-effort or handled so the `{ version: 'builtin' }` response is still returned.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

})
}
// Kill-switch: tell plugin to reset to the store binary (no error/kind).
await sendStatsAndDevice(c, device, [{ action: 'get', versionName: 'builtin' }])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1: Devices can remain on the OTA bundle when the stats/device side effect fails, because the awaited sendStatsAndDevice rejects before the reset response is sent. The kill-switch response is the mechanism that tells the plugin to restore the store binary, so this telemetry write should be best-effort or handled so the { version: 'builtin' } response is still returned.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At supabase/functions/_backend/plugin_runtime/utils/update.ts, line 675:

<comment>Devices can remain on the OTA bundle when the stats/device side effect fails, because the awaited `sendStatsAndDevice` rejects before the reset response is sent. The kill-switch response is the mechanism that tells the plugin to restore the store binary, so this telemetry write should be best-effort or handled so the `{ version: 'builtin' }` response is still returned.</comment>

<file context>
@@ -665,14 +665,15 @@ export async function updateWithPG(
-      })
-    }
+    // Kill-switch: tell plugin to reset to the store binary (no error/kind).
+    await sendStatsAndDevice(c, device, [{ action: 'get', versionName: 'builtin' }])
+    return c.json({ version: 'builtin' }, 200)
   }
</file context>

// plugin_parser rewrites version_name "builtin" -> version_build, so we cannot
// compare version_name === "builtin" here. Store binary => names match build;
// OTA bundle => version_name is the live bundle and differs from version_build.
if (version_name === version_build) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: The kill-switch check version_name === version_build can also match a device that is still running an OTA bundle whose semver happens to equal the native build version (a common case when bundle and native versions are kept in sync). In that scenario the endpoint returns already_on_builtin instead of { version: 'builtin' }, so the plugin never enters its reset-to-store-binary path even though the channel has reverted to built-in. Consider distinguishing “on OTA bundle” vs “on native binary” using a signal other than semver equality (e.g. whether a bundle id/version is actually installed) before short-circuiting to already_on_builtin.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At supabase/functions/_backend/plugin_runtime/utils/update.ts, line 671:

<comment>The kill-switch check `version_name === version_build` can also match a device that is still running an OTA bundle whose semver happens to equal the native build version (a common case when bundle and native versions are kept in sync). In that scenario the endpoint returns `already_on_builtin` instead of `{ version: 'builtin' }`, so the plugin never enters its reset-to-store-binary path even though the channel has reverted to built-in. Consider distinguishing “on OTA bundle” vs “on native binary” using a signal other than semver equality (e.g. whether a bundle id/version is actually installed) before short-circuiting to `already_on_builtin`.</comment>

<file context>
@@ -665,14 +665,15 @@ export async function updateWithPG(
+    // plugin_parser rewrites version_name "builtin" -> version_build, so we cannot
+    // compare version_name === "builtin" here. Store binary => names match build;
+    // OTA bundle => version_name is the live bundle and differs from version_build.
+    if (version_name === version_build) {
       return updateError200(c, 'already_on_builtin', 'Already on builtin')
     }
</file context>

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