Skip to content

A self-improving RLM agent for coding workflows and long-running autonomous tasks.

Rust

fix(coding-agent): accept spawn handles in rlm collect and delete_subagent (#2307)

Seth Karten9e7ac5d5e36a
diff --git a/packages/coding-agent/.changes/rlm-delete-subagent-spawn-handle.md b/packages/coding-agent/.changes/rlm-delete-subagent-spawn-handle.md
new file mode 100644
index 0000000000..cf1e3415d0
--- /dev/null
+++ b/packages/coding-agent/.changes/rlm-delete-subagent-spawn-handle.md
@@ -0,0 +1 @@
+- Fixed `rlm.delete_subagent` rejecting the `RLMSpawnHandle` returned by `rlm.spawn`; it now accepts a spawn handle, a subagent row, or a child id/session name string, matching `rlm.collect`.
diff --git a/prime-agent-runtime/src/rlm/__init__.py b/prime-agent-runtime/src/rlm/__init__.py
index 3fde0442a2..05dc6ca4ce 100644
--- a/prime-agent-runtime/src/rlm/__init__.py
+++ b/prime-agent-runtime/src/rlm/__init__.py
@@ -352,16 +352,24 @@ async def collect(
return [_child_result_from_payload(entry) for entry in results]
-async def delete_subagent(target: str | RLMSubagent) -> RLMSubagent:
- """Delete one running or retained direct child from the current parent session."""
- if isinstance(target, RLMSubagent):
+async def delete_subagent(target: str | RLMSubagent | RLMSpawnHandle) -> RLMSubagent:
+ """Delete one running or retained direct child from the current parent session.
+
+ ``target`` selects the child: the spawn handle returned by ``rlm.spawn``, a
+ subagent row from ``list_subagents()``, or a child id/session name string.
+ """
+ if isinstance(target, RLMSpawnHandle):
+ selector = target.rlm_child_id
+ elif isinstance(target, RLMSubagent):
selector = target.rlm_child_id
elif isinstance(target, str):
selector = target.strip()
if not selector:
raise ValueError("target must not be empty")
else:
- raise TypeError(f"target must be str or RLMSubagent, got {type(target).__name__}")
+ raise TypeError(
+ f"target must be RLMSpawnHandle, RLMSubagent, or str, got {type(target).__name__}"
+ )
payload = await host_request("rlm.delete_subagent", {"target": selector})
return _subagent_from_payload(payload.get("subagent"), "rlm.delete_subagent")
@@ -445,7 +453,7 @@ class _RLMNamespace:
async def list_subagents(self) -> list[RLMSubagent]:
return await list_subagents()
- async def delete_subagent(self, target: str | RLMSubagent) -> RLMSubagent:
+ async def delete_subagent(self, target: str | RLMSubagent | RLMSpawnHandle) -> RLMSubagent:
return await delete_subagent(target)
async def collect(self, targets: Any = None, *, timeout_ms: int = 0) -> list[RLMChildResult]:
diff --git a/prime-agent-runtime/test/test_subagent_registry.py b/prime-agent-runtime/test/test_subagent_registry.py
index b3acddaaf8..66d93c93fe 100644
--- a/prime-agent-runtime/test/test_subagent_registry.py
+++ b/prime-agent-runtime/test/test_subagent_registry.py
@@ -198,6 +198,33 @@ class RlmSubagentRegistryTest(unittest.TestCase):
{"target": "sub-a1b2c3d4"},
)
+ def test_deletes_subagent_by_spawn_handle(self) -> None:
+ handle = rlm_module.RLMSpawnHandle(
+ rlm_child_id="sub-a1b2c3d4",
+ name="api-reviewer",
+ session_dir=Path("/tmp/parent/sub-a1b2c3d4"),
+ model="deepseek/deepseek-v4-flash",
+ )
+ deleted_payload = {
+ "rlm_child_id": handle.rlm_child_id,
+ "active_session_id": None,
+ "session_id": None,
+ "session_name": handle.name,
+ "session_dir": str(handle.session_dir),
+ "status": "completed",
+ }
+ host_request = AsyncMock(return_value={"subagent": deleted_payload})
+
+ with patch.object(rlm_module, "host_request", host_request):
+ deleted = asyncio.run(rlm_module.rlm.delete_subagent(handle))
+
+ self.assertEqual(deleted.rlm_child_id, handle.rlm_child_id)
+ self.assertEqual(deleted.session_name, handle.name)
+ host_request.assert_awaited_once_with(
+ "rlm.delete_subagent",
+ {"target": "sub-a1b2c3d4"},
+ )
+
def test_rejects_invalid_delete_response_and_target(self) -> None:
host_request = AsyncMock(return_value={"subagent": {"status": "completed"}})
@@ -207,7 +234,7 @@ class RlmSubagentRegistryTest(unittest.TestCase):
with self.assertRaisesRegex(ValueError, "target must not be empty"):
asyncio.run(rlm_module.delete_subagent(" "))
- with self.assertRaisesRegex(TypeError, "target must be str or RLMSubagent"):
+ with self.assertRaisesRegex(TypeError, "target must be RLMSpawnHandle, RLMSubagent, or str"):
asyncio.run(rlm_module.delete_subagent(123))
def test_rejects_invalid_registry_payload(self) -> None:
@@ -311,6 +338,32 @@ class RlmCollectTest(unittest.TestCase):
"rlm.collect", {"targets": ["sub-h1", "worker-b"], "timeout_ms": 250}
)
+ def test_collect_accepts_single_spawn_handle_and_subagent_row(self) -> None:
+ handle = rlm_module.RLMSpawnHandle(
+ rlm_child_id="sub-h1",
+ name="worker-h",
+ session_dir=Path("/tmp/parent/sub-h1"),
+ model="anthropic/claude-sonnet-4-5",
+ )
+ subagent = rlm_module.RLMSubagent(
+ rlm_child_id="sub-r1",
+ active_session_id=None,
+ session_id="session-child",
+ session_name="worker-r",
+ session_dir=Path("/tmp/parent/sub-r1"),
+ status="running",
+ )
+
+ for target, expected_selector in ((handle, "sub-h1"), (subagent, "sub-r1")):
+ host_request = AsyncMock(return_value={"results": []})
+ with patch.object(rlm_module, "host_request", host_request):
+ results = asyncio.run(rlm_module.rlm.collect(target))
+
+ self.assertEqual(results, [])
+ host_request.assert_awaited_once_with(
+ "rlm.collect", {"targets": [expected_selector], "timeout_ms": 0}
+ )
+
def test_collect_validates_arguments(self) -> None:
with self.assertRaisesRegex(TypeError, "timeout_ms"):
asyncio.run(rlm_module.rlm.collect(timeout_ms=-1))