fix: Add null checks in local-memory.ts to prevent role crash#438
Open
hggzm wants to merge 2 commits intomicrosoft:mainfrom
Open
fix: Add null checks in local-memory.ts to prevent role crash#438hggzm wants to merge 2 commits intomicrosoft:mainfrom
hggzm wants to merge 2 commits intomicrosoft:mainfrom
Conversation
Fixes microsoft/teams-sdk#2500 Fixes microsoft/teams-sdk#2503 - Add bounds check (len > 0) before accessing messages[0] - Add optional chaining for messages[0]?.role access - Add null guard and bounds check in collapse() loop - Prevents 'Cannot read properties of null (reading role)' crash Root cause: Array access without bounds checking when: 1. Messages array becomes empty during collapse 2. end index exceeds array bounds in collapse loop Co-authored-by: claude-swarm-agent <swarm@local>
- Tests for constructor, get, push, pop, values, where methods - Tests for collapse functionality with different strategies - Specific tests for null safety fixes: - Empty array access prevention - Optional chaining for messages[0].role - Bounds checking in collapse boundary detection All 21 tests pass with 81% coverage on local-memory.ts
Author
|
Added comprehensive test suite for Test Coverage: 81% on local-memory.ts
All tests pass. 🎉 |
|
@hggzm please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
corinagum
reviewed
Feb 12, 2026
Collaborator
corinagum
left a comment
There was a problem hiding this comment.
Thanks for the PR! LGTM. Do you mind rebasing with latest? Otherwise my review will be disregarded.
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.
Summary
Adds defensive null checks to prevent crashes when accessing message properties on empty or boundary arrays.
Changes
len > 0guard before array access in trim loop?.) formessages[0].roleaccesslast &&guard and bounds check in slice operationTesting
Fixes #2500, #2503