Skip to content

fix(cli): reject a non-numeric recall maintenance --threshold - #1799

Merged
SaulMoro merged 1 commit into
Tencent:mainfrom
pcbeingused333:fix/c2156-numeric-options
Nov 9, 2026
Merged

SaulMoro merged 1 commit into
Tencent:mainfrom
pcbeingused333:fix/c2156-numeric-options

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Summary

teamai recall maintenance --prune --threshold abc parsed the threshold with parseFloat, so it reached findPruneCandidates as NaN. NaN is not nullish, so the default threshold did not apply, and confidence < NaN is always false: the command pruned nothing and reported No learnings below threshold. Knowledge base is healthy.. Same pattern as #1781 and #1782.

The option now fails during parsing with --threshold must be a finite number, through the existing command error path. parseFloat also accepted 0.2abc as 0.2; that is rejected now too. No range restriction is added.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature causing existing behavior to change)
  • Documentation only
  • Refactor / internal cleanup

Test Plan

Real CLI record, after npm run build: src/__tests__/maintenance-numeric-options-e2e.test.ts runs dist/cli.js recall maintenance --prune --threshold <value> as a subprocess. abc, NaN, Infinity and 0.2abc exit 1 with the validation error, and failed without the fix; 0.2 is not rejected by option validation (in the uninitialized test workspace, it proceeds to the normal initialization error).

Node 22 Docker verification: the original main parser fails 4 cases and passes the positive case; the fixed parser passes all 5. npm run build, npm run typecheck and npm run lint pass.

  • npx tsc --noEmit passes
  • npm run lint passes
  • The test files that cover what I changed pass (npx vitest run --config vitest.e2e.config.ts <test file>)
  • Added/updated tests for the change

Related Issues

None filed; found next to #1781 and #1782.

Notes for Reviewers

This change was prepared with the assistance of an AI coding tool.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

No findings in the specified diff.

The parser rejects non-finite values and trailing junk while preserving finite thresholds without adding a range restriction.

The PR description documents sufficient testing: a post-build real-CLI subprocess run covering four invalid values and one valid value, plus build, typecheck, and lint results.

I did not run, build, or install anything from the PR.

@SaulMoro SaulMoro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This was generated by AI during triage.

Approving at 867b5fc.

I reproduced the bug on main with a built CLI: recall maintenance --prune --threshold abc exits 0, reports the knowledge base as healthy and keeps the learning. At this head it exits 1 with ✖ --threshold must be a finite number, and the learning stays. The default 0.15 and decimal values behave the same on both builds.

Hidden scope: none. The refusal is the fix itself. No default, flag or other output changes.

[P2 non-blocking] Number() accepts notations that parseFloat did not. --threshold 0x10 used to read as 0 and prune nothing. Now it reads as 16, which prunes every learning:

Number('0x10') === 16    parseFloat('0x10') === 0
Number('0b1')  === 1     parseFloat('0b1')  === 0

Nobody is likely to type that, but it can delete files. A decimal-only test, as parseIntOption in src/cli-int.ts does for integers, would close it. So would refusing values outside 0..1, since a confidence above 1 prunes everything anyway.

[P3 nit] The parser could sit beside parseIntOption in src/cli-int.ts instead of inline in index.ts.

The CI review found nothing. I agree, apart from the notation point above.

@SaulMoro
SaulMoro merged commit c1155f4 into Tencent:main Nov 9, 2026
18 checks passed
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.

3 participants