[bug] ncl groups restart --id <other group> from an agent restarts the caller, not the target
Affected NanoClaw version or commit
c313d061 (v2.4.0)
Host platform
Linux
What happened?
An agent with cli_scope: global ran ncl groups restart --id <another group> --message <text>. The operator approved it. The command returned { "restarted": 1 }, but the target group was never restarted. Instead:
- The on-wake message was written into a new session folder,
data/v2-sessions/<target group>/<caller's session id>/. Nosessionsrow points at it, so nothing ever reads it. - The caller's own container was killed.
This happened three times on one install (2026-09-18 and 09-19), each time from an owner agent trying to restart a different group it had just set up.
The agent branch of the handler uses the caller's session for everything, whatever --id says. src/cli/resources/groups.ts at c313d061:
const id = (args.id as string) || (ctx.caller === 'agent' ? ctx.agentGroupId : undefined);(line 334), then in the agent branch:
await writeSessionMessage(id, ctx.sessionId, {(line 357: target group id, caller session id), and
killContainer(
ctx.sessionId,(lines 368-369: the caller's container). Line 374 wakes getSession(ctx.sessionId), the caller again, and line 380 returns { restarted: 1, … }.
With --rebuild, the target's image is built first (line 350), and then the caller is restarted instead of the target. The target keeps running the old image until it happens to respawn.
cli_scope: group is not affected. src/cli/guard.ts:84 denies a foreign --id under group scope. Global scope skips that check, so the handler receives the foreign id.
Approval does not route around it. Since #2611, an approved request is replayed with the original caller context (src/cli/dispatch.ts, stored at line 160, replayed at lines 234-235), so an approved cross-group restart still takes the agent branch.
What did you expect?
Either the target group's containers are restarted (what the host branch at line 384, restartAgentGroupContainers(id, …), already does), or the command refuses a foreign --id with a clear error. It should not report success while restarting the caller.
How can we reproduce it?
- Two agent groups, A and B. Give A
cli_scope: global(ncl groups config update --id <A> --cli-scope global). - From A's chat, ask the agent to run
ncl groups restart --id <B> --message "check in". Approve the card. - Observe:
- A's container exits (
docker ps --filter label=nanoclaw-group=<A>) and is woken again (line 374), with no on-wake message of its own. - B's containers are untouched.
data/v2-sessions/<B>/<A's session id>/inbound.dbexists with oneon_wakerow, andSELECT * FROM sessions WHERE id='<A's session id>' AND agent_group_id='<B>'returns nothing.
- A's container exits (
Suggested fix
In the agent branch, only use the calling-session path when id === ctx.agentGroupId. For a different group (which only a global-scope caller can reach, and only after approval), fall through to the host path, restartAgentGroupContainers(id, …). That already restarts the right group and handles --message.
The help text at line 328 ("From inside a container, --id is auto-filled and only the calling session is restarted") could then say what happens with an explicit --id.
Related, but not blocking
- #2611 (preserve caller context after approval) is what sends approved replays down this branch. It is correct on its own; the restart handler just never had to handle a foreign id from an agent before.
OS version and CPU architecture
Ubuntu 24.04.4 LTS, x86_64
Install or update path
Something else (customized install, updated with /update-nanoclaw)
Docker version
Docker 29.3.1
Channel or interface
Not channel-specific
Agent provider
Not provider-specific
Last version that worked
Not a regression in this handler: the agent branch has used ctx.sessionId since it was added in be3a8a97. It became reachable through approval with #2611.
Assisted by Claude; reviewed and verified by a human before submission.
Source: nanocoai/nanoclaw