Skip to content

refactor(subagents): centralize requester turn custody - #206286

Merged
vincentkoc merged 2 commits into
mainfrom
refactor/subagent-requester-turn-owner
Nov 27, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
refactor/subagent-requester-turn-owner

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Subagent completion, cleanup, recovery, and status paths repeat the same recorded pause, pending-result, and requester-yield decisions.

User Impact

No intended behavior change. Existing pause, delivery, cancellation, and requester-turn semantics are preserved.

Why This Change Was Made

Adds one runtime-free owner for three predicates: isSubagentPausedByYield, hasPendingRequesterTurnResult, and hasRequesterTurnYielded. Migrates matching decisions in the allowed callers while preserving the separate live-requester and frozen-cohort owners.

Exact requester-turn ID comparisons remain at their existing sites. The original extraction moved one existing equality into the new module, which failed the session-identity per-file ratchet (2 > 0). The follow-up restores those expressions and removes both binding helpers; it changes neither the ratchet nor its allowlist and adds no alternate comparison syntax.

The kill files and announce/subagent-announce*.ts flows are unchanged. No state, schema, public API, configuration, or dependency changes.

Evidence

  • Base: 2ab7b31a13d95bbbb62596679b130445c4c9d3d1; current head: cc429cf90829a20753598a1004ff3863bd3e10bd.
  • Current Blacksmith Testbox run, lease tbx_01m8dn540ww4hbw6xjkskwr4x8: wrapper verified the current source and frozen dependencies; observed 4 CPUs and 15 GB RAM. 316 focused tests and all 2,260 subagent tests passed, with zero failures and one existing opt-in benchmark skipped. pnpm tsgo:core, all pnpm tsgo:test:src shards, and changed-file oxlint passed (zero warnings/errors).
  • Current independent local review at P0–P2: scoped-clean, no actionable findings. A separate read-only review verified exact restoration of the baseline comparisons and complete removal of both helper symbols.
  • Formatting and git diff --check passed. Current-head GitHub CI is green, including the session-identity ratchet and required CI gate. The standalone ratchet probe rejected an unsupported --base= argument before inspecting source; this accounts for the Testbox command's combined exit 1. Its test, typecheck, and lint checks all exited 0. Ratchet proof is the successful exact-head CI job, not the rejected probe.
  • Earlier base/head Testbox comparison at 1078eff569cc190788a30693e30ed3a5c54f5c82: 316 focused tests passed on base and head; full subagent suite had 2,260 passed, zero failed, one opt-in benchmark skipped; core and source-test typechecks and changed-file lint passed. This is historical proof, not a current-head CI claim.

The campaign's known baseline failure was reproduced by running preserves routed native Stop authority and existing receipts (consumed-session) alone on base: expected aborted: false, received aborted: true. It passed in both head runs' full suites. This refactor does not claim to repair that failure; no behavior-fix red/green claim is made.

Measurements and retained semantics

Counts use git grep -c over src/agents/subagents, src/agents/tools/subagents-tool.ts, and src/gateway/session-restart-*.ts, excluding *.test*. Counts are matching lines, not AST reads; field access includes writes, projections, and parameters.

Measurement Base Head including owner Head callers only
Raw requesterTurnRunId / requesterTurnYielded property-access lines 71 66 64
Raw pauseReason ===/!== "sessions_yield" decision lines 77 7 6

The six remaining caller pause comparisons are in excluded kill and announce-flow files. The new owner has three functions with CC 1, 2, 1.

Code-sloppiness scans 15 → 32 cover the same 36 caller files; scan 33 covers the new owner. No parse failures. Largest-function CC remains unchanged: startSubagentAnnounceCleanupFlow 98, scheduleRequesterSettleWake 94, planTerminalCompletion 94, settleRequesterTurnAfterSessionSpawns 86. Caller score 39.0223 → 39.0307; clone SLOC 47 → 47. This centralizes decisions without claiming a complexity-score improvement. Production diff: +141 / -85 across 36 files; test diff: 0.

Retained raw fields serve normalization, writes, forwarding, projections, exact frozen identities, or different presence rules. Memory retirement distinguishes explicit false from an absent completion flag; recovery can require no binding regardless of completion; registry retirement also recognizes frozen membership. Inline acknowledgement keeps its existing truthy yield check; the shared predicate serves strict-true sites.

subagent-requester-turn-liveness.ts remains the physical live-requester owner. subagent-requester-settle-identity.ts remains the frozen-cohort owner. Follow-up through the owning lanes: migrate the excluded kill/announce pause checks. No unrelated behavior repairs are included.

Open PR overlap

