Skip to content

fix(agent): handle None content in context compressor #216

Closed
Farukest wants to merge 1 commit into
NousResearch:mainfrom
Farukest:fix/context-compressor-none-content
Closed

fix(agent): handle None content in context compressor #216
Farukest wants to merge 1 commit into
NousResearch:mainfrom
Farukest:fix/context-compressor-none-content

Conversation

@Farukest

Copy link
Copy Markdown
Contributor

_generate_summary in context_compressor.py crashes with TypeError when any message in the summarized range has content: None.

Root cause

dict.get("content", "") returns the default "" only when the key is missing. When the key exists with value None, it returns None. Calling len(None) on line 90 raises TypeError, and string concatenation on line 96 also fails.

The OpenAI API returns content: null on assistant messages that only contain tool calls. This is normal behavior - every tool-calling conversation will have these messages. When the conversation runs long enough to trigger context compression, these None values reach _generate_summary and crash it.

Fix

Replaced msg.get("content", "") with msg.get("content") or "" in two locations. This handles both missing keys and explicit None values.

Tests

Added TestGenerateSummaryNoneContent with two regression tests:

  • content: None in assistant messages with tool calls
  • content: None in system messages during compress

All 17 tests pass.

Closes #211

teknium1 added a commit that referenced this pull request Mar 2, 2026
The OpenAI API returns content: null on assistant messages that only
contain tool calls. msg.get('content', '') returns None (not '') when
the key exists with value None, causing TypeError on len() and string
concatenation in _generate_summary and compress.

Fix: msg.get('content') or '' — handles both missing keys and None.

Tests from PR #216 (@Farukest). Fix also in PR #215 (@cutepawss).
Both PRs had stale branches and couldn't be merged directly.

Closes #211
@teknium1

teknium1 commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

Thanks @Farukest — great issue report and the regression tests are exactly what we needed! The code fix is identical to PR #215, but your tests add real value.

Unfortunately, the PR branch is based on an older version of main and includes ~9,400 lines of unrelated deletions across 67 files, so we couldn't merge it directly.

We applied the fix + your tests in commit 25c65bc with credit to you. If you'd like to contribute in the future, rebasing onto the latest main before opening a PR will keep things clean. 🙏

@teknium1 teknium1 closed this Mar 2, 2026
@Farukest

Farukest commented Mar 3, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @Farukest — great issue report and the regression tests are exactly what we needed! The code fix is identical to PR #215, but your tests add real value.

Unfortunately, the PR branch is based on an older version of main and includes ~9,400 lines of unrelated deletions across 67 files, so we couldn't merge it directly.

We applied the fix + your tests in commit 25c65bc with credit to you. If you'd like to contribute in the future, rebasing onto the latest main before opening a PR will keep things clean. 🙏

Thanks for applying the fix with credit 👍
Noted on rebasing -- I've been doing that on the later PRs.

angelburgosrosado pushed a commit to angelburgosrosado/hermes-agent that referenced this pull request Apr 27, 2026
…arch#211)

The OpenAI API returns content: null on assistant messages that only
contain tool calls. msg.get('content', '') returns None (not '') when
the key exists with value None, causing TypeError on len() and string
concatenation in _generate_summary and compress.

Fix: msg.get('content') or '' — handles both missing keys and None.

Tests from PR NousResearch#216 (@Farukest). Fix also in PR NousResearch#215 (@cutepawss).
Both PRs had stale branches and couldn't be merged directly.

Closes NousResearch#211
olympus-terminal pushed a commit to olympus-terminal/hermes-agent that referenced this pull request May 16, 2026
…arch#211)

The OpenAI API returns content: null on assistant messages that only
contain tool calls. msg.get('content', '') returns None (not '') when
the key exists with value None, causing TypeError on len() and string
concatenation in _generate_summary and compress.

Fix: msg.get('content') or '' — handles both missing keys and None.

Tests from PR NousResearch#216 (@Farukest). Fix also in PR NousResearch#215 (@cutepawss).
Both PRs had stale branches and couldn't be merged directly.

Closes NousResearch#211
Egavasyug pushed a commit to Egavasyug/hermes-agent that referenced this pull request Jun 10, 2026
…arch#211)

The OpenAI API returns content: null on assistant messages that only
contain tool calls. msg.get('content', '') returns None (not '') when
the key exists with value None, causing TypeError on len() and string
concatenation in _generate_summary and compress.

Fix: msg.get('content') or '' — handles both missing keys and None.

Tests from PR NousResearch#216 (@Farukest). Fix also in PR NousResearch#215 (@cutepawss).
Both PRs had stale branches and couldn't be merged directly.

Closes NousResearch#211
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.

Context compressor crashes with TypeError when message content is None

2 participants