Skip to content

Conversation

@WaelBKZ
Copy link
Contributor

@WaelBKZ WaelBKZ commented Aug 22, 2025

  • Replace unsafe unwrap() calls with defensive pattern matching

Fixes #2586

Overview:

Fixes intermittent logging::tests::test_json_log_capture failures when run with other tests. The test was panicking on .unwrap() calls when accessing span_name fields that don't exist in ERROR logs from background tasks.

Details:

Root cause: logging::tests::test_json_log_capture tests assumed all log lines have span_name field, but PR #2406 introduced error logs using tracing::error! when tasks fail. These error logs contaminate the JSON log output captured by the test but don't contain span_name fields since they're regular log messages, not span events.

Why intermittent:

  • Passes in isolation (no other tests = no contaminating errors)
  • Fails with other tests (failing tasks = log contamination = panic with unwrap)

Solution: Replace unsafe .unwrap() calls with defensive if let pattern matching that gracefully skips log lines without span_name fields.

Testing results: After the fix, ran the test 100 times and it passed 100 times (see test.log)

Where should the reviewer start?

  • lib/runtime/src/logging.rs lines 1011-1047: The three test assertion blocks that were updated with defensive pattern matching

Related Issues:

Summary by CodeRabbit

  • Tests
    • Hardened logging tests to avoid panics by safely handling missing or non-string span_name fields in parent/child/grandchild cases.
    • Maintains existing assertions when fields are present, improving reliability of the test suite and CI stability without altering runtime behavior.
    • No changes to exported APIs or user-facing functionality.

- Replace unsafe unwrap() calls with defensive pattern matching

Fixes ai-dynamo#2586
@WaelBKZ WaelBKZ requested a review from a team as a code owner August 22, 2025 21:57
@copy-pr-bot
Copy link

copy-pr-bot bot commented Aug 22, 2025

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.

@github-actions
Copy link

👋 Hi WaelBKZ! Thank you for contributing to ai-dynamo/dynamo.

Just a reminder: The NVIDIA Test Github Validation CI runs an essential subset of the testing framework to quickly catch errors.Your PR reviewers may elect to test the changes comprehensively before approving your changes.

🚀

@github-actions github-actions bot added the external-contribution Pull request is from an external contributor label Aug 22, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 22, 2025

Walkthrough

Replaces unwrap-based assertions on span_name in logging test blocks (parent/child/grandchild) with nested Option checks using if-let to avoid panics when fields are absent or non-string. Assertions on parent_id relationships remain unchanged. No public API or production code modified.

Changes

Cohort / File(s) Summary
Logging test robustness
lib/runtime/src/logging.rs
Replaced unwrap() chains on span_name with guarded if let checks in parent/child/grandchild blocks; maintained existing assertions on parent_id and span relationships; no API changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Assessment against linked issues

Objective Addressed Explanation
Stabilize logging::tests::test_json_log_capture by removing unwrap-induced panics on missing/non-string span_name (#2586)

Assessment against linked issues: Out-of-scope changes

(no out-of-scope changes identified)

Poem

A rabbit taps the test log stream,
No more panics break the theme.
Parent, child, and grandchild too—
Option nests guide safely through.
Flakes hop off, the runs are clean,
Green meadows fill the build machine. 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

Copy link
Contributor

@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: 0

🧹 Nitpick comments (3)
lib/runtime/src/logging.rs (3)

1012-1017: Simplify nested option checks with a single guard

Current logic is correct and defensive. You can tighten it up by collapsing the nested if-lets into a single guard; this keeps the intent clear and avoids an extra level of indentation.

-                    if let Some(span_name) = log_line.get("span_name") {
-                        if let Some(span_name_str) = span_name.as_str() {
-                            if span_name_str == "parent" {
-                                assert!(log_line.get("parent_id").is_none());
-                            }
-                        }
-                    }
+                    if matches!(log_line.get("span_name").and_then(|v| v.as_str()), Some("parent")) {
+                        assert!(log_line.get("parent_id").is_none());
+                    }

1023-1031: Remove unwraps on parent_id; assert on Option<&str> to stay panic-free

Nice defensive guard for span_name. For consistency with the PR goal (no panics when fields are missing), avoid the remaining unwraps on parent_id. As parent_id is optional in the schema, assert on the Option directly. Behavior is unchanged, but this eliminates a potential panic surface if formatting ever omits/changes the type.

-                    if let Some(span_name) = log_line.get("span_name") {
-                        if let Some(span_name_str) = span_name.as_str() {
-                            if span_name_str == "child" {
-                                assert_eq!(
-                                    log_line.get("parent_id").unwrap().as_str().unwrap(),
-                                    &parent_span_id
-                                );
-                            }
-                        }
-                    }
+                    if matches!(log_line.get("span_name").and_then(|v| v.as_str()), Some("child")) {
+                        assert_eq!(
+                            log_line.get("parent_id").and_then(|v| v.as_str()),
+                            Some(parent_span_id.as_str())
+                        );
+                    }

1037-1045: Mirror the child fix for grandchild to avoid unwraps and keep tests robust

Same rationale as above: compare Option<&str> instead of unwrapping parent_id. This keeps the test resilient if future changes alter the presence/type of parent_id while preserving the assertion semantics.

-                    if let Some(span_name) = log_line.get("span_name") {
-                        if let Some(span_name_str) = span_name.as_str() {
-                            if span_name_str == "grandchild" {
-                                assert_eq!(
-                                    log_line.get("parent_id").unwrap().as_str().unwrap(),
-                                    &child_span_id
-                                );
-                            }
-                        }
-                    }
+                    if matches!(log_line.get("span_name").and_then(|v| v.as_str()), Some("grandchild")) {
+                        assert_eq!(
+                            log_line.get("parent_id").and_then(|v| v.as_str()),
+                            Some(child_span_id.as_str())
+                        );
+                    }
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 0bd4995 and a0e0ff6.

📒 Files selected for processing (1)
  • lib/runtime/src/logging.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: pre-merge-rust (lib/runtime/examples)
  • GitHub Check: pre-merge-rust (.)
  • GitHub Check: pre-merge-rust (lib/bindings/python)
  • GitHub Check: Build and Test - dynamo

Copy link
Contributor

@rmccorm4 rmccorm4 left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @WaelBKZ !

@rmccorm4 rmccorm4 merged commit f19b44a into ai-dynamo:main Aug 22, 2025
13 checks passed
hhzhang16 pushed a commit that referenced this pull request Aug 27, 2025
Signed-off-by: Hannah Zhang <hannahz@nvidia.com>
jasonqinzhou pushed a commit that referenced this pull request Aug 30, 2025
Signed-off-by: Jason Zhou <jasonzho@jasonzho-mlt.client.nvidia.com>
KrishnanPrash pushed a commit that referenced this pull request Sep 2, 2025
Signed-off-by: Krishnan Prashanth <kprashanth@nvidia.com>
nnshah1 pushed a commit that referenced this pull request Sep 8, 2025
Signed-off-by: nnshah1 <neelays@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contribution Pull request is from an external contributor fix size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] intermittent logging::tests::test_json_log_capture failures

2 participants