Skip to content

feat: strenghten the requirement around appName#11628

Open
gastonfournier wants to merge 3 commits intomainfrom
filter-malformed-metrics-earlier
Open

feat: strenghten the requirement around appName#11628
gastonfournier wants to merge 3 commits intomainfrom
filter-malformed-metrics-earlier

Conversation

@gastonfournier
Copy link
Copy Markdown
Contributor

@gastonfournier gastonfournier commented Mar 17, 2026

About the changes

This PR fixes intermittent warnings like:

  • Failed to register clients The query is empty

The issue was malformed client registrations reaching bulkAdd(). In some cases, the set sent to DB upsert ended up effectively empty, which caused Knex to throw "The query is empty".

What changed

  • Added a defensive filter in ClientInstanceService.bulkAdd() to only process registrations with a truthy appName.

This reduces warning noise and prevents invalid payloads from reaching bulk upsert paths.

Discussion points

  • We intentionally keep bulk/metrics API schemas tolerant to avoid dropping otherwise valid data when payloads are aggregated upstream (for example, Edge collecting data from multiple clients).
  • We keep stricter appName validation on register schemas, which aligns with existing runtime behavior using joi validation.
  • The service-side filter is kept to drop malformed registrations while allowing valid metrics in the same request to be processed.

Copilot AI review requested due to automatic review settings March 17, 2026 11:21
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 17, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions
Copy link
Copy Markdown
Contributor

API Changelog 7.5.1 vs. 7.5.1

POST /api/client/register

  • ⚠️ the 'appName' request property's minLength was increased from '0' to '1'

POST /api/frontend/client/register

  • ⚠️ the 'appName' request property's minLength was increased from '0' to '1'

This comment was marked as outdated.

This comment was marked as outdated.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR tightens validation/handling of appName in client registration flows to prevent malformed client registrations from reaching the bulk upsert path that can trigger Knex’s “The query is empty” warning.

Changes:

  • Enforce non-empty appName in OpenAPI schemas for client registration payloads (minLength: 1).
  • Update OpenAPI schema tests to use a non-empty appName.
  • Add a defensive filter in ClientInstanceService.bulkAdd() to skip registrations with falsy appName.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/lib/openapi/spec/frontend-api-client-schema.ts Requires non-empty appName for the frontend client registration schema.
src/lib/openapi/spec/client-application-schema.ts Requires non-empty appName for backend client registration schema used by /api/client/register.
src/lib/openapi/spec/client-application-schema.test.ts Adjusts tests to reflect non-empty appName requirement.
src/lib/features/metrics/instance/instance-service.ts Filters out registrations without a truthy appName before bulk upsert.
Comments suppressed due to low confidence (1)

src/lib/openapi/spec/client-application-schema.test.ts:16

  • The schema now requires non-empty appName, but there’s no explicit test asserting that appName: "" is rejected (the existing tests were changed to use a non-empty value). Please add a negative test case for empty appName to ensure the new constraint is enforced and doesn’t regress.
test('clientApplicationSchema required fields', () => {
    const data: ClientApplicationSchema = {
        appName: 'test-app',
        interval: 0,
        started: 0,
        strategies: [''],
    };

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines 9 to 15
appName: {
description:
'An identifier for the app that uses the sdk, should be static across SDK restarts',
type: 'string',
minLength: 1,
example: 'example-app',
},
Copy link
Copy Markdown
Contributor

@sastromskis sastromskis left a comment

Choose a reason for hiding this comment

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

LG

@github-project-automation github-project-automation bot moved this from New to Approved PRs in Issues and PRs Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Approved PRs

Development

Successfully merging this pull request may close these issues.

3 participants