Searched open subagent PRs before implementation. Known intersecting changes include:
#194275,
#200231,
#199455,
#201097,
#194732,
#186845,
#197335,
#153550,
#197123,
#183715,
#188492,
#136554,
#140956,
#201774,
#191857,
#201613,
#201315,
#150933,
#121309,
#164366,
#179902,
#203303,
#192845.

These are overlap notices; no unrelated fixes are incorporated.

@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: M labels Nov 27, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 27, 2026
@clawsweeper

clawsweeper Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR centralizes repeated subagent pause, requester-turn binding, pending-result, and yield-intent predicates.

Example: A child has pauseReason="sessions_yield".

  • Before: Completion, cleanup, recovery, and status callers compare the recorded pause field directly.
  • After: Migrated callers use the same shared predicate and retain their existing behavior.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch appears mechanically correct, but focused tests, typechecks, and changed-file lint have no completed validation evidence.
Proof confidence 🌊 off-meta tidepool Not applicable: No user-visible behavior changes require shipped-entry-point proof; inspected screenshots belong to the separate progress-card PR #179902 and do not validate this refactor.
Patch quality 🦪 silver shellfish (2/6) The patch appears mechanically correct, but focused tests, typechecks, and changed-file lint have no completed validation evidence.

Product

Kind: Refactor · Worth it: Yes · Fix scope: Complete
Reason: Maintainer authorship establishes direction, and consolidating repeated predicates reduces policy drift while preserving the documented scope exclusions.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this PR open: it is a useful maintainer-directed consolidation, and source review found no definite introduced bug.

Reviewed head: 1078eff569cc190788a30693e30ed3a5c54f5c82

Before merge

  • Improve patch quality - Complete focused requester-yield, retirement, completion, and recovery tests plus core/test typechecks and changed-file lint on the reviewed head.

Findings

None.

Agent review details

How this fits together

The subagent registry consumes recorded child and requester state to decide completion delivery, cleanup, recovery, and status presentation.

flowchart TD
  A[Recorded subagent state] --> B[Requester custody predicates]
  B --> C[Completion and delivery]
  B --> D[Cleanup and recovery]
  B --> E[Status presentation]
  F[Live requester and frozen cohort owners] --> C
Loading

Technical review

Best possible solution:

Retain the shared recorded-state predicates and existing specialized owners, then complete validation before merging.

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

This is a behavior-preserving refactor with no reported defect to reproduce; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The small shared module consolidates repeated recorded-state conditions without replacing liveness, cohort currency, persistence, or authority owners.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Requester retirement keeps the original intent (0fa3412: Keep retirement intent on the row until no settle wake or pending requester result remains.)
  • Requester cohort selection keeps the original intent (fcc6b90: Skip superseded completion records so stale requester transfers cannot abort restart recovery.)
  • Ordered registry mutation and ownership checks keeps the original intent (3f761a8: Serialize overlapping registry writes while preserving rejection of genuine ownership loss.)

Testing

Proof path: none.

Security

None.

Evidence

What I checked:

Likely related people:

  • Vincent Koc: Raw commit 0fa3412 adds src/agents/subagents/registry/subagent-delivery-state.ts:390 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 0fa34123b322; files: src/agents/subagents/registry/subagent-delivery-state.ts)
  • Peter Steinberger: Raw commit fcc6b90 adds src/agents/subagents/registry/subagent-registry-requester-yield.ts:232 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: fcc6b90b0f20; files: src/agents/subagents/registry/subagent-registry-requester-yield.ts)
  • Ayaan Zaidi: Raw commit 57dd84b adds src/agents/subagents/registry/subagent-registry-lifecycle-delivery.ts:65 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 57dd84bd1e0f; files: src/agents/subagents/registry/subagent-registry-lifecycle-delivery.ts)

PR surface

Source +85. Total +85 across 37 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 37 183 98 +85
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 37 183 98 +85

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: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🌊 off-meta tidepool 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:

  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🌊 off-meta tidepool 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 26, 2026, 9:00 PM ET / November 27, 2026, 02:00 UTC.

@vincentkoc
vincentkoc marked this pull request as ready for review November 27, 2026 03:34
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: cc429cf90829a20753598a1004ff3863bd3e10bd
  • Maintainer: @vincentkoc
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/subagents/requester-cron-authority.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

Carefully review these changes before merging.

@vincentkoc
vincentkoc merged commit d95d852 into main Nov 27, 2026
177 checks passed
@vincentkoc
vincentkoc deleted the refactor/subagent-requester-turn-owner branch November 27, 2026 05:22
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

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:session-state Session, memory, transcript, context, or agent state can drift or corrupt. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. security-sensitive-changed 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