feat(aggregations): handle max integer in aggregations COMPASS-6372 - #8301
Conversation
…dle-max-int-query-bar
Co-authored-by: Rhys <Anemy@users.noreply.github.com>
…-safe-integer-linter
There was a problem hiding this comment.
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-documentunsafe-integer parsing guard and its tests/exports. - Extended
createSafeIntegerLinterto report multiple violations and exposedSafeIntegerViolationfor 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
linterthat reconfigures whenannotationschanges; 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
linterso that changes to externalannotationstrigger a linter re-run; otherwise syntax error markers may lag behind until the next text edit.
className={codeEditorStyles}
linter={safeIntegerLinter}
/>
| const annotationsRef = useCurrentValueRef<Annotation[]>(annotations); | ||
| const { safeIntegerLinter } = useSafeIntegerLinter(annotationsRef); | ||
|
|
| const annotationsRef = useCurrentValueRef<Annotation[]>(annotations); | ||
| const { safeIntegerLinter } = useSafeIntegerLinter(annotationsRef); | ||
|
|
Anemy
left a comment
There was a problem hiding this comment.
Looking good, left a couple questions
| onCancel={closeInsertDocumentDialog} | ||
| submitButtonText="Insert" | ||
| submitDisabled={Boolean(documentValidationError)} | ||
| submitDisabled={Boolean(documentValidationError || violationError)} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
(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.
There was a problem hiding this comment.
But maybe we implement this in bson-parser package as well to highlight these violations
There was a problem hiding this comment.
Same question as above, better in the compass-editor package?
There was a problem hiding this comment.
Should we have this in the compass-editor package and then share it with compass-crud and query-bar?
There was a problem hiding this comment.
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.
| validationError={docValidationError} | ||
| validationError={ | ||
| docValidationError ?? | ||
| (violations.length > 0 |
There was a problem hiding this comment.
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.
| const violations: SafeIntegerViolation[] = []; | ||
| tree.iterate({ | ||
| enter: (node) => { | ||
| // Only warn on bare number literals, not on Int64(...) arguments |
There was a problem hiding this comment.
Oh i did not know that. Yes, i'll follow up on this.
There was a problem hiding this comment.
Chatting about this async, let's follow up and I'll create a ticket
…-safe-integer-linter
0e2a3e3 to
42b064d
Compare

Description
Screen.Recording.2026-07-29.at.21.56.17.mov
Checklist
Motivation and Context
Open Questions
Dependents
Types of changes