Skip to content

Track ACP sessions_spawn runs and emit ACP lifecycle events#40885

Merged
vincentkoc merged 6 commits into
openclaw:mainfrom
xaeon2026:fix-acp-sessions-spawn-lifecycle
Mar 29, 2026
Merged

Track ACP sessions_spawn runs and emit ACP lifecycle events#40885
vincentkoc merged 6 commits into
openclaw:mainfrom
xaeon2026:fix-acp-sessions-spawn-lifecycle

Conversation

@xaeon2026

Copy link
Copy Markdown
Contributor

Fixes #40693

Summary

This fixes the missing completion path for ACP sessions_spawn runs in two places:

  • sessions_spawn(runtime="acp") now registers accepted non-streamTo="parent" child runs with the existing subagent registry so agent.wait/announce cleanup can run
  • ACP dispatch now emits lifecycle end/error events using the active run id, so listeners such as the parent stream relay can observe completion consistently

Why both changes are needed

The original issue points at missing ACP lifecycle completion events, which is real, but ACP sessions_spawn also was not feeding accepted child runs into the registry path that powers auto-announce cleanup.

Without registry tracking, one-shot ACP child runs had nothing waiting on agent.wait or triggering the announce flow.
Without ACP lifecycle end/error, listeners that subscribe directly to agent events still missed completion.

This patch keeps the fix narrow:

  • default ACP spawns now opt into the existing announce pipeline
  • streamTo="parent" ACP spawns keep relying on the dedicated parent relay instead of double-announcing through both paths
  • ACP runtime dispatch now reports terminal lifecycle state with the current run id

Tests

Added regression coverage for:

  • ACP sessions_spawn run-mode spawns are tracked for auto-announce cleanup via agent.wait
  • ACP streamTo="parent" spawns do not also register through the auto-announce path
  • ACP dispatch emits lifecycle end events with the active run id
  • ACP dispatch emits lifecycle error events with the active run id

Verification

pnpm vitest run src/agents/openclaw-tools.subagents.sessions-spawn.lifecycle.test.ts
pnpm vitest run src/auto-reply/reply/dispatch-from-config.test.ts

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M labels Mar 9, 2026
@greptile-apps

greptile-apps Bot commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR closes two gaps in the ACP lifecycle completion path: non-streamTo="parent" ACP sessions_spawn runs are now registered with the subagent registry (enabling agent.wait-based announce/cleanup), and tryDispatchAcpReply now emits lifecycle end/error agent events when a runId is present, letting direct onAgentEvent subscribers (e.g. parent stream relays) observe ACP turn completion consistently.

  • sessions-spawn-tool.ts: adds post-spawn registry tracking guarded by shouldTrackViaRegistry; on registration failure, best-effort cleanup deletes the already-created ACP session
  • dispatch-acp.ts: emits lifecycle end/error events via emitAgentEvent using the caller-supplied runId
  • dispatch-from-config.ts: propagates replyOptions?.runId to both the primary and AcpDispatchTailAfterReset ACP dispatch calls
  • Four new regression tests cover: registry tracking for ACP run-mode spawns, exclusion of streamTo="parent" spawns from the registry path, and lifecycle end/error event emission

Confidence Score: 4/5

  • This PR is safe to merge; the logic is sound with targeted changes and good regression test coverage.
  • The core mechanics are correct: shouldTrackViaRegistry correctly gates registry tracking on status === "accepted", non-empty keys, and streamTo !== "parent". The lifecycle event emission in dispatch-acp.ts is properly guarded. The fallback branch in resolveTrackedSpawnMode is dead code in practice (since spawnAcpDirect always populates mode on accepted results) but is harmless. The one area of imprecision is the cleanup-on-registration-failure path: the in-flight ACP turn may continue briefly after sessions.delete since the gateway dispatch is already in progress, but this is best-effort and acknowledged in comments. No data-loss or correctness regressions are introduced.
  • src/agents/tools/sessions-spawn-tool.ts — specifically the cleanup path when registerSubagentRun throws (lines 254–262); callers receiving the error result should not assume the child process has been terminated.

Last reviewed commit: a836cd4

Comment thread src/agents/tools/sessions-spawn-tool.ts
Comment thread src/agents/tools/sessions-spawn-tool.ts

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

Copy link
Copy Markdown

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: b60881f5ab

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/agents/openclaw-tools.subagents.sessions-spawn.lifecycle.test.ts Outdated
@vincentkoc

Copy link
Copy Markdown
Member

Re-checked against current origin/main on 2026-03-29. This one still looks live. The key reason is unchanged: dispatch-acp.ts still does not appear to emit terminal ACP lifecycle events on the normal path, so the lifecycle/announce seam remains open.

