Skip to content

bug: stopped agents cannot be started — recreate guard rejects the start path (#2092 regression) #2195

Closed as not planned

Description

@vybe

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_internal passes require_running=False (and preserve_run_state as appropriate) at lifecycle.py:414
  • repo_binding.py:462 and agent_mcp_key_service.py:795 are 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.

Related: #2092, #2155, #1854, #1816.

Activity

  1. added
    priority-p0
    type-bug
    theme-reliability
    complexity-low
    status-ready
    on Aug 15, 2026
  2. vybe commented on Aug 15, 2026

    @vybe
    ContributorAuthor

    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 behind origin/dev at 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:

    AC Evidence on origin/dev
    start_agent_internal passes require_running=False services/agent_service/lifecycle.py:427-430
    repo_binding.py audited, decision in a code comment repo_binding.py:462-467 — running-only confirmed via the status != "running" gate above the call; default left implicit, with the reverted-explicit-flag attempt recorded
    agent_mcp_key_service.py audited, decision in a code comment agent_mcp_key_service.py:795-797 — caller gates on status == "running"; default correct, stays implicit
    Regression test for a stopped, drifted agent tests/unit/test_2186_start_stopped_agent_recreate.py (plus test_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.

  3. removed
    status-ready
    on Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexity-lowpriority-p0theme-reliabilitytype-bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions