Skip to content

fix(client): require XADD TRIM strategy to match the command grammar - #3418

Merged
nkaradzhov merged 2 commits into
redis:masterfrom
abhijeet117:fix/xadd-trim-strategy-required
Aug 26, 2026
Merged

nkaradzhov merged 2 commits into
redis:masterfrom
abhijeet117:fix/xadd-trim-strategy-required

Conversation

@abhijeet117

@abhijeet117 abhijeet117 commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

SummaryXAddOptions made TRIM.strategy optional while the XADD grammar makes MAXLEN|MINID mandatory inside the trim block. Omitting it emitted a bare number that the server parses as the entry ID (streamParseStrictIDOrReply), so the command added a wrong-ID entry with garbage fields or errored instead of trimming. strategy is now required, matching the XTRIM client API; five spec cases asserted the malformed argv and were corrected.## TestingCompile-time regression test rejects a strategy-less TRIM object: it compiled on master (TS2578) and fails after the fix. Verified against xadd.json and t_stream.c; parser assertions, type tests, build and lint run locally; Docker-backed integration tests run in CI.## Checklist- bug reproduced before fix- root cause identified- bug fixed- tests passed


Note

Medium Risk
Breaking TypeScript API for callers that passed TRIM without strategy, but the old behavior sent invalid commands to Redis; runtime behavior is corrected for properly typed callers.

Overview
Fixes incorrect XADD argv when TRIM omitted MAXLEN/MINID. The client previously allowed TRIM with only threshold, which produced a bare number before the entry ID; Redis treats that as the stream ID, so adds could use wrong IDs or fail instead of trimming.

XAddOptions.TRIM.strategy is now required (aligned with XTRIM), and parseXAddArguments always emits MAXLEN or MINID before the threshold and related trim tokens. Unit expectations in XADD and XADD_NOMKSTREAM specs were updated for modifier, limit, and policy cases; a compile-time test in types-tests rejects strategy-less TRIM objects.

Reviewed by Cursor Bugbot for commit a0b0ad7. Bugbot is set up for automated code reviews on this repo. Configure here.

Release note

XADD TRIM.strategy is now required at compile time: MAXLEN/MINID is mandatory in the XADD grammar, so callers omitting it would previously emit a bare threshold the server parsed as an entry ID.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2af5c789a8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

* Required by the XADD grammar: without MAXLEN or MINID the server parses
* the threshold as the entry ID instead of trimming.
*/
strategy: 'MAXLEN' | 'MINID';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Update the shared NOMKSTREAM trim cases

Because XADD_NOMKSTREAM delegates to parseXAddArguments, this required property also applies to its co-located argument tests, but four cases in XADD_NOMKSTREAM.spec.ts still omit strategy and assert the same malformed wire arguments this change is fixing. The test runner transpiles specs without type-checking, so those assertions continue to pass and leave the suite explicitly blessing invalid XADD grammar; update the NOMKSTREAM cases alongside these XADD cases.

AGENTS.md reference: AGENTS.md:L56-L59

Useful? React with 👍 / 👎.

@PavelPashov

Copy link
Copy Markdown
Contributor

@abhijeet117 Thanks for the PR. We’ll review it when we have capacity.

@nkaradzhov

Copy link
Copy Markdown
Collaborator

Thanks for the fix and the clear write-up — the underlying problem is real. XAddOptions.TRIM.strategy should be required, since the XADD grammar makes MAXLEN|MINID mandatory and the strategy-less form emits a bare threshold the server reads as the entry ID. This matches the XTRIM API, and the compile-time regression test is a good addition.

Before we merge, a few bounded items:

  1. parseXAddArguments still has if (options.TRIM.strategy) { parser.push(...) } — please make that push unconditional so the wire command is fixed at the source, not only at the type layer.
  2. XADD.spec.ts still has a "with TRIM.strategyModifier" case that omits strategy and asserts ['XADD','key','=','1000',...], which is the malformed command this PR removes — please correct it.
  3. The same strategy-less TRIM cases exist in XADD_NOMKSTREAM.spec.ts (it shares this options type via parseXAddArguments) and should be updated too.

Note that .spec.ts files are excluded from the type build and run under tsx, so those contradictions don't surface in CI on their own. Since this is a compile-time break for callers currently omitting strategy, please also add a short release-note entry. Once the parser guard and the remaining specs are aligned, this should be ready for another look.

@nkaradzhov nkaradzhov 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.

Requesting changes: make the parseXAddArguments strategy push unconditional, fix the residual strategy-less TRIM cases in XADD.spec.ts and XADD_NOMKSTREAM.spec.ts, and add a release-note entry for the compile-time break. Details in my comment above.

@nkaradzhov

Copy link
Copy Markdown
Collaborator

Thanks — you've addressed all the points (unconditional strategy push, the remaining specs, and the release note). LGTM.

@nkaradzhov
nkaradzhov merged commit 165ecd0 into redis:master Aug 26, 2026
25 of 26 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