Skip to content

Fix: Create robust client parser for server responses#3

Merged
surfiniaburger merged 1 commit into
mainfrom
dipg-research
Oct 26, 2025
Merged

Fix: Create robust client parser for server responses#3
surfiniaburger merged 1 commit into
mainfrom
dipg-research

Conversation

@surfiniaburger

Copy link
Copy Markdown
Owner

No description provided.

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @surfiniaburger, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on improving the resilience of the client-side data parsing logic. By making the _parse_result method more robust, the client can now reliably interpret server responses despite variations in data structure, such as differing observation nesting levels or entirely missing keys. This enhancement prevents potential crashes and ensures a more stable interaction with the server, ultimately leading to a more fault-tolerant system.

Highlights

  • Robust Server Response Parsing: The client's _parse_result method has been significantly enhanced to robustly handle various inconsistencies and potential missing data in server responses.
  • Flexible Observation Handling: The parser now gracefully manages different nesting levels for the 'observation' key, specifically addressing single-nested structures from /reset and double-nested structures from /step endpoints.
  • Crash Prevention: Logic has been added to prevent crashes by ensuring actual_obs_data is always a dictionary and by using .get() with default values when constructing DIPGObservation, safeguarding against missing 'observation' data or sub-keys like 'context' and 'question'.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@surfiniaburger
surfiniaburger merged commit 7820e02 into main Oct 26, 2025
3 checks passed

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request significantly improves the robustness of the server response parser in the client, correctly handling various structures for the 'observation' data. The changes prevent potential crashes from inconsistent or missing data. My review includes a suggestion to make the parsing logic more concise while retaining its robustness. I've also identified that the done flag is missing from the parsed StepResult, which is a critical piece of information for the agent, and have suggested a fix.

Comment on lines 82 to 84
return StepResult(
observation=obs,
reward=payload.get("reward"),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The StepResult is missing the done flag. Server responses, particularly from the /step endpoint, include this flag to signal episode termination. It's crucial for the agent's control loop to receive this. Please add it to the StepResult construction.

        return StepResult(
            observation=obs,
            reward=payload.get("reward"),
            done=payload.get("done"),

Comment on lines +57 to +71
obs_data = payload.get("observation")

# ROBUSTNESS FIX: The server's /step endpoint returns a double-nested
# observation `{'observation': {'observation': {...}}}` while the /reset
# endpoint returns a single-nested one `{'observation': {...}}`.
# This code checks for the double-nesting and handles both cases gracefully.
if "observation" in obs_data:
# If it's double-nested (from /step), go one level deeper.
actual_obs_data = obs_data["observation"]
# Check if the object is a dictionary and contains the nested 'observation' key.
# This identifies the double-nested structure from the /step endpoint.
if isinstance(obs_data, dict) and "observation" in obs_data:
# If so, go one level deeper to get the actual data payload.
actual_obs_data = obs_data.get("observation")
else:
# If it's single-nested (from /reset), use the data directly.
# Otherwise, it's either the single-nested structure from /reset or None.
actual_obs_data = obs_data

# To prevent crashes, ensure `actual_obs_data` is a dictionary before
# we try to access keys from it. If it was None, it becomes an empty dict.
if not isinstance(actual_obs_data, dict):
actual_obs_data = {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The logic to handle different observation structures (single-nested, double-nested, or missing) is correct but can be made more concise. You can simplify this block to reduce redundancy and improve readability by combining the unwrapping and default-value-setting steps.

        obs_data = payload.get("observation")

        # Unwrap if the observation is double-nested (from /step endpoint)
        if isinstance(obs_data, dict) and "observation" in obs_data:
            obs_data = obs_data.get("observation")

        # Ensure we have a dictionary for the observation data, defaulting to an
        # empty one if it's missing or not a dict. This prevents crashes.
        actual_obs_data = obs_data if isinstance(obs_data, dict) else {}

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