Skip to content

Comments

Fix Realtime message ID#381

Merged
KaQuMiQ merged 1 commit intomainfrom
feature/realtime_id
Jul 31, 2025
Merged

Fix Realtime message ID#381
KaQuMiQ merged 1 commit intomainfrom
feature/realtime_id

Conversation

@KaQuMiQ
Copy link
Collaborator

@KaQuMiQ KaQuMiQ commented Jul 31, 2025

No description provided.

@coderabbitai
Copy link

coderabbitai bot commented Jul 31, 2025

Walkthrough

This set of changes includes updates across several files. The project version in pyproject.toml is incremented from 0.82.0 to 0.82.1. In src/draive/conversation/realtime/default.py, the metadata key "identifier" is renamed to "call_id" for tool call events. The ConversationMessage.from_lmm_context method in src/draive/conversation/types.py is refactored to use explicit type checks instead of a pattern match. In src/draive/openai/lmm_session.py, a helper function centralizes the generation and management of message identifiers using UUIDs, replacing previous direct uses of event and item IDs. In src/draive/stages/stage.py, exception handling is updated to check exception types rather than instances in the fallback logic.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/realtime_id

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@KaQuMiQ KaQuMiQ force-pushed the feature/realtime_id branch from a08b945 to 6490769 Compare July 31, 2025 12:51
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 43d6d05 and 6490769.

📒 Files selected for processing (5)
  • pyproject.toml (1 hunks)
  • src/draive/conversation/realtime/default.py (1 hunks)
  • src/draive/conversation/types.py (1 hunks)
  • src/draive/openai/lmm_session.py (12 hunks)
  • src/draive/stages/stage.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

📄 CodeRabbit Inference Engine (CLAUDE.md)

**/*.py: Use absolute imports from draive package
Follow Ruff import ordering (standard library, third party, local)
Use Python 3.12+ type features (type unions with |, generic syntax)
Use base and abstract types like Sequence or Iterable instead of concrete types
Use custom exceptions for specific errors
Use NumPy docstring convention for all functions, classes, and methods
Skip module-level docstrings unless explicitly requested
Include sections: Parameters, Returns, Raises, Notes (if needed) in docstrings
ALWAYS use Sequence[T] instead of list[T], Mapping[K,V] instead of dict[K,V], and Set[T] instead of set[T] for collections in State, Config and DataModel classes
Immutable updates to State, Config, and DataModel classes should be performed through the .updated() method

Files:

  • src/draive/conversation/realtime/default.py
  • src/draive/stages/stage.py
  • src/draive/conversation/types.py
  • src/draive/openai/lmm_session.py
🧠 Learnings (7)
📓 Common learnings
Learnt from: KaQuMiQ
PR: miquido/draive#338
File: src/draive/lmm/__init__.py:1-2
Timestamp: 2025-06-16T10:28:07.434Z
Learning: The draive project requires Python 3.12+ as specified in pyproject.toml with "requires-python = ">=3.12"" and uses Python 3.12+ specific features like PEP 695 type aliases and generic syntax extensively throughout the codebase.
📚 Learning: the draive project requires python 3.12+ as specified in pyproject.toml with "requires-python = ">=3...
Learnt from: KaQuMiQ
PR: miquido/draive#338
File: src/draive/lmm/__init__.py:1-2
Timestamp: 2025-06-16T10:28:07.434Z
Learning: The draive project requires Python 3.12+ as specified in pyproject.toml with "requires-python = ">=3.12"" and uses Python 3.12+ specific features like PEP 695 type aliases and generic syntax extensively throughout the codebase.

Applied to files:

  • pyproject.toml
📚 Learning: the draive project uses and requires python 3.12+, so pep-695 generic syntax with square brackets (e...
Learnt from: KaQuMiQ
PR: miquido/draive#327
File: src/draive/helpers/instruction_preparation.py:28-34
Timestamp: 2025-05-28T17:41:57.460Z
Learning: The draive project uses and requires Python 3.12+, so PEP-695 generic syntax with square brackets (e.g., `def func[T: Type]()`) is valid and should be used instead of the older TypeVar approach.

Applied to files:

  • pyproject.toml
📚 Learning: applies to **/*.py : use absolute imports from `draive` package...
Learnt from: CR
PR: miquido/draive#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-21T11:09:57.256Z
Learning: Applies to **/*.py : Use absolute imports from `draive` package

Applied to files:

  • pyproject.toml
📚 Learning: applies to **/*.py : use custom exceptions for specific errors...
Learnt from: CR
PR: miquido/draive#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-21T11:09:57.256Z
Learning: Applies to **/*.py : Use custom exceptions for specific errors

Applied to files:

  • src/draive/stages/stage.py
📚 Learning: conversationmessage is a datamodel with built-in runtime validation. when calling methods like conve...
Learnt from: KaQuMiQ
PR: miquido/draive#338
File: src/draive/conversation/completion/state.py:61-68
Timestamp: 2025-06-16T10:01:14.014Z
Learning: ConversationMessage is a DataModel with built-in runtime validation. When calling methods like ConversationMessage.user(multimodal), the DataModel validates types at runtime and raises appropriate exceptions for invalid inputs, eliminating the need for explicit type checking in pattern matching.

Applied to files:

  • src/draive/conversation/types.py
📚 Learning: in the draive.commons.metadata.meta class, properties like `identifier`, `origin_identifier`, `prede...
Learnt from: KaQuMiQ
PR: miquido/draive#338
File: src/draive/conversation/types.py:123-144
Timestamp: 2025-06-16T10:09:51.508Z
Learning: In the draive.commons.metadata.Meta class, properties like `identifier`, `origin_identifier`, `predecessor_identifier`, and `successor_identifier` automatically parse stored hex strings into UUID objects when accessed, returning None if the string is missing or invalid. This means accessing `meta.identifier` returns a UUID object, not a string, even though it's stored internally as a hex string.

Applied to files:

  • src/draive/openai/lmm_session.py
🔇 Additional comments (7)
pyproject.toml (1)

8-8: LGTM - Appropriate version bump.

The patch version increment from 0.82.0 to 0.82.1 correctly follows semantic versioning for a bug fix related to realtime message ID handling.

src/draive/stages/stage.py (1)

1744-1744: Critical bug fix - Exception type checking corrected.

The change from if exc in exceptions: to if type(exc) in exceptions: fixes a logical error where exception instances were being compared to exception types, which would never match. The fallback mechanism now correctly checks if the caught exception's type is in the allowed exceptions collection.

src/draive/conversation/realtime/default.py (1)

136-136: LGTM - Improved metadata key naming.

The rename from "identifier" to "call_id" provides better semantic clarity for tool call events and aligns with the broader effort to standardize identifier management across the codebase.

src/draive/conversation/types.py (1)

127-142: LGTM - Clean refactor to explicit type checking.

The replacement of pattern matching with explicit isinstance checks maintains the same functionality while providing clear, readable type handling. The assertion ensures type safety for the else branch, and the logic correctly maps LMMCompletion to model messages and LMMInput to user messages.

src/draive/openai/lmm_session.py (3)

122-137: LGTM! Well-designed identifier management function.

The message_identifier helper function provides a clean abstraction for UUID-based identifier generation and caching. The implementation correctly:

  • Uses a closure to access current_items
  • Caches identifiers to avoid regeneration for the same item_id
  • Returns consistent UUID strings
  • Stores metadata alongside the identifier

163-163: Consistent identifier usage - excellent standardization.

All the calls to message_identifier(event.item_id) and message_identifier(event.item.id) provide consistent UUID-based identifiers instead of using raw event IDs. This standardization improves identifier management across the session.

Also applies to: 173-173, 183-183, 193-193, 206-206, 216-216, 280-280, 293-293, 303-303


321-322: Improved metadata structure for conversation items.

The changes to explicitly store both "item_id" and "identifier" (as UUID string) in the Meta objects provide better separation of concerns:

  • "item_id" maintains the original OpenAI item identifier
  • "identifier" provides the standardized UUID for internal use

This aligns well with the new message_identifier function's caching mechanism.

Also applies to: 333-334

@KaQuMiQ KaQuMiQ merged commit 7759dd4 into main Jul 31, 2025
5 checks passed
@KaQuMiQ KaQuMiQ deleted the feature/realtime_id branch July 31, 2025 12:56
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