Skip to content

feat(studio): log date range domain + session logRange state - #48401

Merged
charislam merged 3 commits into
masterfrom
charislam/range-domain-session-state
Jul 28, 2026
Merged

charislam merged 3 commits into
masterfrom
charislam/range-domain-session-state

Conversation

@charislam

@charislam charislam commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

I have read the CONTRIBUTING.md file.

YES

What kind of change does this PR introduce?

Feature (+ a small refactor and a docs/convention note). PR 4 of the stacked SQL-editor query-source series (Database vs Logs).

What is the current behavior?

The SQL editor has no representation of a logs query's time range: querySource.ts only knows how to map a snippet type to a source (getSnippetSource), and session state (sql-editor-session-state.ts) tracks results and the row limit but not a per-snippet time range. The Logs date picker's pure range helpers (parseCustomInput, generateDynamicHelper, the Unit type) are trapped inside the Logs.DatePickers.tsx React component.

What is the new behavior?

  • Logs time-range domain in querySource.ts: branded IsoDateTimeString + isoDateTimeString(), RelativeTimeUnit, a LogDateRange discriminated union (relative/absolute), DEFAULT_LOG_DATE_RANGE, a single date-picker parser (datePickerValueToLogDateRange / logDateRangeToDatePickerValue — handles the five presets and dynamic 2h/30m helpers; calcTo === '' means "now"; unparseable helpers degrade to absolute), and resolveLogRunRange which re-resolves relative ranges against now at run time (reusing the existing ResolvedLogDateRange shape).
  • Session state: per-snippet logRange + setLogRange — session-only, never written to snippet content, so it works on read-only shared snippets and is cleaned up in clearForSnippet.
  • Refactor: extracted the picker's framework-free helpers into a new pure Logs.datePickerHelpers.ts; the logs domain now shares the Unit type and reuses generateDynamicHelper instead of duplicating them. Importers point at the new module directly (no re-export shim). Hardened the amount parse against NaN.
  • Full unit coverage in querySource.test.ts. Recorded the no-shim refactoring convention in the studio-best-practices skill.

Verification: pnpm typecheck clean, lint ratchet improved, 43 tests pass (querySource + Logs.Datepickers), Prettier clean.

Additional context

Summary by CodeRabbit

  • New Features
    • Added robust Logs date-range modeling with support for relative (e.g., last N units) and absolute time periods.
    • SQL Editor sessions now remember log date ranges per snippet.
  • Bug Fixes
    • Safer handling of invalid or missing date inputs, with sensible fallback to default/current time.
  • Tests
    • Added/expanded automated coverage for date-range conversion, helper parsing, and resolution behavior.
  • Refactor
    • Centralized date-picker helper utilities for reuse across the Logs and SQL query experience.

@charislam
charislam requested a review from a team as a code owner July 28, 2026 15:51
@vercel

vercel Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
studio-self-hosted Ready Ready Preview, Comment Jul 28, 2026 4:51pm
studio-staging Ready Ready Preview, Comment Jul 28, 2026 4:51pm
5 Skipped Deployments
Project Deployment Actions Updated (UTC)
studio Ignored Ignored Jul 28, 2026 4:51pm
design-system Skipped Skipped Jul 28, 2026 4:51pm
docs Skipped Skipped Jul 28, 2026 4:51pm
ui-library Skipped Skipped Jul 28, 2026 4:51pm
zone-www-dot-com Skipped Skipped Jul 28, 2026 4:51pm

Request Review

@supabase

supabase Bot commented Jul 28, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project xguihxuzqibwxjnimxev because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 6761da5a-5e3f-4b6a-b9c7-ee9d3fd88c86

📥 Commits

Reviewing files that changed from the base of the PR and between be10d93 and f30570e.

📒 Files selected for processing (1)
  • apps/studio/components/interfaces/Settings/Logs/Logs.datePickerHelpers.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/studio/components/interfaces/Settings/Logs/Logs.datePickerHelpers.ts

📝 Walkthrough

Walkthrough

Shared Logs date-picker helpers are extracted into a framework-free module. SQL editor query-source utilities add validated log date-range conversions and resolution, while SQL editor session state stores per-snippet log ranges and clears them with snippet state.

Changes

SQL editor log support

Layer / File(s) Summary
Shared date-picker helpers
apps/studio/components/interfaces/Settings/Logs/Logs.datePickerHelpers.ts, apps/studio/components/interfaces/Settings/Logs/Logs.DatePickers.tsx, apps/studio/tests/features/logs/Logs.Datepickers.test.tsx, apps/studio/CLAUDE.md
Date-picker parsing and relative helper generation move to a shared module, with consumers, tests, and refactoring guidance updated.
Log date-range domain
apps/studio/components/interfaces/SQLEditor/querySource.ts, apps/studio/components/interfaces/SQLEditor/querySource.test.ts
Validated ISO values and relative or absolute LogDateRange conversions are added, including picker rendering and current-time resolution.
Per-snippet log range state
apps/studio/state/sql-editor/sql-editor-session-state.ts
Session state stores log ranges by snippet, provides setLogRange, and clears ranges during snippet cleanup.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 47.83% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately highlights the main change: log date range domain plus session logRange state.
Description check ✅ Passed The description follows the template and covers the current behavior, new behavior, and added context well.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch charislam/range-domain-session-state

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@github-actions

github-actions Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results (tanstack)

passed  243 passed
skipped  5 skipped

Details

stats  248 tests across 29 suites
duration  4 minutes, 4 seconds
commit  f30570e

Skipped tests

Features › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled
Features › sql-editor.spec.ts › SQL Editor › snippet favourite works as expected
Features › sql-editor.spec.ts › SQL Editor › share with team works as expected
Features › sql-editor.spec.ts › SQL Editor › folders works as expected
Features › sql-editor.spec.ts › SQL Editor › other SQL snippets actions work as expected

@charislam
charislam force-pushed the charislam/discriminated-snippet-union-source-aware-writes branch from 0db771a to 66b10a8 Compare July 28, 2026 16:11
Base automatically changed from charislam/discriminated-snippet-union-source-aware-writes to master July 28, 2026 16:28
@charislam
charislam force-pushed the charislam/range-domain-session-state branch from 496637c to 8ee731a Compare July 28, 2026 16:31
- Add the logs time-range domain to querySource.ts: branded IsoDateTimeString,
  LogDateRange (relative/absolute), a single date-picker parser
  (datePickerValueToLogDateRange / logDateRangeToDatePickerValue), and
  resolveLogRunRange that re-resolves relative ranges against now.
- Add per-snippet session logRange state (setLogRange), not persisted, keyed
  by snippet id.
- Extract the picker's pure date helpers into Logs.datePickerHelpers.ts and
  share the Unit type + generateDynamicHelper with the logs domain instead of
  duplicating them; importers updated to the new module (no re-export shim).
Record in the studio-best-practices skill that moving/extracting code must
update importers directly rather than leaving a backward-compat re-export shim.
@charislam
charislam force-pushed the charislam/range-domain-session-state branch from 8ee731a to be10d93 Compare July 28, 2026 16:38

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
apps/studio/state/sql-editor/sql-editor-rules.test.ts (1)

129-133: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Avoid the assertion cast in this test assertion.

Use a structural matcher instead of payload.content as { ... }/as any, e.g. expect(payload).toMatchObject({ content: { content_id: 'log-snippet-1' } }), to keep the test type checked.

🤖 Prompt for 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.

In `@apps/studio/state/sql-editor/sql-editor-rules.test.ts` around lines 129 -
133, Update the test around buildUpsertPayload and the log_sql assertion to
remove the assertion cast on payload.content. Use a structural matcher such as
toMatchObject to validate content.content_id while preserving the existing
payload.type expectation.

Source: Coding guidelines

🤖 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 `@apps/studio/components/interfaces/Settings/Logs/Logs.datePickerHelpers.ts`:
- Around line 30-32: Update the custom range parsing around the parseInt call to
use Number.parseInt with base 10 and reject parsed values unless
Number.isFinite(value) is true, while preserving the existing invalid result for
non-positive values. Ensure only finite positive values reach
generateDynamicHelper().

In `@apps/studio/data/content/content-remap.ts`:
- Around line 33-42: Update remapWireSnippet to validate the external row with a
discriminated Zod schema instead of casting it to SnippetWithContent. Preserve
the wire type distinction by mapping sql content through untrustedSql and
log_sql content through untrustedLogSql, then return the parsed remapped snippet
with status; remove the existing row as SnippetWithContent assertion.

---

Nitpick comments:
In `@apps/studio/state/sql-editor/sql-editor-rules.test.ts`:
- Around line 129-133: Update the test around buildUpsertPayload and the log_sql
assertion to remove the assertion cast on payload.content. Use a structural
matcher such as toMatchObject to validate content.content_id while preserving
the existing payload.type expectation.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 48adf966-2c4d-4b34-8090-748280e9ce7b

📥 Commits

Reviewing files that changed from the base of the PR and between fa5eb17 and 8ee731a.

📒 Files selected for processing (23)
  • apps/studio/CLAUDE.md
  • apps/studio/components/interfaces/SQLEditor/SQLEditor.utils.test.ts
  • apps/studio/components/interfaces/SQLEditor/SQLEditor.utils.ts
  • apps/studio/components/interfaces/SQLEditor/SQLEditorControllers.tsx
  • apps/studio/components/interfaces/SQLEditor/querySource.test.ts
  • apps/studio/components/interfaces/SQLEditor/querySource.ts
  • apps/studio/components/interfaces/SQLEditor/usePrettifyQuery.ts
  • apps/studio/components/interfaces/Settings/Logs/Logs.DatePickers.tsx
  • apps/studio/components/interfaces/Settings/Logs/Logs.datePickerHelpers.ts
  • apps/studio/data/content/content-id-query.ts
  • apps/studio/data/content/content-remap.ts
  • apps/studio/data/content/content-upsert-mutation.ts
  • apps/studio/data/content/sql-folders-query.ts
  • apps/studio/data/content/sql-snippets-query.ts
  • apps/studio/state/sql-editor/sql-editor-rules.test.ts
  • apps/studio/state/sql-editor/sql-editor-rules.ts
  • apps/studio/state/sql-editor/sql-editor-save-scheduler.test.ts
  • apps/studio/state/sql-editor/sql-editor-save.test.ts
  • apps/studio/state/sql-editor/sql-editor-session-state.ts
  • apps/studio/state/sql-editor/sql-editor-state.test.ts
  • apps/studio/state/sql-editor/sql-editor-state.ts
  • apps/studio/tests/features/logs/Logs.Datepickers.test.tsx
  • apps/studio/tests/lib/sql-editor-test-utils.tsx

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 2

🧹 Nitpick comments (1)
apps/studio/state/sql-editor/sql-editor-rules.test.ts (1)

129-133: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Avoid the assertion cast in this test assertion.

Use a structural matcher instead of payload.content as { ... }/as any, e.g. expect(payload).toMatchObject({ content: { content_id: 'log-snippet-1' } }), to keep the test type checked.

🤖 Prompt for 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.

In `@apps/studio/state/sql-editor/sql-editor-rules.test.ts` around lines 129 -
133, Update the test around buildUpsertPayload and the log_sql assertion to
remove the assertion cast on payload.content. Use a structural matcher such as
toMatchObject to validate content.content_id while preserving the existing
payload.type expectation.

Source: Coding guidelines

🤖 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 `@apps/studio/components/interfaces/Settings/Logs/Logs.datePickerHelpers.ts`:
- Around line 30-32: Update the custom range parsing around the parseInt call to
use Number.parseInt with base 10 and reject parsed values unless
Number.isFinite(value) is true, while preserving the existing invalid result for
non-positive values. Ensure only finite positive values reach
generateDynamicHelper().

In `@apps/studio/data/content/content-remap.ts`:
- Around line 33-42: Update remapWireSnippet to validate the external row with a
discriminated Zod schema instead of casting it to SnippetWithContent. Preserve
the wire type distinction by mapping sql content through untrustedSql and
log_sql content through untrustedLogSql, then return the parsed remapped snippet
with status; remove the existing row as SnippetWithContent assertion.

---

Nitpick comments:
In `@apps/studio/state/sql-editor/sql-editor-rules.test.ts`:
- Around line 129-133: Update the test around buildUpsertPayload and the log_sql
assertion to remove the assertion cast on payload.content. Use a structural
matcher such as toMatchObject to validate content.content_id while preserving
the existing payload.type expectation.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 48adf966-2c4d-4b34-8090-748280e9ce7b

📥 Commits

Reviewing files that changed from the base of the PR and between fa5eb17 and 8ee731a.

📒 Files selected for processing (23)
  • apps/studio/CLAUDE.md
  • apps/studio/components/interfaces/SQLEditor/SQLEditor.utils.test.ts
  • apps/studio/components/interfaces/SQLEditor/SQLEditor.utils.ts
  • apps/studio/components/interfaces/SQLEditor/SQLEditorControllers.tsx
  • apps/studio/components/interfaces/SQLEditor/querySource.test.ts
  • apps/studio/components/interfaces/SQLEditor/querySource.ts
  • apps/studio/components/interfaces/SQLEditor/usePrettifyQuery.ts
  • apps/studio/components/interfaces/Settings/Logs/Logs.DatePickers.tsx
  • apps/studio/components/interfaces/Settings/Logs/Logs.datePickerHelpers.ts
  • apps/studio/data/content/content-id-query.ts
  • apps/studio/data/content/content-remap.ts
  • apps/studio/data/content/content-upsert-mutation.ts
  • apps/studio/data/content/sql-folders-query.ts
  • apps/studio/data/content/sql-snippets-query.ts
  • apps/studio/state/sql-editor/sql-editor-rules.test.ts
  • apps/studio/state/sql-editor/sql-editor-rules.ts
  • apps/studio/state/sql-editor/sql-editor-save-scheduler.test.ts
  • apps/studio/state/sql-editor/sql-editor-save.test.ts
  • apps/studio/state/sql-editor/sql-editor-session-state.ts
  • apps/studio/state/sql-editor/sql-editor-state.test.ts
  • apps/studio/state/sql-editor/sql-editor-state.ts
  • apps/studio/tests/features/logs/Logs.Datepickers.test.tsx
  • apps/studio/tests/lib/sql-editor-test-utils.tsx
🛑 Comments failed to post (1)
apps/studio/data/content/content-remap.ts (1)

33-42: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Preserve the logs SQL brand at the wire boundary.

remapWireSnippet() routes log_sql rows through the existing untrustedSql conversion, then Line 40 coerces the result into SnippetWithContent. A persisted logs query can therefore acquire the Postgres SQL brand and be accepted by database-only typed paths. Parse the wire row as a discriminated schema, map sql with untrustedSql and log_sql with untrustedLogSql, and remove this assertion.

As per coding guidelines, “Avoid TypeScript as casts; parse external data with zod using parse or safeParse.”

🤖 Prompt for 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.

In `@apps/studio/data/content/content-remap.ts` around lines 33 - 42, Update
remapWireSnippet to validate the external row with a discriminated Zod schema
instead of casting it to SnippetWithContent. Preserve the wire type distinction
by mapping sql content through untrustedSql and log_sql content through
untrustedLogSql, then return the parsed remapped snippet with status; remove the
existing row as SnippetWithContent assertion.

Source: Coding guidelines

…nite

Use Number.parseInt(base 10) and guard with Number.isFinite so only finite positive values reach generateDynamicHelper(); NaN and Infinity are now rejected alongside the existing non-positive check.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 `@apps/studio/components/interfaces/SQLEditor/querySource.ts`:
- Around line 39-46: Update isoDateTimeString to validate raw input with the
existing ISO datetime schema and strict calendar-aware parsing before returning
the branded value, rejecting overflow dates such as 2022-01-33. Derive the
IsoDateTimeString result from the validated schema output rather than casting
the original text; also update nowIsoDateTime to use the same validated branding
path instead of a direct cast.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 36092837-ca68-4dbd-93ce-6c3b638f87d8

📥 Commits

Reviewing files that changed from the base of the PR and between 8ee731a and be10d93.

📒 Files selected for processing (7)
  • apps/studio/CLAUDE.md
  • apps/studio/components/interfaces/SQLEditor/querySource.test.ts
  • apps/studio/components/interfaces/SQLEditor/querySource.ts
  • apps/studio/components/interfaces/Settings/Logs/Logs.DatePickers.tsx
  • apps/studio/components/interfaces/Settings/Logs/Logs.datePickerHelpers.ts
  • apps/studio/state/sql-editor/sql-editor-session-state.ts
  • apps/studio/tests/features/logs/Logs.Datepickers.test.tsx
🚧 Files skipped from review as they are similar to previous changes (5)
  • apps/studio/state/sql-editor/sql-editor-session-state.ts
  • apps/studio/tests/features/logs/Logs.Datepickers.test.tsx
  • apps/studio/CLAUDE.md
  • apps/studio/components/interfaces/Settings/Logs/Logs.datePickerHelpers.ts
  • apps/studio/components/interfaces/SQLEditor/querySource.test.ts

@charislam
charislam merged commit d5436ae into master Jul 28, 2026
37 checks passed
@charislam
charislam deleted the charislam/range-domain-session-state branch July 28, 2026 17:49
@github-actions

github-actions Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Braintrust eval report

Assistant (master-1785261141)

Score Average Improvements Regressions
Completeness 100% (+0pp) - -
Conciseness 42.9% (+2pp) 7 🟢 6 🔴
Docs Faithfulness 64.5% (+4pp) 3 🟢 3 🔴
Goal Completion 84.1% (+3pp) 5 🟢 2 🔴
Knowledge Usage 100% (+3pp) 1 🟢 -
Tool Usage 72.5% (+0pp) - -
Correctness 70.9% (+1pp) 3 🟢 3 🔴
SQL Identifier Quoting 100% (+0pp) - -
SQL Validity 100% (+5pp) 1 🟢 -
Safety 90% (+4pp) 2 🟢 1 🔴
Time_to_first_token 3.15tok (+0.62tok) 5 🟢 24 🔴
Llm_calls 7.3 (+0.31) 19 🟢 8 🔴
Tool_calls 3.18 (+0.18) 13 🟢 8 🔴
Errors 0.14 (+0.14) - 2 🔴
Llm_errors 0 (+0) - -
Tool_errors 0 (+0) - -
Prompt_tokens 22404.08tok (-2307.75tok) 16 🟢 10 🔴
Prompt_cached_tokens 7226.85tok (-2571.77tok) 7 🟢 19 🔴
Prompt_cache_creation_tokens 0tok (+0tok) - -
Prompt_cache_creation_5m_tokens 0tok (+0tok) - -
Prompt_cache_creation_1h_tokens 0tok (+0tok) - -
Completion_tokens 605.49tok (+2.3tok) 14 🟢 15 🔴
Completion_reasoning_tokens 108.51tok (+8.29tok) 11 🟢 17 🔴
Completion_accepted_prediction_tokens 0tok (+0tok) - -
Completion_rejected_prediction_tokens 0tok (+0tok) - -
Completion_audio_tokens 0tok (+0tok) - -
Total_tokens 23009.57tok (-2305.45tok) 18 🟢 11 🔴
Estimated_cost 0$ (+0$) 16 🟢 11 🔴
Duration 17.97s (+4.92s) 2 🟢 27 🔴
Llm_duration 11.85s (+2.29s) 5 🟢 24 🔴

charislam added a commit that referenced this pull request Jul 29, 2026
…48414)

## 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?

Feature (SQL editor: execution wiring for logs-source snippets). Part of
the stacked SQL-editor "Database vs Logs" query-source series.

## What is the current behavior?

The SQL editor only ever runs queries against the user's Postgres
database. There is no execution path for a logs (`log_sql`) snippet, and
the run-button telemetry event carries no backend discriminator.

## What is the new behavior?

- `useRunSource(id)` derives the run backend from the snippet type; a
`log_sql` snippet resolves to `{ type: 'logs', dateRange }`, pairing the
run with its session time range (default: last hour).
- `useLogsSqlExecution` runs a promoted `SafeLogSqlFragment` against the
analytics OTEL (ClickHouse) endpoint with the resolved time range as
`iso_timestamp_start`/`iso_timestamp_end` request params. The endpoint
is **pinned to OTEL** — a snippet's dialect must not flip with org
migration.
- The run gestures (toolbar button and Cmd+Enter) branch on the source
and promote with the matching `acceptUntrusted*` right at the user
action, preserving the auditable promotion-at-gesture boundary. pg
intellisense is gated off for logs snippets.
- The `sql_editor_query_run_button_clicked` telemetry event gains a
required `{ source: 'database' | 'logs' }` property, fired from both
execution paths.
- Capability guard: a `log_sql` snippet is reachable by direct URL
regardless of the (later) entry-point flag gating, so `executeLogsQuery`
short-circuits when `otelLegacyLogs` is off — recording a clear "not
available yet" result message instead of firing a request that would
only return an opaque backend error on a non-ClickHouse project. This is
a guard on the gesture, not endpoint selection.
- Tests: `useRunSource` routing, `useLogsSqlExecution`
endpoint/range/structured-error/capability-guard, and a reusable `flags`
option on `renderSqlEditorHook`.

No UI entry points are added — the feature runs dark until the
flag-gated creation/nav PRs later in the stack.

## Additional context

Stacked on the query-source series; base branch is `master` now that PR
4 (log date range domain + session state, #48401) is merged. Follow-ups
in the stack add the toolbar/creation UI (with a run-affordance gate on
`otelLegacyLogs`), nav section, AI dialect support, and reports guard.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
  * Added support for running log queries directly from the SQL editor.
* Log query results, errors, and time ranges are now handled within the
editor session.
* Added automatic selection between database and log query execution,
including support for custom date ranges.
* SQL assistance is disabled while editing log queries where database
definitions do not apply.

* **Tests**
* Added coverage for log query execution, date ranges, feature
availability, and execution source selection.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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.

2 participants