Skip to content

fix: stop losing finished subagent results during access-policy outages, steer races and expiry - #200649

Merged
obviyus merged 2 commits into
mainfrom
fix/subagent-results-owed-once
Nov 17, 2026
Merged

obviyus merged 2 commits into
mainfrom
fix/subagent-results-owed-once

Conversation

@obviyus

@obviyus obviyus commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

A finished subagent's result could be lost even though the child did its work. Three paths dropped it on current main:

  • Access-policy outage: a temporary "Gateway access policy is unavailable; retry the operation." during requester settlement was recorded as a permanent delivery failure. The parent never received the result, even after the policy recovered.
  • Steer race: when a busy parent accepted the child's result by steering, and the delivery owner changed afterward, the run was recorded as intentional non-delivery. The parent had the result, but the record said it didn't. The run could later "expire" and send a misleading failure.
  • Expiry: a suspended required completion was discarded after seven days with no notice in the requester conversation. Only an operator log line recorded it.

On one Gateway, the access-policy class alone accounted for 25 failed child results in a week.

User Impact

A temporary access-policy outage now only delays a child's result; it is delivered after the policy returns. A result steered into a busy parent is recorded as delivered. A required result that finally expires records the existing visible failure notice ("The child result couldn't be delivered to this conversation…") instead of disappearing silently.

Why This Change Was Made

Each fix is at the existing owner:

  • Settle wake: a policy-unavailable error now joins the existing "no delivery was admitted, retry" class, alongside database-busy and overloaded errors, instead of the permanent-failure path.
  • Direct delivery: an accepted, committed steer returns delivered before the delivery-owner check. Only an unconfirmed commit still depends on its owner.
  • Seven-day discard: this path now calls the same failure-notice writer that other permanent failures already use (fix(subagents): show required completion delivery failures #198807).

Explicit stop, cancellation, requester deletion and real revocation are unchanged.

Evidence

  • Regressions drive the real lifecycle, announce, completion and SQLite owners: subagent-result-owed.{policy-outage,expiry-discard}.test.ts, plus the updated steering $outcome after $change direct-delivery contract (accepted-steer rows fail on base). Each fails on the base commit and passes with the fix:
    • policy outage: recorded failed before, owed and then delivered after;
    • steer race: receipt not delivered before, {delivered: true, path: "steered"} after;
    • expiry: no notice before, exactly one visible notice after.
  • Existing suites: announce, settle, lifecycle, completion authority, store-replaced, steer-restart and yielded-run settlement all pass, 500+ tests. The steering $outcome after $change contract was updated: an accepted steer is now delivered after an owner change, and indeterminate steers keep the old outcome.
  • End to end (source tier, ocx src): an isolated Gateway with a stub model. A busy parent received its finished child's result through a steer into the same run, and subagent_runs recorded delivered/delivered.
  • Not in this PR: splitting settle batches that mix operator invocations (a separate fix with its own proof), and the session-store-switch suspension policy (fix: keep child notifications out of replaced session stores #152828, unchanged).

…es, steer races and expiry

A transient Gateway access-policy outage during requester settlement was recorded as a permanent delivery failure; it now retains the wake like other pre-admission retries. A completion whose steer already committed into the busy parent's run was recorded as intentional non-delivery when its owner changed afterward; it now counts as delivered. A suspended required completion that expired after seven days was discarded silently; it now records the existing visible failure notice in the requester conversation.
@clawsweeper

clawsweeper Bot commented Nov 17, 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 docs Improvements or additions to documentation agents Agent runtime and tooling size: M labels Nov 17, 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. 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: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and 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 Nov 17, 2026
@clawsweeper

clawsweeper Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR preserves finished child results through temporary policy outages, credits committed steering, and reports expired required completions.

Example: A finished child's requester settlement encounters a temporary Gateway access-policy outage.

  • Before: Settlement records failed delivery and drops the owed continuation.
  • After: The result remains pending for another lifecycle evaluation after policy recovery.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) Useful, focused repair with meaningful owner regressions, but an observed cleanup regression and insufficient inspectable product proof prevent a pass.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦪 silver shellfish (2/6) 2 actionable review findings remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Finished child work can remain undelivered, be recorded as undelivered after successful steering, or expire without a requester-visible outcome.
Reason: The maintainer-authored direction restores existing delivery and visibility contracts without new settings, APIs, or owners.

Merge readiness

⛔ Needs changes before merge - 3 items remain

Keep open: this maintainer-authored PR addresses three concrete completion-delivery defects still present on current main, but the expiry change introduces a cleanup regression.

Priority: P1
Reviewed head: d2466b183a353e55afd978ae73a869930affe30b

Before merge

  • Keep notice reporting from rejecting a yielded cleanup sweep (P2) - The new awaited reporter runs after durable discard but before the remaining throwing cleanup-owner assertion. If the run yields while that work waits, isCleanupOwnerCurrent becomes false and the sweep rejects instead of treating the obsolete cleanup tail as finished. Exact-head CI demonstrates this in subagent-announcement.worker.test.ts's existing yielded case, which now returns completed: false with Subagent suspended delivery cleanup owner changed. This also stops processing later entries in that sweep. Move the reporting to an appropriate completed-cleanup boundary or otherwise preserve the existing non-throwing yielded outcome without weakening the ownership checks.
  • Mark the registry mock's intentional isolation (P2) - This new factory replaces the first-party registry module with a single export. src/agents/AGENTS.md requires real-module pass-through or an adjacent // mock-isolation: explanation, and the exact-head baseline job reports mock-exports failure. The existing explanation can use the required annotation so the test retains its intended sole registry owner without expanding the baseline.
  • Complete next step - The PR owner should consolidate at least 62 net test lines or add the repository's justified 62-line test allocation record to resolve the observed test-lines failure.

Findings

  • [P2] Keep notice reporting from rejecting a yielded cleanup sweep — src/agents/subagents/registry/subagent-registry-suspended-delivery.ts:95-96
  • [P2] Mark the registry mock's intentional isolation — src/agents/subagents/registry/subagent-result-owed.policy-outage.test.ts:30-31

Tests

  • Missing end-to-end proof: Provide redacted Gateway output showing policy-outage recovery, committed steering across owner change, and a final expired required completion appearing in the requester conversation.
Agent review details

How this fits together

The subagent registry tracks finished child results, hands them to requester sessions through completion delivery, and persists delivery outcomes and failure notices.

flowchart TD
  A[Finished child result] --> B[Subagent registry]
  B --> C[Requester settlement]
  B --> D[Direct steering]
  B --> E[Suspended delivery expiry]
  C --> F[Requester conversation]
  D --> F
  E --> G[Failure notice writer]
  G --> F
Loading

Technical review

Best possible solution:

Keep the three repairs in their existing owners while preventing failure reporting from turning an ordinary yielded cleanup into a failed sweep.

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

Current-main source exposes all three reported paths, and the added owner regressions target them; this read-only review executed no target code.

Is this the best way to solve the issue?

The small changes reuse the right owners and preserve admission checks, but the expiry reporter must be placed so its asynchronous work cannot break the established yielded-cleanup contract.

Full review comments:

  • [P2] Keep notice reporting from rejecting a yielded cleanup sweep — src/agents/subagents/registry/subagent-registry-suspended-delivery.ts:95-96
    The new awaited reporter runs after durable discard but before the remaining throwing cleanup-owner assertion. If the run yields while that work waits, isCleanupOwnerCurrent becomes false and the sweep rejects instead of treating the obsolete cleanup tail as finished. Exact-head CI demonstrates this in subagent-announcement.worker.test.ts's existing yielded case, which now returns completed: false with Subagent suspended delivery cleanup owner changed. This also stops processing later entries in that sweep. Move the reporting to an appropriate completed-cleanup boundary or otherwise preserve the existing non-throwing yielded outcome without weakening the ownership checks.
    Confidence: 0.97
  • [P2] Mark the registry mock's intentional isolation — src/agents/subagents/registry/subagent-result-owed.policy-outage.test.ts:30-31
    This new factory replaces the first-party registry module with a single export. src/agents/AGENTS.md requires real-module pass-through or an adjacent // mock-isolation: explanation, and the exact-head baseline job reports mock-exports failure. The existing explanation can use the required annotation so the test retains its intended sole registry owner without expanding the baseline.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 235e38488bf2.

Provenance checked

  • Committed steer classification changes intended behavior with a stated reason (36e277d: The session-controller refactor made native steering outcomes authoritative while retaining a post-steer delivery-owner check.)
  • Requester preparation failure handling keeps the original intent (45d63c1: Transient preparation failures preserve the exact owed batch instead of permanently retiring its continuation.)
  • Suspended expiry and visible failure reporting keeps the original intent (fix(subagents): show required completion delivery failures #198807: Temporary expiry suspension stays quiet while settlement remains possible; final unsuccessful delivery reports a visible requester failure.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/agents/subagents/registry/subagent-announcement.worker.test.ts src/agents/subagents/registry/subagent-result-owed.expiry-discard.test.ts --maxWorkers=1
  • pnpm test src/agents/subagents/registry/subagent-result-owed.policy-outage.test.ts src/agents/subagents/registry/subagent-result-owed.steer-owner-change.test.ts src/agents/subagents/announce/subagent-announce-direct-delivery.test.ts --maxWorkers=1
  • pnpm check:changed
  • git diff --check

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit 5d35af1 adds src/agents/subagents/completion/subagent-completion-admission.store.ts:76 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 5d35af150b07; files: src/agents/subagents/completion/subagent-completion-admission.store.ts)

PR surface

Source +8, Tests +462, Docs +6. Total +476 across 10 files. Added test files: 3.

View PR surface stats
Area Files Added Removed Net
Source 4 14 6 +8
Tests 4 467 5 +462
Docs 2 7 1 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 488 12 +476

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus test growth Production +14/-6; tests +467/-5 The production repair is focused; the tests exercise distinct retention, committed-delivery, and expiry-visibility failures, but exceed the repository's unallocated test budget by 62 lines.

Labels

Label changes:

  • add P1: The reported policy-outage path permanently loses owed child-result delivery, with repeated affected completions reported and the responsible current-main path verified in source.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P1: The reported policy-outage path permanently loses owed child-result delivery, with repeated affected completions reported and the responsible current-main path verified in source.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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.

Reviewed November 17, 2026, 10:13 AM ET / 15:13 UTC.

Recording the notice mid-discard opened a yield point that let a concurrent owner change fail the discard. The notice now runs once the discard is committed and is best-effort. Drop the steer integration test that duplicated the direct-delivery contract table, and mark the policy test's registry mock isolation.
@obviyus

obviyus commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer override: check-lint-core-2 fails on files this PR does not touch.

  • The failing job (CI run 44114139666) reports max-lines violations in src/agents/embedded-agent-runner/run/attempt-stream-prepare.ts (705), src/agents/openclaw-tools.ts (703), src/agents/cli-runner/execute-tool-tracking.ts (703), src/agents/embedded-agent-runner/run/attempt-stream-prepare.test.ts (1011), src/state/openclaw-state-db-readonly.ts (701) and src/plugins/registry-runtime.ts (702).
  • None of these files is in this PR's diff. The same files are already over the cap on main; the shard is skipped on main because it only runs for changed paths.
  • Exact-head proof on aab482a358bd: all other CI jobs are green, the local review is clean, the new regressions fail on base and pass with the fix, and the full build and packaged smoke test pass.

@obviyus
obviyus merged commit 3b61a7c into main Nov 17, 2026
127 of 132 checks passed
@obviyus
obviyus deleted the fix/subagent-results-owed-once branch November 17, 2026 15:41
@obviyus

obviyus commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 3b61a7c.

  • Bug: finished subagent results were lost or misrecorded on three paths: a temporary access-policy outage failed them permanently, a steer committed into a busy parent was recorded as non-delivery, and a suspended required result expired after seven days with no notice to the requester.
  • Fix: policy outages keep the result owed and retry it; a committed steer counts as delivered; expiry records the existing visible failure notice after the discard commits.
  • Proof: regressions that fail on base and pass with the fix, the affected announce/settle/lifecycle/completion suites, a source-tier Gateway E2E (busy parent received a steered child result recorded as delivered), full build with packed smoke, a clean local review, and green CI apart from the inherited max-lines lint shard (override comment above).

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 18, 2026
…es, steer races and expiry (openclaw#200649)

## What Problem This Solves

A finished subagent's result could be lost even though the child did its work. Three paths dropped it on current `main`:

- **Access-policy outage:** a temporary "Gateway access policy is unavailable; retry the operation." during requester settlement was recorded as a permanent delivery failure. The parent never received the result, even after the policy recovered.
- **Steer race:** when a busy parent accepted the child's result by steering, and the delivery owner changed afterward, the run was recorded as intentional non-delivery. The parent had the result, but the record said it didn't. The run could later "expire" and send a misleading failure.
- **Expiry:** a suspended required completion was discarded after seven days with no notice in the requester conversation. Only an operator log line recorded it.

On one Gateway, the access-policy class alone accounted for 25 failed child results in a week.

## User Impact

A temporary access-policy outage now only delays a child's result; it is delivered after the policy returns. A result steered into a busy parent is recorded as delivered. A required result that finally expires records the existing visible failure notice ("The child result couldn't be delivered to this conversation…") instead of disappearing silently.

## Why This Change Was Made

Each fix is at the existing owner:

- **Settle wake:** a policy-unavailable error now joins the existing "no delivery was admitted, retry" class, alongside database-busy and overloaded errors, instead of the permanent-failure path.
- **Direct delivery:** an accepted, committed steer returns `delivered` before the delivery-owner check. Only an unconfirmed commit still depends on its owner.
- **Seven-day discard:** this path now calls the same failure-notice writer that other permanent failures already use (openclaw#198807).

Explicit stop, cancellation, requester deletion and real revocation are unchanged.

## Evidence

- **Regressions** drive the real lifecycle, announce, completion and SQLite owners: `subagent-result-owed.{policy-outage,expiry-discard}.test.ts`, plus the updated `steering $outcome after $change` direct-delivery contract (accepted-steer rows fail on base). Each fails on the base commit and passes with the fix:
  - policy outage: recorded `failed` before, owed and then delivered after;
  - steer race: receipt not delivered before, `{delivered: true, path: "steered"}` after;
  - expiry: no notice before, exactly one visible notice after.
- **Existing suites:** announce, settle, lifecycle, completion authority, store-replaced, steer-restart and yielded-run settlement all pass, 500+ tests. The `steering $outcome after $change` contract was updated: an accepted steer is now delivered after an owner change, and indeterminate steers keep the old outcome.
- **End to end (source tier, `ocx src`):** an isolated Gateway with a stub model. A busy parent received its finished child's result through a steer into the same run, and `subagent_runs` recorded `delivered/delivered`.
- **Not in this PR:** splitting settle batches that mix operator invocations (a separate fix with its own proof), and the session-store-switch suspension policy (openclaw#152828, unchanged).

Co-authored-by: Ayaan Zaidi <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 19, 2026
A sibling resume legitimately remaps requesterSettleWake.batchRunIds while another yielded child's one-shot pause notice is being delivered. Full-cohort equality incorrectly rejects that child's settlement, and the retained rejection then fails against the same snapshot on every sweep.

Let the existing completion store settle the same child's pause notice against the current row despite changed sibling membership. Preserve runtime/requester identity, generation, notice content, delivery policy and cancellation checks, along with the observed delivery outcome and the cohort's future final-result obligation.

Two real lifecycle/SQLite regression cases fail with the repeated warning pair on the base and pass with the fix, including no duplicate dispatch and delivery of a later independent requester batch. All 61 focused tests, targeted typechecks, lint, format and Codex autoreview passed. No Doctor repair or schema change is included. Related: #195275, #194732, #170562.

(cherry picked from commit eea1d5a)

Companion audit: #200649 selected next; pause-notice settlement retains generation and exact notice matching.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit c0824317fd65c47fb05a44d630712553219acd44)
RomneyDa added a commit that referenced this pull request Nov 19, 2026
…es, steer races and expiry (#200649)

## What Problem This Solves

A finished subagent's result could be lost even though the child did its work. Three paths dropped it on current `main`:

- **Access-policy outage:** a temporary "Gateway access policy is unavailable; retry the operation." during requester settlement was recorded as a permanent delivery failure. The parent never received the result, even after the policy recovered.
- **Steer race:** when a busy parent accepted the child's result by steering, and the delivery owner changed afterward, the run was recorded as intentional non-delivery. The parent had the result, but the record said it didn't. The run could later "expire" and send a misleading failure.
- **Expiry:** a suspended required completion was discarded after seven days with no notice in the requester conversation. Only an operator log line recorded it.

On one Gateway, the access-policy class alone accounted for 25 failed child results in a week.

## User Impact

A temporary access-policy outage now only delays a child's result; it is delivered after the policy returns. A result steered into a busy parent is recorded as delivered. A required result that finally expires records the existing visible failure notice ("The child result couldn't be delivered to this conversation…") instead of disappearing silently.

## Why This Change Was Made

Each fix is at the existing owner:

- **Settle wake:** a policy-unavailable error now joins the existing "no delivery was admitted, retry" class, alongside database-busy and overloaded errors, instead of the permanent-failure path.
- **Direct delivery:** an accepted, committed steer returns `delivered` before the delivery-owner check. Only an unconfirmed commit still depends on its owner.
- **Seven-day discard:** this path now calls the same failure-notice writer that other permanent failures already use (#198807).

Explicit stop, cancellation, requester deletion and real revocation are unchanged.

## Evidence

- **Regressions** drive the real lifecycle, announce, completion and SQLite owners: `subagent-result-owed.{policy-outage,expiry-discard}.test.ts`, plus the updated `steering $outcome after $change` direct-delivery contract (accepted-steer rows fail on base). Each fails on the base commit and passes with the fix:
  - policy outage: recorded `failed` before, owed and then delivered after;
  - steer race: receipt not delivered before, `{delivered: true, path: "steered"}` after;
  - expiry: no notice before, exactly one visible notice after.
- **Existing suites:** announce, settle, lifecycle, completion authority, store-replaced, steer-restart and yielded-run settlement all pass, 500+ tests. The `steering $outcome after $change` contract was updated: an accepted steer is now delivered after an owner change, and indeterminate steers keep the old outcome.
- **End to end (source tier, `ocx src`):** an isolated Gateway with a stub model. A busy parent received its finished child's result through a steer into the same run, and `subagent_runs` recorded `delivered/delivered`.
- **Not in this PR:** splitting settle batches that mix operator invocations (a separate fix with its own proof), and the session-store-switch suspension policy (#152828, unchanged).

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 3b61a7c)

Companion audit: #200581 included; existing authority outage classifier and completion failure owner are present.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit eadbf05817ce8aa5dc0c0e8daf8594486dc7e581)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation 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. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant