Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

fix(webv2): correct wildcard import name resolution

joshistoast13a6eeffa666
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.json
index ac43cbbdea..52008e5a03 100644
--- a/invokeai/frontend/webv2/public/locales/en.json
+++ b/invokeai/frontend/webv2/public/locales/en.json
@@ -1001,7 +1001,8 @@
"importRejectedTooLong": "Name too long",
"importRejectedDuplicate": "Repeated in this import",
"importRejectedNoValues": "No values",
- "importRejectedTooManyValues": "Too long for the server",
+ "importRejectedTooManyValues": "Too many values",
+ "importRejectedValueTooLong": "A value is too long",
"importedCount_one": "Imported {{count}} wildcard",
"importedCount_other": "Imported {{count}} wildcards",
"couldNotImport": "Could not import these wildcards",
diff --git a/invokeai/frontend/webv2/src/features/generation/core/wildcardTransfer.test.ts b/invokeai/frontend/webv2/src/features/generation/core/wildcardTransfer.test.ts
index cc1ada0e3a..2261baa758 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/wildcardTransfer.test.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/wildcardTransfer.test.ts
@@ -185,17 +185,34 @@ describe('planWildcardImport', () => {
expect(entry.rejection).toBe('noValues');
});
- it('reports a list past the backend limits', () => {
- const [tooMany, tooLong] = planWildcardImport(
+ // Two different problems with two different remedies: a list to trim, or a
+ // single value to shorten. Reporting both as "too many values" left someone
+ // holding three values and one long paragraph with nothing to act on.
+ it('tells a long list apart from a long value', () => {
+ const [tooMany, valueTooLong] = planWildcardImport(
[
{ name: 'many', values: Array.from({ length: 10_001 }, (_, index) => `v${index}`) },
- { name: 'long', values: ['x'.repeat(2_001)] },
+ { name: 'long', values: ['ok', 'x'.repeat(2_001)] },
],
existing
);
expect(tooMany.rejection).toBe('tooManyValues');
- expect(tooLong.rejection).toBe('tooManyValues');
+ expect(valueTooLong.rejection).toBe('valueTooLong');
+ });
+
+ // Regression: the name was recorded as seen whether or not the entry survived,
+ // so a rejected one shadowed a perfectly good later entry and neither landed.
+ it('does not let a rejected entry shadow a good one with the same name', () => {
+ const entries = planWildcardImport(
+ [
+ { name: 'colours', values: [] },
+ { name: 'colours', values: ['red', 'green'] },
+ ],
+ existing
+ );
+
+ expect(entries.map((entry) => entry.rejection)).toEqual(['noValues', null]);
});
it('keeps the first of a name repeated within one import and reports the rest', () => {
@@ -259,6 +276,24 @@ describe('getWildcardImportActions', () => {
]);
});
+ // Regression: only the catalog seeded the taken set, so "keep both" picked
+ // `colours-2` without noticing the same file was already creating one, and the
+ // two creates raced to the same name — the loser aborting the import.
+ it('does not rename onto a name the same import is creating', () => {
+ const clashing = planWildcardImport(
+ [
+ { name: 'colours', values: ['red'] },
+ { name: 'colours-2', values: ['green'] },
+ ],
+ [{ id: 'w1', name: 'colours' }]
+ );
+
+ expect(getWildcardImportActions(clashing, { colours: 'keepBoth' }, new Set(['colours']))).toEqual([
+ { name: 'colours-3', values: ['red'] },
+ { name: 'colours-2', values: ['green'] },
+ ]);
+ });
+
it('never emits an action for a rejected entry', () => {
const actions = getWildcardImportActions(entries, { 'bad name!': 'replace', colours: 'replace' }, existingNames);
diff --git a/invokeai/frontend/webv2/src/features/generation/core/wildcardTransfer.ts b/invokeai/frontend/webv2/src/features/generation/core/wildcardTransfer.ts
index 5c6217e9cb..60135146c2 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/wildcardTransfer.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/wildcardTransfer.ts
@@ -166,7 +166,13 @@ export const wildcardsToNestedRecord = (wildcards: readonly ParsedWildcard[]): R
return root;
};
-export type WildcardImportRejection = 'duplicate' | 'invalid' | 'noValues' | 'tooLong' | 'tooManyValues';
+export type WildcardImportRejection =
+ | 'duplicate'
+ | 'invalid'
+ | 'noValues'
+ | 'tooLong'
+ | 'tooManyValues'
+ | 'valueTooLong';
export type WildcardImportResolution = 'keepBoth' | 'replace' | 'skip';
@@ -211,12 +217,14 @@ export const planWildcardImport = (
if (wildcard.values.length === 0) {
return 'noValues';
}
- if (
- wildcard.values.length > MAX_WILDCARD_VALUES ||
- wildcard.values.some((value) => value.length > MAX_WILDCARD_VALUE_LENGTH)
- ) {
+ if (wildcard.values.length > MAX_WILDCARD_VALUES) {
return 'tooManyValues';
}
+ // Kept apart from the count: told "too many values", someone holding three
+ // values and one long paragraph has no idea which one to shorten.
+ if (wildcard.values.some((value) => value.length > MAX_WILDCARD_VALUE_LENGTH)) {
+ return 'valueTooLong';
+ }
return null;
};
@@ -224,7 +232,13 @@ export const planWildcardImport = (
return parsed.map((wildcard) => {
const rejection = getRejection(wildcard);
- seen.add(wildcard.name);
+ // Only entries that will actually be written claim the name. Recording
+ // rejected ones too meant an empty `colours.txt` earlier in the selection
+ // made a populated `colours.yaml` later in it read as a repeat, and neither
+ // was imported.
+ if (rejection === null) {
+ seen.add(wildcard.name);
+ }
return {
conflictId: existingByName.get(wildcard.name) ?? null,
@@ -266,6 +280,11 @@ export interface WildcardImportAction {
*
* `taken` grows as it goes, so importing two clashing names as "keep both" gives
* `colours-2` and `colours-3` rather than the same suffix twice.
+ *
+ * It is seeded with the names the import itself is about to claim, not just the
+ * ones already in the catalog. A file holding `colours` (clashing) and a new
+ * `colours-2` otherwise had the first resolve to `colours-2` as well, and the
+ * two creates raced each other to the same name.
*/
export const getWildcardImportActions = (
entries: readonly WildcardImportEntry[],
@@ -275,13 +294,18 @@ export const getWildcardImportActions = (
const taken = new Set(existingNames);
const actions: WildcardImportAction[] = [];
+ for (const entry of entries) {
+ if (!entry.rejection) {
+ taken.add(entry.name);
+ }
+ }
+
for (const entry of entries) {
if (entry.rejection) {
continue;
}
if (entry.conflictId === null) {
- taken.add(entry.name);
actions.push({ name: entry.name, values: entry.values });
continue;
}
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/WildcardImportDialog.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/WildcardImportDialog.tsx
index 4864ca195b..eb172df6ae 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/WildcardImportDialog.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/WildcardImportDialog.tsx
@@ -24,6 +24,7 @@ const REJECTION_KEY: Record<WildcardImportRejection, string> = {
noValues: 'widgets.generate.dynamicPrompts.importRejectedNoValues',
tooLong: 'widgets.generate.dynamicPrompts.importRejectedTooLong',
tooManyValues: 'widgets.generate.dynamicPrompts.importRejectedTooManyValues',
+ valueTooLong: 'widgets.generate.dynamicPrompts.importRejectedValueTooLong',
};
/**