[Bug]: TaskManager loses sub-agent task index across parent conversation resume and mismatches subagent_type

Open
#6,990 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@zsicheng0214 is already working on this.

Since Nov 19, 2026.

  • #6986 by @zsicheng0214 — open

Assessment

Difficulty
4/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python

Research direction

Start with TaskManager._ensure_parent(), TaskManager.close(), and the task resume path; the issue identifies these as the points where the in-memory registry is lost and the original subagent_type is missing. Read the task tests under tests/tools/task/ and run uv run pytest tests/tools/task/ to see the regression coverage. Done means a resumed parent reloads the task index, resumes with the recorded type, and the regression tests pass; linked PR #6986 is already open.

Written by the indexing model from the issue text.

Description

priority:medium ready-for-dev
Is there an existing issue for the same bug?
  • I have searched existing issues and this is not a duplicate. (Related to #5074 which covers server-crash mid-run; this covers clean multi-turn parent conversation resume.)
Bug Description

TaskManager._ensure_parent() persists sub-agent LocalConversation directories under <parent_persistence_dir>/subagents/<subagent_id>/, and TaskManager.close() intentionally preserves that directory when the parent persists. However:

  1. self._tasks (task_00000001 -> Task(conversation_id=...)) is stored only in memory and never reloaded from <parent_persistence_dir>/subagents/, causing task(resume="task_00000001") in a resumed parent session to fail with ValueError: Task 'task_00000001' not found. Available tasks:.
  2. Task does not record the subagent_type it was created with; if the model omits or changes subagent_type on resume, Agent._verify_persisted raises Cannot resume conversation: tools were removed mid-conversation.
Expected Behavior

Resuming a persisted parent conversation in a new process and calling task(resume="task_00000001", prompt=...) should reload the persisted task registry and restore the sub-agent using its original subagent_type.

Actual Behavior

Reproducible via uv run pytest:

  1. Create a LocalConversation with persistence_dir and run TaskManager.start_task(..., subagent_type="code-explorer") (task_00000001), then call manager.close().
  2. Create a new TaskManager attached to the resumed parent conversation and call start_task(resume="task_00000001", prompt="follow up").
  3. ValueError: Task 'task_00000001' not found. Available tasks: is raised despite the sub-agent conversation existing on disk under subagents/.

Discovered via TraceTrial-Bench (arXiv:2610.32285, mechanism node C6). Companion fix ready in #6986.

Acceptance Criteria
  • TaskManager persists tasks_index.json under <parent_persistence_dir>/subagents/ and reloads it when attaching to a persisted parent conversation
  • Resuming a task reuses the subagent_type recorded at creation time so Agent._verify_persisted succeeds
  • Automated regression tests pass via uv run pytest tests/tools/task/

OpenHands AI triage

The following comments and acceptance criteria were added by the OpenHands AI agent.

Triage

Verified against main: TaskManager._tasks is memory-only (never reloaded in _ensure_parent(), cleared in close()), Task carries no subagent_type, and AgentBase._verify_persisted raises "Cannot resume conversation: tools were removed mid-conversation" when a resumed agent lacks tools the persisted conversation had. Both reported failures follow from this, so the issue is reproducible and its expected behavior is unambiguous.

Scope: persist a task index under <parent_persistence_dir>/subagents/ (e.g. tasks_index.json), reload it when attaching to a persisted parent, and restore each task's creation-time subagent_type on resume. Existing lifecycle rules are kept: sub-agent data is preserved when the parent persists, and the temporary subagents directory is removed on close when it does not.

Non-goals: no change to the persisted sub-agent conversation directory layout; no change to the task tool's LLM-facing action/observation schema or prompt; no handling of the server-crash mid-run scenario tracked in #5074.

Priority: medium — external user report with a reproduced failure in the actual product workflow (the companion PR #6986 records a live end-to-end reproduction: session-2 resume of a persisted parent fails on main and succeeds with the fix, with a real LLM and no mocks). Not high: the parent conversation keeps working and can start new tasks; only cross-session resume of a prior sub-agent task fails, and starting a new task is a workaround.

Acceptance Criteria
  • With a parent LocalConversation that has a persistence_dir, after the parent is closed and re-attached in a new session, a fresh TaskManager calling start_task(resume="<earlier task id>", prompt=...) succeeds instead of raising ValueError: Task '<id>' not found, and the sub-agent continues in its original persisted conversation (same conversation ID).
  • A task created with subagent_type X is resumed using X — the type recorded at creation — even when the resume call omits subagent_type or passes a different value, so the persisted sub-agent conversation resumes without raising "Cannot resume conversation: tools were removed mid-conversation".
  • After reloading the persisted index, creating a new task allocates the next unused task ID (e.g. task_00000002 after task_00000001) rather than reusing an existing ID.
  • Attaching a TaskManager to a persisted parent whose subagents/ directory has no task index (e.g. a parent persisted before this change) does not raise, and resuming an unregistered task ID still raises ValueError: Task '<id>' not found. Available tasks: ....
  • With a non-persisted parent, TaskManager.close() still removes its temporary subagents/ directory; with a persisted parent, close() does not delete <parent_persistence_dir>/subagents/.
  • Automated regression tests under tests/tools/task/ cover the cross-session index reload and subagent_type restoration, and uv run pytest tests/tools/task/ passes.
Dominant language
Python
Stars
1.4k
Forks
797
Avg merge
1d 17h
Merged PRs (30d)
354

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from OpenHands/software-agent-sdk

All issues in OpenHands/software-agent-sdk

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.