fix(runners): preserve initial session state keys during rewind#4845
fix(runners): preserve initial session state keys during rewind#4845saiprasanth-git wants to merge 8 commits intogoogle:mainfrom
Conversation
Fixes google#4598: When a URL contains a fragment component (e.g., #triggerId=abc123), the fragment was being silently dropped. This caused HTTP 400 errors when APIs expect fragment-encoded parameters to be passed as query string parameters. This change parses the URL fragment using parse_qs and merges the extracted key-value pairs into query_params (using setdefault to avoid overriding explicitly-passed values), consistent with how URL query strings are handled.
…params Adds test_prepare_request_params_extracts_fragment_key_value_pairs to verify that URL fragments containing key=value pairs (e.g. #action=POST) are correctly parsed and added to query_params, alongside query string params. Regression test for issue google#4598.
Refactor query parameter extraction to handle both query and fragment in a single loop.
Added a test using a realistic Google Cloud integration URL that has both a query string param (triggerId) and a fragment param (httpMethod). Confirms both get moved into query_params and the final URL is clean.
Remove unnecessary check for query and fragment in URL parsing.
Summary of ChangesHello, 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 addresses two distinct issues to improve the robustness of the system. The primary change rectifies a bug in session state management, ensuring that initial state keys are properly maintained across rewind operations, which prevents unintended data loss. Additionally, it enhances the URL parsing logic to correctly extract parameters from URL fragments, resolving a specific problem where such parameters were ignored, leading to API request failures. These changes collectively improve data integrity and API interaction reliability. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request addresses two separate issues. The primary fix ensures that initial session state keys are preserved during a rewind operation. A secondary fix corrects URL parameter parsing to include parameters from the URL fragment. My review identified a critical bug in the rewind logic where a dictionary is incorrectly re-initialized within a loop, which could lead to data loss or a runtime error. The fix for URL parsing and its accompanying test are well-implemented.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
Thanks @gemini-code-assist for the review! Applied the suggested fix in commit 4182ab6 — replaced the imperative loop with a set comprehension and moved |
|
Thanks for the update, @saiprasanth-git! I've reviewed the changes in commit 4182ab6 and they look great. The use of a set comprehension for This effectively resolves the identified issues. Great work! |
Closes #4839
Problem
_compute_state_delta_for_rewindinrunners.pyincorrectly nullifies session state keys that were set viacreate_session(state={...}). These "initial state" keys never appear in any event'sstate_delta, so they were absent fromstate_at_rewind_pointand incorrectly set toNoneafterrewind_async().Root Cause
Step 2 of the rewind state delta computation sets
rewind_state_delta[key] = Nonefor any key incurrent_statenot found instate_at_rewind_point. This over-eagerly nullifies keys that were set as initial session state, not through events.Fix
Before computing the delta, collect
keys_ever_in_event_deltas— the set of all keys that appeared in any event'sstate_deltathroughout the entire session.In step 2, only nullify keys that:
state_at_rewind_point(were not present at rewind point), ANDstate_delta(were set via events, not initial state)Keys that never appeared in any event delta are treated as "initial state" (set via
create_session) and are preserved through rewinds.Test
Reproduction from issue #4839: