Skip to content

fix: annotation behavioral fixes and IO stability#175

Merged
Aiosa merged 1 commit into
kubernetes-mlflow-mergefrom
master
May 27, 2026
Merged

fix: annotation behavioral fixes and IO stability#175
Aiosa merged 1 commit into
kubernetes-mlflow-mergefrom
master

Conversation

@Aiosa
Copy link
Copy Markdown
Member

@Aiosa Aiosa commented May 27, 2026

No description provided.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 27, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 08426d4f-ac0e-44c1-a3fa-366ca7b45bc7

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch master

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 and usage tips.

@Aiosa Aiosa merged commit ec67271 into kubernetes-mlflow-merge May 27, 2026
2 of 3 checks passed
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request improves annotation handling and conversion across ASAP-XML, GeoJSON, and QuPath formats, specifically adding better support for 'line' and 'ruler' types, and fixing coordinate calculations for Ruler and Line annotations. The review feedback highlights several critical safety improvements, including avoiding passing the entire fabric object to factory.configure (which risks circular reference copying), filtering out sparse array slots during ASAP-XML decoding, adding null-checks for missing factories in GeoJSON converters, and filtering out undefined presets in the GUI.

Comment on lines +2203 to +2204
const factory = self.getAnnotationObjectFactory(obj.factoryID);
factory?.configure?.(obj, obj);
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.

high

Passing the entire fabric object obj as the options parameter to factory.configure is highly inefficient and dangerous. In Ruler.configure, $.extend({}, options, ...) and Object.assign({}, options) are called, which will attempt to clone/copy all properties of the fabric instance (including circular references, canvas references, etc.). This can lead to severe performance degradation, memory bloat, or runtime errors.

Instead, extract and pass only the necessary properties as a plain object.

const factory = self.getAnnotationObjectFactory(obj.factoryID);
factory?.configure?.(obj, {
	color: obj.color,
	presetID: obj.presetID,
	zoomAtCreation: obj.zoomAtCreation,
	layerID: obj.layerID
});

if (factory && typeof factory.fromPointArray === "function" &&
typeof factory.create === "function") {
try {
const arrPts = pointArray.map(p => [p.x, p.y]);
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.

medium

If pointArray is sparse (e.g., due to missing or non-sequential Order indices in the XML), pointArray.map will preserve the empty slots as undefined. When passed to fromPointArray, destructuring undefined will throw a TypeError and crash the import process.

Filter out empty/undefined slots to ensure a dense array of coordinates is passed to the factory.

Suggested change
const arrPts = pointArray.map(p => [p.x, p.y]);
const arrPts = pointArray.filter(p => p).map(p => [p.x, p.y]);

const factory = this.context.getAnnotationObjectFactory(object.factoryID);
const converter = OSDAnnotations.AnnotationObjectFactory.withArrayPoint;
object._objects = object.objects; // todo ugly, factory works with live objects
const props = factory.copyNecessaryProperties(object, [], 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.

medium

If factory is undefined, calling factory.copyNecessaryProperties will throw a TypeError. Add a null check to prevent potential crashes if the ruler factory is not registered.

Suggested change
const props = factory.copyNecessaryProperties(object, [], true);
const props = factory ? factory.copyNecessaryProperties(object, [], true) : {};

Comment on lines +118 to +121
const factory = this.context.getAnnotationObjectFactory("line");
const params = factory.fromPointArray(object.geometry.coordinates, ([x, y]) => ({ x, y }));
const opts = $.extend({}, this.context.presets.getCommonProperties(), object.properties);
return factory.create(params, opts);
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.

medium

If the line factory is not registered or found, calling factory.fromPointArray will throw a TypeError. Add a guard to safely handle cases where the factory is missing.

const factory = this.context.getAnnotationObjectFactory("line");
if (!factory) return null;
const params = factory.fromPointArray(object.geometry.coordinates, ([x, y]) => ({ x, y }));
const opts = $.extend({}, this.context.presets.getCommonProperties(), object.properties);
return factory.create(params, opts);

Comment on lines +136 to +139
const factory = this.context.getAnnotationObjectFactory("ruler");
const params = factory.fromPointArray(object.geometry.coordinates, ([x, y]) => ({ x, y }));
const opts = $.extend({}, this.context.presets.getCommonProperties(), object.properties);
const obj = factory.create(params, opts);
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.

medium

If the ruler factory is not registered or found, calling factory.fromPointArray will throw a TypeError. Add a guard to safely handle cases where the factory is missing.

const factory = this.context.getAnnotationObjectFactory("ruler");
if (!factory) return null;
const params = factory.fromPointArray(object.geometry.coordinates, ([x, y]) => ({ x, y }));
const opts = $.extend({}, this.context.presets.getCommonProperties(), object.properties);
const obj = factory.create(params, opts);

groups.push({
name: "Unknown / Unsorted",
presets: unknown
presets: unknown.map(pId => presetManager.get(pId))
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.

medium

If presetManager.get(pId) returns undefined for any of the unknown preset IDs, the presets array will contain undefined values, which can cause rendering issues or crashes later. Filter out any falsy/undefined values to ensure a clean array of presets.

Suggested change
presets: unknown.map(pId => presetManager.get(pId))
presets: unknown.map(pId => presetManager.get(pId)).filter(Boolean)

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.

1 participant