Skip to content

🐛 fix: add typeof guard before .trim() calls in context engine#13715

Merged
arvinxx merged 1 commit into
canaryfrom
fix/context-engine-trim-guard
Apr 10, 2026
Merged

🐛 fix: add typeof guard before .trim() calls in context engine#13715
arvinxx merged 1 commit into
canaryfrom
fix/context-engine-trim-guard

Conversation

@arvinxx

@arvinxx arvinxx commented Apr 10, 2026

Copy link
Copy Markdown
Member

💻 Change Type

  • 🐛 fix

🔗 Related Issue

Production e.trim is not a function TypeError during agent call_llm step.

🔀 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 !value to check for falsy values before calling .trim(), but truthy non-string values (object, array, number) pass that check and crash. This happens in production when agentConfig.systemRole or a buildSystemRoleContent() return value becomes a non-string after Redis serialization round-trips between agent steps.

🧪 How to Test

  • Added/updated tests

New test cases cover object, array, number, and boolean inputs for all three locations.

📝 Generated with Claude Code

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>
@vercel

vercel Bot commented Apr 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lobehub Ready Ready Preview, Comment Apr 10, 2026 6:03am

Request Review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've reviewed this pull request using the Sourcery rules engine

@codecov

codecov Bot commented Apr 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.67%. Comparing base (a23e159) to head (a77224d).
⚠️ Report is 13 commits behind head on canary.

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            
Flag Coverage Δ
app 58.68% <ø> (+<0.01%) ⬆️
database 92.58% <ø> (ø)
packages/agent-runtime 79.72% <ø> (ø)
packages/context-engine 83.33% <100.00%> (ø)
packages/conversation-flow 92.36% <ø> (ø)
packages/file-loaders 87.02% <ø> (ø)
packages/memory-user-memory 74.74% <ø> (ø)
packages/model-bank 99.85% <ø> (ø)
packages/model-runtime 84.58% <ø> (ø)
packages/prompts 69.69% <ø> (ø)
packages/python-interpreter 92.90% <ø> (ø)
packages/ssrf-safe-fetch 0.00% <ø> (ø)
packages/utils 90.14% <ø> (ø)
packages/web-crawler 88.66% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Store 66.77% <ø> (ø)
Services 52.22% <ø> (ø)
Server 66.26% <72.00%> (+0.01%) ⬆️
Libs 52.82% <ø> (ø)
Utils 91.01% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@arvinxx arvinxx merged commit b95720d into canary Apr 10, 2026
31 checks passed
@arvinxx arvinxx deleted the fix/context-engine-trim-guard branch April 10, 2026 06:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant