Skip to content

refactor(subagents): centralize end-of-run decisions - #206454

Merged
vincentkoc merged 3 commits into
mainfrom
refactor/subagent-terminal-decision
Nov 27, 2026
Merged

vincentkoc merged 3 commits into
mainfrom
refactor/subagent-terminal-decision

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Terminal policy is distributed across completion, termination publication, effect dispatch, cleanup bookkeeping, and retries. This cutover gives those adapters one owner for the terminal row and the work owed after publication.

User Impact

No intended behavior change. Result capture, cancellation reconciliation, collector results, cleanup ordering, and requester delivery preserve their existing contracts. No persisted fields, public SDK contracts, or configuration change. One Gateway test is updated to the already accepted admitted-Stop contract.

Why This Change Was Made

The internal transition owner prepares result capture, plans completion and termination, and returns explicit effect, cleanup, and retry decisions. Completion and termination share the outcome writer. The five registry adapters retain persistence, dispatch, and live ownership checks instead of deriving terminal policy again.

Mechanical caller updates

The five registry adapters consume the transition owner. The queued-collector settlement test now acknowledges an admitted Stop after session replacement, retains actual cleanup rejection, compares the full replacement entry, and checks that the original collector terminates without launching or publishing replacement metadata. No announce, requester-custody, or kill implementation files are changed.

Integration and overlap

Rebased onto the merged kill-claim repair from #206405 at be3c73e2becd42a8cb4bfc4aba2698ce00498a04. The moved termination planner retains its exact kill-claim predicate; the adapter passes the claim through and preserves the acquisition-owned session release rule. The separately merged announce-export cleanup in #206429 is included through the base.

PR overlap inventory from the scope search

Other work identified with overlapping scope: #206443, #200231, #199455, #194732, #197335, #136554, #140956, #201774, #191857, #201613, #198689, #198633, #121309, #164366, #203303. Most completion-directory overlaps are outside the edited files.

Evidence

Integration base: be3c73e2becd42a8cb4bfc4aba2698ce00498a04. Pushed head: 1195495e73f208c7fdccdde43096573341834760. Production source is unchanged from the reviewed 92f6467aabbf; the final commit changes only the Gateway test.

  • Fresh independent P0–P2 review of the complete branch at 1195495e73f2 found no actionable defects. It checked exact kill-claim rejection, acquisition-owned session release, terminal ordering, cleanup, retries, and the Gateway test migration with unchanged neighboring owners and tests supplied as source context. The review did not execute tests.
  • All six changed files pass Node syntax checks, repository formatting, and git diff --check. The source-only session-identity ratchet passes against the integration base (1,555 files; 6,191 grandfathered pins).
  • A refreshed static reference audit finds a production reader for each of the 45 named exports in the owned production scope; no dead-export candidates. Test-only helpers remain used by their tests. The prior production/full-tree export audit had no findings in these owned files; final production exports are unchanged, and the static reader audit was refreshed after integration.
  • Final normal PR CI completed successfully at 1195495e73f2; all required checks are green. Job 140392766207 passed all three queued-settlement cases (settled, rejected, and session replaced), giving red/green proof for the test-only correction. All remaining CI gates passed as well. The preceding run at 92f6467aabbf completed: all jobs passed except queued-collector settlement and the aggregate CI gate. The test expected Stop rejection after replacement; it received success, matching the L1 owner’s confirmed admitted-Stop contract. The repair preserves cleanup rejection and strengthens replacement-state assertions. Exact execution of this case on be3c73e2 remains unverified; no inherited-failure exception or baseline-red claim is used. Earlier CI at 54503b9a passed production/test types, core lint, both UI Gateway jobs, and the lifecycle, terminal-effects, completion-runtime, and requester-wake retry suites. That evidence belongs to the previous head.
  • The earlier run also failed four Gateway E2E cases at shutdown with PluginRuntimeCloseRetainedError, caused by Native worker execution owners have not joined: chat-goal-created-authority, chat-goal-created-yield, native-cancellation-authz, and gateway.compaction-hot-reload. The native classifier reports unknown (no matching main job). Identical failure-owner source is not baseline proof. The failure and bounded investigation remain recorded under the test-failure policy; no fix or baseline attribution is claimed.
  • Both requested Blacksmith Testbox allocations queued and were stopped under the campaign capacity rule: initial focused proof and queued-settlement baseline attempt. Neither ran tests. Runtime and broad proof come from PR CI. The final-run logs confirm 99 selected subagent test files; one benchmark file was intentionally skipped. A whole-directory execution of all 188 tracked test files is not claimed. This follows standing rule 06’s queued-Testbox substitution with PR CI.

Measurements

Same engine and selectors, complete coverage, no parse failures. The base scan uses native baseline bd459c651f12; all owned source files are byte-identical to the integration base be3c73e2becd. The head scan is 92f6467aabbf; its production files are identical at 1195495e73f2.

Measurement Base Head
Production SLOC 3,295 3,394
Predicate-containing lines in terminal adapters and owner 76 74
planTerminalCompletion CC 94 97
completeTerminalEffects CC 82 78
completeSubagentRunAttempt CC 45 35
createSubagentRegistryCompletionRuntime CC 48 40
completeCleanupBookkeeping CC 44 24
publishTermination adapter CC 41 9
Sloppiness score 43.41 41.52

The new termination planner has CC 34 and cleanup planner CC 27. The increase in the completion planner reflects decisions moved in from its consumers. This is an ownership cutover, not a claim that all decision complexity disappeared. The original campaign baseline f769a88c6a4 had 3,281 production SLOC and score 43.34, before the intervening L1 changes.

The exact PR production diff before copy detection is 771 additions / 651 deletions, mostly code movement; this does not claim 651 lines of dead code. The mechanical Gateway test repair adds 15 lines and removes 6; no test cases are added or removed.

@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 the P2 Normal backlog priority with limited blast radius. label Nov 27, 2026
@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, termination, cleanup, and retry decisions while leaving persistence and effect dispatch in their existing adapters.

Example: A child publishes “first final” at timestamp 4000, followed by an older receipt at 3999.

  • Before: The completion adapter preserves “first final” while allowing cleanup to continue.
  • After: The shared transition owner makes the same decision.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The inspected implementation is coherent and retains existing stored fields and write boundaries, while unresolved broad CI attribution limits validation confidence.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored refactor has no intended user-visible change; existing owner-level tests and exact-head CI support behavior preservation rather than a new live-behavior claim.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Refactor · Worth it: Yes · Fix scope: Complete
Reason: Maintainer authorship establishes direction, and the diff consolidates policy previously spread across five adapters while preserving their existing operational responsibilities.

Merge readiness

✅ Ready for maintainer review

Keep this maintainer-authored PR open: it makes a coherent ownership cutover, and inspection found no definite introduced bug.

Reviewed head: 54503b9a9bfb1f7fd1f89d1df18eda1ec8caa6f5

Before merge

None.

Findings

None.

Agent review details

How this fits together

Subagent terminal events and Stop requests enter the registry lifecycle; terminal row plans pass through the existing persistence owner before resource cleanup, hooks, and requester delivery run.

flowchart TD
  A[Completion observations] --> C[Terminal transition owner]
  B[Stop requests] --> C
  C --> D[Registry persistence adapters]
  D --> E[Committed terminal rows]
  E --> F[Resource cleanup and hooks]
  E --> G[Requester delivery and settlement]
Loading

Technical review

Best possible solution:

Keep one terminal decision owner while preserving existing persistence admission, cancellation reconciliation, and resource-dispatch ordering.

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

This is an internal refactor with no claimed user-visible defect to reproduce; source comparison preserves the existing terminal-state contracts.

Is this the best way to solve the issue?

The extraction provides one decision owner without introducing parallel persistence or dispatch paths, and the additional decision fields serve the stated maintainer-approved cutover.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +129. Total +129 across 6 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 6 770 641 +129
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 770 641 +129

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.

Rank-up moves

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

  • Attribute the four Gateway shutdown failures using a matching baseline or head/revert comparison.
  • Complete the recorded Stop-repair integration and validate the affected cancellation contracts on the resulting head.

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, 2:31 AM ET / 07:31 UTC.

@vincentkoc
vincentkoc force-pushed the refactor/subagent-terminal-decision branch from 54503b9 to 92f6467 Compare November 27, 2026 08:05
@vincentkoc
vincentkoc marked this pull request as ready for review November 27, 2026 08:06
@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Nov 27, 2026
@vincentkoc
vincentkoc merged commit 42f33ba into main Nov 27, 2026
160 checks passed
@vincentkoc
vincentkoc deleted the refactor/subagent-terminal-decision branch November 27, 2026 08:42
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 28, 2026
* refactor(subagents): centralize terminal transition decisions

* refactor(subagents): simplify cleanup decision booleans

* test(subagents): preserve admitted stop after session replacement
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime 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.

1 participant