Skip to content

Fix: don't skip user messages to extract identity #125

Merged
2 commits merged intomainfrom
fix-maybe-identity
Apr 25, 2026
Merged

Fix: don't skip user messages to extract identity #125
2 commits merged intomainfrom
fix-maybe-identity

Conversation

@ea-rus
Copy link
Copy Markdown
Collaborator

@ea-rus ea-rus commented Apr 21, 2026

self._cortex.maybe_update_identity is called on every 5th message. and only the last message is sent to it
Fix: accumulate previous messages and send all of them on 5th step

@entelligence-ai-pr-reviews
Copy link
Copy Markdown

EntelligenceAI PR Summary

Refactors identity update logic in anton/core/session.py to use a buffered, batched approach for richer context across conversation turns.

  • Introduced _identity_buffer list to accumulate user inputs across turns
  • Every 5 turns, all buffered inputs are joined into a single concatenated string and passed to maybe_update_identity
  • Buffer is cleared after each batch dispatch
  • Removed the prior isinstance(user_input, str) type guard

Confidence Score: 2/5 - Changes Needed

Not safe to merge — the refactor in anton/core/session.py introduces a runtime TypeError by unconditionally appending user_input (typed str | list[dict]) to _identity_buffer: list[str], then calling "\n\n".join(self._identity_buffer) which will crash when user_input is a list[dict]. The PR's goal of buffering and batching identity updates across turns is a reasonable improvement, but removing the isinstance(user_input, str) guard without replacing it with equivalent type-safe handling breaks the multi-modal input path that the guard was explicitly protecting.

Key Findings:

  • In _identity_buffer accumulation logic, user_input of type list[dict] is appended without type-checking, causing "\n\n".join(self._identity_buffer) to raise TypeError at batch dispatch time — a direct crash on any non-string user input.
  • The original isinstance(user_input, str) guard was not merely a style choice; it was load-bearing logic that filtered out structured (multi-modal) inputs before string operations. Removing it without a replacement or serialization strategy is a correctness regression.
  • The batching logic itself (every 5 turns, clear buffer) is otherwise sound in concept, but the buffer should either enforce list[str] at insertion time with a type guard, or serialize list[dict] inputs to a string representation before appending.
Files requiring special attention
  • anton/core/session.py

Copy link
Copy Markdown

@entelligence-ai-pr-reviews entelligence-ai-pr-reviews Bot left a comment

Choose a reason for hiding this comment

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

Refactors identity update logic in anton/core/session.py to use a buffered, batched approach for richer context across conversation turns.

  • Introduced _identity_buffer list to accumulate user inputs across turns
  • Every 5 turns, all buffered inputs are joined into a single concatenated string and passed to maybe_update_identity
  • Buffer is cleared after each batch dispatch
  • Removed the prior isinstance(user_input, str) type guard

Comment thread anton/core/session.py
Comment on lines 784 to +789
self._persist_history()
if self._cortex is not None and self._cortex.mode != "off":
if self._turn_count % 5 == 0 and isinstance(user_input, str):
asyncio.create_task(self._cortex.maybe_update_identity(user_input))
self._identity_buffer.append(user_input)
if self._turn_count % 5 == 0:
buffered = "\n\n".join(self._identity_buffer)
self._identity_buffer.clear()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Correctness: user_input is typed str | list[dict], and the old code guarded with isinstance(user_input, str) before using it; the new code unconditionally appends it to _identity_buffer: list[str], so when user_input is a list[dict], the subsequent "\n\n".join(self._identity_buffer) raises TypeError: sequence item N: expected str instance, list found.

🤖 AI Agent Prompt for Cursor/Windsurf

📋 Copy this prompt to your AI coding assistant (Cursor, Windsurf, etc.) to get help fixing this issue

In anton/core/session.py around line 784, the diff removed the `isinstance(user_input, str)` guard before appending to `self._identity_buffer`. Since `user_input` is typed `str | list[dict]`, appending a `list[dict]` value to `_identity_buffer: list[str]` and then calling `'\n\n'.join(self._identity_buffer)` at line 787 will raise a TypeError at runtime. Fix: wrap the append in `if isinstance(user_input, str):` to restore the original type guard, while keeping the new buffering/flush logic intact.

@ea-rus ea-rus requested a review from tino097 April 22, 2026 09:16
@alecantu7
Copy link
Copy Markdown
Contributor

Nice catch on the missing messages. One concern on the approach: _identity_buffer lives only on the live session, so if Anton restarts mid-window the buffered turns are lost and never scanned. Reading the last 5 user messages from self._history at flush time would be restart-safe and avoid the extra state.

Minor: this diff references user_msg_str, which I don't see defined in main — looks like it depends on a sibling change that hasn't landed yet.

@github-merge-queue github-merge-queue Bot closed this pull request by merging all changes into main in 326dfe2 Apr 25, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 25, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants