Skip to content

Dead code in search threshold schemas: unreachable v === undefined checks and no-op .transform(Number) #1205

Description

@kbpr21

Summary

In packages/validation/api.ts, three threshold fields use a .refine() that
checks v === undefined, but this branch is unreachable, and a .transform(Number)
that is a no-op.

Affected fields:

  • SearchRequestSchema.chunkThreshold
  • SearchRequestSchema.documentThreshold
  • Searchv4RequestSchema.threshold

Why the code is dead

Each field is defined as:

z.number().optional().default(0).refine((v) => v === undefined || (v >= 0 && v <= 1), {...}).transform(Number)

Zod applies .default() before downstream processing. When the field is omitted,
the parsed input is undefined, .default(0) replaces it with 0, and only then
does .refine() run. So v is always a number, never undefined, the
v === undefined || branch can never execute.

Additionally, .transform(Number) runs on a value that is already z.number(),
so it is a no-op.

Question before I open a PR

Happy to submit a PR removing the dead v === undefined checks and the redundant
.transform(Number) across all three fields. Before I do:

Is the .default(0) intentional? If "unset" is meant to be distinguishable from
an explicit 0, that may be worth addressing separately, otherwise I'll keep the
cleanup purely to the dead code and leave the defaults as-is.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions