Skip to content

fix(agents): reconcile child output before lost-context sweep failure#90492

Closed
LiuwqGit wants to merge 1 commit into
openclaw:mainfrom
LiuwqGit:fix/issue-90299-lost-context-with-output
Closed

fix(agents): reconcile child output before lost-context sweep failure#90492
LiuwqGit wants to merge 1 commit into
openclaw:mainfrom
LiuwqGit:fix/issue-90299-lost-context-with-output

Conversation

@LiuwqGit

@LiuwqGit LiuwqGit commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Summary

What problem does this PR solve?

  • Agent Teams could announce failed: subagent run lost active execution context while the same completion event still contained readable child assistant output, so parents treated successful work as a plain failure.

Why does this matter now?

  • Issue #90299: sessions_spawn / sessions_yield orchestration depends on terminal status matching delivered child results; a false failed status breaks multi-agent trust and can trigger unnecessary retries or stalled workflows.

What is the intended outcome?

  • When the subagent sweeper loses live run context and session-store reconciliation cannot settle terminal state, reconcile readable child transcript output first and complete as ok instead of emitting a plain lost-context failure.

What is intentionally out of scope?

  • No new shared-memory layer, Agent Teams plugin changes, or announce formatting changes for unrelated error paths; true failures without usable child output still complete as errors.

What does success look like?

  • Stale active runs with captured assistant output complete with outcome.status: "ok"; runs without output still report subagent run lost active execution context.

What should reviewers focus on?

  • resolveStaleActiveSubagentOutcome in subagent-lost-context-completion.ts and the sweeper branch in subagent-registry.ts that calls it before sweeper-lost-context completion.

Linked context

Which issue does this close?

Closes #90299

Which issues, PRs, or discussions are related?

Was this requested by a maintainer or owner?

  • Community report; user confirmed fix in automation workflow.

Real behavior proof (required for external PRs)

  • Behavior or issue addressed: Lost-context sweeper fallback vs. child output mismatch on Agent Teams completion events.
  • Real environment tested: Local checkout E:\Projects\skills\work\openclaw on branch fix/issue-90299-lost-context-with-output, Node via node scripts/run-vitest.mjs.
  • Exact steps or command run after this patch:
    • node scripts/run-vitest.mjs src/agents/subagent-lost-context-completion.test.ts
    • node scripts/run-vitest.mjs src/agents/subagent-registry.test.ts -t "completes stale active runs as ok when child session has readable output"
  • Evidence after fix:
 Test Files  2 passed (2)
      Tests  2 passed | 120 skipped (122)
   Duration  17.80s
  • Observed result after fix: Unit tests assert resolveStaleActiveSubagentOutcome returns ok when readSubagentOutput yields text, and the registry sweep test completes run-lost-context-with-output with outcome.status: "ok" (no lost-context error) when chat.history contains assistant output.
  • What was not tested: Live Agent Teams sessions_spawn + sessions_yield end-to-end on a gateway host (read-only review path per ClawSweeper).
  • Proof limitations: Regression coverage is source-level via vitest mocks for chat.history and sweep timing, not a reproduced bench transcript from the original report.
  • Before evidence (optional): Sweeper always completed stale active runs without session terminal state using outcome.status: "error" and error: "subagent run lost active execution context" even when announce later read the same child output for the parent message.

Tests and validation

Which commands did you run?

  • node scripts/run-vitest.mjs src/agents/subagent-lost-context-completion.test.ts
  • node scripts/run-vitest.mjs src/agents/subagent-registry.test.ts -t "completes stale active runs as ok when child session has readable output"

What regression coverage was added or updated?

  • subagent-lost-context-completion.test.ts — outcome resolver with/without output.
  • subagent-registry.test.ts — sweep completes stale active run as ok when chat.history has assistant text.

What failed before this fix, if known?

  • Sweeper sweeper-lost-context path emitted error outcome regardless of readable child transcript.

If no test was added, why not?

  • N/A — regression tests added.

Risk checklist

Did user-visible behavior change? (Yes/No)

Yes.

Did config, environment, or migration behavior change? (Yes/No)

No.

Did security, auth, secrets, network, or tool execution behavior change? (Yes/No)

No.

What is the highest-risk area?

  • False-positive ok completion if stale transcript output is unrelated to the current run.

How is that risk mitigated?

  • Output is read only for the specific childSessionKey; session-store terminal reconciliation and notBeforeMs freshness checks still run first; empty/non-readable output keeps the existing lost-context error.

Current review state

What is the next action?

  • Maintainer review

What is still waiting on author, maintainer, CI, or external proof?

  • CI on fork PR

Which bot or reviewer comments were addressed?

  • ClawSweeper narrow fix recommendation: reconcile child output before lost-context failure.

When a subagent run loses live execution context, treat readable child
assistant output as terminal evidence and complete as ok instead of always
emitting lost-context error. Closes openclaw#90299.

Co-authored-by: Cursor <[email protected]>
@clawsweeper

clawsweeper Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close as superseded by the canonical open bug and later maintainer decision: the useful problem remains real, but this branch is not a safe landing candidate because it uses display-oriented child output as a terminal success predicate and has not addressed the existing review blockers.

Canonical path: Keep the canonical bug open and redesign the recovery around the current run's private transcript/status boundary with an explicitly successful terminal child turn; do not land this display-helper recovery branch.

So I’m closing this here because the remaining work is already tracked in the canonical issue.

Review details

Best possible solution:

Keep the canonical bug open and redesign the recovery around the current run's private transcript/status boundary with an explicitly successful terminal child turn; do not land this display-helper recovery branch.

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

Yes, source-level. Current main can fall from unresolved session-store reconciliation into the lost-context fallback while the announce path can still read child output, matching the linked bug's failed-status plus result shape.

Is this the best way to solve the issue?

No. This branch is not the best way to solve the issue because it uses readSubagentOutput/chat.history as a terminal success predicate; the safer path is the maintainer-directed current-run transcript/status boundary with an explicitly successful terminal turn.

Security review:

Security review cleared: The diff changes agent lifecycle source and tests only; I found no concrete dependency, workflow, secret-handling, permissions, or package execution change.

AGENTS.md: found and applied where relevant.

What I checked:

  • Repository policy read: Full root AGENTS.md and scoped src/agents guidance were read; their deep-review, agent lifecycle, proof, and session-state risk rules affected the verdict. (AGENTS.md:1, a02813164dd5)
  • Current main fallback remains unresolved: Current main still completes stale active subagent runs with a hard lost-context error when there is no live run context and session-store reconciliation returns no completion. (src/agents/subagent-registry.ts:962, a02813164dd5)
  • Display helper is broader than terminal result text: readSubagentOutput can return a synthetic tool-call summary when there is no visible assistant result, so it is not a safe terminal-success predicate. (src/agents/subagent-announce-output.ts:196, a02813164dd5)
  • PR success predicate is unsafe: The PR returns ok for any truthy readSubagentOutput result, which includes display-only histories rather than an explicitly successful terminal child turn. (src/agents/subagent-lost-context-completion.ts:16, 1604b7471b13)
  • Existing review blockers remain: The prior ClawSweeper review on this PR found that the predicate can recover tool-call-only histories as ok, that output lookup failure can abort the fallback, and that proof is mock-only; no PR review comments or author follow-up address those blockers. (1604b7471b13)
  • Canonical issue still owns remaining work: The linked bug remains open with source-reproducible session-state impact, so the remaining work has a canonical tracker outside this unsafe branch.

Likely related people:

  • vincentkoc: A repository member with recent adjacent registry/lifecycle work closed the stronger related recovery PR with the current boundary decision for this bug family. (role: recent area contributor and decision author; confidence: medium; commits: c4a0ca0b7a41, 7e0d275f7add; files: src/agents/subagent-registry.ts, src/agents/subagent-registry-lifecycle.ts)
  • steipete: Prior review history identifies multiple recent subagent registry, lifecycle, output, and reconciliation changes by this person around the same terminal-state surface. (role: recent area contributor; confidence: medium; commits: f24a13879095, 1e54e908e2e4, 5d81c29cc4f4; files: src/agents/subagent-registry.ts, src/agents/subagent-registry-lifecycle.ts, src/agents/subagent-announce-output.ts)
  • SebTardif: Related PR history identifies commit 4980c32 as recent failed subagent lifecycle recovery work in the fallback family this PR tries to change. (role: completion-recovery contributor; confidence: medium; commits: 4980c32846c3, 907bc0371c3a; files: src/agents/subagent-registry.ts)

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

@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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jun 5, 2026
@leorivastech

Copy link
Copy Markdown

Hi @LiuwqGit — friendly ping: are you still planning to finish this one? ClawSweeper has been waiting on a real-behavior proof since June 5 and I don't see any follow-up, so I wanted to check before duplicating effort. I'd like to help get #90299 landed. If you've moved on, I'm happy to take this over or open an alternative PR — whatever you prefer. Either way a quick word would help. Thanks!

@clawsweeper

clawsweeper Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

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: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S 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.

[Bug]: Agent Teams subagent completion can report "lost active execution context" while still delivering child output

2 participants