Repository navigation
refactor(agents): consolidate lifecycle and tool execution - #166691
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
|
Codex review: blocked before merge. Reviewed October 7, 2026, 3:22 PM ET / 19:22 UTC (Revision 2). ClawSweeper reviewWhat this changesConsolidates subagent lifecycle and tool execution logic, fixes recorded-agent restart recovery, and rejects stale screenshot frames when computer target references are blank. Merge readiness⛔ Blocked before merge - 2 items remain Keep open: both focused fixes remain absent from the pinned main, and the related merged listing fix does not supersede this work. No blocking introduced defect was found. Priority: P2 Review scores
Verification
How this fits togetherSubagents execute delegated work and return results to their requesting session. Their lifecycle owners coordinate SQLite persistence, recovery, cancellation, and delivery, while agent tools validate requests before dispatch. flowchart TD
A[Agent tool request] --> B[Validate target and current owner]
B --> C[Execute delegated work]
C --> D[Lifecycle and completion owner]
D --> E[Worker write admission]
E --> F[SQLite state and committed receipts]
F --> D
D --> G[Requester result and cleanup]
Before merge
Agent review detailsSecurityNone. PR surfacePR surface statistics unavailable: the file list is incomplete. Review metricsNone. Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep shared lifecycle and dispatch owners while preserving existing authority, receipt, protocol, and persisted-state contracts. Do we have a high-confidence way to reproduce the issue? Yes, from source: a raw child key lacks the agent prefix required by main's recovery reader, and whitespace-only computer references bypass its raw-truthiness frame check. The focused regressions cover both paths; this review did not execute them. Is this the best way to solve the issue? Yes. The fixes reuse recorded ownership and existing string normalization, while the consolidation preserves variant-specific authority and settlement behavior without adding public configuration or parallel APIs. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against cbfbdc8ddb95. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
Share registry and completion write admission, requester mutations, cleanup finalization, scoped reads and prepared spawn facts. Carry existing owners and parameters through tool, media and question lifecycles while keeping variant-specific authority, replay and settlement behavior explicit. Consolidate HTML attribute scanning with distinct render and visibility grammars, plus repeated tool schema and result construction. Keep model prompts, descriptions, protocol shapes and existing test assertions intact.
d287c11 to
9eb0658
Compare
|
Exact-head CI attribution for
The earlier requester-wake fixture recursion was ours and was repaired in this exact head; its complete 35-case file passes. The older Discord preview failure was inherited and fixed upstream by Final exhaustive |
…b [step 2/5] Upstream "consolidate lifecycle and tool execution" (openclaw#166691). Thirteen conflicting files (24 hunks) in the subagent registry and spawn code. The feature's structure is kept, with upstream's semantic changes carried over: - lifecycle-announce-cleanup: upstream re-indented the cleanup driver (runCleanup). The feature's fence placement (onBeforeDispatch at the sessions.delete handoff) is re-applied in upstream's block. The announce params take upstream's `...pendingPayload` spread, plus the feature's legacy-row requesterAgentId fallback. - run-launch: failed queued launches use upstream's createFailedQueuedRun and then clear the feature's launchDispatch marker. The imports of both sides are reconciled. - queries/read: upstream retired resolveRequesterForChildSessionFromRuns (read uses getLatestSubagentRunForChild); the feature's listAncestorSessionKeysFromRuns is kept. - sweeper/registry: upstream dropped the resumedRuns and contextCleanup params; the feature keeps its shouldDeferArchive / callGatewayForSweep and its extracted collector-group sweep. The extracted mutators follow upstream's void mutateCleanup contract (no `return draft`). - run-liveness: the feature's tunable stale cutoff and liveness verdict are kept, and upstream's new isYieldedSubagentRun is added. - session-cleanup: the feature's continuation guard block is kept, with upstream's destructure. - attachments: the feature's shared inline-attachment validation is kept. Upstream had inlined the attachment limits, which auto-merged past the feature's tighten-only clamp; the call to resolveAttachmentLimits is restored. - spawn-request/spawn: upstream flattened the resolved request; the feature's continuation fields are added flat, and the feature helpers that read the old nested shape (spawn-continuation, spawn-registration) now read the flat one. - subagent-announce: hasUsableSessionEntry now lives upstream in subagent-announce-delivery.runtime, so the local copy is dropped. - Tests: the feature's tests move to upstream's consolidated mutateRequesterCompletionBatch (rejection-write, requester-agent), and restore-recovery no longer passes hasUsableSessionEntry through its mock. Checks: typecheck clean for core and every core test shard plus extensions-test. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Jhynq2GVpzuVQQieebEubg
…166691) * fix(subagents): honor recorded owners during restart recovery * fix(computer): require current frames for blank target references * refactor(agents): consolidate subagent lifecycles and tool dispatch Share registry and completion write admission, requester mutations, cleanup finalization, scoped reads and prepared spawn facts. Carry existing owners and parameters through tool, media and question lifecycles while keeping variant-specific authority, replay and settlement behavior explicit. Consolidate HTML attribute scanning with distinct render and visibility grammars, plus repeated tool schema and result construction. Keep model prompts, descriptions, protocol shapes and existing test assertions intact. * fix(agents): preserve shared reader fixture coverage and type contracts * test(agents): preserve real exports in consolidated mocks * test(subagents): preserve announce runtime predicates in fixtures * refactor(agents): satisfy lint in consolidated tool paths * test(subagents): preserve composed requester-wake mutation spies
Related: #166550
What Problem This Solves
Consolidates repeated subagent lifecycle and tool execution logic, and fixes two adjacent owner-validation defects found during the pass.
User Impact
All existing features, tool descriptions, prompts, configuration and protocol shapes remain intact. Watched children using raw keys such as
globalrecover under their recorded agent; whitespace-only computer target references no longer bypass screenshot-frame validation. No migration or operator action is required.Why This Change Was Made
Shared cores now own registry/completion write admission and receipt settlement, requester mutations, cleanup finalization, scoped reads, prepared spawn facts, media dispatch, and question prompt lifecycle. Real differences remain explicit, including authority checks, recovery/replay rules, await boundaries, and the distinct HTML rendering and visibility grammars.
The two bug fixes are separate commits. Restart recovery ignored
childAgentIdand omitted the explicit agent read scope. Computer frame admission tested raw reference truthiness even though request construction discarded blank references.Net production reduction: 1,686 lines (3,911 added / 5,597 deleted), 1.89% of the original 89,099-line subsystem. This includes replacement helpers and excludes tests, fixtures, test support, generated output and declarations. Every original production file was covered; alternatives that grew code or obscured ownership were measured and rejected. Existing assertions remain intact; test changes adapt removed private seams or add regressions. All three canonical baseline updates only shrink allowances.
Evidence
459d1757d2e13c1d3d5ac90fd86082b239dee4c3. The conflict-only rebase preserved main's scheduler-slot aliases and Gateway authority forwarding; all affected integration tests plus lint-suppression tests passed on rebased head6137ef76df0217ae0f60bc5646a7e9dc76f0f5d8(900.59 seconds wrapper wall time).d287c11728d9d19336ae6ced258d53f572e7c176has 650 additional focused tests passing across 12 files (220.86 seconds), a fresh core typecheck, and runtime/Madge cycle counts of 0. That committed tree matches its tested and reviewed tree. The complete changed-file packet passed all source guards, production types, all 27 test type graphs, and all three Knip scans. Its final lint stage found nine lane issues; those were corrected and independently reviewed with no findings. The full core lint rerun has no remaining lane findings; only the four untouched size violations listed below remain, waived by the campaign rule.deferredinstead ofterminal); all 30 integration tests passed after it (896.33 seconds wrapper wall time). Both blank-reference regressions dispatched stale-frame clicks before the fix; all 58 computer tests passed after it (221.22 seconds). These times include compiler preparation; hosted CI timing will be visible in the attached exact-head run.77d2f0d5). The earlier parameter-type correction emits identical JavaScript; final lint corrections and rebase integration have fresh focused, type, and cycle proof without import or public declaration changes.The full packet initially exposed two fixture seams after shared-reader/runtime consolidation. They now preserve the real exports and use the same test-owned reader; the existing cancellation and announcement assertions pass unchanged. The old-base changed checker also found an untouched UI test type error; main commit
1d10375ee56, included in this rebase, fixes it.The separate raw-key reconciliation path still needs worker reads and owner-aware cleanup routing. That repair is being prepared for a separate sequential bug-fix PR; this PR does not claim to fix it.
The standalone core lint rerun reports pre-existing max-lines violations in
ui/src/components/session-organizer-operations.runtime.ts,src/cli/update-cli/update-command-service-maintenance.ts,src/agents/worktrees/service-preparation.ts, andsrc/agents/tools/message-tool-execution.ts. All four files are untouched and byte-identical to origin/main. No cap, ignore, or suppression was added; the obsolete sessions-send max-lines allowance was removed through the canonical ratchet.The first hosted run found one lane-owned fixture issue: the reservation test wrapped the same mutable spy installed by beforeEach after two mutation APIs were consolidated. It now captures the existing implementation, preserving the settlement-failure wrapper and every assertion. The original-order negative control reproduced the stack overflow/missing retry deadline; the complete 35-case E2E file and 3 lint-suppression tests pass after repair (482.07 seconds including cold build). Its scoped lint/typecheck and fresh P2 review pass.
Current head is
9eb0658df94b62de8af8d338823824fdf9d95a4f, rebased ontod449d77dd1cbd9aad682b25ef92f1d4afc052c81to incorporate upstream Discord fix9df0cd095766ff05864aa67aa91b627a347a4d1a. That separate hosted failure reproduced on clean main before the fix; the same whole 30-case file passes after it. All eight lane commits are patch-identical through the rebase. Fresh core types, runtime/Madge cycle checks (both zero), and lint-suppression tests (3) pass on the rebased head. The two cancelled auxiliary runs from the first hosted attempt were rerun successfully; exact-head CI is required again after this push.