Skip to content

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

Merged
fuller-stack-dev merged 5 commits into
openclaw:mainfrom
fuller-stack-dev:feat/plugin-requester-scheduled-commands
Oct 22, 2026
Merged

fuller-stack-dev merged 5 commits into
openclaw:mainfrom
fuller-stack-dev:feat/plugin-requester-scheduled-commands

Conversation

@fuller-stack-dev

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

Copy link
Copy Markdown
Member

Depends on #180173 (plugin commands launch native subagents), now merged; this PR is based on it.

What Problem This Solves

Plugin commands that start native subagents have no host-owned way to continue unattended later (for example a watch-PR follow-up or a long review that hands off and resumes): a plugin must either fall back to an ordinary cron job, which runs with system or operator authority and prompts the model, or lose the continuation.

User Impact

Plugin authors can call ctx.runtimeContext.scheduledTurns.schedule(...) from an eligible authenticated requester command to schedule bounded follow-up turns of that same command. Each occurrence runs as the original requester under current policy, and model work must go through admitted native subagents.

v1 scope: schedules end when the Gateway restarts. A schedule never survives a Gateway restart or a plugin reload. It is retired at its next occurrence without running plugin code, and the plugin must re-enroll from a later requester command (for example an explicit resume command). Restart continuity was a follow-up, not part of this PR; it is implemented in #180844.

Operators see these schedules as cron jobs. There is no configuration change and no migration. Plugins can detect support through the command-scheduled-turns-v1 runtime capability and register a variant without scheduled turns on older hosts.

Why This Change Was Made

  • Opt-in and requester-bound. The surface is offered only inside a requester command that declares runtimeCapabilities: ["subagents", "scheduledTurns"], the matching manifest contracts (commandRuntimeCapabilities, sessionScheduledTurns: ["requester-command"]) and requireAuth: true. The cron store keeps the requester's invocation facts privately. Each occurrence restores the original requester, rechecks the exact parent session and the exact loaded plugin instance against the live registry, and refuses llm.complete and continueAgent.
  • Bounded.
    • Deadline at most 7 days; maxRuns 1–100.
    • At most 4 schedules per invocation and 8 active schedules per loaded plugin instance and parent session. Only enabled schedules of the same plugin instance in the current Gateway process count; leftovers from an earlier process or a replaced instance can never run plugin code and do not block re-enrollment.
    • Attempts are charged atomically at launch and never refunded.
  • Retirement. In the same transaction that launches the final allowed attempt, or finds a schedule expired, exhausted, invalid or created by a previous Gateway process, the scheduler disables the job and clears its next run. The final attempt still launches. A disabled schedule refuses force runs. The first occurrence that finds another live instance of its plugin is refused before any plugin code runs and retires the schedule, instead of erroring until generic auto-disable.
  • Why restarts end schedules. Plugin instance identities are process-local, and persisted plugin metadata (id, source, root, version) does not prove that the same code is loaded after a restart: a reload with the same metadata can run different code. No existing durable authority proves implementation identity across processes, so continuing would run unverified code with the requester's authority. Leftover rows can accumulate, one generation per restart or reload, until each retires at its next occurrence or its 7-day deadline; they never run plugin code. After an in-process plugin reload, the first occurrence spends one attempt being refused, then retires.
  • Downgrade safety. Rows persist under a dedicated pluginCommand payload kind, never as an ordinary agentTurn. A host without this feature that opens the same state schema rejects the unknown payload kind through its row codec (invalid-payload, recorded in its quarantine audit records), so the row is never loaded or run as a model prompt. Hosts with an older state schema refuse to open the database at all; that boundary comes from main.
  • No session-event fallback. A scheduled occurrence never takes the session-event prompt route and never prepares or leases the parent session's pending automation notices. These route predicates now live in src/cron/service/timer-session-route.ts, which keeps timer-execution.ts within the line cap.

This adds a plugin SDK surface and changes cron security boundaries; none of the changed paths are listed in .github/CODEOWNERS. The sibling owned-native-children change (#180274) landed first; its capability constant and list entry in src/plugins/runtime/runtime-base.ts are kept alongside this one.

Evidence

Head 7c28cbee34b4e66db567c8e418ce0b8098e2c560 on main f2fccc2d677c7b354689fced0d4bae706350562b (which includes #180173, #180283 and #180274). Commands ran with inherited OPENCLAW_* stripped and private HOME, state, TMPDIR and handoff-store paths. Dependencies came from the shared pnpm store.

Check Result
Focused S6 and S1 command files, subagent-spawn, requester model catalog and native subagent context 14 files, 194 passed
pnpm test src/cron 2141 of 2142 passed at 2e1a75a8 (on main 7ba05b68); the one failure, isolated-agent/run.meta-error-status.test.ts, is outside this change and passed in three isolated reruns
Affected command, plugin, Gateway cron, cron-tool, caller-scope, system-event and model-catalog files (39) 661 passed at 711441ed
tsgo:core and core test graphs no diagnostics in changed files; the only diagnostics are also present on main (openai-responses-websocket.ts TS2353; ui/src in the four Gateway graphs)
Type-aware lint, format, git diff --check, line-cap ratchet, import cycles (including madge), plugin SDK surface and export checks pass (type-aware oxlint 0 warnings/0 errors on 56 changed files; madge 0 cycles)
  • Queued child authority after the occurrence settles. A scheduled occurrence queues a native child (swarm capacity held), settles, and the child then launches through the real Gateway instance runtime, in one fixture:
    • While the requester stays authorized, the child passes the agent turn's admission revalidation. This harness publishes no reply runtime, so the turn stops at that next seam, still before the model runner.
    • After the requester is demoted while the next child is queued (committed and published as users.setRole does), that child is refused at admission with Queued channel operator authority changed; submit a new request., before any model runner.
    • Removing the launch-time owner-authority recheck in operator-run-recovery.ts makes the test fail.
    • Main's subagent-spawn.production-boundary test separately proves that an admitted queued child reaches the embedded model runner. Running the two cases as separate fixtures in one worker showed a cross-fixture owner-authority state leak (fresh state directory, same synthetic sender), so they share one fixture; within one fixture the demotion is enforced.
  • Regression tests on the real layers.
    • A real job-mutation worker still admits a full cap for the live plugin instance when a full cap of rows from a previous Gateway process and another from a replaced instance exist, and refuses the next one.
    • Under the live scheduler, a replaced-instance refusal retires the schedule on its first occurrence without auto-disable, while a non-permanent refusal keeps it waking.
    • A real same-metadata plugin reload is refused before any plugin code runs and retires the schedule; a later force run does not run.
    • A scheduled occurrence never prepares the parent session's pending automation notices.
  • Mutation checks. Each of these source mutations makes at least one test fail:
    • persisting a schedule as an ordinary agentTurn, or trusting a stored agentTurn copy;
    • skipping retirement on a budget error or on the final charge, or dropping the previous-process check;
    • letting a disabled schedule force-run;
    • removing either cap, counting every enabled schedule, or ignoring the plugin instance or Gateway process when counting;
    • not advertising the capability, or reading the caller's capability array;
    • routing a schedule through the session-event path, or preparing parent notices for it;
    • refusing the retired final attempt at launch, or omitting the scheduler's process identity;
    • keeping a failed requestId pinned to its rejection;
    • ignoring the permanent refusal at settlement, not classifying a replaced instance as permanent, retiring on any error, or treating a disposed instance as replaced.
  • Downgrade. A database written by this branch was loaded by a main host with the same state schema, a real wall-clock scheduler and spy runners. The command row was not listed or loaded, run(..., "force") returned unknown cron job id, no isolated, session-event or system-event run happened, and the ordinary job still loaded. With the row persisted as agentTurn instead, the same host loaded it and ran it through the session-event prompt path. Neither harness read the quarantine audit record itself; that part rests on main's row-codec code path. This was run before the rebase, and storage has not changed since.
  • SDK. build:plugin-sdk:strict-smoke and an external consumer compiled only against the built package exports passed before the rebase; the SDK surface has not changed since.
  • Import cycles. The first head failed the madge architecture check (also flagged by ClawSweeper): the schedule contract, cron types and creation module imported each other, as did the native subagent runtime and scheduled turns. The stored schedule contract and its reserved message now live in src/cron/plugin-command-schedule.types.ts, and the native subagent request source in src/agents/plugin-native-subagent.types.ts. No behavior change; madge reports 0 cycles.
  • Upgrade compatibility. This PR adds no schema migration; existing rows without a command envelope keep their current codec path.
    • A database written by main 7ba05b68 (immediately before this PR) with five ordinary jobs was loaded by this head and by that host, each on its own copy: an isolated job with a provider model, thinking level, timeout and tool allowlist on a cron expression with a time zone; a main-session system event; a session: agent turn; a one-shot at job with deleteAfterRun; and a disabled job. The loaded configuration, listing, next-run times, force-run results and runner routing (including the model and thinking passed to the isolated runner) were identical, and the one-shot job was removed after its run on both.
    • A database written by v2026.10.5 needs main's pending state-schema and client-credential migration (openclaw doctor --fix) before either main 7ba05b68 or this head opens it; both refuse with the identical message, so this PR does not change that upgrade path. The doctor migration itself was not run here because it can manage the Gateway service on the host.
  • Rebase onto feat(plugins): let plugins recover native subagents they launched #180274. Both add a runtime capability (kept both), and feat(plugins): let plugins recover native subagents they launched #180274 added prepareCurrentCapabilityProfile to the native subagent request source, which now lives in the leaf plugin-native-subagent.types.ts. The command runtime keeps scheduledTurns outside ctx.runtimeContext.subagents and forwards feat(plugins): let plugins recover native subagents they launched #180274's optional list there. A real command invocation pins the helper set (collect, list, spawn) and fails without the forwarding (flagged by ClawSweeper).
  • Merge with the requester model catalog (feat(plugins): expose requester-scoped model catalogs #180283). Both PRs add a command runtime capability. The merge keeps main's capability rules table and adds scheduledTurns to it (requires auth and a manifest contract, and still requires subagents), advertises both requester-model-catalog-v1 and command-scheduled-turns-v1, and exposes models and scheduledTurns side by side. A scheduled occurrence still receives no direct model access: the scheduled runner does not supply the interactive catalog factory.
  • Rebase onto current main. Main retired the cron heartbeat hooks (refactor(automations): retire heartbeat SDK and scheduling entry points #180106) while this was waiting on feat(plugins): let authenticated commands launch native subagents #180173. The rebase keeps main's removal in server-cron.ts, timer-execution.ts and job-mutations.ts (including the retired monitor guard) and drops the requestHeartbeat stubs from the two new test files; S6 behavior is unchanged.
  • Independent review. An independent reviewer rated the pre-rebase head 122cdd8d44e73a754077074cb790c6dc033eea66 ready for an upstream PR. In its own isolated worktree it ran: focused 101 passed; src/cron 2178 passed; affected (33 files) 582 passed; merged with main b3245a24, 266 passed; merge-tree clean against main 175ded9d. Its own probes and mutation checks confirmed the cap and retirement behavior. The rebase changed only the base and moved the two route predicates into a sibling module, with no behavior change.
  • Test cost. src/auto-reply/reply/commands-plugin.scheduled-turns.test.ts exceeds the 30 s budget: 23 tests, about 48–63 s. Each case loads a third-party plugin from disk, real admin ingress and a real cron service, because the behaviors under test (requester restoration, plugin-instance binding, reload refusal, transcript commitment, native child lineage) live in those layers. Sharing one plugin load is unsafe because several cases reload or retire the plugin registry, reset the parent session or revoke the operator.

CI failures on the first head not caused by this PR: checks-node-changed-compact-large-30-2 fails in src/plugins/memory-background-reload.test.ts (four 120 s timeouts in the Bun agentic-plugins shard); the same three tests also time out locally on main d20b7fbc, and #180173 failed them identically. checks-ui-e2e (1/9) fails ui/src/pages/plugins/plugins-lifecycle.e2e.test.ts; this PR changes no UI.

Not proved:

  • a scheduled native child completing real inference against a real provider: this harness stops the admitted child at reply-runtime publication, before the model runner;
  • the v2026.10.5 doctor migration run end to end on a fresh state copy;
  • an npm-packed tarball install, check-openclaw-package-tarball, or a Docker package install;
  • the changed-test wrapper's advisory 720-root budget, which main already exceeds in several shards.

Follow-ups (optional):

  • Restart continuity: let a schedule continue across a Gateway restart once a durable authority can prove plugin implementation identity across processes. Implemented in feat(plugins): keep requester command schedules across Gateway restarts #180844, which uses the captured source digest of the loaded plugin generation as that identity.
  • Overall ceiling: add an aggregate enabled ceiling that includes leftover rows from earlier generations, or retire previous-process rows when the scheduler starts.
  • Transient-refusal test: add a real-runner test where a transient refusal (a retired registry that shows another live instance, or a configuration change before admission) leaves the job enabled with a next run. Today two mutations of that path survive; both over-retire and never run anything.

@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 gateway Gateway runtime agents Agent runtime and tooling plugin: file-transfer size: XL labels Oct 22, 2026
@fuller-stack-dev
fuller-stack-dev marked this pull request as ready for review October 22, 2026 04:06
@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. 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. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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 real behavior proof before merge.

What this changes

This PR lets authenticated plugin commands schedule bounded follow-up commands under the original requester's current authority.

Example: An authenticated /review-pr command requests a follow-up every 60 seconds for 30 minutes, capped at 10 attempts.

  • Before: The plugin has no supported requester-bound continuation and must arrange another invocation.
  • After: Cron invokes the plugin command under current requester policy, stopping at the attempt limit, deadline, Gateway restart, or plugin replacement.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The previous actionable defect is repaired and the implementation is coherent; final-effect authority and stable-upgrade qualification still limit merge confidence.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: Plugins cannot resume unattended command work later under the original requester without arranging a broader ordinary automation or another user invocation.
Reason: The maintainer-authored direction supplies a narrow missing host capability, and its restart-scoped limitation is explicitly accepted and documented.

Merge readiness

⛔ Blocked before merge - 3 items remain

The native-child list regression is fixed, and no new concrete correctness defect was found; this useful maintainer-authored PR should remain open.

Priority: P2
Reviewed head: 7c28cbee34b4e66db567c8e418ce0b8098e2c560

Before merge

  • Add real behavior proof - Authority-chain proof required: the real-owner scheduled harness queues a native child, settles its occurrence, and rejects requester demotion at admission, but the authorized child stops at missing reply-runtime publication before the model runner. The separate ordinary-child test does not complete this scheduled flow. Supply redacted output showing authorized provider I/O and demoted-requester rejection before I/O, removing IPs, API keys, phone numbers, and non-public endpoints. The reported pre-PR-main database comparison is useful, but identical migration-required refusals do not establish the unrun stable-release upgrade. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Resolve security review attention item - Deferred requester execution composes live operator, session, plugin, and occurrence authority checks, with no concrete bypass established.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

None.

Tests

  • Missing end-to-end proof: Missing the scheduled queued-child provider-boundary scenario and a v2026.10.5 Doctor upgrade with existing settings, jobs, and routing intact.
Agent review details

How this fits together

The command runtime captures requester and parent-session facts, the existing cron worker stores and charges occurrences, and the Gateway restores current authority before dispatching the command and admitting native children.

flowchart TD
  A[Authenticated requester command] --> B[Command runtime capability]
  B --> C[Cron creation owner]
  C --> D[SQLite scheduler worker]
  D --> E[Gateway authority restoration]
  E --> F[Scheduled plugin command]
  F --> G[Native child admission]
  G --> H[Model provider]
Loading

Technical review

Best possible solution:

Provide bounded requester-owned follow-ups through the existing cron and native-child owners, with explicit retirement on restart or plugin replacement.

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

This is an additive capability; source inspection confirms current main lacks requester-bound scheduled command turns, and the previous list-helper regression is repaired on the reviewed head.

Is this the best way to solve the issue?

The design uses the existing cron persistence, worker accounting, command dispatch, and native admission owners; its new adapters serve distinct creation and execution boundaries rather than introducing another scheduler.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

Needs attention: Deferred requester execution composes live operator, session, plugin, and occurrence authority checks, with no concrete bypass established.

Evidence

What I checked:

  • Previous finding resolved: The exact-head repair forwards the optional list helper alongside spawn and collect; the command-boundary regression calls list and checks its result. (src/plugins/plugin-command-execution.ts:105, 7c28cbee34b4)
  • Authority evidence stops before the final effect: The scheduled queued-child test expects the authorized child to stop with a missing reply-runtime error and the demoted requester to be rejected at admission; it does not exercise authorized provider I/O. (src/auto-reply/reply/commands-plugin.scheduled-turns.test.ts:813, 7c28cbee34b4)
  • Full discussion and upgrade limits: The full PR body and latest author response explicitly retain both the provider-boundary gap and the unrun v2026.10.5 Doctor upgrade; matching migration-required refusals establish neither a completed upgrade nor preservation afterward. (7c28cbee34b4)
  • Existing scheduler owns persistence and accounting: The worker atomically charges launches and retires terminal schedules; the existing storage codec writes a dedicated pluginCommand payload rather than a runnable legacy agentTurn. (src/cron/store/job-config-codec.ts:52, 7c28cbee34b4)
  • Direction and lifecycle tradeoff recorded: The maintainer-authored PR explicitly limits v1 schedules to the current Gateway process and loaded plugin instance, documenting re-enrollment after restart or replacement. Public docs: docs/plugins/sdk-runtime/background-work.md. (docs/plugins/sdk-runtime/background-work.md:135, 7c28cbee34b4)
  • Current main and review state: Fetched main does not contain this scheduledTurns capability; GitHub reports the reviewed head mergeable with checks still pending, without a reported conflict. (47eaf429b321)

Likely related people:

  • Jason (Json): Raw commit 46d7d89 adds src/agents/plugin-native-subagent.ts:46 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 46d7d8943ec3; files: src/agents/plugin-native-subagent.ts)
  • Peter Steinberger: Raw commit 3d2f7ca adds src/cron/service/timer-execution.ts:369 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3d2f7ca06b26; files: src/cron/service/timer-execution.ts)

PR surface

Source +1704, Tests +2172, Docs +114. Total +3990 across 59 files. Added test files: 7.

View PR surface stats
Area Files Added Removed Net
Source 44 1798 94 +1704
Tests 13 2175 3 +2172
Docs 2 115 1 +114
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 59 4088 98 +3990

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a useful optional plugin capability with no demonstrated urgent production regression.
  • merge-risk: 🚨 compatibility: The PR expands the public command runtime and persisted cron payload contract; feature detection and downgrade handling are explicit, while stable-release upgrade qualification remains incomplete.
  • merge-risk: 🚨 security-boundary: Deferred execution restores requester authority after the originating invocation ends, and the scheduled queued-child path has not been demonstrated through the final provider effect.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

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

  • Complete the scheduled queued-child allowed and demoted scenarios through the final provider boundary.
  • Run the v2026.10.5 Doctor upgrade on an isolated state copy and verify existing settings, jobs, and routing remain intact.

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 (4 earlier review cycles)
  • reviewed 2026-10-22T04:25:20.430Z sha ca0e27e25a9cea117a3c77396f6e125bd4391df3 :: blocked before merge. :: [P2] Break the new static cycles in the schedule contract
  • reviewed 2026-10-22T04:45:16.392Z sha 2e1a75a836396316d0d4895fb20643a80a12c346 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-22T05:42:36.402Z sha ec2e15c34b6f2a3cd2696d20435a47f50d7ace2c :: needs real behavior proof before merge. :: [P2] Preserve the optional native-child listing method
  • reviewed 2026-10-22T05:58:15.861Z sha a21b3b3 :: needs real behavior proof before merge. :: [P2] Preserve the optional native-child listing method

Reviewed October 22, 2026, 2:27 AM ET / 06:27 UTC (Revision 5).

@fuller-stack-dev

fuller-stack-dev commented Oct 22, 2026 •

Copy link
Copy Markdown
Member Author

Addressed the ClawSweeper review of ca0e27e2 in commit 2e1a75a8, then rebased onto main 414a00cd after the requester model catalog (#180283) landed. Current head: 711441edc2980ebcdcdcdfad203b5bbf1a046b5a.

  • P2 static import cycles: moved the stored schedule contract (PluginCommandSchedule) and the reserved payload constant into the leaf src/cron/plugin-command-schedule.types.ts. Cron types, creation, storage and the Gateway runner now consume that leaf. The native subagent request source moved to the leaf src/agents/plugin-native-subagent.types.ts, which removes the second cycle between plugin-native-subagent.ts and plugin-scheduled-command.ts. check-madge-import-cycles reports 0 cycles. Requester authority and retirement behavior are unchanged; the focused S6 and S1 files plus subagent-spawn pass (11 files, 165 tests), as do tsgo:core and all 21 core test graphs (only diagnostics also present on main).

  • Data-model compatibility: this PR adds no schema migration.

    • A main 7ba05b68 database with five ordinary jobs (an isolated job with model, thinking, timeout and tool allowlist on a cron expression with a time zone; a main-session system event; a session: agent turn; a one-shot at job; and a disabled job) loads under this head with identical configuration, listing, next runs, force-run results and runner routing compared with the old host on its own copy.
    • A v2026.10.5 database needs main's existing openclaw doctor --fix state migration before either main or this head can open it; both refuse with the identical message, so the release upgrade path is unchanged by this PR.
    • Details are in the PR body.
  • Rebase onto feat(plugins): expose requester-scoped model catalogs #180283: both PRs add a command runtime capability. The resolution keeps main's capability rules table, adds scheduledTurns to it (requires auth and a manifest contract, and still requires subagents), and advertises both capabilities. Scheduled occurrences still get no direct model access. Focused files plus the requester model catalog tests pass (12 files, 178 tests); tsgo:core, all 21 core test graphs, madge and the line-cap ratchet are clean.

@fuller-stack-dev

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

The import-cycle repair and upgrade-compatibility evidence are current on head 2e1a75a836396316d0d4895fb20643a80a12c346; please review this revision.

@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 22, 2026
@fuller-stack-dev
fuller-stack-dev force-pushed the feat/plugin-requester-scheduled-commands branch from 2e1a75a to 711441e Compare October 22, 2026 04:53
@fuller-stack-dev

fuller-stack-dev commented Oct 22, 2026 •

Copy link
Copy Markdown
Member Author

Follow-up for the ClawSweeper review of 2e1a75a8 (current head a21b3b3, rebased onto main f2fccc2d after #180274 landed):

  • Queued scheduled child authority (proof and merge risk): new test admits a queued scheduled child's agent turn only while its requester stays authorized in commands-plugin.scheduled-turns.test.ts. A scheduled occurrence queues a native child, settles, and the child launches afterwards through the real Gateway instance runtime.
    • An authorized requester's child passes the agent turn's admission revalidation.
    • After a demotion committed and published as users.setRole does, the next queued child is refused at that admission ("Queued channel operator authority changed; submit a new request."), before any model runner.
    • Removing the launch-time owner-authority recheck in operator-run-recovery.ts makes the test fail.
    • This harness publishes no reply runtime, so the admitted child stops at that seam rather than at provider I/O. Main's subagent-spawn.production-boundary test covers an admitted queued child reaching the embedded runner.
  • Merge conflicts: resolved by rebasing onto feat(plugins): expose requester-scoped model catalogs #180283 and feat(plugins): let plugins recover native subagents they launched #180274. All runtime capabilities are kept, and feat(plugins): let plugins recover native subagents they launched #180274's new request-source field moved into the leaf type. Focused files including feat(plugins): let plugins recover native subagents they launched #180274's native subagent context tests pass (14 files, 194 tests). tsgo:core, all 21 core test graphs, madge (0 cycles) and the line-cap ratchet are clean.
  • Data model: this PR adds no migration. Data from the pre-PR main loads and routes identically under this head. A v2026.10.5 database needs main's existing openclaw doctor --fix migration before main or this head opens it, with identical refusal text on both. I did not run that doctor migration on this host because it can manage the Gateway service.

@fuller-stack-dev

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

The queued-child authority proof, the #180283 merge and the upgrade evidence are current on head ec2e15c34b6f2a3cd2696d20435a47f50d7ace2c; please review this revision.

@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

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.
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.
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.
@fuller-stack-dev
fuller-stack-dev force-pushed the feat/plugin-requester-scheduled-commands branch from ec2e15c to b8f6e2e Compare October 22, 2026 05:45
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Rebased onto main after #180274 landed; the queued-child authority proof, conflict resolution and upgrade evidence are current on head b8f6e2e.

@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@fuller-stack-dev

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

The native-child list regression is fixed on head 7c28cbe; please review this revision.

@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Merging at 7c28cbee34b4e66db567c8e418ce0b8098e2c560 despite a red openclaw/ci-gate, under the maintainer's scoped instruction to land this PR. The only failure is inherited from main:

  • Only failing job: checks-node-changed-compact-large-3 (job 119673182528, run 39733179230, attempt 1): 4 failed and 757 passed tests in the Bun agentic-plugins shard. The only failures are four 120 s timeouts in src/plugins/memory-background-reload.test.ts:
    • retires live watchers and starts successor indexing;
    • restarts memory watchers after reload waits for active indexing past its stop deadline;
    • syncs detached background work after reload (replace Memory Core: false/true).
  • Reproduced on main without this PR: the same tests time out locally on main d20b7fbc alone. feat(plugins): let authenticated commands launch native subagents #180173 failed them identically and documented the bisect to 6387f3a (fix(memory): resume background reindex after foreground turns #178979, "fix(memory): resume background reindex after foreground turns").
  • Out of scope for this PR: it changes no memory or memory-core code. The suite runs only because the PR touches src/plugins/**.

Every other check passes or was skipped, including the security-sensitive review, dependency review and all Security High boundary checks. ClawSweeper at this head reports no findings. Its remaining requests are proof items that the PR body lists under "Not proved": provider I/O for a scheduled queued child, and a completed v2026.10.5 doctor upgrade. The authority decision is proven at the agent-turn admission, and the pre-PR data path is proven identical.

@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Follow-up evidence for the three proof gaps ClawSweeper flagged on this PR. All runs used current main at aa52e91bf9de, which includes this PR's squash ad407430.

Isolation for every run:

  • private HOME, state, config and TMPDIR, with inherited OPENCLAW_* removed;
  • loopback-only Gateway on a free port, OPENCLAW_DISABLE_BONJOUR=1;
  • a local mock OpenAI Responses provider (qa-lab mock-openai) behind a real models.providers entry, so the real embedded runner and provider transport are exercised;
  • no live Gateway and no shared config.

(a) A scheduled child performs a real provider call; a demoted requester's queued child is refused before any call

Setup:

  • The requester is a durable profile, s6-requester, with role s6-admin, authenticated through trusted-proxy behind a local header-injecting proxy.
  • A third-party plugin from disk registers /s6proof with runtimeCapabilities: ["subagents", "scheduledTurns"].
  • tools.swarm.maxConcurrent is 1.
Step Observed
Requester chat.send /s6proof enroll {scheduledTurns: true, subagents: true}, then a scheduled job (every 10 min, deadline +30 min, maxRuns 3)
cron.run force, occurrence 1: plugin spawns a child, then collects Mock provider got one agent-initial request carrying the child marker. Collect returned status: done, result: "S6-AUTHORIZED-CHILD-OK". agent.wait → ok, effective mock-openai/gpt-5.6-luna, visible terminal reply
Occurrence 2: plugin spawns a holder child, then the target child The holder occupies the lane inside a before_agent_run hook, so no provider I/O. The target stays queued: agent.wait returns timeout and the run has no startedAt
users.setRole → s6-member, then release the holder Target child terminal error: "Restart recovery operator authority changed; start a new user turn.", with no acceptedAt or startedAt. It ended 12 ms after the role commit. The in-flight holder was terminated too
Provider requests during occurrence 2 0

The queued-child refusal through the channel ingress path is already covered by the harness test (Queued channel operator authority changed). This run proves the Gateway-client path end to end.

(b) Upgrade from v2026.10.5, rollback reader

  1. v2026.10.5 writes the profile. Installed from the npm [email protected] tarball, it wrote state schema 20:
    • a user profile with role s6-admin;
    • a chat transcript with a real provider reply;
    • cron rows: an isolated agentTurn every-job, a main-session systemEvent at-job, a disabled job, plus managed heartbeat and dreaming jobs.
  2. openclaw doctor --fix --non-interactive --yes from current main, against only this profile. Exit 0, schema 20 → 31. A launchctl shim on PATH refused and recorded every service call; the only call was the read-only print gui/501/ai.openclaw.gateway.
  3. Current main Gateway on the upgraded profile.
    • Data loads: all cron jobs are listed (doctor converted the managed heartbeat to agentTurn), the pre-upgrade transcript and reply are intact, and the role is still s6-admin (roleSource: assigned).
    • S6 works: /s6proof enrolls, the job is stored with payload_kind = pluginCommand, and a forced occurrence's child performs a provider call and completes done.
  4. Rollback reader.
    • The v2026.10.5 build refuses the upgraded profile at startup with exit 78: state database … uses schema 31; this build supports 20. It fails closed and nothing is read or rewritten.
    • The newest pre-S6 main build (8b8291fed34, same schema 31) starts normally. It does not list the pluginCommand row, and cron.run on it returns Automation not found. The row is quarantined, with its full payload, as a cron.quarantine diagnostic event with reason: invalid-payload. All other jobs, the transcript and the role load unchanged, and the provider received 0 requests.

(c) Harness order dependence: fixed in #180818

This was a test-harness flaw, not a product cache. The capacity blocker's maxConcurrent: 1 was overridden by the child's own reservation, which re-applies the configured lane limit of 32. The child therefore launched immediately, and in a warm second test it passed admission before the demotion.

#180818:

  • pins the configured limit;
  • asserts the child holds a reservation without launching;
  • splits the queued-child cases back into separate tests.

Two mutation checks back it: dropping the pin fails the three hold-dependent tests, and skipping the queued authority recheck fails the demotion test.

Observations, not addressed here

  • A plugin command arriving as channel text (Slack signed ingress, qa-channel) never gets runtimeContext.subagents or scheduledTurns. Only Gateway chat.send supplies the replyOptions.runId and user-turn recorder that runWithCommandNativeSubagents requires. With a linked Slack administrator, the gate saw operatorAuthority: true but runId and recorder both false. This affects command-native children generally (feat(plugins): let authenticated commands launch native subagents #180173), not just scheduling, and the docs describe channel senders as eligible.
  • cron.list shows the stored pluginCommand job as payload.kind: "agentTurn" with the [plugin-command-scheduled-turn:v1] sentinel message, although the stored row is pluginCommand.

fuller-stack-dev added a commit to fuller-stack-dev/openclaw that referenced this pull request Oct 22, 2026
Requester-admitted scheduled command turns (openclaw#180282) ended when the Gateway
restarted. Accepted schedules now survive a restart, within their original
bounds and under the same per-occurrence authority checks.

- A schedule accepted from a plugin whose loaded source has a captured
  digest records a private restart binding in job state: the serving
  Gateway process and plugin instance, plus that source digest. The released
  `pluginCommand` envelope and payload kind are unchanged; no table, column or
  schema version is added.
- After a restart, the scheduler's launch claim re-arms the schedule onto the
  newly loaded instance only if it runs the same code: the same plugin ID,
  source, root and version, the exact captured source digest, and the target
  command still registered. The re-arm, the budget check, the receipt and the
  charge share one state transaction. The Gateway thread supplies the loaded
  instances.
- The deadline, maxRuns and spent attempts carry over. Expired, exhausted,
  disabled, removed and completed schedules are never re-armed. Without a
  matching instance (disabled, uninstalled or changed plugin) the claim
  retires the schedule before running plugin code or spending an attempt.
- Each occurrence still restores the original requester and rechecks the
  operator, parent session, plugin instance and code, command and tool
  ceiling; a demoted or removed requester is refused before the command runs.
- In-process plugin reloads still retire schedules bound to the replaced
  instance. Core-bundled plugins have no captured digest and keep
  restart-scoped schedules.
- The active cap also counts unexpired restartable schedules of the same
  code left by an earlier process.
- `command-scheduled-turns-restart-v1` advertises continuity, and `schedule()`
  returns `survivesRestart` for each accepted schedule.
- Released openclaw#180282 readers decode the unchanged envelope, ignore the binding
  and end the schedule at its next occurrence; that ended schedule stays
  ended after upgrading again.
fuller-stack-dev added a commit that referenced this pull request Oct 22, 2026
…ts (#180844)

* feat(plugins): keep requester command schedules across Gateway restarts

Requester-admitted scheduled command turns (#180282) ended when the Gateway
restarted. Accepted schedules now survive a restart, within their original
bounds and under the same per-occurrence authority checks.

- A schedule accepted from a plugin whose loaded source has a captured
  digest records a private restart binding in job state: the serving
  Gateway process and plugin instance, plus that source digest. The released
  `pluginCommand` envelope and payload kind are unchanged; no table, column or
  schema version is added.
- After a restart, the scheduler's launch claim re-arms the schedule onto the
  newly loaded instance only if it runs the same code: the same plugin ID,
  source, root and version, the exact captured source digest, and the target
  command still registered. The re-arm, the budget check, the receipt and the
  charge share one state transaction. The Gateway thread supplies the loaded
  instances.
- The deadline, maxRuns and spent attempts carry over. Expired, exhausted,
  disabled, removed and completed schedules are never re-armed. Without a
  matching instance (disabled, uninstalled or changed plugin) the claim
  retires the schedule before running plugin code or spending an attempt.
- Each occurrence still restores the original requester and rechecks the
  operator, parent session, plugin instance and code, command and tool
  ceiling; a demoted or removed requester is refused before the command runs.
- In-process plugin reloads still retire schedules bound to the replaced
  instance. Core-bundled plugins have no captured digest and keep
  restart-scoped schedules.
- The active cap also counts unexpired restartable schedules of the same
  code left by an earlier process.
- `command-scheduled-turns-restart-v1` advertises continuity, and `schedule()`
  returns `survivesRestart` for each accepted schedule.
- Released #180282 readers decode the unchanged envelope, ignore the binding
  and end the schedule at its next occurrence; that ended schedule stays
  ended after upgrading again.

* test(plugins): simulate the restarted process without a production hook

Remove the test-only process identity setter from the scheduler module. The
in-process restart tests now replace the identity the Gateway thread reports
to the scheduler with a module mock; the claim, plugins and state database stay
real, and real Gateway processes cover the same restart in the E2E.
fuller-stack-dev added a commit to fuller-stack-dev/openclaw that referenced this pull request Oct 22, 2026
Plugin commands typed in Slack, Discord and other channels never received
the command-scoped native subagents (openclaw#180173) or scheduled turns
(openclaw#180282), although the docs describe authorized channel senders as
eligible. Channel ingress already binds the verified sender's operator
authority, but the native gate also required a Gateway chat.send run id
and user-turn recorder, which channel dispatch never supplies.

For channel ingress only, the host now mints that run id and recorder,
and only for the operator authority host ingress bound to the message's
verified principal. The existing gate is unchanged: command authorization,
the declared capability, the requester's native tool policy, admission
and per-call authority rechecks still decide. Unlinked, unverified,
demoted or unauthorized senders keep seeing no capability.

The committed input uses the message's route-scoped source turn id, so a
continuing agent turn and restart recovery join it, and it stores the
same redacted form the delivered-command transcript mirror records. That
mirror now records only the reply once a native command committed the
input.
fuller-stack-dev added a commit that referenced this pull request Oct 22, 2026
…#180968)

Plugin commands typed in Slack, Discord and other channels never received
the command-scoped native subagents (#180173) or scheduled turns
(#180282), although the docs describe authorized channel senders as
eligible. Channel ingress already binds the verified sender's operator
authority, but the native gate also required a Gateway chat.send run id
and user-turn recorder, which channel dispatch never supplies.

For channel ingress only, the host now mints that run id and recorder,
and only for the operator authority host ingress bound to the message's
verified principal. The existing gate is unchanged: command authorization,
the declared capability, the requester's native tool policy, admission
and per-call authority rechecks still decide. Unlinked, unverified,
demoted or unauthorized senders keep seeing no capability.

The committed input uses the message's route-scoped source turn id, so a
continuing agent turn and restart recovery join it, and it stores the
same redacted form the delivered-command transcript mirror records. That
mirror now records only the reply once a native command committed the
input.
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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 23, 2026
…ts (openclaw#180844)

* feat(plugins): keep requester command schedules across Gateway restarts

Requester-admitted scheduled command turns (openclaw#180282) ended when the Gateway
restarted. Accepted schedules now survive a restart, within their original
bounds and under the same per-occurrence authority checks.

- A schedule accepted from a plugin whose loaded source has a captured
  digest records a private restart binding in job state: the serving
  Gateway process and plugin instance, plus that source digest. The released
  `pluginCommand` envelope and payload kind are unchanged; no table, column or
  schema version is added.
- After a restart, the scheduler's launch claim re-arms the schedule onto the
  newly loaded instance only if it runs the same code: the same plugin ID,
  source, root and version, the exact captured source digest, and the target
  command still registered. The re-arm, the budget check, the receipt and the
  charge share one state transaction. The Gateway thread supplies the loaded
  instances.
- The deadline, maxRuns and spent attempts carry over. Expired, exhausted,
  disabled, removed and completed schedules are never re-armed. Without a
  matching instance (disabled, uninstalled or changed plugin) the claim
  retires the schedule before running plugin code or spending an attempt.
- Each occurrence still restores the original requester and rechecks the
  operator, parent session, plugin instance and code, command and tool
  ceiling; a demoted or removed requester is refused before the command runs.
- In-process plugin reloads still retire schedules bound to the replaced
  instance. Core-bundled plugins have no captured digest and keep
  restart-scoped schedules.
- The active cap also counts unexpired restartable schedules of the same
  code left by an earlier process.
- `command-scheduled-turns-restart-v1` advertises continuity, and `schedule()`
  returns `survivesRestart` for each accepted schedule.
- Released openclaw#180282 readers decode the unchanged envelope, ignore the binding
  and end the schedule at its next occurrence; that ended schedule stays
  ended after upgrading again.

* test(plugins): simulate the restarted process without a production hook

Remove the test-only process identity setter from the scheduler module. The
in-process restart tests now replace the identity the Gateway thread reports
to the scheduler with a module mock; the claim, plugins and state database stay
real, and real Gateway processes cover the same restart in the E2E.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 23, 2026
…openclaw#180968)

Plugin commands typed in Slack, Discord and other channels never received
the command-scoped native subagents (openclaw#180173) or scheduled turns
(openclaw#180282), although the docs describe authorized channel senders as
eligible. Channel ingress already binds the verified sender's operator
authority, but the native gate also required a Gateway chat.send run id
and user-turn recorder, which channel dispatch never supplies.

For channel ingress only, the host now mints that run id and recorder,
and only for the operator authority host ingress bound to the message's
verified principal. The existing gate is unchanged: command authorization,
the declared capability, the requester's native tool policy, admission
and per-call authority rechecks still decide. Unlinked, unverified,
demoted or unauthorized senders keep seeing no capability.

The committed input uses the message's route-scoped source turn id, so a
continuing agent turn and restart recovery join it, and it stores the
same redacted form the delivered-command transcript mirror records. That
mirror now records only the reply once a native command committed the
input.
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 gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant