Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ Preconditions:
event file, skips a top-level `acp/` directory, and redacts JSON/JSONL
credential fields plus any Fernet token. Each request builds its own temp
zip (`F14.trajectory-concurrent`) and reads `conversations_path` from the
live `app.state.config`, so it follows an init-time path
live server context's config, so it follows an init-time path
(`F14.trajectory-init-path`).
- No file route emits conversation events or WebSocket frames; their second
views are downloads, listings, archives and the disk.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ Preconditions:
`running` is false, so the body is exactly `{"url": null}` on both routes,
as a keyless server answers (`F16.vscode-url-no-key`) and as a server that
receives the very same key through `POST /api/init` answers
(`F16.vscode-url-after-init`). `get_vscode_service()` seeds the token from
(`F16.vscode-url-after-init`). `create_vscode_service()` seeds the token from
`session_api_keys[0]` before `start()` runs, but `get_vscode_url` returns a
URL only while the server is running, so no dead "open VS Code" link (and no
session key) is handed out for a server that is not there.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,9 +683,11 @@ Preconditions:

## Gotchas

- The workspaces store is a process-wide singleton created on the first
request (`get_workspaces_store`), so the file location is fixed for the
life of the process: changing `OH_PERSISTENCE_DIR` needs a restart.
- The workspaces store belongs to the server context
(`ServerStores.workspaces`) and its location is resolved when that context
is built, so it is fixed for the life of the process: changing
`OH_PERSISTENCE_DIR` needs a restart (a deferred-init server resolves it
again at `POST /api/init`).
Without it, the location follows `conversations_path`, which for the
default relative `workspace/conversations` is `./workspace/.openhands`
under the server's working directory. The contents are not cached: every
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3688,7 +3688,7 @@ def route_templates(checkout: Path | None = None) -> list[dict[str, Any]]:
"from fastapi.routing import APIRoute, APIWebSocketRoute\n"
"from starlette.routing import Route\n"
"from openhands.agent_server.api import create_app\n"
"from openhands.agent_server.config import get_default_config\n"
"from openhands.agent_server.config import load_config\n"
"def table(app):\n"
" out = []\n"
" for r in app.routes:\n"
Expand All @@ -3708,7 +3708,7 @@ def route_templates(checkout: Path | None = None) -> list[dict[str, Any]]:
" return out\n"
"out = table(create_app())\n"
"seen = {(r['method'], r['path']) for r in out}\n"
"docker = get_default_config().model_copy(update={'conversation_runtime': 'docker'})\n"
"docker = load_config().model_copy(update={'conversation_runtime': 'docker'})\n"
"for r in table(create_app(docker)):\n"
" if (r['method'], r['path']) not in seen:\n"
" out.append({**r, 'config': 'conversation_runtime=docker'})\n"
Expand Down
13 changes: 0 additions & 13 deletions openhands-agent-server/openhands/agent_server/_secrets_exposure.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,6 @@
ExposeSecretsMode = Literal["encrypted", "plaintext"]


def get_config(request: Request):
"""Get config from app state, raising 503 if uninitialized."""
config = getattr(request.app.state, "config", None)
if config is None:
raise Unavailable("Server not fully initialized")
return config


def get_cipher(request: Request) -> Cipher | None:
"""Get the configured cipher (``None`` when ``OH_SECRET_KEY`` is unset)."""
return get_config(request).cipher


def parse_expose_secrets_header(request: Request) -> ExposeSecretsMode | None:
"""Parse the ``X-Expose-Secrets`` header.

Expand Down
19 changes: 11 additions & 8 deletions openhands-agent-server/openhands/agent_server/acp_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
from collections.abc import Awaitable, Callable, Mapping
from dataclasses import dataclass, field

from fastapi import APIRouter, Request
from fastapi import APIRouter, Depends, Request
from pydantic import BaseModel, Field

from openhands.agent_server._secrets_exposure import get_config
from openhands.agent_server.config import Config
from openhands.agent_server.credential_binding import LocalVersionedCredentialBinding
from openhands.agent_server.persistence import get_secrets_store
from openhands.agent_server.dependencies import get_config, get_secrets_store
from openhands.agent_server.persistence import FileSecretsStore
from openhands.sdk.agent.acp_file_credentials import CODEX_AUTH_SECRET_NAME
from openhands.sdk.agent.acp_model_discovery import discover_acp_models
from openhands.sdk.agent.acp_models import ACPModelDiscovery
Expand Down Expand Up @@ -131,11 +131,10 @@ def _cache_key(


def _codex_bindings(
settings: ACPAgentSettings, config: Config, secrets: dict[str, str]
settings: ACPAgentSettings, store: FileSecretsStore, secrets: dict[str, str]
) -> dict[str, VersionedCredentialBinding]:
if settings.acp_server != "codex":
return {}
store = get_secrets_store(config)
if store.get_secret(CODEX_AUTH_SECRET_NAME) is None:
return {}
# A stored ChatGPT login refreshes through the store, as in a conversation.
Expand All @@ -149,15 +148,17 @@ def _codex_bindings(

@acp_router.post("/models", response_model=ACPModelDiscovery)
async def discover_models(
body: ACPModelDiscoveryRequest, request: Request
body: ACPModelDiscoveryRequest,
request: Request,
config: Config = Depends(get_config),
secrets_store: FileSecretsStore = Depends(get_secrets_store),
) -> ACPModelDiscovery:
"""Start the ACP server in a throwaway session and report its models.

The server answers with its default model and the models it offers for the
given credentials; a launch or authentication failure comes back in
``error`` rather than as an HTTP error.
"""
config: Config = get_config(request)
if config.conversation_runtime == "docker":
raise NotSupported(
"ACP model discovery runs only where conversations run in-process"
Expand All @@ -169,7 +170,9 @@ async def discover_models(
raise Unprocessable(str(exc)) from exc

secrets = await asyncio.to_thread(_resolve_secrets, body.secrets)
bindings = await asyncio.to_thread(_codex_bindings, settings, config, secrets)
bindings = await asyncio.to_thread(
_codex_bindings, settings, secrets_store, secrets
)
key = _cache_key(settings, command, secrets)

async def run() -> ACPModelDiscovery:
Expand Down
Loading
Loading