Skip to content

refactor(subagents): centralize completion delivery decisions - #206383

Merged
vincentkoc merged 2 commits into
mainfrom
refactor/subagent-announce-obligation
Nov 27, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
refactor/subagent-announce-obligation

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Closes #206373
Related: #204178

What Problem This Solves

Maintainers currently have to follow subagent completion decisions through direct response classification, announce-flow reporting, and lifecycle cleanup. The same delivery obligation is interpreted in several places, making receipt precedence and fallback changes difficult to review.

This is the maintainer-requested cutover to one completion-decision owner.

User Impact

No intentional user-visible behavior change. Direct delivery, queue custody, requester handoff, and requester-history settlement retain their existing behavior. The legacy suspended, failed, and discarded readers and active admission expiry remain intact.

Why This Change Was Made

The obligation module owns reply policy, response/fallback decisions, once-only receipt reporting, and cleanup outcomes. Transport adapters execute those decisions and return receipts; the existing lifecycle owners still persist state. Child-result preparation is separated from dispatch. Existing import surfaces used by sessions_send continue to expose the same implementations.

The explicit decision and fact contracts add 286 production SLOC in the measured scope while reducing the large functions below. No stored-state format or configuration is added.

Evidence

Pinned base: 2ab7b31a13d95bbbb62596679b130445c4c9d3d1
Current head: 41a93922a7d9133306268d767bb7d1894f3f9d14
Runtime-proof head: 5639d82df867f6078604bec1df5611609770b839

Validation ran on Blacksmith Testbox tbx_01m8dj32n7ns87rv8wnj2zynme (4 CPUs, about 16 GB RAM, Node 24.22.1, pnpm 12.15.0), using the repository source-capsule wrapper. Allocation workflow; the command receipts verified the runtime-proof head above independently of the allocation workflow.

  • Focused announce, sessions_send, and prompt-prefix coverage: 434 tests passed in 37 files, five shards.
  • pnpm tsgo:core: passed.
  • pnpm tsgo:test:src: passed.
  • Targeted oxlint on all seven changed files: 0 warnings, 0 errors.
  • pnpm test src/agents/subagents --maxWorkers=2: all six shards passed; existing skips were retained.
  • The campaign-listed preserves routed native Stop authority and existing receipts (consumed-session) case passed in this run. The previously reported failure did not reproduce here; this PR does not claim to fix it.
  • Local branch review at P0–P2: no actionable findings. Unchanged delivery-state, lifecycle, transport, history-admission, and regression-test neighbors were supplied as source context.
  • Formatting and git diff --check: passed. Live-provider tests were not run.
  • CI assertion-ratchet repair: document the existing typed receipt assertion and remove its obsolete allowance from the old file. The local assertion SAFETY ratchet passed at the current head. The source delta since the runtime-proof head is one comment, so the runtime and type/lint proof above is reused; current-head PR CI remains required.

code-sloppiness 0.2.0+vk.4, identical scope/engine, complete coverage with no parse failures:

Function Base CC Head CC
runSubagentAnnounceFlowBound 143 101
sendSubagentAnnounceDirectlyBound 109 90
createDirectAnnounceResponseClassifier 101 1
startSubagentAnnounceCleanupFlow 98 92

The new response-decision functions have CC 45 and 35; classification complexity was split along evidence and outcome boundaries, not discarded. Measured production SLOC: 5,178 → 5,464.

git grep -c over production announce files and the two cleanup files, using \.delivered|delivery\??\.status|announceOutcome ===: 45 → 43 matching lines. Legacy-state predicates in subagent-delivery-state.ts: 5 → 5.

Open overlap: #198204 — completion review no longer repeats a result the user already saw also changes the announce flow. This branch remains pinned to its reviewed base; integration belongs to the coordinator.

@vincentkoc vincentkoc self-assigned this Nov 27, 2026
@clawsweeper

clawsweeper Bot commented Nov 27, 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 agents Agent runtime and tooling size: XL labels Nov 27, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:message-loss Channel message delivery can be lost, duplicated, or misrouted. labels Nov 27, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review November 27, 2026 04:42
@vincentkoc
vincentkoc enabled auto-merge (squash) November 27, 2026 04:56
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Nov 27, 2026
@clawsweeper

clawsweeper Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: passed.

What this changes

This PR centralizes subagent completion policy while retaining the existing transport and lifecycle persistence owners.

