Skip to content

fix(agent-server): honor create_app config for the conversation service - #5686

Merged
jpshackelford merged 1 commit into
mainfrom
fix/agent-server-honor-app-config
Oct 18, 2026
Merged

jpshackelford merged 1 commit into
mainfrom
fix/agent-server-honor-app-config

Conversation

@jpshackelford

@jpshackelford jpshackelford commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

HUMAN:

Running the test suite from a cloud sandbox created 17 conversations on our staging deployment because the test isolation was incomplete: the server ignored the tests' config and used the sandbox's settings.


AGENT:

Why

Without deferred init, the agent-server's startup built its conversation service with get_default_conversation_service(). That reloads config from the OH_* environment variables and ignores the Config passed to create_app(). Tests that pass an isolated config (a temp conversations directory, no webhooks) therefore saved conversations to OH_CONVERSATIONS_PATH and sent conversation webhooks to OH_WEBHOOKS_*, authenticated with SESSION_API_KEY. On CI and laptops those variables are unset, so nothing happens. Inside an OpenHands sandbox they are the sandbox's own settings, so running tests/agent_server there registered the test conversations with the real app server, under the sandbox owner's account.

Startup now builds the service from api.state.config, which is what POST /api/init already does for deferred-init servers. The production server is unaffected: it runs create_app() with no argument, which uses get_default_config(), the same config the old call loaded. As a second guard, tests/conftest.py removes the variables that point an agent server at, or authenticate it to, a live deployment. It does this in pytest_configure, before collection, because some modules read the config when they're imported.

Summary

  • Startup builds its conversation service from the config passed to create_app(), not the environment.
  • pytest_configure removes webhook, conversations and bash-events path, session-key, internal-server-URL and LLM key-refresh variables.
  • Adds a regression test in tests/agent_server/test_api.py; the existing startup tests now patch ConversationService.get_instance.

Issue Number

Fixes #5590

How to Test

uv run pytest tests/agent_server/test_api.py -k lifespan_conversation_service_uses_app_config sets OH_CONVERSATIONS_PATH and OH_WEBHOOKS_0_BASE_URL, starts an app with its own config, and checks that the running service uses the app's conversations directory and has no webhooks.

  • Env guard under xdist: running pytest with -n 2 and dummy values for every guarded variable, a probe test saw all of them removed in the worker, while an unrelated OH_* variable was kept.

Video/Screenshots

N/A

Design Doc

N/A

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

Startup still gets the bash events, VSCode and tool-preload services from the global config. They only touch local paths and ports, not a remote server, so they're left for a follow-up.

This PR was drafted by an AI agent on behalf of the user.

@jpshackelford can click here to continue refining the PR


🐳 Agent Server images for this PR — GHCR package, pull/run commands, and all pushed tags (click to expand)

• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server

Variants & Base Images

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python-slim amd64, arm64 python-node-runtime Link
python-minimal amd64, arm64 python-node-runtime Link
python amd64, arm64 python-node-runtime Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:c8d59c8-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-c8d59c8-python \
  ghcr.io/openhands/agent-server:c8d59c8-python

All tags pushed for this build

ghcr.io/openhands/agent-server:c8d59c8-golang-amd64
ghcr.io/openhands/agent-server:c8d59c889715243443c3d9e669475a3ebcf68ef7-golang-amd64
ghcr.io/openhands/agent-server:fix-agent-server-honor-app-config-golang-amd64
ghcr.io/openhands/agent-server:c8d59c8-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:c8d59c8-golang-arm64
ghcr.io/openhands/agent-server:c8d59c889715243443c3d9e669475a3ebcf68ef7-golang-arm64
ghcr.io/openhands/agent-server:fix-agent-server-honor-app-config-golang-arm64
ghcr.io/openhands/agent-server:c8d59c8-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:c8d59c8-java-amd64
ghcr.io/openhands/agent-server:c8d59c889715243443c3d9e669475a3ebcf68ef7-java-amd64
ghcr.io/openhands/agent-server:fix-agent-server-honor-app-config-java-amd64
ghcr.io/openhands/agent-server:c8d59c8-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:c8d59c8-java-arm64
ghcr.io/openhands/agent-server:c8d59c889715243443c3d9e669475a3ebcf68ef7-java-arm64
ghcr.io/openhands/agent-server:fix-agent-server-honor-app-config-java-arm64
ghcr.io/openhands/agent-server:c8d59c8-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:c8d59c8-python-amd64
ghcr.io/openhands/agent-server:c8d59c889715243443c3d9e669475a3ebcf68ef7-python-amd64
ghcr.io/openhands/agent-server:fix-agent-server-honor-app-config-python-amd64
ghcr.io/openhands/agent-server:c8d59c8-python-node-runtime-amd64
ghcr.io/openhands/agent-server:c8d59c8-python-arm64
ghcr.io/openhands/agent-server:c8d59c889715243443c3d9e669475a3ebcf68ef7-python-arm64
ghcr.io/openhands/agent-server:fix-agent-server-honor-app-config-python-arm64
ghcr.io/openhands/agent-server:c8d59c8-python-node-runtime-arm64
ghcr.io/openhands/agent-server:c8d59c8-python-minimal-amd64
ghcr.io/openhands/agent-server:c8d59c889715243443c3d9e669475a3ebcf68ef7-python-minimal-amd64
ghcr.io/openhands/agent-server:fix-agent-server-honor-app-config-python-minimal-amd64
ghcr.io/openhands/agent-server:c8d59c8-python-node-runtime-minimal-amd64
ghcr.io/openhands/agent-server:c8d59c8-python-minimal-arm64
ghcr.io/openhands/agent-server:c8d59c889715243443c3d9e669475a3ebcf68ef7-python-minimal-arm64
ghcr.io/openhands/agent-server:fix-agent-server-honor-app-config-python-minimal-arm64
ghcr.io/openhands/agent-server:c8d59c8-python-node-runtime-minimal-arm64
ghcr.io/openhands/agent-server:c8d59c8-python-slim-amd64
ghcr.io/openhands/agent-server:c8d59c889715243443c3d9e669475a3ebcf68ef7-python-slim-amd64
ghcr.io/openhands/agent-server:fix-agent-server-honor-app-config-python-slim-amd64
ghcr.io/openhands/agent-server:c8d59c8-python-node-runtime-slim-amd64
ghcr.io/openhands/agent-server:c8d59c8-python-slim-arm64
ghcr.io/openhands/agent-server:c8d59c889715243443c3d9e669475a3ebcf68ef7-python-slim-arm64
ghcr.io/openhands/agent-server:fix-agent-server-honor-app-config-python-slim-arm64
ghcr.io/openhands/agent-server:c8d59c8-python-node-runtime-slim-arm64
ghcr.io/openhands/agent-server:c8d59c8-golang
ghcr.io/openhands/agent-server:c8d59c889715243443c3d9e669475a3ebcf68ef7-golang
ghcr.io/openhands/agent-server:fix-agent-server-honor-app-config-golang
ghcr.io/openhands/agent-server:c8d59c8-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:c8d59c8-java
ghcr.io/openhands/agent-server:c8d59c889715243443c3d9e669475a3ebcf68ef7-java
ghcr.io/openhands/agent-server:fix-agent-server-honor-app-config-java
ghcr.io/openhands/agent-server:c8d59c8-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:c8d59c8-python-minimal
ghcr.io/openhands/agent-server:c8d59c889715243443c3d9e669475a3ebcf68ef7-python-minimal
ghcr.io/openhands/agent-server:fix-agent-server-honor-app-config-python-minimal
ghcr.io/openhands/agent-server:c8d59c8-python-node-runtime-minimal
ghcr.io/openhands/agent-server:c8d59c8-python-slim
ghcr.io/openhands/agent-server:c8d59c889715243443c3d9e669475a3ebcf68ef7-python-slim
ghcr.io/openhands/agent-server:fix-agent-server-honor-app-config-python-slim
ghcr.io/openhands/agent-server:c8d59c8-python-node-runtime-slim
ghcr.io/openhands/agent-server:c8d59c8-python
ghcr.io/openhands/agent-server:c8d59c889715243443c3d9e669475a3ebcf68ef7-python
ghcr.io/openhands/agent-server:fix-agent-server-honor-app-config-python
ghcr.io/openhands/agent-server:c8d59c8-python-node-runtime

About Multi-Architecture Support

  • Each variant tag (e.g., c8d59c8-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., c8d59c8-python-amd64) are also available if needed

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-agent-server/openhands/agent_server
   api.py4043392%139, 193–194, 203–204, 206, 209–210, 217–218, 232–233, 250, 256, 259–260, 334, 340, 402, 407, 420–422, 447, 476, 482, 486, 507–508, 712, 794, 797, 803
TOTAL506402016060% 

… config

The non-deferred lifespan built its ConversationService with
get_default_conversation_service(), which loads config from OH_* env and
ignores the Config passed to create_app(). Tests that pass an isolated
Config therefore persisted conversations to OH_CONVERSATIONS_PATH and
posted webhooks to OH_WEBHOOKS_*; inside an OpenHands sandbox those point
at the live deployment.

Build the service from api.state.config, as the deferred /api/init path
already does, and strip live-deployment env vars in pytest_configure.

Co-authored-by: openhands <openhands@all-hands.dev>
@jpshackelford
jpshackelford force-pushed the fix/agent-server-honor-app-config branch from a1db7da to c8d59c8 Compare October 17, 2026 22:22
@jpshackelford
jpshackelford marked this pull request as ready for review October 17, 2026 22:32
@jpshackelford

Copy link
Copy Markdown
Member Author

Just discovered that #5592 has overlap. Will see if we can merge that instead and narrow the scope of this PR....

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This review was posted by an AI agent (OpenHands).

Scope

The change belongs in this repository. It touches the Agent Server's own startup path (openhands-agent-server/openhands/agent_server/api.py) plus its tests, which this repo owns. No product/architecture decision is required.

What the change does

The non-deferred branch of api_lifespan now builds the conversation service with ConversationService.get_instance(config) from api.state.config instead of get_default_conversation_service(), which re-derives its config from the OH_* environment. POST /api/init already used ConversationService.get_instance(new_config) for deferred pods, so the legacy path now matches the deferred one. Production is unaffected: create_app() with no argument passes get_default_config(), the same config the old call resolved. The change is confined to startup wiring; no public symbol, REST/WebSocket contract, or persisted format changes.

Verification on this head (c8d59c88)

I reproduced the reported failure and its fix through the real lifespan, not constructed unit state:

  • Base (fd268089) fails. With OH_CONVERSATIONS_PATH and OH_WEBHOOKS_0_BASE_URL set and create_app(config) given an isolated config, the service built by the lifespan used the env conversations dir and the env webhook (HONORS_APP_CONFIG: False), running against the base sources via a pinned PYTHONPATH.
  • Head passes. The identical scenario on this head yields the app's conversations dir and no webhooks (HONORS_APP_CONFIG: True), and the PR's test_lifespan_conversation_service_uses_app_config_not_env passes. This matches the reported in-process symptom: conversations/webhooks/session key leaking to the ambient OH_* deployment.
  • Focused suites on head: test_api.py, test_env_parser.py, test_init_router.py, test_local_storage.py, test_sockets_service_getters.py, test_preload_modules.py → 225 passed. tests/cross also passes.
  • Env guard: pytest_configure removes the guarded variables before collection, including for a bare pytest (testpaths) run, and leaves unrelated variables intact; tests that need those values set them explicitly.
  • Current-head CI: all required checks pass (build-binary-and-test, pre-commit, Check OpenAPI Schema, sdk-tests, tools-tests, agent-server-tests, cross-tests).

Non-blocking context

  • The non-required Validate PR description check fails on this head because ## Issue Number is None; the repo gate asks for a linked issue. It is not a required status check, so it does not block merge, but linking one would satisfy the gate.
  • The author has noted that #5592 overlaps and may supersede part of this work; that is a maintainer sequencing decision, not a code defect.
  • The PR intentionally leaves the bash-events, VSCode, and tool-preload services on the global config as a follow-up; those use local paths/ports rather than a remote deployment, so the stated scope of the reported bug is met.

No material correctness, security, or compatibility defect found in the changed lines.

✅ APPROVED

@jpshackelford
jpshackelford merged commit 7a714f4 into main Oct 18, 2026
58 of 59 checks passed
@jpshackelford
jpshackelford deleted the fix/agent-server-honor-app-config branch October 18, 2026 00:56
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.

[Bug]: api_lifespan ignores the Config passed to create_app(), leaking conversations into OH_CONVERSATIONS_PATH

3 participants