This is currently my leading candidate for the lifecycle side of the ACP relay family.

1 similar comment
@vincentkoc

Copy link
Copy Markdown
Member

Re-checked against current origin/main on 2026-03-29. This one still looks live. The key reason is unchanged: dispatch-acp.ts still does not appear to emit terminal ACP lifecycle events on the normal path, so the lifecycle/announce seam remains open.

This is currently my leading candidate for the lifecycle side of the ACP relay family.

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

Copy link
Copy Markdown

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: 230247d74d

ℹ️ 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".

Comment thread src/agents/tools/sessions-spawn-tool.ts
@vincentkoc

Copy link
Copy Markdown
Member

Follow-up review note after re-checking current main: codex-connector d/ looks valid. spawnAcpDirect() computes effectiveStreamToParent, but the accepted return shape still does not surface that bit, so sessions-spawn-tool.ts can only gate on the explicit streamTo !== "parent" request. That leaves the implicit parent-relay path at risk of being registry-tracked and double-signaled. This PR likely needs one more narrow fix before merge.

@vincentkoc vincentkoc merged commit 4432954 into openclaw:main Mar 29, 2026
8 checks passed

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

Copy link
Copy Markdown

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: 219aa92af0

ℹ️ 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".

cleanup: trackedCleanup,
label: label || undefined,
runTimeoutSeconds,
expectsCompletionMessage: true,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Suppress completion announces for inline ACP deliveries

When an ACP run-mode spawn originates from a non-subagent session with a usable delivery target, spawnAcpDirect already sends the child result inline to the user (deliver: true via its bootstrap delivery plan). This new registration always sets expectsCompletionMessage: true, which causes the subagent cleanup pipeline to run an additional completion announce and produce a second user-facing message for the same run. In normal channel sessions this creates deterministic duplicate replies; this should be gated so completion announces are only enabled for ACP spawns that were not already delivered inline.

Useful? React with 👍 / 👎.

Alix-007 pushed a commit to Alix-007/openclaw that referenced this pull request Mar 30, 2026
…#40885)

* Fix ACP sessions_spawn lifecycle tracking

* fix(tests): resolve leftover merge markers in sessions spawn lifecycle test

* fix(agents): clarify acp spawn cleanup semantics

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
alexjiang1 pushed a commit to alexjiang1/openclaw that referenced this pull request Mar 31, 2026
…#40885)

* Fix ACP sessions_spawn lifecycle tracking

* fix(tests): resolve leftover merge markers in sessions spawn lifecycle test

* fix(agents): clarify acp spawn cleanup semantics

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
pgondhi987 pushed a commit to pgondhi987/openclaw that referenced this pull request Mar 31, 2026
…#40885)

* Fix ACP sessions_spawn lifecycle tracking

* fix(tests): resolve leftover merge markers in sessions spawn lifecycle test

* fix(agents): clarify acp spawn cleanup semantics

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
@pidgeon777

pidgeon777 commented Apr 1, 2026

Copy link
Copy Markdown

We really hope this PR is merged soon because OpenClaw is currently unusable with sub-agents. In the latest version (2026.03.31), the inability to use sub-agents causes significant operational delays and makes the system much slower for multi-task workflows.

@TheBlippo

Copy link
Copy Markdown

This PR is what got sub-agents working again for me. Thanks @xaeon2026 for the thorough fix and @vincentkoc for pushing it through to merge. The detailed breakdown in the description made it easy to follow what was going wrong. Much appreciated.

lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
…#40885)

* Fix ACP sessions_spawn lifecycle tracking

* fix(tests): resolve leftover merge markers in sessions spawn lifecycle test

* fix(agents): clarify acp spawn cleanup semantics

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
Tardisyuan pushed a commit to Tardisyuan/openclaw that referenced this pull request Apr 30, 2026
…#40885)

* Fix ACP sessions_spawn lifecycle tracking

* fix(tests): resolve leftover merge markers in sessions spawn lifecycle test

* fix(agents): clarify acp spawn cleanup semantics

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
…#40885)

* Fix ACP sessions_spawn lifecycle tracking

* fix(tests): resolve leftover merge markers in sessions spawn lifecycle test

* fix(agents): clarify acp spawn cleanup semantics

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
…#40885)

* Fix ACP sessions_spawn lifecycle tracking

* fix(tests): resolve leftover merge markers in sessions spawn lifecycle test

* fix(agents): clarify acp spawn cleanup semantics

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
…#40885)

* Fix ACP sessions_spawn lifecycle tracking

* fix(tests): resolve leftover merge markers in sessions spawn lifecycle test

* fix(agents): clarify acp spawn cleanup semantics

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ACP sessions never trigger auto-announce (missing lifecycle event in dispatch-acp path)

4 participants