Repository navigation
Fix the real-HTTP test hang, the fresh-clone hook test and the README hackathon line - #16
Merged
Merged
Conversation
Real-HTTP tests hung because stopping one in-process uvicorn test server ended every later SSE response in the pytest process. Root cause: uvicorn installs Server.handle_exit for SIGINT and SIGTERM while it serves (capture_signals). The harnesses' install_signal_handlers override targets a method uvicorn no longer has, so it did nothing. sse-starlette's shutdown watcher polls every 0.5 s, finds the server through the SIGTERM handler, and when that server's should_exit is True it sets the process-wide AppStatus.should_exit, which is never reset. After that every EventSourceResponse ends before sending headers. The MCP streamable-HTTP transport answers each POST with SSE, so every later initialize() got no answer: SENTINEL's downstream connections timed out at 30 s each, and test clients with no bound waited until pytest-timeout's 120 s thread mode ended the run with no summary. Whether a teardown outlasted one 0.5 s poll decided whether the flag latched, which is why the hang looked intermittent. Fix: the test servers replace capture_signals with contextlib.nullcontext. No product code changes: sentinel serve runs one server per process, so the flag still latches only at real shutdown, as sse-starlette intends. Evidence (Linux, Python 3.12.16; Windows, Python 3.11.9): - new test_stopping_one_server_does_not_silence_the_next: 3/3 red on the old harness, 5/5 green with the fix - tests/test_downstream_remote_paths.py, opted in: 8 failed, 4 passed in 248 s before; passes in the default suite after - that file, then the gateway file: ended by the 120 s timeout after 349 s with no summary before; 23 passed in about 10 s after With the defect fixed the quarantine goes: the SENTINEL_RUN_REAL_MCP_TESTS gate, the non-blocking real-MCP diagnostics CI job, and the strict xfail on test_real_http_sessions_after_remote_downstream. The teardown doc now records the cause, and docs/mcp_repro_standalone.py reproduces it with mcp, uvicorn and sse-starlette alone. Findings TCD-04 and OWN-6.
test_pre_commit_hook_is_installed failed on every fresh clone, which has no .git/hooks/pre-commit until pre-commit install runs. Outside CI it now skips and says why. CI runs pre-commit install before the tests, so with CI=true a missing hook still fails, and an installed hook is still checked.
The README's last line said SENTINEL was "originally built for" the Microsoft Build AI Hackathon 2026. It is a personal project and was not submitted there. PyPI takes the project description from README.md (readme in pyproject.toml), so the next release's page shows the corrected line; a wheel built from this tree carries it and passes twine check.
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 and why
Three fixes, one commit each. There is no issue to link; these were reported directly.
1. The real-HTTP test hang (a661f96). On Linux with Python 3.12,
tests/test_downstream_remote_paths.pyandtests/test_phase9_mcp_gateway.pycould hang until pytest-timeout's 120 s thread mode ended the whole run with no summary. The cause is in the test harness, not in SENTINEL or the MCP SDK:Server.handle_exitfor SIGINT and SIGTERM while it serves (capture_signals()). The harnesses'install_signal_handlers = lambda: Nonetargets a method uvicorn no longer has, so it did nothing.signal.getsignal(SIGTERM).__self__, and when that server'sshould_exitis True it sets the class attributeAppStatus.should_exit = Truefor the whole process. Nothing resets it.EventSourceResponsecancels itself before sending headers. The MCP streamable-HTTP transport answers every POST with SSE, so no laterinitialize()got an answer: SENTINEL's downstream connections timed out after 30 s each, and test clients with no bound waited until the run was killed.Whether a teardown outlasted one 0.5 s poll decided whether the flag latched, which is why the hang looked intermittent. The test servers now replace
capture_signalswithcontextlib.nullcontext. With the defect gone, the quarantine goes too: theSENTINEL_RUN_REAL_MCP_TESTSgate, the non-blockingreal-mcp-diagnosticsCI job, and the strict xfail ontest_real_http_sessions_after_remote_downstream.docs/mcp-streamable-http-teardown.mdis rewritten around the cause, anddocs/mcp_repro_standalone.pynow reproduces it with mcp, uvicorn and sse-starlette alone.2. The pre-commit hook test on a fresh clone (0e54eaf).
test_pre_commit_hook_is_installedfailed on every fresh clone. Outside CI, with no hook installed, it now skips and says why. CI installs the hook before the tests, so withCI=truea missing hook still fails.3. The README's hackathon line (cdfecb7). It said SENTINEL was "originally built for" the Microsoft Build AI Hackathon 2026. It is a personal project and was not submitted there. PyPI takes the project description from
README.md, so the next release's page shows the correction; a wheel built from this branch carries it and passestwine check.Evidence for the hang
test_stopping_one_server_does_not_silence_the_nextalone (Linux)tests/test_downstream_remote_paths.py, whole filetests/test_phase9_mcp_gateway.py(Linux)test_remote_http_tool_servers_are_secured, thentest_real_http_sessions_after_remote_downstream(Windows)Full suite,
python -m pytest -qpython:3.12(3.12.16), fresh cloneThe skip is the hook test on a clone without a hook. 714 is the previous 713 plus the new regression test.
Notes for the reviewer
sentinel serve(uvicorn.runinsrc/sentinel/cli.py) and the demo tool server (src/sentinel/demo/toolserver_main.py) each run one uvicorn server per process, so in a deployment the flag latches only at real shutdown, which is the graceful drain sse-starlette intends.Security invariants
Test, CI and doc changes only;
src/is untouched. No security policy, default-deny behaviour or test assertion is weakened. Removing the strict xfail and the opt-in skip makes those tests required to pass, and the hook test still fails in CI when the hook is missing.Checklist
test_stopping_one_server_does_not_silence_the_nextfails without the fix (3/3) and passes with it.python -m pytest,python -m ruff check src testsandpython -m mypy srcpass locally.website/or.env.exampledescribed the quarantine, so neither needed a change.CHANGELOG.mdhas entries under Unreleased.