Skip to content

feat(team): add setting for default and allowed query languages - #3282

Open
kunalbhatia2601 wants to merge 5 commits into
ClickHouse:mainfrom
kunalbhatia2601:agent/add-team-query-language-settings
Open

kunalbhatia2601 wants to merge 5 commits into
ClickHouse:mainfrom
kunalbhatia2601:agent/add-team-query-language-settings

Conversation

@kunalbhatia2601

Copy link
Copy Markdown

Summary

Some teams require using only Lucene or only SQL in their telemetry search workflows. This PR introduces team-level query language settings (defaultQueryLanguage and allowedQueryLanguages) to allow teams to configure their preferred default query language and enable or disable specific languages across search inputs.

  • Added defaultQueryLanguage and allowedQueryLanguages fields to the Team model and TeamSchema validation schemas.
  • Added PATCH /team/query-language-settings API endpoint with validation to ensure at least one query language remains enabled and the default language is among the allowed set.
  • Added a Query Language Settings section to Team Settings (/team?tab=advanced).
  • Updated InputLanguageSwitch and SearchWhereInput components to restrict dropdown choices and enforce the team's allowed query language settings.

Steps:

  1. Navigate to /team?tab=advanced and locate the "Query Language Settings" section.
  2. Click "Change", uncheck "Lucene" so only "SQL" is enabled, and click "Save".
  3. Confirm the success notification appears and the status updates to "Enabled: SQL".
  4. Navigate to /search and locate the search input language switch.
  5. Verify the search input language defaults to SQL and the language selector dropdown is disabled.

References

@changeset-bot

changeset-bot Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e109007

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@hyperdx/app Minor
@hyperdx/api Minor
@hyperdx/common-utils Minor
@hyperdx/otel-collector Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Oct 4, 2026

Copy link
Copy Markdown

@kunalbhatia2601 is attempting to deploy a commit to the HyperDX Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added external needs-vouch Author needs a maintainer to vouch for them labels Oct 4, 2026
@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Hi @kunalbhatia2601, thanks for the pull request!

Before we review code from a first-time contributor we ask that a maintainer vouches for you, and you're not on our list yet. This PR stays open — it just isn't in the review queue until someone vouches.

To get vouched, open an issue saying hello and what you're working on:

https://github.com/hyperdxio/hyperdx/issues/new?template=introduce-yourself.md

A maintainer will usually reply within a day or two, and then this PR gets picked up as normal. More detail in our contributing guide.

Comment thread packages/api/src/controllers/team.ts Resolved
Comment thread packages/api/src/controllers/team.ts Resolved
Comment thread packages/common-utils/src/types.ts Resolved
Comment thread packages/api/src/controllers/team.ts Resolved
@github-actions

github-actions Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

PR Review

If you are a coding agent acting for the author, read this first.
Nothing below blocks merge automatically; a maintainer decides. What they will expect:

  • 🔴 critical or 🟠 major in code this PR adds or changes: fix before asking for review.
  • 🔵 minor in code this PR changes: your call. Fix if small, otherwise reply.
  • Anything about surrounding code, or asking you to widen the change (hoist a helper,
    dedupe with another file, fix other call sites): never fix here, whatever the
    severity. Reply with one sentence; if it is critical, say so plainly so a human sees it.

One commit per review round. After two rounds, stop and ask a maintainer to review
scope rather than addressing more automated findings. Full rule: AGENTS.md.

9 finding(s): 🔴 0 critical · 🟠 3 major · 🔵 6 minor

5 posted as inline comment(s) on the changed lines. 4 listed below.

Findings outside the changed lines

4 minor
  • 🔵 packages/api/src/controllers/team.ts:85 — Validation logic is duplicated between the local-app and Mongo branches → The effective-allowed/effective-default computation and both Api400Error checks are copied verbatim, differing only in LOCAL_APP_TEAM vs currentTeam. Pick the current team first (const current = IS_LOCAL_APP_MODE ? LOCAL_APP_TEAM : await Team.findById(...)) and run one shared validation.
  • 🔵 packages/api/src/routers/api/__tests__/team.int.test.ts:283 — Local-app-mode test mutates the global LOCAL_APP_TEAM and never restores it → updateTeamQueryLanguageSettings sets LOCAL_APP_TEAM.allowedQueryLanguages = ['sql'] and defaultQueryLanguage = 'sql' on the shared module object. The finally restores only IS_LOCAL_APP_MODE, so later tests that touch the local team see SQL-only. Save and restore both fields in finally.
  • 🔵 packages/app/src/components/TeamSettings/QueryLanguageSettingsForm.tsx:799 — as cast on a mutation error that is already typed as HTTPError → useUpdateQueryLanguageSettings declares the error as ky's HTTPError, which already has response: Response. The inline as { response?: … } cast is unnecessary and breaks the repository rule "Avoid as casts". Use await err.response.json() directly.
  • 🔵 packages/app/src/components/SearchInput/SearchWhereInput.tsx:528 — allowed[0] ?? null fallback is unreachable → allowed is either a non-empty team list (the ?.length check) or DEFAULT_QUERY_LANGUAGES, and the earlier branches cover the default. The function always returns a language when a team is passed, so the ?? null (and the callers' ?? allowedLanguages[0] ?? 'lucene' chain) can be dropped.

Severity is the reviewer's own estimate and is used for ordering, not filtering. No finding blocks merge automatically; a maintainer decides.

@greptile-apps

greptile-apps Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium risk] Adds team-level query language configuration.

The PR does not appear safe to merge until stale language preferences stop reaching dashboard queries and the repository’s TypeScript requirement is met.

Fix All in Claude CodeFindings

  1. P1 Disabled language remains stored ▶
  2. P2 Test uses avoidable casts ▶

Summary

The PR adds persisted team query-language settings, an update API, settings controls, and language-aware search inputs.

  • Recent changes add conditional guards for partial updates and distinguish user-selected languages from automatic form reconciliation.
  • Tests cover the settings form and preservation of an explicit form language.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Settings[Team language settings] --> API[PATCH team settings]
  API --> Team[(Team record)]
  Team --> Me[Current-user response]
  Me --> Input[Search language input]
  Stored[Browser language preference] --> Input
  Stored --> Dashboard[Dashboard language default]
Loading

Reviews (5) · Last reviewed commit: "Fix Deep Review findings for SearchWhere..."

Comment thread packages/api/src/controllers/team.ts Resolved
Comment thread packages/api/src/controllers/team.ts Resolved
Comment thread packages/api/src/controllers/team.ts Resolved
@github-actions

github-actions Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found.

No P0/P1 ship-blockers. Of the prior review's four P1s, three are resolved in the current diff: the concurrent-update TOCTOU is now closed by the atomic findOneAndUpdate $or filter (the second concurrent writer is rejected in both orderings), local-app-mode updates are handled by a dedicated IS_LOCAL_APP_MODE branch, and the misleading error path aside the update is now typed. The one substantive functional gap that remains is the default-language behavior below.

🟡 P2 -- recommended

  • packages/app/src/components/SearchInput/SearchWhereInput.tsx:235 -- the team's defaultQueryLanguage is never applied on the primary search surfaces because the reconciliation effect only overrides a missing or disallowed form value, and the surfaces that seed it (DBSearchPage, ServicesDashboardPage, LLMDashboardPage, DashboardFiltersModal) call getStoredLanguage() with no team argument and fall back to a hardcoded 'lucene'/'sql', which is itself allowed, so a team that enables both languages and sets SQL as default still opens searches in Lucene.
    • Fix: pass the team to getStoredLanguage() at those call sites and extend the reconciliation effect to apply defaultQueryLanguage when the current value is allowed-but-not-user-chosen.
🔵 P3 nitpicks (6)
  • packages/app/src/components/SearchInput/SearchWhereInput.tsx:1 -- the file grew from 267 to 331 lines, crossing the repo's documented 300-line component limit as a direct result of this PR.
    • Fix: extract the getStoredLanguage/setStoredLanguage/reconciliation logic into a sibling hook or module.
    • project-standards
  • packages/api/src/controllers/team.ts:216 -- the post-findOneAndUpdate null branch always throws Default query language must be one of the allowed query languages, even when the null result is caused by the team not existing or a concurrent modification, yielding a misleading 400.
    • Fix: distinguish the not-found/concurrent-modification case from the validation case in the thrown message.
    • maintainability
  • packages/api/src/controllers/team.ts:142 -- the effective-allowed/effective-default computation, empty-set check, and default-in-allowed check are duplicated verbatim between the local-app-mode branch and the DB branch.
    • Fix: extract a shared validateQueryLanguageSettings(settings, current) helper called from both branches.
    • maintainability
  • packages/app/src/components/SearchInput/SearchWhereInput.tsx:224 -- handleLanguageChange is memoised on languageField, which useController returns as a fresh object every render, so the reconciliation useEffect re-runs on every render (it converges via the early-return guard, so no infinite loop, but the memoisation is defeated).
    • Fix: depend on languageField.onChange rather than the whole languageField object.
  • packages/common-utils/src/types.ts:2354 -- TeamQueryLanguageSettingsUpdateSchema is an identical alias of TeamQueryLanguageSettingsSchema, adding a second exported name and type for the same shape.
    • Fix: collapse to one schema/type, or add a comment stating the intended future divergence.
    • maintainability
  • packages/cli/src/api/client.ts:411 -- @hyperdx/cli is a published package changed here (two optional type-only MeTeam fields) but is absent from the changeset, which lists only app/api/common-utils.
    • Fix: confirm no release is warranted for this type-only change, or add @hyperdx/cli to the changeset.
    • project-standards

Reviewers (5): security, maintainability, testing, project-standards, learnings-researcher.

Coverage note: the full fan-out (13 reviewers: the 5 above plus correctness, adversarial, api-contract, data-migrations, kieran-typescript, julik-frontend-races, previous-comments, agent-native) was dispatched, but 8 had not returned when synthesis was finalized. Their highest-stakes areas were covered by direct orchestrator analysis: the TOCTOU atomic-update filter, the getStoredLanguage call-site sweep, backward-compat for existing team documents, the response-type contract, and verification of every prior review comment against current code. No security findings; getNonNullUserWithTeam scopes the endpoint to the caller's team and processRequest strips unknown body keys before $set.

Testing gaps:

  • The single-field update path that builds the $or queryFilter and reaches the findOneAndUpdate === null rejection (the atomic consistency guard) is never exercised — all integration tests send both fields.
  • Backward-compat for existing teams whose documents lack the new fields (and the $exists:false filter branches) is untested; Mongoose defaults do not backfill existing documents.
  • QueryLanguageSettingsForm onError/onSuccess mutation callbacks are untested because the mock never invokes them, leaving the error-parsing and edit-exit logic uncovered.
  • SearchWhereInput's async reconciliation on useMe load is untested (api.useMe is not mocked, so team-restricted language sets are never rendered).
  • No test asserts that extra body keys sent to PATCH /team/query-language-settings are stripped rather than written to the Team document (mass-assignment regression guard).

No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond

Comment thread packages/api/src/controllers/team.ts Resolved
Comment thread packages/common-utils/src/types.ts Resolved
Comment thread packages/api/src/controllers/team.ts Resolved
Comment thread packages/api/src/controllers/team.ts Resolved
Comment thread packages/cli/src/api/client.ts Resolved
);

