Skip to content

Fix /subagents list requester resolution for native commands - #33579

Closed
liuxiaopai-ai wants to merge 1 commit into
openclaw:mainfrom
liuxiaopai-ai:codex/fix-33508-subagents-list-target-session
Closed

liuxiaopai-ai wants to merge 1 commit into
openclaw:mainfrom
liuxiaopai-ai:codex/fix-33508-subagents-list-target-session

Conversation

@liuxiaopai-ai

Copy link
Copy Markdown
Contributor

Summary

Testing

  • pnpm vitest src/auto-reply/reply/commands.test.ts src/auto-reply/reply/commands-subagents-spawn.test.ts
  • pnpm format:check

Closes #33508

@greptile-apps

greptile-apps Bot commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a session-resolution bug in the /subagents list native command handler: it was resolving the requester against the transient slash-command session (sessionKey) instead of the intended conversation session (CommandTargetSessionKey), causing the listing to show (or miss) the wrong set of subagent runs. The one-line change in commands-subagents.ts brings list in line with the existing spawn behaviour by setting preferCommandTarget: true for both actions. The accompanying test cleanly replaces the old (incorrect) assertion with a scenario that asserts the target-session run is shown and the slash-session run is not.

Key changes:

  • commands-subagents.ts: extend preferCommandTarget condition from action === "spawn" to action === "spawn" || action === "list" so native /subagents list resolves against CommandTargetSessionKey
  • commands.test.ts: update the regression test to set up two distinct run fixtures keyed to different sessions, then assert the correct (target-session) run appears and the slash-session run does not
  • CHANGELOG.md: add fix entry under 2026.3.3 referencing Native /subagents list resolves requester to slash session instead of CommandTargetSessionKey #33508

Notable observation: The other run-targeting actions (kill, info, log, send, steer, focus, unfocus) still resolve requesterKey from sessionKey first under native routing. Since ctx.runs is derived from requesterKey and shared by all actions, index-based targeting (e.g., /subagents kill 1) could silently operate against the wrong run list when invoked natively. This may be worth a follow-up.

Confidence Score: 4/5

  • Safe to merge; the fix is small, correct, and well-tested, with one non-blocking style concern about session resolution consistency for other actions.
  • The core one-line change is logically sound and directly mirrors the already-approved spawn precedent. The test provides clear before/after coverage. Score is 4 rather than 5 because the other run-targeting actions (kill, info, log, send, steer, focus, unfocus) have the same potential session-resolution mismatch under native routing, which is left unaddressed and could cause subtle index-based targeting failures in follow-on commands.
  • src/auto-reply/reply/commands-subagents.ts — consider whether the preferCommandTarget guard should extend to the remaining run-targeting actions for consistency.

Last reviewed commit: 5de5247

Comment on lines 50 to 52
const requesterKey = resolveRequesterSessionKey(params, {
preferCommandTarget: action === "spawn",
preferCommandTarget: action === "spawn" || action === "list",
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other mutating actions may have the same session-resolution gap

list now correctly prefers CommandTargetSessionKey for native routing, but ctx.runs is built from requesterKey and shared by every action in the switch. When kill, info, log, send, steer, focus, and unfocus are invoked natively (i.e., CommandTargetSessionKey is present but preferCommandTarget is still false for them), requesterKey resolves to the transient slash-command session. Any index-based targeting (e.g., /subagents kill 1) would then search against that wrong run list and likely fail to find the intended subagent.

Consider extending the preferCommandTarget guard to all actions that operate on specific runs, or extracting a helper that maps action → preferCommandTarget to make future additions explicit:

const preferCommandTarget =
  action === "spawn" ||
  action === "list"  ||
  action === "kill"  ||
  action === "info"  ||
  action === "log"   ||
  action === "send"  ||
  action === "steer" ||
  action === "focus" ||
  action === "unfocus";

If there is a deliberate reason to keep those actions on the slash-command session, a brief comment here would help future reviewers understand the intent.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/auto-reply/reply/commands-subagents.ts
Line: 50-52

Comment:
**Other mutating actions may have the same session-resolution gap**

`list` now correctly prefers `CommandTargetSessionKey` for native routing, but `ctx.runs` is built from `requesterKey` and shared by every action in the switch. When `kill`, `info`, `log`, `send`, `steer`, `focus`, and `unfocus` are invoked natively (i.e., `CommandTargetSessionKey` is present but `preferCommandTarget` is still `false` for them), `requesterKey` resolves to the transient slash-command session. Any **index-based targeting** (e.g., `/subagents kill 1`) would then search against that wrong run list and likely fail to find the intended subagent.

Consider extending the `preferCommandTarget` guard to all actions that operate on specific runs, or extracting a helper that maps action → `preferCommandTarget` to make future additions explicit:

```ts
const preferCommandTarget =
  action === "spawn" ||
  action === "list"  ||
  action === "kill"  ||
  action === "info"  ||
  action === "log"   ||
  action === "send"  ||
  action === "steer" ||
  action === "focus" ||
  action === "unfocus";
```

If there is a deliberate reason to keep those actions on the slash-command session, a brief comment here would help future reviewers understand the intent.

How can I resolve this? If you propose a fix, please make it concise.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5de52479b9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


const requesterKey = resolveRequesterSessionKey(params, {
preferCommandTarget: action === "spawn",
preferCommandTarget: action === "spawn" || action === "list",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Align native subagent requester resolution across actions

/subagents list now resolves runs from CommandTargetSessionKey, but follow-up management commands (/kill, /steer, /subagents info, etc.) still resolve from the transient command session because only action === "list" was added to preferCommandTarget. In native slash flows where SessionKey and CommandTargetSessionKey differ (for example src/slack/monitor/slash.ts sets SessionKey to slash:<user> and CommandTargetSessionKey to the routed conversation), users can list target-session runs but immediately fail to act on them via index/id in the next command, since those commands query a different requester scope.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native /subagents list resolves requester to slash session instead of CommandTargetSessionKey

2 participants