Repository navigation
fix: add auth_code guard to set_gateway_state stale cleanup - #3792
Merged
crivetimihai merged 7 commits intoMar 23, 2026
Merged
Conversation
When an OAuth authorization_code gateway transitions from offline to online, set_gateway_state re-initializes without a valid token, receives empty results, and deletes all existing tools/resources/prompts as stale. Add the same auth_code guard that _refresh_gateway_tools_resources_prompts already has (PR IBM#2537): skip stale cleanup when the response is empty for authorization_code gateways. Signed-off-by: kimsehwan96 <[email protected]>
Replace string-parsing assert with call_count check to match the existing test patterns in test_gateway_service.py. Signed-off-by: kimsehwan96 <[email protected]>
Skip gateway.tools/resources/prompts list filtering when stale cleanup is skipped, and verify all existing tools are preserved by id. Signed-off-by: kimsehwan96 <[email protected]>
Rename _is_auth_code_gw to is_auth_code_gateway and _skip_stale_cleanup to skip_stale_cleanup to match _refresh_gateway_tools_resources_prompts naming. Signed-off-by: kimsehwan96 <[email protected]>
Add two tests for set_gateway_state auth_code guard: - Non-auth_code gateway with empty results still runs stale cleanup - Auth_code guard preserves resources and prompts (not just tools) Signed-off-by: Mihai Criveti <[email protected]>
Verify that an authorization_code gateway returning partial results (some tools) still runs stale cleanup, ensuring the guard only activates when all three collections are empty. Signed-off-by: Mihai Criveti <[email protected]>
crivetimihai
force-pushed
the
fix/set-gateway-state-authcode-guard
branch
from
March 23, 2026 15:49
de86e0a to
5da5e3d
Compare
crivetimihai
requested review from
crivetimihai,
kevalmahajan and
madhav165
as code owners
March 23, 2026 15:49
Member
|
Rebased onto main (clean, no conflicts) and added three additional tests for full differential coverage:
All 272 tests pass (271 passed, 1 pre-existing skip). The guard logic is correct and consistent with the existing pattern in |
crivetimihai
previously approved these changes
Mar 23, 2026
crivetimihai
left a comment
Member
There was a problem hiding this comment.
LGTM — guard is correct, consistent with the existing pattern, and well-tested.
Signed-off-by: Mihai Criveti <[email protected]>
msureshkumar88
pushed a commit
that referenced
this pull request
May 13, 2026
* fix: prevent tool deletion on auth_code gateway reactivation When an OAuth authorization_code gateway transitions from offline to online, set_gateway_state re-initializes without a valid token, receives empty results, and deletes all existing tools/resources/prompts as stale. Add the same auth_code guard that _refresh_gateway_tools_resources_prompts already has (PR #2537): skip stale cleanup when the response is empty for authorization_code gateways. Signed-off-by: kimsehwan96 <[email protected]> * test: align assert style with existing conventions Replace string-parsing assert with call_count check to match the existing test patterns in test_gateway_service.py. Signed-off-by: kimsehwan96 <[email protected]> * fix: also guard in-memory list reassignment and improve test coverage Skip gateway.tools/resources/prompts list filtering when stale cleanup is skipped, and verify all existing tools are preserved by id. Signed-off-by: kimsehwan96 <[email protected]> * style: align variable naming with existing convention Rename _is_auth_code_gw to is_auth_code_gateway and _skip_stale_cleanup to skip_stale_cleanup to match _refresh_gateway_tools_resources_prompts naming. Signed-off-by: kimsehwan96 <[email protected]> * test: add negative and resource/prompt coverage for auth_code guard Add two tests for set_gateway_state auth_code guard: - Non-auth_code gateway with empty results still runs stale cleanup - Auth_code guard preserves resources and prompts (not just tools) Signed-off-by: Mihai Criveti <[email protected]> * test: add partial-results coverage for auth_code guard Verify that an authorization_code gateway returning partial results (some tools) still runs stale cleanup, ensuring the guard only activates when all three collections are empty. Signed-off-by: Mihai Criveti <[email protected]> * fix(sdist): include infra/s390x/Containerfile in MANIFEST.in Signed-off-by: Mihai Criveti <[email protected]> --------- Signed-off-by: kimsehwan96 <[email protected]> Signed-off-by: Mihai Criveti <[email protected]> Co-authored-by: Mihai Criveti <[email protected]>
kamath-a
pushed a commit
to kamath-a/mcp-context-forge
that referenced
this pull request
Jun 26, 2026
* fix: prevent tool deletion on auth_code gateway reactivation When an OAuth authorization_code gateway transitions from offline to online, set_gateway_state re-initializes without a valid token, receives empty results, and deletes all existing tools/resources/prompts as stale. Add the same auth_code guard that _refresh_gateway_tools_resources_prompts already has (PR IBM#2537): skip stale cleanup when the response is empty for authorization_code gateways. Signed-off-by: kimsehwan96 <[email protected]> * test: align assert style with existing conventions Replace string-parsing assert with call_count check to match the existing test patterns in test_gateway_service.py. Signed-off-by: kimsehwan96 <[email protected]> * fix: also guard in-memory list reassignment and improve test coverage Skip gateway.tools/resources/prompts list filtering when stale cleanup is skipped, and verify all existing tools are preserved by id. Signed-off-by: kimsehwan96 <[email protected]> * style: align variable naming with existing convention Rename _is_auth_code_gw to is_auth_code_gateway and _skip_stale_cleanup to skip_stale_cleanup to match _refresh_gateway_tools_resources_prompts naming. Signed-off-by: kimsehwan96 <[email protected]> * test: add negative and resource/prompt coverage for auth_code guard Add two tests for set_gateway_state auth_code guard: - Non-auth_code gateway with empty results still runs stale cleanup - Auth_code guard preserves resources and prompts (not just tools) Signed-off-by: Mihai Criveti <[email protected]> * test: add partial-results coverage for auth_code guard Verify that an authorization_code gateway returning partial results (some tools) still runs stale cleanup, ensuring the guard only activates when all three collections are empty. Signed-off-by: Mihai Criveti <[email protected]> * fix(sdist): include infra/s390x/Containerfile in MANIFEST.in Signed-off-by: Mihai Criveti <[email protected]> --------- Signed-off-by: kimsehwan96 <[email protected]> Signed-off-by: Mihai Criveti <[email protected]> Co-authored-by: Mihai Criveti <[email protected]>
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.
🔗 Related Issue
Closes #3788
📝 Summary
When an auth_code gateway transitions from offline → online,
set_gateway_statecalls_initialize_gatewaywhich connects without a valid OAuth token, receives empty results, and deletes all existing tools, resources, prompts, and their virtual server associations as "stale."This PR mirrors the existing guard from
_refresh_gateway_tools_resources_prompts(line 4558) intoset_gateway_state, skipping stale cleanup when the response is empty for authorization_code gateways.🏷️ Type of Change
🧪 Verification
make lintmake testmake coverage✅ Checklist
make black isort pre-commit)📓 Notes (optional)
What the guard protects:
server_tool_association)gateway.tools = [...]filtering)What it does NOT change: