Skip to content

Fix MessageValidator default message metadata#2011

Open
fallintoplace wants to merge 1 commit into
NVIDIA:developfrom
fallintoplace:fix/message-validator-defaults
Open

Fix MessageValidator default message metadata#2011
fallintoplace wants to merge 1 commit into
NVIDIA:developfrom
fallintoplace:fix/message-validator-defaults

Conversation

@fallintoplace

@fallintoplace fallintoplace commented Jun 7, 2026

Copy link
Copy Markdown

Summary

  • Generate message IDs and timestamps inside the MessageValidator factory methods when callers omit them.
  • Replace factory-level content defaults with None where the helper builds fallback content.
  • Add regression coverage for all four WebSocket message factories.

Root cause

Python evaluates default arguments once when the function is defined. The previous UUID, timestamp, and content defaults were reused across calls that omitted those parameters, which could duplicate WebSocket message IDs and preserve stale timestamps in validation/error paths.

Validation

  • uv run --frozen --extra test pytest packages/nvidia_nat_core/tests/nat/front_ends/test_message_validator.py
  • uv run --frozen --extra test pytest packages/nvidia_nat_core/tests/nat/server/test_unified_api_server.py -k "websocket_message or create_observability_trace_message or websocket_error_message"
  • uv run --frozen ruff check packages/nvidia_nat_core/src/nat/front_ends/fastapi/message_validator.py packages/nvidia_nat_core/tests/nat/front_ends/test_message_validator.py

Summary by CodeRabbit

New Features

  • Enhanced message creation capabilities with support for optional custom identifiers and timestamps; system automatically generates these values when not explicitly supplied.
  • Improved system message content defaults with optional configuration.

Tests

  • Comprehensive test coverage added to verify automatic ID and timestamp generation across all message creation scenarios.

@fallintoplace fallintoplace requested a review from a team as a code owner June 7, 2026 15:34
@copy-pr-bot

copy-pr-bot Bot commented Jun 7, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Jun 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 1cadda0b-d083-4a31-b4a3-b3daa6cce0a2

📥 Commits

Reviewing files that changed from the base of the PR and between 1cd7a85 and 12b0564.

📒 Files selected for processing (2)
  • packages/nvidia_nat_core/src/nat/front_ends/fastapi/message_validator.py
  • packages/nvidia_nat_core/tests/nat/front_ends/test_message_validator.py

Walkthrough

Four factory methods in MessageValidator are refactored to accept optional message_id, content, and timestamp parameters, moving default value generation from function signatures to method bodies. Tests validate that defaults are correctly generated when parameters are omitted.

Changes

Message Factory Default Refactoring

Layer / File(s) Summary
Factory method signature and implementation updates
packages/nvidia_nat_core/src/nat/front_ends/fastapi/message_validator.py
create_system_response_token_message, create_system_intermediate_step_message, create_system_interaction_message, and create_observability_trace_message now accept optional message_id and timestamp parameters. Default value generation for UUIDs and timestamps moves from function signatures into method bodies. SystemResponseContent and SystemIntermediateStepContent become optional parameters with defaults assigned inside the method.
Test validation of factory defaults
packages/nvidia_nat_core/tests/nat/front_ends/test_message_validator.py
Imports are expanded to include datetime, uuid, and additional message type dependencies. New TestMessageFactoryDefaults test class monkeypatches UUID and datetime generation inside the message validator module, then invokes all four factory methods to verify that fresh sequential IDs and incrementing timestamps are generated when optional parameters are omitted.

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change—fixing how MessageValidator handles default message metadata by generating them inside factory methods rather than at definition time.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Signed-off-by: Minh Vu <vuhoangminh97@gmail.com>
@fallintoplace fallintoplace force-pushed the fix/message-validator-defaults branch from 689f4d1 to 12b0564 Compare June 7, 2026 15:35
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