Skip to content

fix(core): normalise session message limits at the store boundary - #983

Merged
dezren39 merged 1 commit into
mainfrom
queue/3936-981-session-messages-limit
Oct 30, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/3936-981-session-messages-limit

Conversation

@dezren39

@dezren39 dezren39 commented Oct 30, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #981

Type of change

  • Bug fix

What does this PR do?

SessionStore.messages took limit from a plain TypeScript type and handed it straight to Drizzle. In the SQLite dialect that means:

  • a negative or NaN limit emits no LIMIT clause at all, so the read returns the whole session history and the protocol's [1,200] page cap is bypassed;
  • a fractional or Infinity limit is bound as a parameter and SQLite rejects the query with a datatype mismatch;
  • 0 returns 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 use 50 (the HTTP handler's page size) for non-finite values. An omitted limit keeps today's unbounded behaviour, which session/transfer.ts relies on for the full settled history. Valid limits behave exactly as before.

The sibling SessionStore.list was checked for the same dialect behaviour: its limit is typed with the PositiveInt schema and validated at the API door, but the store does not decode ListInput at 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 pins undefined (250, unbounded), 2 -> 2, 2.9 -> 2, 1.5 -> 1, 0 -> 1, -5 -> 1, NaN/+/-Infinity -> 50, and 500 -> 200.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

Summary by CodeRabbit

  • Bug Fixes
    • Message retrieval limits are now normalized consistently: fractional values are rounded down, limits are capped at 200 and kept to at least 1, and non-finite values default to 50. Leaving the limit unset still returns all matching messages.

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>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T12:03:02.270225Z 56062b6 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 69fa3acd-68d8-4297-a32a-a2d80e44a6e8
Commits

Reviewing files that changed from the base of the PR and between 654a398 and 56062b6.

Files selected for processing: 2
  • packages/core/src/session/store.ts
  • packages/core/test/session-store.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

SessionStore.messages now normalizes supplied limits before querying. Omitted limits still return all matching messages. Tests cover fractional, zero, negative, non-finite, and above-maximum values.

Changes: Message limit handling

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: Normal

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: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: normalizing session message limits at the store boundary.
Description check Passed 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 Passed Directly linked issue #981 has 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 Passed The whole-PR diff (merge base 654a398 to head 56062b6) changes two files.

- packages/core/src/session/store.ts adds the MessageLimit constant and the messagesLimit helper. It also changes t…
Docstring Coverage Passed 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 #981 has 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]. messagesLimit in packages/core/src/session/store.ts applies Math.floor, then Math.max(1, ...), then Math.min(200, ...). The messages method calls it when input.limit is defined.
  2. Non-finite limits use a documented default of 50. messagesLimit returns MessageLimit.default (50) when Number.isFinite(limit) is false. The NaN, +Infinity, and -Infinity cases all take this path. The constant comment cites the HTTP handler page size.
  3. An omitted limit stays unbounded. When input.limit === undefined, limit is undefined and the code runs query.all() with no .limit() call.
  4. Valid limits keep their behavior. Integers in [1, 200] pass through messagesLimit unchanged.
  5. 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.
  6. No HTTP or protocol schema change. The diff touches only store.ts and the store test.
  7. Sibling SessionStore.list check. The issue asks for the check and a note on the issue. The diff leaves list unchanged, 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.

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 MessageLimit constant and the messagesLimit helper. It also changes the messages read 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.list path, the protocol schema, the HTTP handler, and session/transfer.ts are not changed. The session/transfer.ts caller keeps its unbounded read because the omitted-limit branch is unchanged. Every changed line supports the linked objective.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dezren39
dezren39 merged commit 7b8d55b into main Oct 30, 2026
1 check passed
@dezren39
dezren39 deleted the queue/3936-981-session-messages-limit branch October 30, 2026 12:26
@dezren39
dezren39 restored the queue/3936-981-session-messages-limit branch November 1, 2026 10:28
@dezren39
dezren39 deleted the queue/3936-981-session-messages-limit branch November 2, 2026 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant