Skip to content

Commit e4a183b

Browse files
committed
fix(agents): bound union scans before literal-union analysis
1 parent b485a13 commit e4a183b

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

‎src/agents/tool-schema-hints.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,14 @@ function compactSchemaUnion(
128128
return UNKNOWN_HINT;
129129
}
130130
const variants = hasAnyOf ? schema.anyOf : schema.oneOf;
131-
if (!Array.isArray(variants) || variants.length === 0) {
131+
// Bound before any per-variant scan: neither the eight-value literal cap nor
132+
// the four-variant structural cap can render a larger union, so oversized
133+
// unions must be rejected in O(1) instead of O(variants).
134+
if (
135+
!Array.isArray(variants) ||
136+
variants.length === 0 ||
137+
variants.length > MAX_COMPACT_ENUM_VALUES
138+
) {
132139
return UNKNOWN_HINT;
133140
}
134141
// A union plus a base structural shape is an intersection. This compact

0 commit comments

Comments
 (0)