Skip to content

Conversation

@masenf
Copy link
Collaborator

@masenf masenf commented Oct 22, 2025

No description provided.

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 22, 2025

CodSpeed Performance Report

Merging #5920 will create unknown performance changes

Comparing masenf/test-client-storage-oopsie (1d4ffa5) with main (b6b7f32)

Summary

⚠️ No benchmarks were detected in both the base of the PR and the PR.
Please ensure that your benchmarks are correctly instrumented with CodSpeed.

Check out the benchmarks creation guide

⏩ 8 skipped1

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Overview

Summary

Fixed race condition in test_client_storage.py where test cleanup could fail with KeyError when StateManagerDisk's background task concurrently removes expired tokens. Changed from del dict[key] to dict.pop(key, None) for atomic, safe deletion.

  • Replaced del app_state_manager.states[token] with app_state_manager.states.pop(token, None) on line 662
  • Replaced del app_state_manager._write_queue[token] with app_state_manager._write_queue.pop(token, None) on line 663
  • The .pop() method with default value prevents KeyError if the background task (_process_write_queue) has already removed the token

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • The change is a straightforward and correct fix for a race condition in test cleanup code. Using .pop(key, None) instead of del dict[key] is the standard Python idiom for safe dictionary deletion when the key might not exist. This eliminates test flakiness without any functional changes to production code
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
tests/integration/test_client_storage.py 5/5 Replaced unsafe dictionary deletion with safe .pop() method to prevent race condition with background state manager task

Sequence Diagram

sequenceDiagram
    participant Test as Test Code
    participant StateManager as StateManagerDisk
    participant BgTask as Background Task (_process_write_queue)
    participant Dict as states/write_queue

    Note over Test,Dict: Before the fix (Race Condition)
    Test->>StateManager: Check token exists in states
    BgTask->>Dict: pop(token) - removes expired token
    Test->>Dict: del states[token]
    Dict-->>Test: KeyError! (Race condition)

    Note over Test,Dict: After the fix (Safe)
    Test->>StateManager: Clean up test state
    BgTask->>Dict: pop(token) - may remove expired token
    Test->>Dict: pop(token, None)
    Dict-->>Test: None (safe, no error)
Loading

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@adhami3310 adhami3310 merged commit e53b65d into main Oct 22, 2025
46 of 47 checks passed
@adhami3310 adhami3310 deleted the masenf/test-client-storage-oopsie branch October 22, 2025 18: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.

3 participants