Files
claude[bot] 4e280d4498 fix(studio): disambiguate query cancel telemetry and gate live-mode hotkey (#49137)
<!-- ccr-slack-attribution -->
_Requested by **Pam Chia** · [Slack
thread](https://supabase.slack.com/archives/C076KTY11DF/p1786930264662829?thread_ts=1786930264.662829&cid=C076KTY11DF)_

## I have read the
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
file.

YES

## What kind of change does this PR introduce?

Bug fix. Two telemetry correctness fixes in the Database Connections
feature preview. No visual changes, no new events.

Linear:
[GROWTH-1107](https://linear.app/supabase/issue/GROWTH-1107/fix-database-connections-feature-preview-banner-dead-end-plus)

## What is the current behavior?

### 1. `query_cancel_button_clicked` cannot tell its two surfaces apart

"Cancel query" is reachable from two places on
`/observability/connections`. One is the three-dot dropdown menu on an
activity row. The other is inside the "Confirm to terminate this
session?" dialog, which offers "Cancel query" alongside "Terminate" when
the session is running a query.

**Before:** both buttons fire `query_cancel_button_clicked` with an
identical payload (`activityState`, `isBlocking`). In analysis the two
are one undifferentiated number, so there is no way to see whether
people cancel straight from the row or only after opening the terminate
dialog and reading the "Cancelling it may solve the problem without
closing the connection" warning. That warning is the main nudge away
from terminating, and today we cannot measure whether it lands.

### 2. The live-mode hotkey fires telemetry for users who do not have
the feature

**Before:** the Mod+J live-mode shortcut is registered whenever the page
mounts, regardless of whether the Database Connections feature preview
is enabled. The live badge, the toggle button and the activity query are
all gated on the feature, so a user without it can press Mod+J, emit
`database_connections_live_mode_clicked`, and see nothing change. Those
events inflate the metric with interactions that had no effect.

## What is the new behavior?

### 1. `query_cancel_button_clicked` carries an `origin`

**After:** the event reports which surface it came from, so the two
flows can be split in analysis. Nothing changes for the user.

`QueryCancelButtonClickedEvent` in
`packages/common/telemetry-constants.ts` gains a required `origin:
'dropdown_menu' | 'terminate_dialog'` property, following the shape
already used by `index_advisor_enable_button_clicked` (`origin: 'banner'
| 'dialog'`). Values are snake_case to match the dominant convention
among the existing `origin` unions in that file. In `ActivityRow.tsx`
the shared `onCancelQuery` handler now takes the origin as an argument
and each of the two call sites passes its own value. Because `track()`
is strictly typed per action, the required property is enforced at
compile time rather than by convention.

### 2. The live-mode hotkey is gated on the feature

**After:** Mod+J only does something, and only reports something, for
users who actually have Database Connections enabled. Everyone else is
unaffected, as before.

`useShortcut` already accepts an `enabled` option that disables the
hotkey and hides the command-menu entry. The registration in
`pages/project/[ref]/observability/connections.tsx` now passes `enabled:
isDatabaseConnectionsEnabled`, reusing the value already read from
`useIsDatabaseConnectionsEnabled()` and already used to gate the
activity query and the visible controls on the same page.

## Additional context

**Scope was reduced from the original plan.** GROWTH-1107 originally
covered four items. #49132 rewrote the Database Connections gating model
and superseded three of them, so only the two above remain:

- The feature preview banner is no longer flag-gated, so there is
nothing to gate on `topForPostgres`.
- `isEnabled` on `database_connections_banner_cta_button_clicked` is now
a real variable rather than a constant, since it is true on the new
"Explore Database Connections" variant. It stays as is.
- The wrong-feature fallback in the feature preview modal no longer
triggers for this preview.

Nothing in that area is touched here. GROWTH-1107 has been updated to
reflect the reduced scope.

**Validation** (run locally):

- `tsc --noEmit` in `packages/common` and in `apps/studio`. Studio
reports the same two pre-existing errors before and after this change
and none in the changed files.
- `eslint` on both changed studio files: clean. `lint:ratchet`: passes.
- `vitest --run
components/interfaces/Observability/DatabaseConnections`: 36 passed.
- Prettier check on all three files: clean.


## To test

Verified in a real browser on the studio-staging Vercel preview,
checking telemetry at the wire level (network inspection of `POST
/platform/telemetry/event`). Checks derived from the diff, covering both
fixes and their negative cases.

- [x] Mod+J with the Database Connections feature preview off: no
`database_connections_live_mode_clicked` request fired and no UI change;
the page stays on the enable-preview gate screen
- [x] Mod+J with the preview on: the live badge visibly toggles and
exactly one event fires per press (`newState: "disabled"` on the first
press since live mode starts on by default, then `"enabled"` on the
second)
- [x] "Cancel query" from the activity row dropdown on an active
`pg_sleep(120)` session: `query_cancel_button_clicked` with
`custom_properties:
{"activityState":"active","isBlocking":false,"origin":"dropdown_menu"}`
- [x] "Cancel query" inside the "Confirm to terminate this session?"
dialog: `query_cancel_button_clicked` with `custom_properties:
{"activityState":"active","isBlocking":false,"origin":"terminate_dialog"}`

Opening the terminate dialog in the last check also fired
`session_terminate_button_clicked`, correctly distinct from the cancel
event. No new console errors versus the page-load baseline across all
four checks.

Co-authored-by: Claude <noreply@anthropic.com>
2026-08-19 15:39:07 +08:00
..