feat(oauth_state_manager): public cleanup API, TTL cleanup, and tests#1371
Open
dive2tech wants to merge 2 commits intoeigent-ai:mainfrom
Open
feat(oauth_state_manager): public cleanup API, TTL cleanup, and tests#1371dive2tech wants to merge 2 commits intoeigent-ai:mainfrom
dive2tech wants to merge 2 commits intoeigent-ai:mainfrom
Conversation
- Add remove_state(provider) to drop state and cancel if in progress; validate provider
- Add list_states() for API/debugging
- Add clear_completed(max_age_seconds) to prune terminal states with optional TTL
- Add TERMINAL_STATUSES constant; use in update_status and clear_completed
- tool_controller: use remove_state('google_calendar') instead of _states.pop
- Add tests/app/utils/test_oauth_state_manager.py for OAuthState, create_state, get_state, update_status, remove_state, list_states, clear_completed, and concurrency
Co-authored-by: Cursor <cursoragent@cursor.com>
…, remove unused) Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This pull request hardens the OAuth authorization state manager by adding a public cleanup API, optional TTL-based pruning of completed flows, and a dedicated test suite. It improves the robustness of long-lived background authorization flows and removes the last direct access to internal state from callers.
Motivation
oauth_state_manager._statesto clear state, which is brittle and bypasses synchronization.Changes
backend/app/utils/oauth_state_manager.pyremove_state(provider):list_states():Tests
backend/tests/app/utils/test_oauth_state_manager.py(new)OAuthStatetests:to_dict()for both pending and completed states.is_cancelled()before and after cancel().cancel()sets the cancel event, status, and completed_at.OAuthStateManagertests:create_state/get_statecreate and retrieve a state for a provider.update_statussets status,error, andcompleted_atforsuccessandfailed.update_statusis a no-op for unknown providers.remove_state:FalseforNone/empty provider names and missing providers.Truewhen a state is present and removes it.clear_completed:0when there are no states.max_age_secondsso very recent completions are retained while older ones are pruned.create_statefor the same provider; the manager remains consistent and returns a non-None state at the end.