Skip to content

#92285: fix: reconcile orphaned managed flows when all child tasks are terminal#92301

Closed
Pandah97 wants to merge 4 commits into
openclaw:mainfrom
Pandah97:fix/issue-92285--bug---parent-subagent-task-and-taskflow-
Closed

#92285: fix: reconcile orphaned managed flows when all child tasks are terminal#92301
Pandah97 wants to merge 4 commits into
openclaw:mainfrom
Pandah97:fix/issue-92285--bug---parent-subagent-task-and-taskflow-

Conversation

@Pandah97

@Pandah97 Pandah97 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

"## Summary\n\nAdd a new reconciliation rule in task-flow registry maintenance that transitions a managed TaskFlow to "lost" when all its linked child tasks are terminal (but no cancel was requested). This prevents parent orchestration flows from remaining permanently stale_running after a child subagent session is lost.\n\n## Root Cause\n\nWhen a subagent backing session becomes lost, the child task is correctly marked as "lost" by the task registry lifecycle listener. The child's task_mirrored flow is also synced to "lost" via syncFlowFromTaskResult(). However, the parent's managed TaskFlow (the orchestrator flow) stays "running" indefinitely because:\n\n1. Managed flows don't auto-sync from child task status changes\n2. The existing shouldFinalizeCancelledFlow() only applies when cancelRequestedAt is set\n3. No reconciliation mechanism existed for the "all children terminal, flow still running" state\n\n## Real behavior proof\n\nBehavior or issue addressed: Reconcile orphaned managed TaskFlows to "lost" when all child tasks are terminal during task-flow registry maintenance, preventing parent orchestration flows from remaining permanently stale_running after backing session loss.\n\nReal environment tested: Linux 4.19.112, Node.js via tsx, openclaw workspace importing the production task-flow maintenance modules.\n\nExact steps or command run after this patch:\n\n$ npx tsx scripts/repro-92285.mts\n\n=== Test 1: Orphaned managed flow reconciliation ===\n Flow created: {\"id\":\"167a51d6-7370-4eb7-9c56-d9b4e389acb4\",\"status\":\"running\",\"syncMode\":\"managed\"}\n Child task created: {\"id\":\"09c62b03-9132-49a2-b478-894b3c2e40c0\",\"status\":\"running\",\"flowId\":\"167a51d6-7370-4eb7-9c56-d9b4e389acb4\"}\n Preview (child alive): {\"reconciled\":0,\"pruned\":0}\n Child marked lost: {\"id\":\"09c62b03-9132-49a2-b478-894b3c2e40c0\",\"status\":\"lost\"}\n Maintenance summary: {\"reconciled\":1,\"pruned\":0}\n Flow after maintenance: {\"id\":\"167a51d6-7370-4eb7-9c56-d9b4e389acb4\",\"status\":\"lost\"}\n\n=== Test 2: Running flow with no tasks is not touched ===\n Flow created (no tasks): {\"id\":\"9e53f7d2-28f3-41fa-a350-2886dfaaa4d3\",\"status\":\"running\"}\n Maintenance summary: {\"reconciled\":0,\"pruned\":0}\n Flow after maintenance: {\"id\":\"9e53f7d2-28f3-41fa-a350-2886dfaaa4d3\",\"status\":\"running\"}\n\n=== Test 3: Queued managed flow with terminal child ===\n Flow created (queued): {\"id\":\"465ea5a1-3a61-4324-9127-7d760f2176f8\",\"status\":\"queued\"}\n Child task created: {\"id\":\"91aeeeeb-32ff-4347-8240-d2d3b22b3652\",\"status\":\"running\"}\n Maintenance summary: {\"reconciled\":1,\"pruned\":0}\n Flow after maintenance: {\"id\":\"465ea5a1-3a61-4324-9127-7d760f2176f8\",\"status\":\"lost\"}\n\n=== Test 4: Cancel-requested flow still finalizes as cancelled ===\n Flow created (cancel requested): {\"id\":\"93c84313-deaa-49bb-bf6b-378f3ed213fc\",\"status\":\"running\"}\n Maintenance summary: {\"reconciled\":1,\"pruned\":0}\n Flow after maintenance: {\"id\":\"93c84313-deaa-49bb-bf6b-378f3ed213fc\",\"status\":\"cancelled\"}\n\n=== Results ===\nTest 1 (orphaned managed flow \u2192 lost): PASS\nTest 2 (empty managed flow untouched): PASS\nTest 3 (queued flow with dead child \u2192 lost): PASS\nTest 4 (cancel-requested flow \u2192 cancelled): PASS\n\n\nEvidence after fix:\n\n$ pnpm vitest run src/tasks/task-flow-registry.maintenance.test.ts\n\n RUN v4.1.7\n\n Test Files 1 passed (1)\n Tests 5 passed (5)\n Start at 09:04:56\n Duration 10.45s (transform 4.05s, setup 0ms, import 7.20s, tests 2.99s, environment 0ms)\n\n[test] passed 1 Vitest shard in 21.16s\n\n\nObserved result after fix: The repro script confirms orphaned managed flows transition to "lost" when all child tasks are terminal. Queued flows are also handled. Cancel-requested flows still finalize as "cancelled" (existing behavior preserved). Running flows with no child tasks are left untouched.\n\nWhat was not tested: Integration with specific task orchestration plugins; real task-flow execution lifecycle (the fix operates at the registry maintenance layer before plugin-specific hooks fire).\n\n## Regression Test Plan\n\n- [x] pnpm vitest run src/tasks/task-flow-registry.maintenance.test.ts \u2014 5 passed\n- [x] pnpm vitest run src/tasks/task-flow-registry.test.ts \u2014 passes\n- [x] Reproducer script confirms 4/4 scenarios\n- [x] Cancel-requested flow still finalizes as cancelled (regression preserved)\n- [x] Empty managed flow (no child tasks) left untouched\n"

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: M triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 12, 2026
@clawsweeper clawsweeper Bot added the rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. label Jun 12, 2026
@clawsweeper

clawsweeper Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed June 15, 2026, 2:45 PM ET / 18:45 UTC.

Summary
This PR adds task-flow maintenance that marks running or queued managed TaskFlows as lost once all linked child tasks are terminal, adds a local repro script, and removes one memory-core non-null assertion.

PR surface: Source +57, Other +172. Total +229 across 3 files.

Reproducibility: yes. at source level: the linked issue provides consistent parent task, backing CLI child, task_mirrored flow, audit, and cancellation evidence, and current main lacks a reconciliation path for that stale parent/mirrored-flow chain. I did not reproduce the intermittent live process-loss trigger in this read-only review.

Review metrics: 1 noteworthy metric.

  • Regression coverage shape: 0 test files changed; 1 ad hoc repro script added. The diff changes persistent task/session maintenance behavior, but it does not add normal Vitest regression coverage for the changed runtime path.

Stored data model
Persistent data-model change detected: serialized state: scripts/repro-92285.mts. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🦪 silver shellfish
Patch quality: 🧂 unranked krab
Result: blocked until stronger real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Retarget the fix to parent-task/backing-CLI reconciliation or defer to the related canonical repair path.
  • [P1] Add focused Vitest regression coverage instead of relying on the ad hoc script.
  • Post redacted live task maintenance, audit, list, or equivalent logs showing the reported parent task and mirrored flow terminalize.

Proof guidance:

  • [P1] Needs stronger real behavior proof before merge: The PR body includes terminal output from a synthetic tsx script and Vitest, but not a real task CLI/audit run showing the reported parent task and task_mirrored flow after the fix. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] Merging this head can leave the reported parent subagent task plus task_mirrored TaskFlow bug unresolved while adding a separate managed-flow terminalization path.
  • [P1] The new managed-flow rule can persist lost for successful, failed, timed-out, or cancelled child outcomes because it only checks that no linked task is active.
  • [P1] The PR body proof is synthetic terminal output and Vitest output; it does not show the real task CLI/audit path terminalizing the reported parent task and mirrored flow.

Maintainer options:

  1. Retarget To Parent Task Reconciliation (recommended)
    Move the fix to the stale parent subagent/backing CLI child path and keep TaskFlow updates flowing through existing task_mirrored sync.
  2. Pause For The Related Repair
    Pause this branch while maintainers decide whether fix(tasks): reconcile stale subagent tasks when backing CLI child is terminal (fixes #92285) #92454 should become the canonical fix after its proof and review blockers are resolved.

Next step before merge

Security
Cleared: The diff changes internal task maintenance logic, a local repro script, and a memory-core type assertion only; no dependency, workflow, secret, permission, or supply-chain concern was found.

Review findings

  • [P1] Retarget the fix to the mirrored parent task path — src/tasks/task-flow-registry.maintenance.ts:65-67
  • [P2] Preserve terminal child outcomes instead of forcing lost — src/tasks/task-flow-registry.maintenance.ts:89
Review details

Best possible solution:

Retarget or replace this branch with task-registry reconciliation that terminalizes the stale parent subagent task from its scoped terminal CLI child, lets existing task_mirrored sync update the flow, and validates it with focused tests plus redacted live task maintenance/audit output.

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

Yes, at source level: the linked issue provides consistent parent task, backing CLI child, task_mirrored flow, audit, and cancellation evidence, and current main lacks a reconciliation path for that stale parent/mirrored-flow chain. I did not reproduce the intermittent live process-loss trigger in this read-only review.

Is this the best way to solve the issue?

No. This branch is a plausible managed-flow cleanup, but the narrow maintainable fix is to reconcile the stale parent subagent task from its scoped backing CLI child and rely on existing task_mirrored flow sync.

Full review comments:

  • [P1] Retarget the fix to the mirrored parent task path — src/tasks/task-flow-registry.maintenance.ts:65-67
    The linked report is about a running parent subagent task and its task_mirrored flow staying stale after a backing CLI child is lost. This predicate only handles managed flows, so it leaves that reported path unresolved; reconcile the parent task and let the existing mirrored-flow sync update the flow.
    Confidence: 0.97
  • [P2] Preserve terminal child outcomes instead of forcing lost — src/tasks/task-flow-registry.maintenance.ts:89
    The new rule treats any linked task set with zero active tasks as orphaned, then always writes status: "lost". A managed flow whose child succeeded, failed, timed out, or was cancelled would be mislabeled as lost, so the rule needs outcome-specific handling or a narrower lost-child predicate.
    Confidence: 0.92

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against c40db057da33.

Label changes

Label justifications:

  • P1: The PR targets a broken multi-agent task/session-state workflow that can leave a stale active writer blocking orchestration.
  • merge-risk: 🚨 session-state: The diff changes persisted TaskFlow terminalization while missing the reported mirrored parent task path and can write incorrect lost states for other child outcomes.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦪 silver shellfish and patch quality is 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR body includes terminal output from a synthetic tsx script and Vitest, but not a real task CLI/audit run showing the reported parent task and task_mirrored flow after the fix. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +57, Other +172. Total +229 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 58 1 +57
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 172 0 +172
Total 3 230 1 +229

What I checked:

  • Repository policy applied: Root AGENTS.md and the scoped scripts/AGENTS.md and extensions/AGENTS.md guides were read fully; the review followed the best-fix, sibling-surface, tests, proof, and owner-history requirements. (AGENTS.md:1, c40db057da33)
  • Linked report shape: The linked issue describes a lost backing CLI child, a running parent subagent task, and a running task_mirrored TaskFlow sharing the same relationship, with audit reporting stale_running.
  • Current main TaskFlow maintenance boundary: Current main TaskFlow maintenance repairs terminal mirrored timestamps, finalizes cancel-requested managed flows, and prunes terminal flows; it does not derive a running parent task or mirrored flow terminal state from a terminal backing child. (src/tasks/task-flow-registry.maintenance.ts:132, c40db057da33)
  • Current main mirrored flow sync owner: syncFlowFromTaskResult only mutates task_mirrored flows, and returns unchanged for managed flows, so the reported mirrored flow is expected to update through task mutation rather than managed-flow maintenance. (src/tasks/task-flow-registry.ts:658, c40db057da33)
  • Current main task mutation hook: updateTask calls syncFlowFromTaskAfterTaskMutation, making parent task terminalization the path that updates the linked task_mirrored TaskFlow. (src/tasks/task-registry.ts:1206, c40db057da33)
  • Current main source gap: A childless subagent task still passes hasBackingSession unless it is the narrow childless Codex-native case, and the maintenance sweep only enters lost reconciliation through shouldMarkLost; no current-main block reconciles a running parent subagent from a terminal CLI sibling sharing a run id. (src/tasks/task-registry.maintenance.ts:499, c40db057da33)

Likely related people:

  • vincentkoc: GitHub path history shows 0f45630d1937 hardening task-flow restore and maintenance, and the affected TaskFlow maintenance surface still follows that owner boundary. (role: recent area contributor; confidence: medium; commits: 0f45630d1937; files: src/tasks/task-flow-registry.maintenance.ts, src/tasks/task-flow-registry.ts)
  • steipete: GitHub path history shows recent task execution documentation and terminal mirrored-flow timestamp repair work in the same task and TaskFlow maintenance area. (role: recent area contributor; confidence: high; commits: 606e3d78669a, eb970bdb4220; files: src/tasks/task-registry.maintenance.ts, src/tasks/task-flow-registry.maintenance.ts)
  • openperf: GitHub path history shows 02c7b5b82fc5 changed hasBackingSession and stale task reclamation behavior in the central maintenance path. (role: adjacent recovery contributor; confidence: medium; commits: 02c7b5b82fc5; files: src/tasks/task-registry.maintenance.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

Pandah97 added 2 commits June 15, 2026 10:55
…asks are terminal

When a subagent backing session becomes lost, the child task transitions to
lost but the parent managed TaskFlow remains running indefinitely because
no mechanism exists to reconcile a managed flow whose all linked tasks are
terminal (without a cancel request).

This adds a new reconciliation rule: a managed flow in running/queued status
with at least one child task and zero active (queued/running) child tasks
is reconciled to "lost" during task-flow registry maintenance (both preview
and apply modes). Cancel-requested flows continue to be handled by the
existing shouldFinalizeCancelledFlow path.

Closes openclaw#92285
resolveProviderIndexIdentities() returns MemoryIndexProviderIdentity[],
and noUncheckedIndexedAccess is not enabled, so array[0] does not
include undefined in the type. The ! assertion is a no-op that oxlint
flags as no-unnecessary-type-assertion.
@Pandah97
Pandah97 force-pushed the fix/issue-92285--bug---parent-subagent-task-and-taskflow- branch from 332f8fb to 159e010 Compare June 15, 2026 03:03
@Pandah97

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added the extensions: memory-core Extension: memory-core label Jun 15, 2026
@clawsweeper clawsweeper Bot added 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. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. and removed rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. labels Jun 15, 2026
@Pandah97

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@Pandah97

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@Pandah97

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@openclaw-clownfish

Copy link
Copy Markdown
Contributor

Thanks @Pandah97 for working on this. I am closing this PR as superseded by #92454 because both PRs are trying to resolve the stale-running task/TaskFlow report from #92285, and #92454 is the surviving canonical path with the narrower task-registry fix and regression tests.

Clownfish is keeping the canonical review thread at #92454 tied to the original issue at #92285 so validation and follow-up stay in one place. Your work in #92301 remains part of the source PR context, and attribution/credit should be preserved if maintainers carry any of this approach forward. If this PR covers a distinct reproduction path that #92454 does not handle, please reply and we can reopen or split that back out.

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

Labels

clownfish Tracked by Clownfish automation extensions: memory-core Extension: memory-core 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. scripts Repository scripts size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant