Skip to content

fix(agents): preserve ACP lifecycle ownership - #122849

Closed
markGenhealth wants to merge 1 commit into
openclaw:mainfrom
markGenhealth:agent/gen-6353-preserve-acp-session
Closed

markGenhealth wants to merge 1 commit into
openclaw:mainfrom
markGenhealth:agent/gen-6353-preserve-acp-session

Conversation

@markGenhealth

@markGenhealth markGenhealth commented Aug 12, 2026 •

Copy link
Copy Markdown

Summary

  • keep spawned ACP runs under their canonical acp task owner while retaining a topology/control observer in the subagent registry
  • stop ACP observer rows from creating duplicate subagent task projections, terminal delivery obligations, or child-session cleanup authority
  • upgrade persisted legacy ACP mirrors during normalization and use the active ACP turn or canonical durable task as observer liveness
  • emit a specific ACP owner-loss reason and preserve one-shot session state until a later corroborating maintenance pass

Fixes GEN-6353.

What Problem This Solves

An ACP spawn created the canonical runtime=acp task, then the shared spawn pipeline registered the same run as a native subagent. The mirror's sweeper checked getAgentRunContext, which never represented external ACP liveness, so it false-failed after the stale grace and ran session-scoped cleanup. Task maintenance later treated only the process-local ACP turn marker as backing evidence, marked the canonical task lost after its grace, and could close the one-shot session in that same pass.

The observed production intervals match those two grace periods plus sweep cadence.

Design

Patterns found and retained:

  • the shared spawn registry remains the source for child topology, admission caps, status, and control
  • the ACP manager/task registry remains the canonical lifecycle, progress, delivery, and cleanup owner
  • observer ownership is persisted in the existing forward-compatible payload JSON; no SQLite schema change is required
  • legacy ACP rows are recognized by their canonical ACP session key and normalized into observer-only state

Patterns intentionally not used:

  • native subagent restart recovery and native AgentRunContext liveness, because Codex/ACP has a separate durable thread/session identity and resume contract
  • deleting ACP rows from the subagent registry, which would regress topology and child controls
  • immediate session deletion after declaring loss; cleanup now requires a later pass and rechecks the active turn

Evidence

  • pnpm test src/agents/subagents/registry/subagent-delivery-state.test.ts src/agents/subagents/registry/subagent-registry-run-launch.test.ts src/agents/subagents/registry/subagent-registry-sweeper-recovery.test.ts src/agents/subagents/registry/subagent-run-liveness.test.ts src/agents/subagents/spawn/acp-spawn.test.ts src/tasks/task-registry.test.ts
    • 239 tests passed across 3 Vitest shards
  • pnpm tsgo
  • pnpm tsgo:test
  • scoped oxlint and oxfmt --check

pnpm check:changed could not run because the local Crabbox binary failed its built-in version/help sanity check; the equivalent scoped formatting, lint, type, and focused test checks above passed.

@clawsweeper

clawsweeper Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Aug 12, 2026
Prevent ACP observer rows from creating native subagent task projections or owning delivery and session cleanup. Reconcile legacy ACP mirrors through canonical task liveness and defer destructive cleanup after a lost decision.

Refs GEN-6353
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Aug 12, 2026
@markGenhealth
markGenhealth force-pushed the agent/gen-6353-preserve-acp-session branch from e3fdebf to 0defd41 Compare August 12, 2026 22:35
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 12, 2026
@clawsweeper

clawsweeper Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

The PR makes spawned ACP children registry observers while assigning delivery and cleanup to ACP tasks.

Example: Spawn run-acp-observer in agent:codex:acp:child.

  • Before: The registry creates a second subagent task and applies native execution-liveness rules.
  • After: The proposed observer skips the duplicate task and checks ACP liveness, but cannot reliably record completion.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Useful ownership repair, but two confirmed completion defects and unit-only evidence prevent merge.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦪 silver shellfish (2/6) 2 actionable review findings remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Externally executed ACP children can be treated as abandoned native subagents and acquire competing delivery or cleanup owners.
Reason: Lifecycle ownership is a concrete reliability concern, and the maintainer coordination comment explicitly preserves this contribution’s distinct scope.

Merge readiness

⛔ Blocked before merge - 5 items remain

Keep this PR open: it retains distinct, maintainer-engaged ACP lifecycle work, but both prior completion defects remain and its Tasks-based implementation needs adaptation to current main.

Priority: P1
Reviewed head: 0defd415de89f4650ccaa7c38d4781871ee2c02e

Before merge

  • Add real behavior proof - The complete PR body and contributor discussion provide mocked unit tests and static checks, without an after-fix shipped-entry-point run showing ACP observer completion, restart reconciliation, and cleanup; provide redacted terminal output or logs covering that lifecycle. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Record ACP observer completion without the recovery fence (P1) - Every normalized ACP observer receives suppressSessionEffects=true. completeSubagentRunAttempt returns at lines 143–152 for that flag when recoverInterrupted is false and no kill intent exists, so ordinary waiter, lifecycle-event, and sweeper completion cannot set execution.endedAt or the terminal outcome. A completed ACP child therefore remains running in registry topology and admission accounting. Separate observer side-effect suppression from the sticky native-recovery terminal fence, preserving the latter’s existing contract. This prior finding remains unchanged on the reviewed head.
  • Reconcile terminal ACP outcomes through their durable owner (P1) - After restart, a saved succeeded or cancelled ACP task no longer satisfies this active-only lookup, and agent.wait may have no process-local job snapshot. The sweep then reads native session terminal fields or reports lost execution context instead of adopting the canonical ACP outcome; the ACP manager records its result on the task and sets ACP metadata to idle. The separate suppression-fence defect currently blocks that fallback too, so fixing the fence alone still leaves successful work misclassified. Observe the exact ACP run’s terminal outcome through its owner rather than reducing that owner to a liveness boolean. This prior finding remains unchanged.
  • Complete next step - Resolve the reported conflicts against current main while preserving Tasks retirement and the newer registry ownership contracts.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

  • [P1] Record ACP observer completion without the recovery fence — src/agents/subagents/registry/subagent-delivery-state.ts:27
  • [P1] Reconcile terminal ACP outcomes through their durable owner — src/agents/subagents/registry/subagent-run-liveness.ts:38-39

Provenance

  • Current-main Tasks retirement: original intent not found (6652f7e: Tasks duplicated state owned by session, native execution, and other retained lifecycle owners.)

Tests

  • Missing end-to-end proof: Missing a production-boundary ACP spawn-to-terminal/restart/cleanup run and a regression demonstrated failing before the fix.
Agent review details

How this fits together

The shared spawn pipeline registers child topology; ACP executes externally, while registry completion, delivery, persistence, and maintenance determine the child’s visible lifecycle.

flowchart TD
  A[Sessions spawn] --> B[Shared spawn pipeline]
  B --> C[ACP manager]
  B --> D[Registry observer]
  C --> E[External harness]
  C --> F[Canonical ACP task]
  F --> D
  D --> G[Topology and child controls]
Loading

Technical review

Best possible solution:

Integrate ACP terminal observation through its current lifecycle owner, preserve native recovery fencing, and remove dependencies on the retired Tasks runtime.

Do we have a high-confidence way to reproduce the issue?

The reviewed head deterministically sets the flag that rejects ordinary observer completion; no runtime reproduction was executed, and current main has retired the original task-maintenance half of the report.

Is this the best way to solve the issue?

The ownership distinction is useful, but this is not the best complete fix: it reuses a native recovery terminal fence and observes only ACP activity, whereas the existing ACP owner should supply terminal facts directly.

Full review comments:

  • [P1] Record ACP observer completion without the recovery fence — src/agents/subagents/registry/subagent-delivery-state.ts:27
    Every normalized ACP observer receives suppressSessionEffects=true. completeSubagentRunAttempt returns at lines 143–152 for that flag when recoverInterrupted is false and no kill intent exists, so ordinary waiter, lifecycle-event, and sweeper completion cannot set execution.endedAt or the terminal outcome. A completed ACP child therefore remains running in registry topology and admission accounting. Separate observer side-effect suppression from the sticky native-recovery terminal fence, preserving the latter’s existing contract. This prior finding remains unchanged on the reviewed head.
    Confidence: 0.99
  • [P1] Reconcile terminal ACP outcomes through their durable owner — src/agents/subagents/registry/subagent-run-liveness.ts:38-39
    After restart, a saved succeeded or cancelled ACP task no longer satisfies this active-only lookup, and agent.wait may have no process-local job snapshot. The sweep then reads native session terminal fields or reports lost execution context instead of adopting the canonical ACP outcome; the ACP manager records its result on the task and sets ACP metadata to idle. The separate suppression-fence defect currently blocks that fallback too, so fixing the fence alone still leaves successful work misclassified. Observe the exact ACP run’s terminal outcome through its owner rather than reducing that owner to a liveness boolean. This prior finding remains unchanged.
    Confidence: 0.94

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 989d76f74947.

