Skip to content

feat(plugins): let plugins recover native subagents they launched - #180274

Merged
fuller-stack-dev merged 1 commit into
openclaw:mainfrom
fuller-stack-dev:feat/plugin-native-children-recovery
Oct 22, 2026
Merged

fuller-stack-dev merged 1 commit into
openclaw:mainfrom
fuller-stack-dev:feat/plugin-native-children-recovery

Conversation

@fuller-stack-dev

@fuller-stack-dev fuller-stack-dev commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

A plugin that launches native subagents can lose track of an accepted child: if it crashes or is interrupted after the host accepts the spawn but before the plugin saves the returned ID, spawn and collect alone give it no way to find that child again.

User Impact

Plugin developers can call the new optional ctx.runtimeContext.subagents.list({ status? }) to recover the native children their plugin launched for the current requester, then collect them as usual. Hosts advertise support with the native-subagent-list-v1 capability; older hosts simply do not offer list. Plugins can only see their own children for the same requester and parent session, never another plugin's, another requester's, or a reset parent's. Children accepted before this change carry no ownership record and are intentionally not listed.

Why This Change Was Made

Recovery reads the host's existing native-child registry instead of adding a plugin-side store or a second index.

  • Ownership is recorded by the host. At spawn time the host stores which plugin, requester and original request launched the child, in the existing native run record before acceptance. Callers cannot choose or forge these values, and ownership is never inferred for older records.
  • Listing uses the same gates as collect. Each call rechecks the active request, plugin and requester authority and the exact parent session. It rebuilds the requester's current tool policy, including sandbox policy, under the latest runtime config, and requires a callable native agents_wait. A reader that is missing, denied for the turn, blocked by sandbox policy, or shadowed by a same-named tool is refused, with no administrator fallback. Spawn and collect now use the same callable-reader check, so a name-only match can no longer pass on the joined spawn path either. A config change during a listing fails with a retryable error instead of returning a stale answer.
  • The result is bounded and deterministic. At most the 200 most recent matching children are returned, newest first. The status filter is applied before the bound, and an unknown status value is rejected. Ties are ordered by the returned ID in code-unit order. Each entry is { runId, childSessionKey, requestId, label?, status }, with no task text, results or authority material. Terminal execution is reported as such and is not presented as successful completion.

Spawn, collect and reply-dispatch signatures are unchanged; the reply adapter forwards list only when the runtime implements it. No hook, scheduler, pagination, database or plugin-specific routing is added.

Builds on #180173 (plugin commands launching native subagents), now merged; this branch is rebased onto main containing it.

Evidence

Run at this head on main (including #180173 and #180283), with task-private HOME, TMPDIR, state and handoff SQLite store, and inherited OPENCLAW_* removed. No live Gateway or provider was used.

Check Result
Full native production-boundary suite (subagent-spawn.production-boundary.test.ts) 76/76 passed
Affected suites (14 files: tool availability, turn authority, registry read API, swarm, plugin-command native subagents, request native subagent, plugin-SDK native-subagent types, native-subagent registry/context, runtime base, requester models) 123 passed, 0 failed
Core typecheck and core test typegraphs (tsgo) exit 0, no diagnostics
Type-aware lint, oxfmt --check, export-name-collision guard clean

The new behavioral cases run through the real reply/command native facade, admission and SQLite registry:

  • lost-receipt recovery in a fresh invocation, with isolation by plugin, requester and parent incarnation, and a reset parent seeing nothing;
  • list, collect and spawn refused, with no preparation, registry row or model run, when agents_wait is absent, denied for the turn, or shadowed by a same-named tool;
  • list rejected under an explicit sandbox deny, the sandbox default allowlist, and a sandbox-required session, and allowed otherwise; live tool-policy revocation; operator-source revocation;
  • the 200-entry bound applied after filtering, terminal execution distinguished from completion, and unknown-status rejection.
  • stored-data compatibility: a row written before this feature loads unchanged after a simulated restart and is not listed. An owned row survives restart and is recovered. The frozen v2026.9.4 reader still selects both rows, and ownership survives its full snapshot rewrite. Ownership lives in the existing JSON payload, with no schema change.

These tests failed before the fixes. Two of the failures: a denied reader made list return [] instead of rejecting, and a sandbox-denied list returned the child. Reverting the tie-break to locale order, or to internal-ID order, fails the tie test.

An independent review of the same change on its previous base measured the Plugin SDK API acknowledgement digest 10f223cf. It found no new public facade API beyond the optional list method and its child type, and one internal declaration (isAgentToolExecutionAvailable). The digest will be rechecked by CI on this base.

check-changed passed 34 of 37 gates. The three failures do not involve this change. The max-lines suppression ratchet flags three untouched UI files. The core test-shard root budget is over in the gateway-root and infra graphs. The dead-export scan lists none of this change's exports. All three also appear without this change.

src/plugins/memory-background-reload.test.ts times out on main without this change. It reproduces locally on #180173's base d20b7fbc6c7, and #180173 attributes it to #178979. That suite runs here only because this change touches src/plugins/**.

@clawsweeper

clawsweeper Bot commented Oct 22, 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 plugin: file-transfer size: XL labels Oct 22, 2026
@clawsweeper clawsweeper Bot added the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Oct 22, 2026
@fuller-stack-dev
fuller-stack-dev force-pushed the feat/plugin-native-children-recovery branch 2 times, most recently from 1a119c0 to 4189d83 Compare October 22, 2026 04:25
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 22, 2026
@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR lets plugins rediscover their native subagents through an optional, requester-scoped list method.

Example: Plugin test-plugin loses the acceptance receipt for request owned.

  • Before: The plugin cannot discover the child using spawn and collect alone.
  • After: A later eligible invocation can recover runId owned with list(), then collect its result.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused implementation with no identified defects and sufficient additive-storage compatibility evidence; behavioral evidence is an in-process production-boundary harness rather than a live Gateway run.
Proof confidence 🦐 gold shrimp (3/6) Ordinary shipped-entry-point proof is exempt for this maintainer-authored PR; reviewed production-owner harness cases and the reported exact-head run cover allowed listing, forbidden principals, reset parents, policy denial, and revoked authority.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: A plugin can lose an accepted child's ID before saving its receipt and then cannot recover that child.
Reason: The maintainer-authored feature closes a concrete recovery gap through a narrow optional capability while preserving existing custody and authority.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR adds useful receipt recovery, the earlier storage compatibility concern is resolved, and no actionable introduced defects were found; required CI remains pending.

Priority: P2
Reviewed head: 68bc6607a10af3a023dee2886bff6de6b9dd24ef

Before merge

None.

Findings

None.

Agent review details

How this fits together

The plugin runtime adapts requester-authorized native tools; spawn records ownership in the existing subagent registry, and listing returns bounded child metadata after current authority and policy checks.

flowchart TD
  A[Eligible plugin invocation] --> B[Requester runtime facade]
  B --> C[Current authority and tool policy]
  C --> D[Native spawn owner]
  D --> E[Existing SQLite registry]
  C --> E
  E --> F[Scoped child metadata]
  F --> A
Loading

Technical review

Best possible solution:

Keep host-captured ownership in the existing registry and expose only the bounded, currently authorized recovery projection.

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

Source confirms that current main has no plugin-scoped discovery method after an acceptance receipt is lost; the supplied boundary cases exercise that recovery scenario.

Is this the best way to solve the issue?

The change uses the existing spawn, registry, and requester-policy owners, with necessary ownership metadata and no competing store or lifecycle manager.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Requester-bound native facade and ingress preparation keeps the original intent (46d7d89: Expose native delegation while retaining requester identity, lifecycle, tool policy, and sandbox restrictions; authenticated command ingress subsequently reused this owner.)
  • Offered versus callable collector reader keeps the original intent (b326dc0: Keep tool definitions stable across turns while enforcing per-turn execution authority; the patch preserves offered schemas and strengthens the callable-reader check.)
  • Native policy and sandbox test extraction keeps the original intent (8ccf0cc: Consolidate overlapping fixtures while retaining distinct authorization and lifecycle coverage; the moved cases remain registered and gain listing-specific checks.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +261, Tests +540, Docs +27. Total +828 across 21 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 14 327 66 +261
Tests 6 752 212 +540
Docs 1 28 1 +27
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 21 1107 279 +828

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Receipt recovery is a useful plugin reliability improvement with a bounded surface.
  • merge-risk: 🚨 compatibility: This extends the public plugin runtime contract and persisted metadata; the maintainer-authored direction, optional method, capability advertisement, and verified no-migration storage contract address the concrete compatibility concerns.
  • 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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-22T04:42:29.070Z sha 4189d835c3ef76a3262bcf11c32b557f0fa3a0a5 :: blocked before merge. :: none

Reviewed October 22, 2026, 1:03 AM ET / 05:03 UTC (Revision 2).

@fuller-stack-dev
fuller-stack-dev force-pushed the feat/plugin-native-children-recovery branch from 4189d83 to bdbe90c Compare October 22, 2026 04:50
Add optional NativeSubagentRuntime.list({ status? }), advertised as native-subagent-list-v1, so a plugin can rediscover requester-owned native children it accepted but did not persist. Ownership is host-captured at spawn, listing reuses the canonical registry and the current tool/sandbox policy, and spawn/list/collect share one callable native reader check.
@fuller-stack-dev
fuller-stack-dev force-pushed the feat/plugin-native-children-recovery branch from bdbe90c to 68bc660 Compare October 22, 2026 04:58
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Addressed the data-model compatibility item at 68bc6607a10af3a023dee2886bff6de6b9dd24ef. The branch is also rebased onto main with #180283; both capability strings are kept.

Ownership is stored in the existing payload_json. There is no new column, no schema or user_version change, and the record codec is unchanged. The new SQLite-backed case keeps stored registry rows compatible across upgrade, rollback and restart (src/agents/plugin-native-subagent.list.test-support.ts) runs through the real state database and checks:

  • Upgrade: a row written without the ownership field loads unchanged after a simulated Gateway restart (database handle closed, resident registry and read caches cleared). It is never listed, because ownership is not inferred.
  • Restart: the owned row reloads with its ownership intact, and list() recovers it in the fresh process state.
  • Rollback: a separate read-only connection using the frozen v2026.9.4 reader (releasedSubagentPayloadFilter and isReleasedSubagentRunRecord) still selects and parses both rows. When that reader's snapshot is rewritten in full and the registry is restarted again, ownership survives and list() still recovers the child.

Mutation check: a reader that drops stored ownership, or one that rejects rows without it, makes this case fail. The source was restored and its hash verified afterwards.

Exact-head local results:

Check Result
Native production-boundary suite 76/76 passed
Affected suites (including requester-models.test.ts) 123 passed
Core and core-test typecheck passed
Type-aware lint passed
Format passed
Export-name-collision guard passed

The only failing CI shard so far is the inherited src/plugins/memory-background-reload.test.ts timeout. It reproduces on main without this change, as noted on #180173.

@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 22, 2026
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Merging with openclaw/ci-gate red because of an inherited failure that is not from this PR.

The only failing job is checks-node-changed-compact-large-22. Its only failures are four 120 s timeouts in src/plugins/memory-background-reload.test.ts; all other CI passed.

That same test fails on main without this PR (base d20b7fbc) and was bisected to #178979 (6387f3ad); see #180173 (comment 6332244405), #180283 and #180079. ClawSweeper's review of this exact head (68bc6607) reports no actionable findings.

@fuller-stack-dev
fuller-stack-dev merged commit f255f9e into openclaw:main Oct 22, 2026
145 of 148 checks passed
fuller-stack-dev added a commit to fuller-stack-dev/openclaw that referenced this pull request Oct 22, 2026
The command runtime projected `subagents` to spawn and collect so scheduling
stays outside that object, which dropped the optional `list` helper added by
openclaw#180274 for every command. Forward `list` when the native runtime provides
it, and pin the exact helper set through a real command invocation.
fuller-stack-dev added a commit that referenced this pull request Oct 22, 2026
#180282)

* feat(plugins): let requester commands schedule bounded follow-up turns

Authenticated requester commands that opt into `scheduledTurns` can schedule
bounded follow-up turns of the same command. Each occurrence restores the
original requester under current policy, rechecks the exact parent session and
loaded plugin instance, refuses direct model calls, and must route model work
through admitted native subagents.

- Bounds: deadline at most 7 days, maxRuns 1-100, 4 schedules per invocation
  and 8 active schedules per loaded plugin instance and parent session. Only
  enabled schedules of the same instance in the current Gateway process count.
- Retirement: the scheduler disables the job and clears its next run in the
  same transaction that launches the final allowed attempt or finds it
  expired, exhausted, invalid or from a previous process. A replaced plugin
  instance retires the schedule on its first refusal.
- v1 scope: schedules end when the Gateway restarts or the plugin reloads;
  plugins re-enroll from a later requester command.
- Rows persist under a dedicated `pluginCommand` payload kind so hosts without
  this feature quarantine them instead of running a model prompt.
- `command-scheduled-turns-v1` advertises support.
- The session-event route predicates move to `timer-session-route.ts` so a
  scheduled occurrence can never prepare parent notices or prompt the model.

* refactor(plugins): break scheduled command import cycles

Move the stored schedule contract and its reserved message into
`src/cron/plugin-command-schedule.types.ts`, and the native subagent request
source into `src/agents/plugin-native-subagent.types.ts`, so cron types,
creation and storage, and the native subagent runtime and scheduled turns no
longer import each other. No behavior change.

* test(plugins): prove queued scheduled children re-admit their requester

A scheduled occurrence queues a native child, settles, and the child launches
later through the real Gateway instance runtime. While the requester stays
authorized the child passes the agent turn's admission revalidation; after the
requester is demoted (committed and published as `users.setRole` does), the
next queued child is refused at that admission, before any model runner.

* test(plugins): close the agent turn runtime without awaiting a void result

* fix(plugins): keep the native child list helper in command runtimes

The command runtime projected `subagents` to spawn and collect so scheduling
stays outside that object, which dropped the optional `list` helper added by
#180274 for every command. Forward `list` when the native runtime provides
it, and pin the exact helper set through a real command invocation.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 23, 2026
…#180274)

Add optional NativeSubagentRuntime.list({ status? }), advertised as native-subagent-list-v1, so a plugin can rediscover requester-owned native children it accepted but did not persist. Ownership is host-captured at spawn, listing reuses the canonical registry and the current tool/sandbox policy, and spawn/list/collect share one callable native reader check.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 23, 2026
openclaw#180282)

* feat(plugins): let requester commands schedule bounded follow-up turns

Authenticated requester commands that opt into `scheduledTurns` can schedule
bounded follow-up turns of the same command. Each occurrence restores the
original requester under current policy, rechecks the exact parent session and
loaded plugin instance, refuses direct model calls, and must route model work
through admitted native subagents.

- Bounds: deadline at most 7 days, maxRuns 1-100, 4 schedules per invocation
  and 8 active schedules per loaded plugin instance and parent session. Only
  enabled schedules of the same instance in the current Gateway process count.
- Retirement: the scheduler disables the job and clears its next run in the
  same transaction that launches the final allowed attempt or finds it
  expired, exhausted, invalid or from a previous process. A replaced plugin
  instance retires the schedule on its first refusal.
- v1 scope: schedules end when the Gateway restarts or the plugin reloads;
  plugins re-enroll from a later requester command.
- Rows persist under a dedicated `pluginCommand` payload kind so hosts without
  this feature quarantine them instead of running a model prompt.
- `command-scheduled-turns-v1` advertises support.
- The session-event route predicates move to `timer-session-route.ts` so a
  scheduled occurrence can never prepare parent notices or prompt the model.

* refactor(plugins): break scheduled command import cycles

Move the stored schedule contract and its reserved message into
`src/cron/plugin-command-schedule.types.ts`, and the native subagent request
source into `src/agents/plugin-native-subagent.types.ts`, so cron types,
creation and storage, and the native subagent runtime and scheduled turns no
longer import each other. No behavior change.

* test(plugins): prove queued scheduled children re-admit their requester

A scheduled occurrence queues a native child, settles, and the child launches
later through the real Gateway instance runtime. While the requester stays
authorized the child passes the agent turn's admission revalidation; after the
requester is demoted (committed and published as `users.setRole` does), the
next queued child is refused at that admission, before any model runner.

* test(plugins): close the agent turn runtime without awaiting a void result

* fix(plugins): keep the native child list helper in command runtimes

The command runtime projected `subagents` to spawn and collect so scheduling
stays outside that object, which dropped the optional `list` helper added by
openclaw#180274 for every command. Forward `list` when the native runtime provides
it, and pin the exact helper set through a real command invocation.
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 merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. plugin: file-transfer 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