Skip to content

fix(agent-server): sync Codex credentials in Docker - #7013

Open
Vietpr wants to merge 2 commits into
OpenHands:mainfrom
Vietpr:fix/docker-codex-credential-sync
Open

Vietpr wants to merge 2 commits into
OpenHands:mainfrom
Vietpr:fix/docker-codex-credential-sync

Conversation

@Vietpr

@Vietpr Vietpr commented Nov 19, 2026 •

Copy link
Copy Markdown

HUMAN:
I reviewed the Docker credential sync flow and understand how token rotation works.


AGENT:

Why

Existing Docker conversations keep the Codex credential snapshot captured when the container starts. After OAuth rotation on the host, those conversations continue using the stale token while newly created conversations work.

Summary

  • Add an authenticated host-side versioned credential broker for each Docker runtime.
  • Activate the Codex credential binding before start or resume, including legacy-container recreation when needed.
  • Preserve compare-and-swap write-back semantics and log sanitized binding selection/fallback outcomes.
  • Recreate a legacy container only when its durable state and runtime leases are idle; active turns and concurrent use return a conflict without stopping the container.

Issue Number

Closes #6533
Related to OpenHands/OpenHands#19837

How to Test

  • uv run pytest tests/agent_server/docker_runtime/test_routes.py -q -k "not test_a_symlinked_conversation_dir_is_rejected" -> 33 passed, 1 deselected.
  • uv run pytest tests/agent_server/docker_runtime/test_mediation.py -q -> 23 passed.
  • Credential-binding regression selection completed 32 passing tests before a Windows asyncio teardown interruption; no assertion failed.
  • Ruff, pycodestyle, import-boundary, async-safety, and secret-field hooks passed. Pyright reached only the existing Windows-only os.getuid/os.getgid errors in
    egistry.py:749.
  • A live Docker workflow was not run because the Docker daemon is unavailable in this environment.

Video/Screenshots

Not applicable; this changes server-side credential synchronization.

Design Doc

Not included. The implementation reuses the existing versioned credential-binding contract and limits the new broker to one authenticated internal route.

Type

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

Notes

The broker exposes only CODEX_AUTH_JSON, validates the requesting runtime's per-conversation key, and does not log credential values.

Co-authored-by: openhands <openhands@all-hands.dev>
@yjjnls

yjjnls commented Nov 23, 2026

Copy link
Copy Markdown

Thanks — read the full diff and ran the affected tests locally at this head. A few notes.

On the follow-up in OpenHands#19837 (new-conversation total failure): not covered. The broker only relays what the authoritative store holds; nothing here repairs a present but provider-rejected refresh token (the Nov-20 refresh_token_reused state), and the generic "did not complete in time" message is unchanged. New Docker conversations do change behavior: the binding is activated before the inner start and the request snapshot is dropped (routers.py:458-462, :610-611), so they read the host store live instead of a per-start copy — but if the store itself is invalidated, a new conversation still fails; the actionable "sign in again" error fires only when the secret is missing (broker GET 404 → activation 422). A fresh OAuth login remains the only recovery in that state, so it may be worth stating this scope on the issue.

Verified locally (uv run --frozen, PR head 570950f): test_routes.py 31 passed — including test_a_symlinked_conversation_dir_is_rejected, which the command in the PR description deselects (it passes on Linux; is that exclusion Windows-only?); test_mediation.py 23 passed; test_credential_binding.py 34 passed. The CAS boundary is sound: version compare and write happen under the same file lock (persistence/store.py:787-817), and a separate two-writer check confirms a stale expected_version is rejected. The check_session_api_key bypass is narrowly scoped to this route and the broker still gates on the per-conversation runtime key (token_urlsafe(32), hmac.compare_digest).

Questions

  1. The legacy 409 path stops and recreates the container even when ACP is already initialized and a turn may be in flight (routers.py:464-479). Is that restricted to the cases that need it (no binding / binding URL changed), or can a resume of a running conversation kill an active turn?
  2. Which paths do you consider blocked on live evidence? host.docker.internal:host-gateway is wired at container creation (registry.py:753-754), but the PR states no Docker run. One live scenario would cover most of it: start a Codex Docker conversation → rotate CODEX_AUTH_JSON on the host → resume → confirm the new generation is used and write-back lands; plus the 409 recreate path.

Known scope: the broker serializes writes but does not fence provider refreshes across runtimes, so two runtimes can still race on the same refresh token. That matches the deferred #4171/#4268 decision, but #19837's "concurrent conversations do not invalidate one another" criterion is narrowed, not met.

@Vietpr

Vietpr commented Nov 25, 2026

Copy link
Copy Markdown
Author

Good catch on the 409 path. I pushed 20b3204 to remove the unconditional restart. Recovery now reloads the durable execution status and only considers idle/paused/terminal states restartable; running, waiting-for-confirmation, missing, or unreadable state returns 409 without stopping the container. For an eligible state it releases only its own lease and uses the registry generation token plus stop_if_idle and the expected container, so a concurrent request or attached session also prevents the stop. The new regressions cover the active-turn, idle-restart, and concurrent-use cases.

The affected route suite passes 33/33 here (the symlink test is Windows-only deselected), and mediation passes 23/23. I still cannot claim live Docker evidence: the Docker client is installed, but the Desktop Linux daemon is unavailable on this machine. The PR body now states that limitation and the Windows-only Pyright/asyncio teardown blockers explicitly. The provider-rejected refresh-token case remains outside this PR's scope as noted.

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]: Docker Codex conversation credentials diverge from stored secret after refresh

2 participants