fix(gateway): harden kanban and provider cleanup races - #29479
Merged
teknium1 merged 1 commit intoMay 20, 2026
Conversation
helix4u
marked this pull request as ready for review
May 20, 2026 21:15
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.
What does this PR do?
Hardens two gateway-adjacent failure paths that can combine under long-running Kanban workloads:
17 03 03 00 13at byte offset 5.This does not claim the fd-reuse/TLS writer root cause is proven. It removes a concrete broken cleanup path, reduces request-client lifecycle races, and makes corrupted Kanban DBs fail with actionable evidence instead of a generic
PRAGMA journal_mode=WALtraceback.Related Issue
Related to #26479 and #10324. Replaces the useful socket traversal portion of closed PR #6216.
Type of Change
Changes Made
agent/agent_runtime_helpers.py: add shared socket-pool traversal that descends throughconn._connectionfor httpcore 1.x and reuse it from dead-connection cleanup and force-close cleanup.agent/chat_completion_helpers.py: add thread-safe request-client take-and-close helpers for non-streaming and streaming calls so stale/interrupt/final cleanup paths close each request client at most once.hermes_cli/kanban_db.py: validate existing non-empty DB headers beforesqlite3.connect()/WAL setup and include TLS-record signature details when page 0 looks clobbered.tests/run_agent/test_create_openai_client_reuse.py: cover httpcore 1.x wrapper socket traversal.tests/run_agent/test_openai_client_lifecycle.py: cover single-owner request-client cleanup on stale non-streaming calls.tests/hermes_cli/test_kanban_db.py: cover TLS-looking Kanban DB header classification.How to Test
scripts/run_tests.sh tests/run_agent/test_openai_client_lifecycle.py tests/run_agent/test_create_openai_client_reuse.py tests/hermes_cli/test_kanban_db.py tests/hermes_cli/test_kanban_core_functionality.py -n 4scripts/run_tests.sh tests/run_agent/test_openai_client_lifecycle.py tests/run_agent/test_create_openai_client_reuse.py tests/hermes_cli/test_kanban_db.py -n 4python -m compileall -q agent/agent_runtime_helpers.py agent/chat_completion_helpers.py hermes_cli/kanban_db.pyscripts/run_tests.sh -n 4Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AFor New Skills
Screenshots / Logs
Targeted tests passed:
332 passed in 17.13s
167 passed in 9.55s
compileall completed successfully
Full suite result after creating the draft PR:
scripts/run_tests.sh -n 4
9 failed, 24640 passed, 54 skipped, 250 warnings in 588.11s (0:09:48)
Full-suite failures observed:
tests/gateway/test_api_server.py::TestAdapterInit::test_default_configtests/gateway/test_approve_deny_commands.py::TestBlockingApprovalE2E::test_blocking_approval_approve_oncetests/gateway/test_approve_deny_commands.py::TestBlockingApprovalE2E::test_blocking_approval_denytests/gateway/test_config.py::TestLoadGatewayConfig::test_bridges_quoted_false_platform_enabled_from_config_yamltests/gateway/test_discord_bot_filter.py::TestDiscordBotFilter::test_default_is_nonetests/agent/test_context_compressor.py::TestCompress::test_truncation_fallback_no_clienttests/gateway/test_runner_startup_failures.py::test_start_gateway_replace_force_uses_terminate_pidtests/plugins/web/test_web_search_provider_plugins.py::TestBundledPluginsRegister::test_all_seven_plugins_present_in_registrytests/tools/test_tirith_security.py::TestDiskFailureMarker::test_cosign_missing_marker_clears_when_cosign_appearsThese failures are outside the files changed in this PR and appear unrelated to the Kanban/provider-cleanup hardening. The approval E2E failures included
tirith not found — downloading latest release...; the gateway config failures showed local config/default-port differences such asport: 8643where tests expected 8642.