Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue Link (REQUIRED)
Fixes #732
Summary
Changes
The TypeScript
ChatStorage.trimConversation()rounds an oddmaxHistorySizedown to keep complete user/assistant pairs, then slicesconversation.slice(-adjustedMaxHistorySize):For
maxHistorySize=0(and=1, rounded to 0)adjustedis 0, andconversation.slice(-0)isconversation.slice(0)— the whole array. Asking to keep at most 0 messages therefore kept all of them.InMemoryChatStorage.saveChatMessage()andfetchChat()both use this helper, so TS callers passing 0 or 1 get unbounded history.This PR adds an explicit guard returning
[]whenadjustedMaxHistorySize <= 0, and a regression test intypescript/tests/storage/ChatStorage.test.tscovering 0, 1, a size >= 2, andundefined. No change forundefinedor even/odd sizes >= 2.The Python implementation had the same
[-0:]defect and was fixed in #731. This is the independent TypeScript codebase (different file, different language, different test suite), so it needs its own fix; without it TS users remain affected.User experience
Before:
fetchChat(..., 0)andfetchChat(..., 1)returned the entire history. After: both return an empty list.Checklist
Is this a breaking change?
No. Only the 0/1 boundary changes; all sizes >= 2 and
undefinedbehave as before.Verification
Compiled the real
typescript/src/storage/chatStorage.ts(andmemoryChatStorage.ts) with TypeScript 5.5.4 to CommonJS in an isolated task-directory environment, with minimal stubs only for thetypes/loggertype imports. No AWS SDK, jest, or global install was needed. Node 22 executed the compiled production code.trimConversationon a 10-item conversation:0 -> 10,1 -> 10,2 -> 2,3 -> 2,4 -> 4,5 -> 4,10 -> 10,undefined -> 10.0 -> 0,1 -> 0, with 2/3/4/5/10/undefined unchanged. 8assert.strictEqualchecks passed.InMemoryChatStoragepublic API (save 4 alternating-role messages, thenfetchChat):(...,0) -> 0,(...,1) -> 0,(...,2) -> 2,(...,undefined) -> 4, and the last kept message isAnother answer. These are exactly the assertions in the new jest regression test.git diff --checkpasses. Net diff is 2 files, 26 insertions / 1 deletion.Not done: the repository's full
npm test(jest + ts-jest) was not run because installing the full dev dependency tree (AWS SDK and friends) did not complete in this environment. Instead the compiled production TypeScript was exercised directly with Node assertions, as described above. No cloud services were used.AI Assistance
This PR was prepared with the help of an AI coding agent (WorkBuddy). The agent read the TypeScript and Python implementations, compiled the real TypeScript source, ran the reproduction and assertions above locally, and reviewed the resulting diff. The account owner has not personally run these tests.
Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.