Repository navigation
fix(core): normalise session message limits at the store boundary - #983
Conversation
Present message limits were passed verbatim to Drizzle, where negative or NaN values drop the LIMIT clause, zero returns no rows, and fractional or infinite values fail SQLite's datatype check. Floor and clamp present limits to [1,200] and use 50 for non-finite values, matching the HTTP handler's page size. An omitted limit still returns the full history. Refs #981 Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Normalize limits before querying packages/core/src/session/store.ts, packages/core/test/session-store.test.ts |
Present limits are floored and clamped to 1–200. Non-finite limits become 50. Tests verify these results and confirm that omitted limits return all 250 messages. |
Priority:
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Medium
Suggested reviewers: kitlangton
Merge Risk: 
Minimal · up to 56062
-
Message limits are normalized while omitted limits remain unbounded. No merge-blocking risk is identified.
Pre-merge checks: 
5
-
Check name Status Explanation Title check The title clearly and concisely describes the main change: normalizing session message limits at the store boundary. Description check The description covers the issue, change rationale, verification results, and checklist. It omits the screenshots section, but that section is not relevant because this is not a UI change. Linked Issues check Directly linked issue #981has these coding requirements. Each one is met by the diff at the reviewed head.
1. Normalize a present limit at the store boundary: floor it and clamp it to [1, 200]. `mes…Out of Scope Changes check The whole-PR diff (merge base 654a398 to head 56062b6) changes two files.
- packages/core/src/session/store.ts adds theMessageLimitconstant and themessagesLimithelper. It also changes t…Docstring Coverage No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Full details: Linked Issues check
-
Explanation
Directly linked issue
#981has these coding requirements. Each one is met by the diff at the reviewed head.- Normalize a present limit at the store boundary: floor it and clamp it to [1, 200].
messagesLimitin packages/core/src/session/store.ts appliesMath.floor, thenMath.max(1, ...), thenMath.min(200, ...). Themessagesmethod calls it wheninput.limitis defined. - Non-finite limits use a documented default of 50.
messagesLimitreturnsMessageLimit.default(50) whenNumber.isFinite(limit)is false. The NaN, +Infinity, and -Infinity cases all take this path. The constant comment cites the HTTP handler page size. - An omitted limit stays unbounded. When
input.limit === undefined,limitis undefined and the code runsquery.all()with no.limit()call. - Valid limits keep their behavior. Integers in [1, 200] pass through
messagesLimitunchanged. - Tests cover the required cases. packages/core/test/session-store.test.ts seeds 250 messages and asserts: omitted gives 250; 2 gives 2; 2.9 gives 2; 1.5 gives 1; 0 gives 1; -5 gives 1; NaN gives 50; +Infinity and -Infinity give 50; 500 gives 200.
- No HTTP or protocol schema change. The diff touches only store.ts and the store test.
- Sibling
SessionStore.listcheck. The issue asks for the check and a note on the issue. The diff leaveslistunchanged, as the issue permits. The note itself is a non-code action and is not verified here.
I did not run the test suite. The pass result rests on the diff and on the test assertions. The test runs were reported in the PR description, and I did not re-run them.
- Normalize a present limit at the store boundary: floor it and clamp it to [1, 200].
Full details: Out of Scope Changes check
-
Explanation
The whole-PR diff (merge base 654a398 to head 56062b6) changes two files.
- packages/core/src/session/store.ts adds the
MessageLimitconstant and themessagesLimithelper. It also changes themessagesread to use the helper. This is the requirement from#981. - packages/core/test/session-store.test.ts adds one test case for the new limit behavior.
No other file changes appear in the diff. The
SessionStore.listpath, the protocol schema, the HTTP handler, andsession/transfer.tsare not changed. Thesession/transfer.tscaller keeps its unbounded read because the omitted-limit branch is unchanged. Every changed line supports the linked objective. - packages/core/src/session/store.ts adds the
Full details: Docstring Coverage
-
Explanation
No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 2 files.
-
Finishing Touches
-
📝 Generate docstrings
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
Issue for this PR
Closes #981
Type of change
What does this PR do?
SessionStore.messagestooklimitfrom a plain TypeScript type and handed it straight to Drizzle. In the SQLite dialect that means:NaNlimit emits noLIMITclause at all, so the read returns the whole session history and the protocol's[1,200]page cap is bypassed;Infinitylimit is bound as a parameter and SQLite rejects the query with a datatype mismatch;0returns no rows.The HTTP door already validates (
packages/protocol/src/groups/message.ts), but in-process callers reach the store directly. This normalises a present limit at the store boundary: floor it, clamp to[1,200](the protocol range), and use50(the HTTP handler's page size) for non-finite values. An omitted limit keeps today's unbounded behaviour, whichsession/transfer.tsrelies on for the full settled history. Valid limits behave exactly as before.The sibling
SessionStore.listwas checked for the same dialect behaviour: itslimitis typed with thePositiveIntschema and validated at the API door, but the store does not decodeListInputat runtime, so an in-process caller bypassing the schema would hit the same dialect outcome. Noted on the issue rather than changed here, to keep this PR to the messages path.How did you verify your code works?
packages/core->bun run test test/session-store.test.ts: 3 pass, 0 fail. The new test seeds 250 messages and pinsundefined(250, unbounded),2-> 2,2.9-> 2,1.5-> 1,0-> 1,-5-> 1,NaN/+/-Infinity-> 50, and500-> 200.Checklist
Need help on this PR? Tag
@codesmith-botwith what you need.Summary by CodeRabbit