Skip to content

Fix the real-HTTP test hang, the fresh-clone hook test and the README hackathon line - #16

Merged
Harshith029 merged 3 commits into
mainfrom
fix/test-hang-and-claims
Nov 22, 2026
Merged

Harshith029 merged 3 commits into
mainfrom
fix/test-hang-and-claims

Conversation

@Harshith029

Copy link
Copy Markdown
Owner

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.py and tests/test_phase9_mcp_gateway.py could 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:

  • uvicorn installs Server.handle_exit for SIGINT and SIGTERM while it serves (capture_signals()). The harnesses' install_signal_handlers = lambda: None targets a method uvicorn no longer has, so it did nothing.
  • sse-starlette 3.4.4's shutdown watcher polls every 0.5 s, finds the uvicorn server through signal.getsignal(SIGTERM).__self__, and when that server's should_exit is True it sets the class attribute AppStatus.should_exit = True for the whole process. Nothing resets it.
  • From then on EventSourceResponse cancels itself before sending headers. The MCP streamable-HTTP transport answers every POST with SSE, so no later initialize() 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_signals with contextlib.nullcontext. With the defect gone, the quarantine goes too: 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. docs/mcp-streamable-http-teardown.md is rewritten around the cause, and docs/mcp_repro_standalone.py now 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_installed failed on every fresh clone. Outside CI, with no hook installed, it now skips and says why. CI installs the hook before the tests, so with CI=true a 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 passes twine check.

Evidence for the hang

Check Before After
test_stopping_one_server_does_not_silence_the_next alone (Linux) failed 3/3 passed 5/5
tests/test_downstream_remote_paths.py, whole file 8 failed, 4 passed in 248 s (opted in) passes in the default suite
That file, then tests/test_phase9_mcp_gateway.py (Linux) ended by the 120 s timeout after 349 s, no summary 23 passed in about 10 s
test_remote_http_tool_servers_are_secured, then test_real_http_sessions_after_remote_downstream (Windows) failed 3/3 passed 3/3

Full suite, python -m pytest -q

Environment Collected Passed Skipped Failed
Linux, Docker python:3.12 (3.12.16), fresh clone 714 713 1 0
Linux, Ubuntu 24.04 system Python 3.12.3, fresh clone 714 713 1 0
Windows 11, Python 3.11.9, hook installed 714 714 0 0

The 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

  • No product code changes. sentinel serve (uvicorn.run in src/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.
  • The 0.2.2 CHANGELOG entry saying the defect "is still present in 1.30.0" is left as history; the new Unreleased entry corrects the record.
  • The Render demo link is gone from the README, the site and the current PyPI page. The service answers 503 "Service Suspended" (suspended by its owner), so it is not a sleeping free instance and there is no link to annotate. The frozen PyPI pages for 0.1.0, 0.1.1, 0.2.1 and 0.2.2 still link it.

Security invariants

  • This change does not weaken a security invariant, or the PR explains why it is still safe.

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

  • Tests cover the change. test_stopping_one_server_does_not_silence_the_next fails without the fix (3/3) and passes with it.
  • python -m pytest, python -m ruff check src tests and python -m mypy src pass locally.
  • Docs are updated where behaviour changed: the README, the teardown doc, CONTRIBUTING and the design notes. Nothing in website/ or .env.example described the quarantine, so neither needed a change.
  • CHANGELOG.md has entries under Unreleased.

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.
@Harshith029
Harshith029 merged commit 0041b4c into main Nov 22, 2026
6 checks passed
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.

1 participant