Skip to content

fix(agent-server): skip the inert ACP agent LLM when auto-titling - #4868

Closed
lkshrk wants to merge 4 commits into
OpenHands:mainfrom
lkshrk:fix/acp-title-llm
Closed

lkshrk wants to merge 4 commits into
OpenHands:mainfrom
lkshrk:fix/acp-title-llm

Conversation

@lkshrk

@lkshrk lkshrk commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

HUMAN:

Found this on a self-hosted Agent Canvas worker running ACP with Claude Code on
subscription auth: every conversation surfaced a credentials error in the UI while
the conversation and its MCP tools worked normally. Confirmed on that host that the
agent LLM is inert under ACP and nothing should be calling it for titles, and that
title_llm_profile was unset so the fallback was the only path in play. The
agent-server suite and linters were run locally on the branch, and the new test was
checked to fail with the fix reverted. Not able to run a patched agent-server against
that deployment, since it consumes released images.


AGENT:

Why

Auto-titling falls back to agent.llm when no title_llm_profile is configured. ACPAgent.llm only defaults to the acp-managed sentinel (acp_agent.py:1673), so a backend that persists an agent LLM keeps that model on the agent while the conversation itself runs in the ACP subprocess under its own credentials. The sentinel guard in generate_title_from_message (title_utils.py:186) matches on usage_id == "acp-managed" and therefore never fires, and the title call reaches a real provider with no key:

[agent-server] ERROR   litellm.InternalServerError: InternalServerError: OpenAIException -
  Missing credentials. Please pass an `api_key`, `workload_identity`, `admin_api_key`,
  or set the `OPENAI_API_KEY` or `OPENAI_ADMIN_KEY` environment variable.. Attempt #3
[agent-server] WARNING Error generating conversation title with LLM: ...  title_utils.py:152

Four retries per conversation, and since #16686 the failure is published to the frontend as well, so ACP users see a credentials error on a backend that deliberately holds no model credentials. Agent Canvas states the same contract from the other side: for agent_kind: "acp", "The LLM / condenser settings are inert; mcp_config and acp_command / acp_args / acp_model / acp_server apply instead."

Summary

  • AutoTitleSubscriber no longer falls back to agent.llm for an ACP agent, using the existing public AgentBase.agent_kind property rather than an isinstance check, so the SDK's agent surface stays the seam.
  • title_llm_profile keeps precedence, so an ACP deployment that wants generated titles configures one; otherwise titling falls through to truncation, which is where a credential-less agent already ended up after four failed attempts.
  • Adds TestAutoTitle::test_autotitle_skips_inert_acp_agent_llm, which asserts the title path receives llm=None and the stored title comes from truncation.

Deliberately not treating any credential-less LLM as unusable. That would need a heuristic for "has a usable key", would silently change behaviour for a misconfigured non-ACP backend that today surfaces a real error, and would hide exactly the class of misconfiguration #16686 set out to make visible. ACP is the case where the contract already says the LLM is inert, so that is where the skip belongs. If you would rather generalize, say so and I will rework it.

Issue Number

Fixes #4867

How to Test

uv run pytest tests/agent_server/test_conversation_service.py -q   # 114 passed
uv run ruff check <changed>                                        # All checks passed!
uv run ruff format --check <changed>                               # 2 files already formatted

The new test is regression-sensitive: reverting only the conversation_service.py hunk and re-running gives

FAILED tests/agent_server/test_conversation_service.py::TestAutoTitle::test_autotitle_skips_inert_acp_agent_llm
1 failed, 6 passed

Reproduced on a self-hosted worker running openhands-agent-server 1.44.0 with agent_kind: "acp", acp_server: "claude-code", subscription auth, title_llm_profile: null, and an active_agent_profile_id whose model matches the one named in the error. Every new conversation produces the log above while the conversation and its MCP tools work normally.

I could not run a patched agent-server against that deployment: it consumes released images, so the end-to-end evidence here is the failure reproduction plus the unit-level proof rather than a patched round trip.

Type

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

Notes

One workaround is worth recording as a trap: exporting OPENAI_API_KEY for the agent-server does make titling work, but ACP subprocesses inherit the parent environment and the Codex CLI prefers OPENAI_API_KEY when present, which can silently switch the main workload from subscription auth to API auth.

Linked issue #4867 was originally written free-form and so carried none of the bug-template headings, which is why Validate PR description failed here with "Linked issue(s) (#4867) carry neither ready-for-dev nor a pre-rollout creation date." It has been restructured onto the template — all 16 fields, a runnable reproduction under ### Actual Behavior, and acceptance criteria — and now carries ready-for-dev.

Auto-titling falls back to `agent.llm` when no `title_llm_profile` is
configured. `ACPAgent.llm` only defaults to the `acp-managed` sentinel, so
a backend that stores an agent LLM keeps that model on the agent while the
conversation runs in the ACP subprocess under its own credentials. The
sentinel guard in `generate_title_from_message` does not match, and the
title call reaches a real provider with no key:

    litellm.InternalServerError: OpenAIException - Missing credentials.
    Please pass an `api_key` ... or set the `OPENAI_API_KEY` ...

Retried four times per conversation, and since #16686 the failure is also
surfaced to the UI, so ACP users see a credentials error on a backend that
deliberately has no model credentials.

Skip `agent.llm` for ACP agents and fall through to truncation.
`title_llm_profile` still takes precedence, so an ACP deployment that wants
generated titles can configure one.
@github-actions

github-actions Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor
  ✅ **PR Artifacts Cleaned Up**

  The `.pr/` directory is no longer present.

@lkshrk
lkshrk marked this pull request as ready for review September 13, 2026 05:25
@all-hands-bot

Copy link
Copy Markdown
Collaborator

🚦 CI is currently failing on this PR's latest commit.

Please fix the failing checks before OpenHands reviews it - this is re-checked automatically once you push a new commit. (A maintainer can also request @all-hands-bot as a reviewer to have it reviewed regardless of CI status.)

This is an automated check - no AI was used to generate this comment.

@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).

Verdict: targeted fix, correct seam

The change addresses a real defect: auto-titling fell back to agent.llm, but for an ACP agent created from ACPAgentSettings that LLM is attribution-only. ACPAgentSettings.create_agent() (openhands-sdk/openhands/sdk/settings/model.py:1846) copies the settings' llm onto the agent and only the acp_model is propagated — the acp-managed/ACP_SENTINEL_USAGE_ID marker lives on _make_dummy_llm() (acp_agent.py:268), so a settings-built ACP agent's LLM keeps usage_id == "default" (model gpt-5.5 by default). I verified this directly:

settings llm usage_id: default model: gpt-5.5
agent llm usage_id:    default model: gpt-5.5
agent_kind: acp
direct ACPAgent usage_id: acp-managed acp-managed acp

That is exactly why the existing sentinel guard in title_utils.py:181 (usage_id == "acp-managed") never fires on the reported host, and why the title call reaches a credential-less provider. Deferring to the public AgentBase.agent_kind property rather than an isinstance check keeps the guard honest for both construction paths (settings-built and direct ACPAgent), and preserves title_llm_profile precedence. Non-ACP behavior is unchanged.

Verification on the checked-out head (9a67db942f70bfacbe52571a526ee7d4fd2dfa21):

  • uv run pytest tests/agent_server/test_conversation_service.py -q → 114 passed
  • uv run pytest tests/sdk/conversation/test_generate_title.py -q → 12 passed
  • uv run ruff check / ruff format --check on both changed files → clean

The new test test_autotitle_skips_inert_acp_agent_llm asserts llm is None reaches generate_title_from_message and that the stored title is the truncation fallback, which is the right observable.

Non-blocking observation (out of scope for this PR)

The same inert-LLM reachability still exists on the SDK-level explicit path this PR does not touch: LocalConversation.generate_title (local_conversation.py:2937) and RemoteConversation.generate_title (remote_conversation.py:1533) both fall back to self.agent.llm, and generate_title_from_message only skips the usage_id == "acp-managed" sentinel. For a settings-built ACP agent (usage_id == "default"), an explicit conversation.generate_title() would still call the attribution-only model. The agent-server REST route is gone and auto-titling is now covered, so this does not block the PR — but if the intended contract is "an ACP agent's LLM is never invoked for titles," the guard may be worth consolidating at the sentinel-detection layer so every caller inherits it. Flagging for a possible follow-up only.

No blocking findings.

✅ APPROVED

@neubig neubig left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ACP agent LLM settings are inert for execution and are not a valid implicit title-generation credential source. The agent-kind guard is the correct seam: it preserves explicit title profiles and all non-ACP behavior while avoiding credential heuristics. The regression test covers the resulting truncation path.

AI disclosure: This review was submitted by OpenHands on behalf of @neubig.

@simonrosenberg

Copy link
Copy Markdown
Member

Thanks @lkshrk for tracking this down. Your repro pointed us to the root cause.

#5434 (merged) fixes it at the source. ACPAgentSettings.create_agent() no longer replaces the ACP agent's acp-managed sentinel LLM. Title generation already skips that sentinel, so ACP conversations now fall back to a truncated title on every path: auto-titling, generate_title(), Agent Profiles and canvas agent_settings launches. A configured title_llm_profile is still used. #5434 also closed #4867.

That makes this guard redundant, so I'm closing this PR in favor of #5434.

This comment was posted by an AI agent (Claude Code) on behalf of the requesting user.

auto-merge was automatically disabled October 1, 2026 13:49

Pull request was closed

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]: ACP mode: conversation title generation fails with missing credentials (explicit LLM without a key)

4 participants