Example: A parent silently consumes child result ALPHA.

  • Before: Response classification, announcement reporting, and cleanup interpret delivery across separate modules.
  • After: The completion obligation supplies those decisions, preserving successful silent consumption and existing cleanup.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A coherent ownership refactor with no actionable findings and broad reported regression coverage; validation remains test-based.
Proof confidence 🦐 gold shrimp (3/6) No user-visible behavior change is intended or identified; reported regression suites support equivalence, while inspected linked media documents separate earlier changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Refactor · Worth it: Yes · Fix scope: Complete
User problem: Distributed completion decisions make future changes to reliable child-result delivery harder to review consistently.
Reason: Maintainer authorship establishes direction, and the inspected cutover consolidates policy without introducing configuration, storage formats, or intentional delivery changes.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR implements the requested ownership consolidation, and the pinned diff contains no actionable regression.

Reviewed head: 41a93922a7d9133306268d767bb7d1894f3f9d14

Before merge

None.

Findings

None.

Agent review details

How this fits together

Subagent announcement code receives child outcomes and requester receipts, chooses delivery or handoff outcomes, and passes them to existing transport, history, and registry owners.

flowchart TD
  A[Child terminal outcome] --> B[Child result preparation]
  B --> C[Completion obligation]
  C --> D[Transport adapters]
  D --> E[Requester receipts]
  E --> C
  C --> F[Lifecycle cleanup]
  F --> G[Registry and requester history]
Loading

Technical review

Best possible solution:

Land the completion-decision cutover with its existing transport and persistence boundaries once the required current-head checks pass.

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

This is a behavior-preserving ownership refactor, with no new user-facing defect claimed; source inspection confirms the distributed decisions it consolidates, and no target code was executed.

Is this the best way to solve the issue?

The cutover fits the requested scope: it removes the previous decision implementations, preserves existing helper consumers, and leaves transport execution and durable writes with their established owners.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +339, Other -1. Total +338 across 8 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 7 992 653 +339
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 8 992 654 +338

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.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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 27, 2026, 12:05 AM ET / 05:05 UTC.

@vincentkoc
vincentkoc merged commit 811f999 into main Nov 27, 2026
135 checks passed
@vincentkoc
vincentkoc deleted the refactor/subagent-announce-obligation branch November 27, 2026 05:10
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash auto-merge.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 28, 2026
…aw#206383)

* refactor(subagents): centralize completion delivery decisions

* docs(subagents): explain trusted delivery receipt assertion
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
Preserve the existing requester restart reason in announce classification so unconsumed completed results remain pending for startup custody. Existing consumption receipts prevent replay; permanent refusals, explicit cancellation, and ambiguous sends retain their policies.

(cherry picked from commit b8b06c4)

Follow-ups: fca5133 fix: preserve child completion inputs across Gateway restarts (#208367) [not selected for this narrow backport]; b7967b2 fix: deliver a saved child answer after a Gateway crash (#207706) [not selected for this narrow backport]; 17e2ec9 fix: tell the user when a finished subagent's report can't start in their chat (#207194) [not selected for this narrow backport]; 811f999 refactor(subagents): centralize completion delivery decisions (#206383) [not selected for this narrow backport]; 50a6774 fix: retain channel requester when child completion resumes parent [separately ordered lane row]; d2699a8 chore: carry and enforce participant limits on admitted runs (#204847) [not selected for this narrow backport]; 57dd84b fix(agents): settle every undelivered child completion into history; drop delivery dispositions (#204260) [separately ordered lane row]; cded11f fix(agents): deliver a child's end state as parent history, not a turn obligation (#204178) [not selected for this narrow backport]; 92e92d7 fix: preserve restarted child results and gateway test ownership (#203839) [not selected for this narrow backport]; 09d956b fix(subagents): wake a yielded requester for each ready child result (#203176) [not selected for this narrow backport]; 9f35510 fix: retain child results behind live requester turns (#203198) [separately ordered lane row]; c23cd7f fix: preserve private child results during restart (#203156) [separately ordered lane row]

Release adaptation: Keep stable requester fixture setup and insert the two consumed/unconsumed restart cases without moving its existing lost-yield test.

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

Labels

agents Agent runtime and tooling impact:message-loss Channel message delivery can be lost, duplicated, or misrouted. P2 Normal backlog priority with limited blast radius. 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.

refactor(subagents): centralize completion delivery decisions

1 participant