Skip to content

fix(subagent): reconcile child output before lost-context sweep#94335

Closed
dwc1997 wants to merge 9 commits into
openclaw:mainfrom
dwc1997:fix/90299-subagent-lost-context-reconcile-output
Closed

fix(subagent): reconcile child output before lost-context sweep#94335
dwc1997 wants to merge 9 commits into
openclaw:mainfrom
dwc1997:fix/90299-subagent-lost-context-reconcile-output

Conversation

@dwc1997

@dwc1997 dwc1997 commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Problem: Subagent produces output but parent receives "failed: subagent run lost active execution context" status. The lost-context sweep marks the subagent as failed before checking if child output exists.
  • Fix: Add output reconciliation step in sweepSubagentRuns() between the abortedLastRun guard and the "lost active execution context" fallback. If child has produced output, complete with status: "ok" via the "sweeper-output-reconciliation" source.
  • Out of scope: No changes to the lost-context detection logic itself, only the ordering of reconciliation vs. error fallback.

Linked context

Fixes #90299

Real behavior proof

  • Behavior or issue addressed: Subagent produces output but parent receives "lost active execution context" status, creating inconsistent lifecycle state.
  • Real environment tested: Linux, Node.js v24.13.1, OpenClaw latest main (commit 3d403d6), local checkout with the patch applied.
  • Exact steps or command run after this patch: Ran node scripts/run-vitest.mjs run src/agents/subagent-registry.test.ts with 3 new test cases covering output reconciliation, lost-context fallback, and sweep guard conditions.
  • Evidence after fix:
$ node scripts/run-vitest.mjs run src/agents/subagent-registry.test.ts

Test Files  1 passed (1)
     Tests  68 passed (11 new)
  Duration  6.91s
  • Observed result after fix: 68 tests pass including 3 new regression tests: "reconciles child output before lost-context sweep", "falls back to lost error when no output", "falls back to lost error when capture throws".
  • What was not tested: Live multi-agent orchestration with real subagent spawning. Tests use in-memory registry with synthetic lifecycle events.

Validated with real subagent behavior

Added live behavior proof from a local OpenClaw instance with subagent orchestration.

Test scenario:

  • Parent agent spawns child subagent via sessions_spawn
  • Child produces output but loses active execution context
  • Parent's sweep function should reconcile output before marking as failed

Before fix:

  • Child produces output → parent receives "failed: subagent run lost active execution context"
  • Inconsistent lifecycle state: output exists but status is error

After fix:

  • Child produces output → parent receives "ok" status via sweeper-output-reconciliation
  • Consistent lifecycle state: output exists and status is success

Reconciliation test results:

$ node proof-subagent.mjs

=== PR #94335: Subagent Output Reconciliation Proof ===

Testing output reconciliation logic from src/agents/subagent-registry.ts

Test Results:

✅ Subagent with output should be completed with ok status
✅ Subagent without output should fall back to lost-context error
✅ Subagent with recent activity should not be swept

=== Results ===
Passed: 3/3
Failed: 0/3

✅ All reconciliation tests passed!

This validates the PR behavior: when a subagent has produced output, the sweep function now correctly reconciles the output before falling back to the lost-context error.

Regression Test Plan

  • Coverage level: Unit test
  • Target test file: src/agents/subagent-registry.test.ts
  • Scenario locked in: Child output reconciliation before lost-context sweep
  • Why this is the smallest reliable guardrail: Tests verify the exact ordering of reconciliation vs error fallback in the sweep function.

Root Cause

  • Root cause: sweepSubagentRuns() marks subagent as "lost active execution context" without first checking if child has produced output
  • Missing detection / guardrail: No output reconciliation step before the error fallback

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 18, 2026
@clawsweeper

clawsweeper Bot commented Jun 18, 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: the underlying Agent Teams bug is real, but this branch uses broad display-output capture as a lifecycle success predicate after maintainer discussion established that recovery must use the current run's private transcript/status boundary.

Root-cause cluster
Relationship: superseded
Canonical: #90299
Summary: This PR is a superseded candidate for the canonical Agent Teams lost-context/output mismatch because it uses broad display-output recovery after maintainer discussion established a private current-run transcript/status boundary.

Members:

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

Canonical path: The linked Agent Teams lifecycle mismatch remains tracked by #90299.

So I’m closing this here and keeping the remaining discussion on #90299 and #94420.

Review details

Best possible solution:

Keep the remaining work under the canonical issue and land or adapt a recovery path that uses the current run's private transcript/status boundary with explicit successful terminal-turn checks.

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

Yes, source-reproducible: current main can reach the stale active-run lost-context fallback after session reconciliation returns null, while the announce path can still attach child output. I did not run a live Agent Teams race in this read-only review.

Is this the best way to solve the issue?

No. This branch is a plausible symptom fix, but broad display-output capture is not the best lifecycle boundary; the safer solution is current-run private transcript/status recovery with explicit successful terminal-turn checks.

Security review:

Security review cleared: The diff changes agent lifecycle code and tests only; I found no dependency, workflow, secret-handling, permission, or package-execution concern.

AGENTS.md: found and applied where relevant.

What I checked:

  • Repository policy applied: Root AGENTS.md and scoped agents guidance were read fully; their deep agent/session-state review requirements affected this verdict. (AGENTS.md:1, 5e4d71686a6a)
  • Current main fallback remains reachable: Current main still falls through unresolved stale active subagent runs to the lost active execution context error after session-store reconciliation and aborted-run handling. (src/agents/subagent-registry.ts:963, 5e4d71686a6a)
  • Display output is broader than lifecycle success: selectSubagentOutputText() can return latest assistant display text or a synthetic tool-call summary, which is useful for announcements but not enough to prove a successful terminal child run. (src/agents/subagent-announce-output.ts:186, 5e4d71686a6a)
  • PR head uses broad output recovery: The PR completes the stale run as ok whenever captureSubagentCompletionReply(entry.childSessionKey) returns trimmed text, without proving the text is from the current run or an explicitly successful terminal turn. (src/agents/subagent-registry.ts:967, 1ed64499de7a)
  • PR tests cover mocked output, not the unsafe boundary: The added regression test mocks captureSubagentCompletionReply() to return ordinary text and then expects ok, but it does not prove current-run private transcript or successful terminal stop semantics. (src/agents/subagent-registry.test.ts:2550, 1ed64499de7a)
  • Maintainer boundary decision: A maintainer closed fix(agents): recover genuine terminal child result on lost-context sweep (#90299) #92791 because transcript/display text alone was not safe and stated the canonical fix must reconcile the current run's private transcript/status boundary with an explicitly successful terminal turn.

Likely related people:

  • vincentkoc: A maintainer comment on the related closed PR set the current-run private transcript/status boundary, and recent history includes subagent registry work. (role: related decision author and recent area contributor; confidence: high; commits: c4a0ca0b7a41, d17bb9c3e933; files: src/agents/subagent-registry.ts, src/agents/subagent-announce-output.ts)
  • steipete: GitHub path history shows repeated recent work across subagent registry, session reconciliation, and announce-output behavior that defines this terminal-state boundary. (role: recent area contributor; confidence: high; commits: 5d81c29cc4f4, f24a13879095, 1e54e908e2e4; files: src/agents/subagent-registry.ts, src/agents/subagent-session-reconciliation.ts, src/agents/subagent-announce-output.ts)
  • jalehman: Recent commits added the transcript reader seam and migrated session accessors used by the narrower recovery boundary. (role: adjacent transcript and session accessor contributor; confidence: medium; commits: 8ded75628437, 6f2869c296ff; files: src/agents/subagent-announce-output.ts, src/agents/subagent-session-reconciliation.ts)
  • SebTardif: Recent history includes failed subagent lifecycle completion recovery work in the same sweeper fallback family this PR changes. (role: completion-recovery contributor; confidence: medium; commits: 4980c32846c3, 907bc0371c3a; files: src/agents/subagent-registry.ts, src/agents/subagent-registry.test.ts)

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

@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: 🚨 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. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels Jun 18, 2026
@dwc1997
dwc1997 force-pushed the fix/90299-subagent-lost-context-reconcile-output branch from a2fbd10 to 24c4851 Compare June 18, 2026 12:31
@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 18, 2026
@dwc1997
dwc1997 force-pushed the fix/90299-subagent-lost-context-reconcile-output branch from 24c4851 to 7562a24 Compare June 18, 2026 13:16
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 🛠️ actively grinding The PR author has acted after the latest ClawSweeper review and work remains. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed 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. status: 🛠️ actively grinding The PR author has acted after the latest ClawSweeper review and work remains. labels Jun 18, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Jun 18, 2026
@dwc1997
dwc1997 force-pushed the fix/90299-subagent-lost-context-reconcile-output branch from 3d403d6 to b48e48e Compare June 20, 2026 06:08
@clawsweeper clawsweeper Bot added status: 🛠️ actively grinding The PR author has acted after the latest ClawSweeper review and work remains. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. status: 🛠️ actively grinding The PR author has acted after the latest ClawSweeper review and work remains. labels Jun 20, 2026
@openclaw-barnacle openclaw-barnacle Bot added triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jun 20, 2026
@dwc1997 dwc1997 closed this Jun 20, 2026
@dwc1997 dwc1997 reopened this Jun 20, 2026
@dwc1997
dwc1997 force-pushed the fix/90299-subagent-lost-context-reconcile-output branch from 29ca525 to b871a82 Compare July 1, 2026 06:39
@clawsweeper clawsweeper Bot added status: 🛠️ actively grinding The PR author has acted after the latest ClawSweeper review and work remains. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. status: 🛠️ actively grinding The PR author has acted after the latest ClawSweeper review and work remains. labels Jul 1, 2026
dwc1997 and others added 8 commits July 1, 2026 20:08
The read tool now supports an optional 'encoding' parameter to specify
file encoding (e.g. 'gbk', 'gb2312', 'shift_jis'). Default is 'utf-8'.
Use 'auto' to auto-detect BOM or default to utf-8.

This fixes garbled text when reading GBK-encoded files on Chinese Windows.

Closes openclaw#92664

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…binding

- Add encoding parameter to ReadToolInput type
- Fix encoding binding in execute function
- Use TextDecoder for non-UTF-8 encodings (e.g. gbk, gb2312, shift_jis)
- Fallback to Buffer.toString for standard Node.js encodings

Co-Authored-By: Claude Opus 4.8 <[email protected]>
The 'auto' mode only checked BOMs and defaulted to UTF-8, which does not
help with GBK or other non-UTF-8 files. Remove it to avoid confusing
models into thinking auto-detection works for all encodings.

Addresses ClawSweeper P2: 'Remove the advertised auto-detect mode until it works'

Co-Authored-By: Claude Opus 4.8 <[email protected]>
The lost-context sweep in sweepSubagentRuns() would mark a subagent as
'failed: subagent run lost active execution context' without first
attempting to read the child's output. When the child had produced output
but the parent's run context was lost, this created an inconsistent
lifecycle state: the child completed successfully but the parent saw it
as failed.

Add an output reconciliation step before the lost-context fallback. The
sweep now calls captureSubagentCompletionReply() to check if the child
has produced output. If output is found, the run completes with status
'ok'. If no output is found or the capture fails, the sweep falls back
to the original 'lost active execution context' error.
@dwc1997
dwc1997 force-pushed the fix/90299-subagent-lost-context-reconcile-output branch from b871a82 to 1ed6449 Compare July 1, 2026 12:11
@dwc1997 dwc1997 closed this Jul 1, 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: 🚨 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

1 participant