Skip to content

feat(aggregations): handle max integer in aggregations COMPASS-6372 - #8301

Merged
mabaasit merged 31 commits into
mainfrom
use-safe-integer-linter
Aug 4, 2026
Merged

feat(aggregations): handle max integer in aggregations COMPASS-6372#8301
mabaasit merged 31 commits into
mainfrom
use-safe-integer-linter

Conversation

@mabaasit

@mabaasit mabaasit commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Description

  1. Removed initial implementation of validating for max integer for document json-editor and insert. Used codemirror linter.
  2. Added validation for stage builder and pipeline as text
  3. TODO (In follow up): Align tooltips with design
Screen.Recording.2026-07-29.at.21.56.17.mov

Checklist

  • New tests and/or benchmarks are included
  • Documentation is changed or added
  • If this change updates the UI, screenshots/videos are added and a design review is requested
  • If this change could impact the load on the MongoDB cluster, please describe the expected and worst case impact
  • I have signed the MongoDB Contributor License Agreement (https://www.mongodb.com/legal/contributor-agreement)

Motivation and Context

  • Bugfix
  • New feature
  • Dependency update
  • Misc

Open Questions

Dependents

Types of changes

  • Backport Needed
  • Patch (non-breaking change which fixes an issue)
  • Minor (non-breaking change which adds functionality)
  • Major (fix or feature that would cause existing functionality to change)

Copilot AI review requested due to automatic review settings July 29, 2026 19:51
@mabaasit
mabaasit requested a review from a team as a code owner July 29, 2026 19:51
@mabaasit
mabaasit requested a review from paula-stacho July 29, 2026 19:51
@github-actions github-actions Bot added the feat label Jul 29, 2026

Copilot AI 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.

Pull request overview

This PR shifts “unsafe integer” handling away from hadron-document parsing-time validation and toward CodeMirror-based linting + quick-fix actions in the JSON/pipeline editors, aiming to better support max-int scenarios in aggregations and editing flows.

Changes:

  • Removed hadron-document unsafe-integer parsing guard and its tests/exports.
  • Extended createSafeIntegerLinter to report multiple violations and exposed SafeIntegerViolation for consumers.
  • Adopted the safe-integer linter in CRUD and Aggregations editors (with conversion actions) and updated related UI wiring.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/hadron-document/test/unsafe-integer-validation.test.ts Removes unit tests for the old parsing-time unsafe-integer validator.
packages/hadron-document/test/document.test.ts Removes Document.FromEJSON unsafe-number behavior tests.
packages/hadron-document/src/unsafe-integer-validation.ts Deletes the unsafe-integer validator implementation.
packages/hadron-document/src/index.ts Removes export of the deleted UnsafeIntegerValidationError.
packages/hadron-document/src/document.ts Removes pre-parse unsafe-integer guard from FromEJSON / FromEJSONArray.
packages/compass-query-bar/src/components/option-editor.tsx Updates query options editor to consume the new multi-violation linter callback.
packages/compass-editor/src/index.ts Re-exports createSafeIntegerLinter plus the new SafeIntegerViolation type.
packages/compass-editor/src/editor.tsx Adjusts lint styling (hides .cm-lintPoint marker pseudo-element).
packages/compass-editor/src/codemirror/safe-integer-linter.ts Changes linter API to provide a list of violations; introduces SafeIntegerViolation.
packages/compass-editor/src/codemirror/safe-integer-linter.test.ts Updates tests to match the new linter callback and violation shape.
packages/compass-crud/src/utils/use-json-editor-annotations.ts Removes the previous approach that turned hadron-document unsafe-integer errors into annotations.
packages/compass-crud/src/components/use-safe-integer-linter.ts Adds a CRUD-specific hook to run the safe-integer linter and provide “convert to $numberLong” actions.
packages/compass-crud/src/components/json-editor.tsx Switches JSON editor from annotations to linter; adds “Convert to Long” UI link.
packages/compass-crud/src/components/insert-json-document.tsx Switches insert JSON editor to use the linter instead of annotations.
packages/compass-crud/src/components/insert-document-dialog.tsx Wires linter into insert dialog and passes new validation error path to the banner.
packages/compass-crud/src/components/insert-document-dialog-banner.tsx Uses SafeIntegerValidationError for banner action rendering.
packages/compass-aggregations/src/components/use-safe-integer-linter.ts Adds aggregations-specific linter hook with a Long("...") conversion action and annotation merging.
packages/compass-aggregations/src/components/stage-editor/stage-editor.tsx Switches stage editor from annotations prop to linter-based diagnostics.
packages/compass-aggregations/src/components/pipeline-builder-workspace/pipeline-as-text-workspace/pipeline-editor.tsx Switches pipeline-as-text editor from annotations prop to linter-based diagnostics.
Comments suppressed due to low confidence (2)

packages/compass-aggregations/src/components/stage-editor/stage-editor.tsx:237

  • Use the memoized linter that reconfigures when annotations changes; otherwise external diagnostics may remain stale until the next editor update.
          className={codeEditorStyles}
          id={`aggregations-stage-editor-${index}`}
          completer={completer}
          onBlur={onBlurEditor}
          linter={safeIntegerLinter}

packages/compass-aggregations/src/components/pipeline-builder-workspace/pipeline-as-text-workspace/pipeline-editor.tsx:223

  • Use the memoized linter so that changes to external annotations trigger a linter re-run; otherwise syntax error markers may lag behind until the next text edit.
          className={codeEditorStyles}
          linter={safeIntegerLinter}
        />

Comment thread packages/compass-crud/src/components/json-editor.tsx Outdated
Comment thread packages/compass-crud/src/components/use-safe-integer-linter.ts Outdated
Comment thread packages/compass-crud/src/components/insert-document-dialog.tsx Outdated
Comment on lines +211 to +213
const annotationsRef = useCurrentValueRef<Annotation[]>(annotations);
const { safeIntegerLinter } = useSafeIntegerLinter(annotationsRef);

Comment on lines +199 to +201
const annotationsRef = useCurrentValueRef<Annotation[]>(annotations);
const { safeIntegerLinter } = useSafeIntegerLinter(annotationsRef);

@Anemy
Anemy self-requested a review July 30, 2026 00:57
@Anemy Anemy changed the title feat(aggregations): handle max integer in aggregations feat(aggregations): handle max integer in aggregations COMPASS-6372 Jul 30, 2026

@Anemy Anemy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looking good, left a couple questions

onCancel={closeInsertDocumentDialog}
submitButtonText="Insert"
submitDisabled={Boolean(documentValidationError)}
submitDisabled={Boolean(documentValidationError || violationError)}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Starting to write this logic makes me wonder if we should have the parsing EJSON and parsing shell bson fail when they encounter these with a descriptive error so we bring it upstream more. I'll give this a bit more of a think, I'm curious if that approach might end up being cleaner.

We would still want the linter though, but we could make the linter more generic and show the error that the parsing returns. Not a blocker for this pr, but I do want to make sure we've considered it before we wrap this up. We might want other errors from parsing to show up in gutters in a fixable way eventually.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

(we discussed this on slack) The initial idea was to add this in the bson-parser library. However Sergey suggested that we do this using codemirror as it offers linting api that exposes the tree which we can use to find the safe integer violation.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

But maybe we implement this in bson-parser package as well to highlight these violations

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same question as above, better in the compass-editor package?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we have this in the compass-editor package and then share it with compass-crud and query-bar?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I wanted to do that, but both are different (${numberLong: text} | Long(text)). I guess we can merge them into one and make it configurable. Let me try that.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Did the clean up.

validationError={docValidationError}
validationError={
docValidationError ??
(violations.length > 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Still a similar nit to before, here and in a few other places we use the wording "violations" which is fairly generic and then use it explicitly for safe integers. Having it non-generic for for now, like safeIntegerViolations would help ensure we don't unintentionally add the wrong message for new violations we might add. Totally fine as is, pretty low chance of it causing an issue.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 524b3ac

const violations: SafeIntegerViolation[] = [];
tree.iterate({
enter: (node) => {
// Only warn on bare number literals, not on Int64(...) arguments

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We do want to error on Int64(...) arguments. Can we update this? Or follow up with an update?

Image

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Oh i did not know that. Yes, i'll follow up on this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Chatting about this async, let's follow up and I'll create a ticket

@mabaasit
mabaasit force-pushed the use-safe-integer-linter branch from 0e2a3e3 to 42b064d Compare August 3, 2026 23:10
@mabaasit
mabaasit merged commit ddcbdac into main Aug 4, 2026
97 of 103 checks passed
@mabaasit
mabaasit deleted the use-safe-integer-linter branch August 4, 2026 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants