Skip to content

fix: Add null checks in local-memory.ts to prevent role crash#1

Open
hggzm wants to merge 2 commits intomainfrom
fix/null-role-crash
Open

fix: Add null checks in local-memory.ts to prevent role crash#1
hggzm wants to merge 2 commits intomainfrom
fix/null-role-crash

Conversation

@hggzm
Copy link
Copy Markdown
Owner

@hggzm hggzm commented Jan 23, 2026

Summary

Fixes random 'Cannot read properties of null (reading role)' crashes in the AI package.

Issues

Changes

  • 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

Root Cause

Array access without bounds checking when:

  1. Messages array becomes empty during collapse
  2. End index exceeds array bounds in collapse loop

Testing

  • ESLint passes
  • TypeScript type-safe (optional chaining)

This PR is for review before contributing to microsoft/teams.ts

hggzm and others added 2 commits January 22, 2026 05:52
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
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