🐛 fix: add typeof guard before .trim() calls in context engine#13715
Merged
Conversation
Add `typeof !== 'string'` checks before `.trim()` calls in BaseSystemRoleProvider, SystemRoleInjector, and BaseProcessor to prevent TypeError when a non-string truthy value (e.g. object, array, number) is passed at runtime. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## canary #13715 +/- ##
========================================
Coverage 66.67% 66.67%
========================================
Files 1998 1998
Lines 169045 169063 +18
Branches 20404 19654 -750
========================================
+ Hits 112708 112728 +20
+ Misses 56214 56212 -2
Partials 123 123
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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.
💻 Change Type
🔗 Related Issue
Production
e.trim is not a functionTypeError during agentcall_llmstep.🔀 Description of Change
Add
typeof !== 'string'guard before.trim()calls in three locations within the context engine:BaseSystemRoleProvider.doProcess()—content.trim()SystemRoleInjector.buildSystemRoleContent()—systemRole.trim()BaseProcessor.isEmptyMessage()—message.trim()These locations use
!valueto check for falsy values before calling.trim(), but truthy non-string values (object, array, number) pass that check and crash. This happens in production whenagentConfig.systemRoleor abuildSystemRoleContent()return value becomes a non-string after Redis serialization round-trips between agent steps.🧪 How to Test
New test cases cover object, array, number, and boolean inputs for all three locations.
📝 Generated with Claude Code