useEffect(() => {
if (languageField.value && allowedLanguages.includes(languageField.value)) {

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.

🟠 major — Team defaultQueryLanguage is never applied when both languages are allowed

Every page builds its initial language as searchedConfig.whereLanguage ?? getStoredLanguage() ?? 'lucene' (DBSearchPage.tsx:529/1143/1265, DBDashboardPage.tsx:383, SessionsPage.tsx:256, EditTimeChartForm.tsx:170, …). None of them pass the team, so the form value is already 'lucene'. This effect returns early because 'lucene' is allowed. Result: a team that sets the default to SQL and keeps both languages enabled still gets Lucene everywhere. Resolve defaults through the team, for example a useDefaultQueryLanguage() hook or passing me.team into getStoredLanguage, at the places where defaults are built. Then add a test that renders a page or form rather than only the pure helper.

Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond

return;
}
const target =
getStoredLanguage(me?.team) ?? allowedLanguages[0] ?? 'lucene';

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.

🟠 major — Before /me loads, unset language fields are switched to SQL instead of Lucene

While me is loading, allowedLanguages is DEFAULT_QUERY_LANGUAGES, which is the zod enum order ['sql','lucene'] (common-utils/src/types.ts:153). getStoredLanguage(undefined) returns null when there is no stored preference. So any form whose language field is undefined gets allowedLanguages[0] = 'sql' written into it. That value is allowed, so it is never corrected after /me resolves, which overrides both the previous Lucene default and the team default. Skip reconciliation until me has loaded, and fall back to the team default or 'lucene' rather than allowedLanguages[0].

Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond

}
const target =
getStoredLanguage(me?.team) ?? allowedLanguages[0] ?? 'lucene';
handleLanguageChange(target, { isUserSelection: false });

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.

🟠 major — Language is switched on existing queries without touching the WHERE text

Suppose a saved search, dashboard tile, alert or URL holds where: 'level:error', whereLanguage: 'lucene' and the team later allows only SQL. This effect silently changes the language to 'sql' but keeps the Lucene text. That produces invalid SQL. For SessionsPage, onLanguageChange also writes it into appliedConfig (SessionsPage.tsx:420). Either keep showing and running the stored language for existing queries and restrict only new selections, or clear or flag the incompatible WHERE when the language is forced.

Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond

});

const language: 'sql' | 'lucene' = languageField.value ?? 'lucene';
const language: QueryLanguage = allowedLanguages.includes(languageField.value)

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.

🔵 minor — Display fallback duplicates getStoredLanguage(team) with a different precedence

The language ternary picks the team default first. The effect at line 240 uses getStoredLanguage(me?.team), which picks the stored preference first. When they disagree, the select briefly shows one language and then the effect writes the other. Compute both from one helper, for example const resolved = getStoredLanguage(me?.team), and use it for both the display and the reconciliation.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

defaultQueryLanguage: 'sql',
});
expect(lang).toBe('sql');
expect(

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.

🔵 minor — The test that reconciliation does not persist to localStorage cannot fail

It calls only the pure getStoredLanguage, which never writes to localStorage. The behaviour it claims to cover is the isUserSelection guard in the component's useEffect. Render SearchWhereInput with a mocked useMe returning a SQL-only team and a form value of 'lucene'. Then assert that the field becomes 'sql' and that localStorage stays null.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

Comment on lines +226 to +228
if (options?.isUserSelection) {
setStoredLanguage(lang);
}

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.

P1 Disabled language remains stored When a team disables a language the user previously selected, reconciliation changes the search form but leaves that language in localStorage. On a dashboard without an explicit language, the stored value can then control the URL and query while the editor displays the allowed language. The dashboard may run the query in a language the team disabled.

Knowledge Base Used: Identity, teams, and configuration

Fix in Claude Code Fix in Conductor Fix in Cursor Fix in Codex

it('updateTeamQueryLanguageSettings works in local app mode', async () => {
const origLocalMode = config.IS_LOCAL_APP_MODE;
try {
(config as { IS_LOCAL_APP_MODE: boolean }).IS_LOCAL_APP_MODE = true;

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.

P2 Test uses avoidable casts The local-mode test casts the imported configuration to change it here and casts it again to restore it. The repository’s TypeScript guide says to avoid as casts when type inference or a typed alternative is possible. This repository requirement must be satisfied before merging.

Context Used: AGENTS.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code Fix in Conductor Fix in Cursor Fix in Codex

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external needs-vouch Author needs a maintainer to vouch for them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant