Skip to content

fix(media-understanding): guard malformed attachments arrays#28024

Merged
steipete merged 1 commit intoopenclaw:mainfrom
claw9267:fix/malformed-attachments-guards
Mar 2, 2026
Merged

fix(media-understanding): guard malformed attachments arrays#28024
steipete merged 1 commit intoopenclaw:mainfrom
claw9267:fix/malformed-attachments-guards

Conversation

@claw9267
Copy link
Contributor

Fixes crashes when media-understanding receives malformed shapes (e.g. attachments undefined / non-array), which previously caused errors like: Cannot read properties of undefined (reading 'filter').\n\nChanges:\n- Add guard tests for malformed attachments/attempts arrays\n- Use Array.isArray guards in attachments selection/ordering and decision summary formatting\n\nTests:\n- `pnpm vitest run --config vitest.unit.config.ts src/media-understanding/*.test.ts\n

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 26, 2026

Greptile Summary

Added defensive guards to prevent crashes when media-understanding receives malformed data. The implementation properly handles cases where attachments or attempts arrays are undefined or non-arrays by using Array.isArray() checks and optional chaining.

Changes:

  • selectAttachments and orderAttachments now guard against undefined/non-array attachments parameters
  • formatDecisionSummary guards against malformed decision.attachments and entry.attempts arrays
  • Added comprehensive test coverage for all guard scenarios

Code Quality:

  • Defensive programming approach prevents runtime crashes from malformed input
  • Guards are placed early in functions before any array operations
  • Optional chaining (?.) consistently used for safe property access
  • Test coverage validates both undefined and non-array edge cases
  • Implementation follows repository TypeScript style guidelines

Confidence Score: 5/5

  • Safe to merge with high confidence
  • The changes are defensive guards that only improve safety without altering existing logic. The implementation is straightforward, well-tested, and follows best practices. All edge cases are properly handled with Array.isArray() checks and optional chaining. The test coverage validates the guard behavior for both undefined and non-array inputs.
  • No files require special attention

Last reviewed commit: 705b8ad

@steipete steipete merged commit 9c9ab89 into openclaw:main Mar 2, 2026
5 checks passed
@steipete
Copy link
Contributor

steipete commented Mar 2, 2026

Landed via temp rebase onto main.

  • Gate: pnpm vitest src/media-understanding/attachments.guards.test.ts src/media-understanding/runner.entries.guards.test.ts
  • Land commit: d4f3bf141e0097cfe2e1b521d6c918f32aab159d
  • Merge commit: 9c9ab89

Thanks @claw9267!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants