Skip to content

fix(agents): preserve subagent results when delivery fails - #118360

Merged
joshavant merged 20 commits into
mainfrom
joshavant/issue-112616-20260802t224048z-ce294c65
Aug 3, 2026
Merged

joshavant merged 20 commits into
mainfrom
joshavant/issue-112616-20260802t224048z-ce294c65

Conversation

@joshavant

@joshavant joshavant commented Aug 3, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #112616

What Problem This Solves

Fixes an issue where a successful subagent run could lose or strand its result when delivery back to the requester was queued, ambiguous, or failed. Delivery could stop after three attempts even while the documented 30-minute recovery window remained, restart settlement could race queued results, and operators had no safe way to inspect or recover a blocked completion.

Why This Change Was Made

Completion delivery now has one durable owner across the SQLite-backed subagent, task, and session-queue records. Execution success is tracked separately from delivery state, retries remain bounded by the hard-expiry window, and producer state settles before the queue reaches a terminal outcome. Startup recovery, scheduled delivery, and targeted recovery share the same settlement path.

Blocked results are retained for seven days and can be retried or intentionally dismissed through additive operator.write Gateway methods, CLI commands, and the Tasks UI. A one-way idempotent database-open migration promotes shipped payload-only results into canonical completion and task state before obsolete fallback reads are removed; no schema-version bump is required. The permanent recovery API and the seven-day, 25-warning, 50-spawn-cap, and ten-generation defaults have maintainer approval.

User Impact

Successful child execution remains successful even when result delivery is delayed or blocked. Operators can inspect and copy retained results, retry an ambiguous or failed delivery with a duplicate-risk warning, or dismiss it without losing access to the result. OpenClaw warns when 25 blocked completions are retained and pauses new subagent spawns at 50 instead of deleting recovery evidence.

Existing installations automatically normalize legacy retained-result rows on database open, preserving useful fallback output—including results captured before a final NO_REPLY—across restart, retry, dismissal, queue recovery, and collector wait. Producer-owned visible terminal replies remain authoritative, while intentionally silent terminal replies never expose retained fallback text.

Evidence

  • Rebased exact-head CI passed at 129ff55e57060eb9e875ce2a85810604f10e2127 with 73 successful jobs, 5 skipped jobs, and zero failures, including openclaw/ci-gate, Node/Windows, protocol and boundary checks, iOS, Android, QA smoke, and Control UI E2E.
  • Rebased exact-head terminal-reply restart/recovery proof runs the production SQLite stores, two reload cycles, canonical visible/silent selection, and the exported tasks.retry / tasks.dismiss Gateway handlers. It shows visible results survive retry, silent results remain absent through retry and dismissal, generation 2 and intentional dismissal persist across a second restart, and retained fallback text does not leak.
  • Focused verification repeated after the rebase and passed 454 tests across completion selection, state migration, SQLite persistence, completion admission, announcement output/delivery, registry lifecycle, timeout handling, and format E2E; the redacted Gateway runtime harness also passed at the same exact head.
  • Maintainer contract approval confirms the two permanent Gateway write methods and the seven-day, 25/50, and ten-generation defaults.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime cli CLI command changes commands Command implementations agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Aug 3, 2026
@joshavant joshavant self-assigned this Aug 3, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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: 🚨 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. labels Aug 3, 2026
@clawsweeper

clawsweeper Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 3, 2026, 3:46 AM ET / 07:46 UTC.

ClawSweeper review

What this changes

The branch preserves successful subagent results when requester delivery fails by storing completion and delivery state durably, then adds retry/dismiss recovery through Gateway methods, CLI commands, and the Tasks UI.

Merge readiness

⚠️ Needs maintainer review before merge - 3 items remain

This PR addresses a real current-main failure mode: successful subagent completions can stop after a three-attempt announce retry limit, clear retained fallback output, and leave delivery blocked. The proposed durable owner, SQLite recovery path, and operator recovery actions are a coherent fix direction with strong submitted restart proof, but the branch is behind main and changes persisted state plus public Gateway contracts, so it needs maintainer review and an exact-head refresh before merge.

Priority: P1
Reviewed head: 129ff55e57060eb9e875ce2a85810604f10e2127
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The runtime proof is strong and the repair direction matches a current-main defect, but the broad persisted-state and public-contract change still needs maintainer review after a current-base refresh.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The contributor supplied redacted exact-head terminal proof through production SQLite persistence, two restart reloads, canonical terminal-reply selection, and exported Gateway recovery handlers; it shows the intended after-fix behavior.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The contributor supplied redacted exact-head terminal proof through production SQLite persistence, two restart reloads, canonical terminal-reply selection, and exported Gateway recovery handlers; it shows the intended after-fix behavior.
Evidence reviewed 5 items Current-main retry-limit defect: Current main computes a retry count and gives up once it reaches the hardcoded maximum, before the documented completion hard-expiry window necessarily elapses. This directly supports the linked report's stranded-delivery premise.
Current-main result-loss path: On give-up, current main clears the pending delivery and clears fallback completion text after marking the task delivery failed/blocked, so recovery evidence is not retained by the existing lifecycle path.
Submitted real behavior proof: The PR's exact-head proof at 129ff55 exercises production SQLite stores, two reload cycles, canonical visible/silent reply selection, and the exported tasks.retry/tasks.dismiss handlers; it shows visible output survives recovery while intentionally silent output remains absent.
Findings None None.
Security None None.

How this fits together

A subagent finishes work and records a task result before OpenClaw hands that result back to the requester through direct or queued session delivery. This PR changes the durable boundary between the subagent registry, task records, SQLite delivery queue, and operator recovery surfaces when that handoff cannot complete.

flowchart LR
  A[Subagent execution] --> B[Canonical completion result]
  B --> C[Task and subagent state]
  C --> D[Session delivery queue]
  D --> E{Delivery outcome}
  E -->|Delivered| F[Requester session]
  E -->|Blocked| G[Gateway, CLI, or Tasks recovery]
  G --> D
Loading

Decision needed

Question Recommendation
Does the final rebased branch retain the approved permanent tasks.retry/tasks.dismiss contract and safe upgrade behavior for existing SQLite-backed task and subagent records? Refresh and approve the exact head: Rebase onto current main, rerun migration and restart-recovery proof on that head, and confirm the two recovery methods and retention defaults remain the intended public contract.

Why: This is a broad persisted-state and public Gateway-contract change; the PR reports approval, but its final mergeable head must be reviewed after the current-base refresh rather than inferred from an earlier proof run.

Before merge

  • Resolve merge risk (P1) - The branch is reported as behind current main; because it changes SQLite-backed completion state, task projections, and Gateway methods, rebase and exact-head upgrade/restart proof should be refreshed before merge.
  • Resolve merge risk (P1) - The two permanent operator-write Gateway recovery methods and their seven-day retention/cap defaults expand an existing public control-plane contract; the PR body cites approval, but maintainer review should confirm the final rebased API and upgrade behavior.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Public recovery operations 2 added Gateway write methods tasks.retry and tasks.dismiss create a new additive operator recovery contract that native clients, CLI users, and the Tasks UI must keep compatible.

Stored data model

Persistent data-model change detected: database schema: src/state/openclaw-state-db-legacy-backfills.test.ts, serialized state: src/agents/tools/sessions-spawn-tool.test.ts, serialized state: src/infra/delivery-queue-sqlite-bound.ts, serialized state: src/infra/session-delivery-queue-recovery.ts, serialized state: src/infra/session-delivery-queue-storage.ts, serialized state: src/state/openclaw-state-db-legacy-backfills.test.ts, and 9 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Refresh exact-head upgrade proof (recommended)
    Rebase onto current main and verify the database-open migration plus two-restart recovery flow against the exact merge candidate before merging.
  2. Accept the approved API contract
    If maintainers confirm the recovery methods and retention policy are the intended permanent contract, accept the additive control-plane surface after the refreshed proof.
  3. Pause for API direction
    Pause the PR if maintainers do not want persistent operator recovery methods or the stated retention defaults in the permanent Gateway contract.

Technical review

Best possible solution:

Land one canonical durable completion-delivery flow only after the rebased head proves legacy-row normalization, restart settlement, visible-versus-silent result selection, and the additive recovery API contract against current main.

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

Yes — current main source has a concrete path: a required completion increments delivery attempts and gives up at the three-attempt cap, then clears pending/fallback result state while recording failed delivery and a blocked terminal outcome.

Is this the best way to solve the issue?

Yes, with maintainer confirmation — moving completion output into canonical durable state and settling correlated queue/task/subagent records through one owner is a better fix than extending the existing retry-limit workaround or adding another runtime fallback reader.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: The PR repairs a user-visible agent workflow where successful child work can otherwise be stranded or silently fail to reach its requester.
  • merge-risk: 🚨 compatibility: The patch adds public Gateway recovery operations and task-summary fields while normalizing existing persisted records during database open.
  • merge-risk: 🚨 session-state: The patch changes persisted completion selection, blocked terminal outcomes, delivery generations, and restart settlement across subagent, task, and queue state.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The contributor supplied redacted exact-head terminal proof through production SQLite persistence, two restart reloads, canonical terminal-reply selection, and exported Gateway recovery handlers; it shows the intended after-fix behavior.
  • proof: sufficient: Contributor real behavior proof is sufficient. The contributor supplied redacted exact-head terminal proof through production SQLite persistence, two restart reloads, canonical terminal-reply selection, and exported Gateway recovery handlers; it shows the intended after-fix behavior.

Evidence

What I checked:

  • Current-main retry-limit defect: Current main computes a retry count and gives up once it reaches the hardcoded maximum, before the documented completion hard-expiry window necessarily elapses. This directly supports the linked report's stranded-delivery premise. (src/agents/subagent-registry-cleanup.ts:41, c49b68328ef2)
  • Current-main result-loss path: On give-up, current main clears the pending delivery and clears fallback completion text after marking the task delivery failed/blocked, so recovery evidence is not retained by the existing lifecycle path. (src/agents/subagent-registry-lifecycle-cleanup.ts:72, c49b68328ef2)
  • Submitted real behavior proof: The PR's exact-head proof at 129ff55 exercises production SQLite stores, two reload cycles, canonical visible/silent reply selection, and the exported tasks.retry/tasks.dismiss handlers; it shows visible output survives recovery while intentionally silent output remains absent. (src/gateway/server-methods/tasks.ts:144, 129ff55e5706)
  • Current behavior provenance: Blame attributes the current retry-limit and suspended-delivery lifecycle path to commit 6f6d501, making Peter Steinberger the strongest current-main routing candidate for the replaced behavior. (src/agents/subagent-registry-cleanup.ts:62, 6f6d501ccf9a)
  • Release and main context: The checked-out current main is c49b683; the supplied latest release is v2026.7.1 at 2d2ddc4. The bug remains present on current main, so this PR is not obsolete or already implemented. (src/agents/subagent-registry-cleanup.ts:66, c49b68328ef2)

Likely related people:

  • Peter Steinberger: Current-main blame ties the retry-limit and suspended-delivery cleanup path to commit 6f6d501, and the same code owns the bug the PR replaces. (role: current behavior introducer and recent area contributor; confidence: high; commits: 6f6d501ccf9a; files: src/agents/subagent-registry-cleanup.ts, src/agents/subagent-registry-lifecycle-cleanup-base.ts, src/agents/subagent-registry-lifecycle-cleanup.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Rebase onto current main and repeat the SQLite migration/restart proof on the exact merge candidate.
  • Confirm the permanent Gateway recovery API and retention/cap defaults during maintainer review.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

History

Review history (19 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-03T05:15:00.757Z sha a2c1dd5 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-03T05:30:27.289Z sha a2c1dd5 :: found issues before merge. :: [P1] Migrate retained payload results before removing fallback reads
  • reviewed 2026-08-03T06:12:43.593Z sha a25f2c492cb23235af75acea2e112c2942737dba :: needs maintainer review before merge. :: none
  • reviewed 2026-08-03T06:24:42.565Z sha a25f2c492cb23235af75acea2e112c2942737dba :: needs maintainer review before merge. :: none
  • reviewed 2026-08-03T06:33:46.042Z sha a25f2c492cb23235af75acea2e112c2942737dba :: needs maintainer review before merge. :: none
  • reviewed 2026-08-03T07:05:11.049Z sha e1aeae1161752ebc1bd60c203a4ac8cd430c3e7b :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-03T07:23:42.725Z sha e1aeae1161752ebc1bd60c203a4ac8cd430c3e7b :: needs maintainer review before merge. :: none
  • reviewed 2026-08-03T07:31:11.507Z sha 129ff55 :: needs maintainer review before merge. :: none

@joshavant
joshavant force-pushed the joshavant/issue-112616-20260802t224048z-ce294c65 branch from 8ffbb9d to 9d85ecc Compare August 3, 2026 02:28
@openclaw-barnacle openclaw-barnacle Bot added the app: android App: android label Aug 3, 2026
@joshavant
joshavant force-pushed the joshavant/issue-112616-20260802t224048z-ce294c65 branch 2 times, most recently from bf6b5c3 to dacad35 Compare August 3, 2026 02:33
@joshavant

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 3, 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: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@joshavant
joshavant marked this pull request as ready for review August 3, 2026 02:37
@joshavant
joshavant marked this pull request as draft August 3, 2026 02:37
@joshavant
joshavant force-pushed the joshavant/issue-112616-20260802t224048z-ce294c65 branch from dacad35 to be4476d Compare August 3, 2026 02:39
@joshavant
joshavant marked this pull request as ready for review August 3, 2026 02:39
@joshavant
joshavant force-pushed the joshavant/issue-112616-20260802t224048z-ce294c65 branch 4 times, most recently from 778f0cf to 82d2ed5 Compare August 3, 2026 03:08
@clawsweeper clawsweeper Bot removed the rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. label Aug 3, 2026
@clawsweeper

clawsweeper Bot commented Aug 3, 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: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@joshavant

Copy link
Copy Markdown
Collaborator Author

Rebased exact-head terminal-reply restart/recovery proof

Head: 129ff55e57060eb9e875ce2a85810604f10e2127
Rebased base: 5151dc481d71940300e4022f2b1894265a7b1b18
CI: 30793638254 (running)

After rebasing all 20 signed commits onto then-current origin/main, I repeated the isolated production proof through the SQLite subagent/task stores, two process-local teardown/reload cycles, canonical terminal-reply selection, and the exported Gateway tasks.retry / tasks.dismiss handlers. The intervening main commits had no touched-file overlap. Only the post-retry scheduler-resume edge was replaced with an in-process spy; no store, selector, persistence layer, or Gateway handler was mocked. The temporary harness and state were removed after the run, and the worktree is clean.

Command: node scripts/run-vitest.mjs src/gateway/server-methods/tasks.recovery-proof.test.ts --reporter=verbose

{"head":"129ff55e57060eb9e875ce2a85810604f10e2127","base":"5151dc481d71940300e4022f2b1894265a7b1b18","database":{"engine":"SQLite","exists":true,"path":"[redacted-temp-state]"},"firstRestart":{"visible":{"terminalReply":{"disposition":"visible","text":"VISIBLE_EXACT_HEAD_RESULT"},"result":"VISIBLE_EXACT_HEAD_RESULT"},"silentRetry":{"terminalReply":{"disposition":"silent"},"result":null},"silentDismiss":{"terminalReply":{"disposition":"silent"},"result":null}},"gateway":{"retry":[{"taskId":"task-visible-retry","ok":true,"duplicateRisk":true,"deliveryStatus":"pending","terminalOutcome":"succeeded","result":"VISIBLE_EXACT_HEAD_RESULT"},{"taskId":"task-silent-retry","ok":true,"duplicateRisk":true,"deliveryStatus":"pending","terminalOutcome":"succeeded","result":null}],"dismiss":[{"taskId":"task-silent-dismiss","ok":true,"duplicateRisk":false,"deliveryStatus":"dismissed","terminalOutcome":"blocked","result":null}]},"secondRestart":{"visibleRetry":{"delivery":"pending","generation":2,"result":"VISIBLE_EXACT_HEAD_RESULT"},"silentRetry":{"delivery":"pending","generation":2,"result":null},"silentDismiss":{"delivery":"discarded","disposition":"intentional_non_delivery","result":null}},"fallbackLeak":false}

The rebased exact head preserves the same observed contract: visible output survives restart and retry, intentionally silent output remains absent through retry and dismissal, generation 2 and intentional dismissal survive a second restart, and the retained visible fallback sentinel never reaches Gateway output.

@joshavant

Copy link
Copy Markdown
Collaborator Author

Merged via rebase.

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

Labels

agents Agent runtime and tooling app: android App: android app: web-ui App: web-ui cli CLI command changes commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR 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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Subagent announce: hardcoded 3 retries (~3s) discards results; delivery-fail stamps blocked while status=succeeded

1 participant