Provenance checked

  • Shared ACP spawn registration changes intended behavior with a stated reason (c1e714e: The shared spawn refactor consolidated admission and registration while deliberately preserving separate execution backends.)
  • Native restart recovery and terminal fencing changes intended behavior with a stated reason (7aaf302: Recovery records authoritative terminal ownership and fences stale lifecycle effects; existing tests require the suppression fence to reject later ordinary callbacks.)

Testing

Proof path: unit tests only.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 64b9faf adds src/agents/subagent-registry-sweeper.ts:33 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 64b9fafc7574; files: src/agents/subagent-registry-sweeper.ts)
  • Vincent Koc: Raw commit d30d22d adds src/agents/subagent-registry-sweeper.ts:72 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d30d22d33c17; files: src/agents/subagent-registry-sweeper.ts)

PR surface

Source +71, Tests +215, Docs +1. Total +287 across 13 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 7 87 16 +71
Tests 5 217 2 +215
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 13 305 18 +287

Review metrics

Metric Value Why it matters
Production versus test LOC Production +87/-16 (net +71); tests +217/-2 (net +215) Growth implements an ownership distinction and cleanup ordering, but the current-main port should absorb it into retained lifecycle owners and delete obsolete Tasks-dependent machinery.

Root-cause cluster

Relationship: canonical
Canonical: #122849
Summary: The discussion preserves this PR’s distinct child-lifecycle scope; related work covers narrower duplicate projection or source-recovery boundaries.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Ordinary ACP completion can leave registry children running indefinitely, affecting child topology and admission accounting.
  • merge-risk: 🚨 session-state: The observer flag suppresses terminal recording, and canonical ACP terminal outcomes are not reconciled into observer state.
  • merge-risk: 🚨 compatibility: Normalization changes saved ACP records’ delivery obligations and lifecycle flags; persisted-row upgrade and reopen compatibility are unproved.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (8 earlier review cycles)
  • reviewed 2026-08-12T22:42:52.242Z sha 0defd41 :: needs real behavior proof before merge. :: [P1] Record observer termination without suppressing it | [P1] Route ACP observer stops to ACP cancellation | [P2] Remove the release-owned changelog entry
  • reviewed 2026-08-19T11:12:56.697Z sha 0defd41 :: needs real behavior proof before merge. :: [P1] Record ACP observer termination without session effects | [P1] Route ACP observer stops to ACP cancellation | [P2] Remove the release-owned changelog entry
  • reviewed 2026-08-25T09:34:32.079Z sha 0defd41 :: needs real behavior proof before merge. :: [P1] Do not wait for ACP observers via the native agent API | [P1] Forward observer stops to ACP cancellation
  • reviewed 2026-09-02T04:33:25.505Z sha 0defd41 :: needs real behavior proof before merge. :: [P1] Stop ACP observers from starting the native completion waiter | [P1] Route ACP observer stops through the ACP session manager
  • reviewed 2026-09-03T01:25:00.543Z sha 0defd41 :: needs real behavior proof before merge. :: [P1] Do not start the native waiter for ACP observers | [P1] Route ACP observer Stop through the ACP session manager | [P2] Remove the release-only changelog entry
  • reviewed 2026-09-22T06:50:57.650Z sha 0defd41 :: needs real behavior proof before merge. :: [P1] Record ACP observer completion without the recovery fence
  • reviewed 2026-09-27T10:59:09.965Z sha 0defd41 :: needs real behavior proof before merge. :: [P1] Record ACP observer completion without the recovery fence | [P1] Observe ACP completion through its task owner
  • reviewed 2026-10-03T20:18:52.809Z sha 0defd41 :: needs real behavior proof before merge. :: [P1] Record ACP observer completion without the recovery fence | [P1] Reconcile terminal ACP outcomes through their durable owner

Reviewed October 17, 2026, 8:14 PM ET / October 18, 2026, 00:14 UTC (Revision 9).

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Aug 19, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Sep 2, 2026
@fuller-stack-dev

Copy link
Copy Markdown
Member

Coordination for the current 0defd415de89f4650ccaa7c38d4781871ee2c02e head: I am carrying a separate current-process subagent accounting repair. It keeps a run counted past the age cutoff only when the existing live execution owner or exact queued collector reservation is still present. It also stops treating retained routing metadata as a live executor.

This contribution does not change ACP lifecycle ownership, ACP tasks or spawn, wait/terminal classification, completion delivery, cleanup, or persistence. Your PR remains canonical for ACP lifecycle ownership; I will not push to its branch or add a competing ACP implementation. The shared-file overlap is the liveness/view predicate, so later composition should use the existing owner-aware predicate while preserving this PR's distinct contract.

The repair is integrated on current main and is completing changed-base qualification. I found no current public write reservation on this exact head. If there is an active reservation that intersects this narrow accounting scope, please identify its file boundary and checkpoint. No author acceptance is assumed.

obviyus added a commit that referenced this pull request Sep 19, 2026
Closes #150402
Related: #122849

## What Problem This Solves

Fixes one spawned ACP task appearing twice in Tasks, once as Subagent and once as ACP, even though only one backend execution exists.

## User Impact

New ACP child runs have one task card and one canonical task identity to inspect or stop. Existing records are not rewritten. This does not change task retention, restart recovery, stale-task classification, cleanup policy, or session-key adoption.

## Why This Change Was Made

The ACP manager already creates the task for the accepted run. ACP spawn now uses the existing Gateway-owned task selector so subagent registration retains the child relationship and controls without creating a second task projection. Ordinary subagent registration is unchanged.

Thanks to @saariuslystoned for the report and @markGenhealth for identifying the overlapping ownership problem in #122849. This narrow duplicate-production fix does not replace or close that broader lifecycle proposal.

## Evidence

- Reproduced on main `0b753f1e15b2`: the actual Control UI invoked `sessions_spawn(runtime=acp)` through an isolated Gateway and normally registered synthetic ACP backend. One held HTTP work request produced two public task IDs and two visible cards.
- On `32a00c1d4d30`, the same flow produced one ACP task ID and one visible card for one backend request. Normal completion succeeded; the remaining card's Stop action cancelled the physical HTTP request and the canonical task.
- The public `subagents` tool retained the active ACP child and later listed completed ACP, cancelled ACP, and ordinary subagent children. The ordinary subagent still produced exactly one succeeded subagent task.
- The real-registration regression failed on the original producer with the extra task IDs; all 101 tests in the two affected spawn suites pass after the fix. Targeted typed lint, formatting, structural ratchets, and the runtime build pass.

The provider and ACP backend are controlled local fixtures. This is actual Gateway/UI and HTTP-boundary proof, not a native Cursor/Codex, live-channel, badge/liveness, or restart-recovery claim.

[Inspected before/after screenshots](#153071 (comment)) show the same Tasks panel with two cards before and one canonical ACP card after.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 20, 2026
Closes openclaw#150402
Related: openclaw#122849

## What Problem This Solves

Fixes one spawned ACP task appearing twice in Tasks, once as Subagent and once as ACP, even though only one backend execution exists.

## User Impact

New ACP child runs have one task card and one canonical task identity to inspect or stop. Existing records are not rewritten. This does not change task retention, restart recovery, stale-task classification, cleanup policy, or session-key adoption.

## Why This Change Was Made

The ACP manager already creates the task for the accepted run. ACP spawn now uses the existing Gateway-owned task selector so subagent registration retains the child relationship and controls without creating a second task projection. Ordinary subagent registration is unchanged.

Thanks to @saariuslystoned for the report and @markGenhealth for identifying the overlapping ownership problem in openclaw#122849. This narrow duplicate-production fix does not replace or close that broader lifecycle proposal.

## Evidence

- Reproduced on main `b16cb8c0cbe3`: the actual Control UI invoked `sessions_spawn(runtime=acp)` through an isolated Gateway and normally registered synthetic ACP backend. One held HTTP work request produced two public task IDs and two visible cards.
- On `32a00c1d4d30`, the same flow produced one ACP task ID and one visible card for one backend request. Normal completion succeeded; the remaining card's Stop action cancelled the physical HTTP request and the canonical task.
- The public `subagents` tool retained the active ACP child and later listed completed ACP, cancelled ACP, and ordinary subagent children. The ordinary subagent still produced exactly one succeeded subagent task.
- The real-registration regression failed on the original producer with the extra task IDs; all 101 tests in the two affected spawn suites pass after the fix. Targeted typed lint, formatting, structural ratchets, and the runtime build pass.

The provider and ACP backend are controlled local fixtures. This is actual Gateway/UI and HTTP-boundary proof, not a native Cursor/Codex, live-channel, badge/liveness, or restart-recovery claim.

[Inspected before/after screenshots](openclaw#153071 (comment)) show the same Tasks panel with two cards before and one canonical ACP card after.

Co-authored-by: Ayaan Zaidi <[email protected]>
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Sep 29, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Oct 18, 2026
@clawsweeper clawsweeper Bot removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 18, 2026
@steipete

Copy link
Copy Markdown
Contributor

Thanks for the PR. We're closing older pull requests that have gone stale against current main.

This draft has had no commits since 2026-08-12 and still needs real behavior proof. Please open a fresh PR against current main if this ACP ownership change is still needed.

@steipete steipete closed this Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants