hermes - ✅(Solved) Fix API server still uses string aiohttp app keys, triggering NotAppKeyWarning on startup/tests [3 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#11635Fetched 2026-04-18 05:59:41
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Timeline (top)
cross-referenced ×3commented ×1referenced ×1

Fix Action

Fixed

PR fix notes

PR #11638: fix: use web.AppKey for api_server adapter to avoid NotAppKeyWarning

Description (problem / solution / changelog)

Summary

Fixes the NotAppKeyWarning emitted by aiohttp when using plain string keys for application state in the API server adapter.

Root Cause

aiohttp deprecated the use of plain string keys for application state and recommends using instances instead. The warning fires during normal startup and tests.

Fix

  • Introduce a module-level as a typed (when aiohttp is available)
  • Update all read/write paths to use this typed key instead of the plain string
  • Update test helpers that set the adapter on the app

Test Plan

  • bringing up nodes... bringing up nodes...

........................................................................ [ 63%] .......................................... [100%] =============================== warnings summary =============================== tests/gateway/test_api_server.py::TestAdapterInit::test_default_config tests/gateway/test_api_server.py::TestResponseStore::test_get_missing_returns_none tests/gateway/test_api_server.py::TestCheckRequirements::test_returns_true_when_aiohttp_available tests/gateway/test_api_server.py::TestAuth::test_missing_auth_header_returns_401 tests/gateway/test_api_server.py::TestResponseStore::test_update_existing_key tests/gateway/test_api_server.py::TestAuth::test_no_key_configured_allows_all /Volumes/PS3000/GitHub/hermes-agent/tests/conftest.py:296: DeprecationWarning: There is no current event loop loop = asyncio.get_event_loop_policy().get_event_loop()

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html 114 passed, 6 warnings in 3.33s passes (114 tests)

  • bringing up nodes... bringing up nodes...

................................... [100%] 35 passed in 1.17s passes (35 tests)

  • No NotAppKeyWarning emitted during test runs

Closes NousResearch/hermes-agent#11635

Changed files

  • gateway/platforms/api_server.py (modified, +8/-2)
  • tests/gateway/test_api_server.py (modified, +2/-1)
  • tests/gateway/test_api_server_jobs.py (modified, +2/-1)

PR #11669: fix(api-server): use AppKey for aiohttp adapter state

Description (problem / solution / changelog)

Summary

  • replace the API server adapter's raw string app-state key with a shared aiohttp.web.AppKey
  • update the existing API server and jobs test helpers to use the same typed key
  • add non-network regression tests that fail on NotAppKeyWarning if the old string-key path returns

Test Plan

  • PYTHONPATH="..." /Users/bytedance/MySpace/open-source/hermes-agent/.venv/bin/python -m pytest -q tests/gateway/test_api_server_bind_guard.py::TestConnectBindGuard::test_refuses_ipv4_wildcard_without_key -W default -o addopts=''
  • PYTHONPATH="..." /Users/bytedance/MySpace/open-source/hermes-agent/.venv/bin/python -m pytest -q tests/gateway/test_api_server.py::TestAppKeyRegression tests/gateway/test_api_server_jobs.py::TestAppKeyRegression -W default -o addopts=''
  • PYTHONPATH="..." /Users/bytedance/MySpace/open-source/hermes-agent/.venv/bin/python -m pytest -q tests/gateway/test_api_server.py -W default -o addopts='' -k 'TestCheckRequirements or TestResponseStore or TestAdapterInit or TestAuth or TestAppKeyRegression or test_models_returns_explicit_model_name or test_resolve_model_name_explicit or test_resolve_model_name_default_profile or test_resolve_model_name_named_profile or TestDeriveChatSessionId or TestConfigIntegration or TestSendMethod or test_origin_allowed_for_non_browser_client or test_origin_rejected_by_default or test_origin_allowed_for_allowlist_match or test_cors_headers_for_origin_disabled_by_default or test_cors_headers_for_origin_matches_allowlist or test_cors_headers_for_origin_rejects_unknown_origin'

Local broad HTTP-route tests that rely on aiohttp.TestServer binding 127.0.0.1:0 were blocked by the sandbox (PermissionError: [Errno 1] Operation not permitted), so I added direct AppKey regression coverage for the affected non-network code paths instead.

Closes #11635

Changed files

  • gateway/platforms/api_server.py (modified, +4/-2)
  • scripts/release.py (modified, +1/-0)
  • tests/gateway/test_api_server.py (modified, +32/-2)
  • tests/gateway/test_api_server_jobs.py (modified, +16/-2)
  • tests/tools/test_approval_heartbeat.py (modified, +30/-5)

PR #11709: fix(api-server): use aiohttp AppKey for adapter state

Description (problem / solution / changelog)

Summary

  • replace the API server's string-based aiohttp app-state key with a typed web.AppKey
  • update the API server test helpers to use the same typed key
  • add a regression test that verifies connect() no longer emits NotAppKeyWarning

Verification

  • source venv/bin/activate && pytest -q tests/gateway/test_api_server_bind_guard.py::TestConnectBindGuard::test_connect_does_not_emit_not_app_key_warning
  • source venv/bin/activate && pytest -q tests/gateway/test_api_server.py tests/gateway/test_api_server_jobs.py
  • source venv/bin/activate && pytest -q tests/gateway/test_api_server_bind_guard.py::TestConnectBindGuard::test_refuses_ipv4_wildcard_without_key -W default

Closes #11635

Changed files

  • gateway/platforms/api_server.py (modified, +7/-2)
  • tests/gateway/test_api_server.py (modified, +2/-1)
  • tests/gateway/test_api_server_bind_guard.py (modified, +18/-0)
  • tests/gateway/test_api_server_jobs.py (modified, +2/-2)

Code Example

cd /Users/genie/.hermes/hermes-agent
source venv/bin/activate
pytest -q tests/gateway/test_api_server_bind_guard.py::TestConnectBindGuard::test_refuses_ipv4_wildcard_without_key -W default

---

/Users/genie/.hermes/hermes-agent/gateway/platforms/api_server.py:1784:
NotAppKeyWarning: It is recommended to use web.AppKey instances for keys.
RAW_BUFFERClick to expand / collapse

Bug Description

gateway/platforms/api_server.py stores and reads the API server adapter via a plain string app key:

  • gateway/platforms/api_server.py:245request.app.get("api_server_adapter")
  • gateway/platforms/api_server.py:1784self._app["api_server_adapter"] = self

On current aiohttp this already emits NotAppKeyWarning during normal startup/tests, and future aiohttp releases may tighten this further.

Why this is a bug

This is not just style drift: the app is relying on a deprecated access pattern for request/application state. The warning fires in regular test runs, which means the production code path is already exercising the deprecated behavior.

Minimal Reproduction

cd /Users/genie/.hermes/hermes-agent
source venv/bin/activate
pytest -q tests/gateway/test_api_server_bind_guard.py::TestConnectBindGuard::test_refuses_ipv4_wildcard_without_key -W default

Observed warning:

/Users/genie/.hermes/hermes-agent/gateway/platforms/api_server.py:1784:
NotAppKeyWarning: It is recommended to use web.AppKey instances for keys.

The broader batch review also reproduced the same warning repeatedly from:

  • tests/gateway/test_api_server.py
  • tests/gateway/test_api_server_jobs.py

Expected Behavior

API server startup and its tests should not emit NotAppKeyWarning; app state should use web.AppKey consistently.

Actual Behavior

The adapter is attached with a string key, generating warnings on startup/test paths.

Suggested Investigation Direction

  • Introduce a module-level web.AppKey for the adapter reference.
  • Update both the app write path and middleware/request read path to use that typed key.
  • Update test helpers that currently set app["api_server_adapter"] = adapter so the warning disappears from the suite.

extent analysis

TL;DR

Introduce a web.AppKey instance for the API server adapter reference to replace the plain string app key and update relevant code paths to use the typed key.

Guidance

  • Identify the specific lines of code where the plain string app key is used (gateway/platforms/api_server.py:245 and gateway/platforms/api_server.py:1784) and plan to replace it with a web.AppKey instance.
  • Update the app write path (self._app["api_server_adapter"] = self) to use the new web.AppKey instance for storing the adapter reference.
  • Modify the middleware/request read path (request.app.get("api_server_adapter")) to retrieve the adapter using the web.AppKey instance.
  • Review and update test helpers that set app["api_server_adapter"] = adapter to use the web.AppKey instance, ensuring the warning is resolved in the test suite.

Example

from aiohttp import web

# Introduce a module-level web.AppKey for the adapter reference
API_SERVER_ADAPTER_KEY = web.AppKey('api_server_adapter')

# Update the app write path to use the web.AppKey instance
self._app[API_SERVER_ADAPTER_KEY] = self

# Update the middleware/request read path to use the web.AppKey instance
adapter = request.app.get(API_SERVER_ADAPTER_KEY)

Notes

This solution assumes that the web.AppKey instance can be used consistently throughout the application and test suite. If there are any version-specific limitations or constraints, additional investigation may be necessary.

Recommendation

Apply the workaround by introducing a web.AppKey instance for the API server adapter reference and updating the relevant code paths, as this approach addresses the deprecated access pattern and resolves the NotAppKeyWarning.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - ✅(Solved) Fix API server still uses string aiohttp app keys, triggering NotAppKeyWarning on startup/tests [3 pull requests, 1 comments, 2 participants]