Repository navigation
Description
Summary
POST /api/agents/{name}/start returns HTTP 500 for any stopped agent whose container config has drifted. Observed on dev against 5 of 6 stopped agents on a local instance. Starting an agent is the most fundamental journey on the platform.
500 {"detail":"Failed to start agent (ValueError — details in backend logs)"}
Context
Found during an exploratory E2E sweep of dev @ c1cc22bc.
Root cause, captured by invoking the service directly inside the backend container:
File "/app/services/agent_service/lifecycle.py", line 414, in start_agent_internal
await recreate_container_with_updated_config(
File "/app/services/agent_service/lifecycle.py", line 842, in recreate_container_with_updated_config
raise ValueError(
ValueError: recreate_container_with_updated_config would START agent
'<agent>', whose container is 'exited'. Pass require_running=False to do that
deliberately, and preserve_run_state=True to leave it stopped afterwards (#2092).
start_agent_internal takes the config-drift recreate branch (base-image drift, MCP-key drift per #1854, git-env drift, …) and calls the helper without require_running=False. The #2092 guard defaults to require_running=True, so it rejects precisely the case that start exists to serve.
Only agents with no config drift start successfully — they skip the recreate branch entirely, which is why the failure is not universal and is easy to miss.
Introduced by: ecf1327f — "fix(agents): recreate no longer starts a stopped agent silently (#2092) (#2155)".
Ancestry: on dev ✅ · on origin/main ❌ → dev-only, unreleased. Blocks a release cut.
The other two production call sites also omit the flag
| Call site | Risk |
|---|---|
src/backend/services/agent_service/lifecycle.py:414 |
Confirmed broken (above) |
src/backend/services/agent_service/repo_binding.py:462 |
Binding a stopped agent would fail at step 6 → BIND_RECREATE_FAILED after history was pushed and origin repointed, leaving partial state. Not reproduced; no upstream running-gate visible at the call site. |
src/backend/services/agent_mcp_key_service.py:795 (_recreate_with_env) |
Docstring says "replace the running container" — lower risk, still unguarded at the call site. |
Each should be decided deliberately rather than fixing only the one that reproduced.
Acceptance Criteria
- A stopped agent with config drift starts successfully via
POST /api/agents/{name}/start -
start_agent_internalpassesrequire_running=False(andpreserve_run_stateas appropriate) atlifecycle.py:414 -
repo_binding.py:462andagent_mcp_key_service.py:795are each audited and either pass the flag or gain an explicit upstream running-gate — decision recorded in a code comment - Regression test: starting a stopped agent whose config has drifted goes through the recreate path and succeeds (the existing suite did not catch a total break of the start path)
- Agent remains stopped-then-running with its volumes, ownership row, and name reservation intact after the recreate
Technical Notes
Suggested fix at the start_agent_internal call site:
await recreate_container_with_updated_config(
agent_name, container, "system",
env_overrides=mcp_env_overrides,
require_running=False, # starting a stopped agent is this path's job
)The UI already surfaces the failure honestly (a toast, not a silent no-op), but the message — Failed to start agent (ValueError — details in backend logs) — is developer-facing and gives an operator nothing actionable. Worth improving alongside the fix.
Activity
vybe commentedon Aug 15, 2026
Closing as a duplicate of #2186 — the fix is already merged on
dev.This was found during an exploratory sweep of
dev @ c1cc22bc, which was 40 commits behindorigin/devat the time of filing. #2186's fix landed on Aug 14 (35a24d0c, PR #2187), before this issue was filed on Aug 15, so the sweep could not see it.Verified against
origin/dev@58df9aed— every acceptance criterion here is already satisfied:origin/devstart_agent_internalpassesrequire_running=Falseservices/agent_service/lifecycle.py:427-430repo_binding.pyaudited, decision in a code commentrepo_binding.py:462-467— running-only confirmed via thestatus != "running"gate above the call; default left implicit, with the reverted-explicit-flag attempt recordedagent_mcp_key_service.pyaudited, decision in a code commentagent_mcp_key_service.py:795-797— caller gates onstatus == "running"; default correct, stays implicittests/unit/test_2186_start_stopped_agent_recreate.py(plustest_2092_recreate_run_state.py)PR #2187 also added the static guard asserting every call site states its run-state intent — the "fix the class, not the instance" point raised here.
No further work required. Tracking issue: #2186.