Skip to content

fix(plugins): scheduled command turns ignore the requester's tool policy - #186283

Open
nxmxbbd wants to merge 7 commits into
openclaw:mainfrom
nxmxbbd:fix/scheduled-command-tool-policy-pub
Open

nxmxbbd wants to merge 7 commits into
openclaw:mainfrom
nxmxbbd:fix/scheduled-command-tool-policy-pub

Conversation

@nxmxbbd

@nxmxbbd nxmxbbd commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Closes #186281

What Problem This Solves

Fixes: occurrences of requester-scheduled plugin commands resolve tool policy like a live turn with no sender, so the guest toolsBySender["*"] entry applies to them (with a subagent deny there, every occurrence fails), and the requester account's current tool policy and the removed-account refusal are skipped.

User Impact

User impact: scheduled command turns resolve tool policy the way capped automations do. Guest wildcard sender entries no longer apply to them, each occurrence uses the requester account's current group/channel tool policy, and an occurrence whose requester account its channel no longer lists is refused before it runs, naming the account. As for capped automations, sender-specific toolsBySender entries, including "*", no longer apply to occurrences, and a later change to the requester's own entry does not reach existing schedules. Plugin schedules now share the capped-automation account check, so open reports of false refusals there (#156895, #186008) would affect them too until that check is fixed.

Why This Change Was Made

Each occurrence now resolves the job's stored scheduled tool policy once, as capped automations do, and passes it to both admission and native tool preparation (before, preparation never received it). Command schedules record no creator origin, so the schedule's own channel (captured from the live command and checked against the stored job on every occurrence) stands in for it; schedules created from a direct chat on a named account keep working, where a capped automation without a recorded origin would refuse them. The account check runs right after the source check, before the occurrence accepts any input. The background-work docs now say how scheduled command turns resolve tool policy.

Evidence

  • Real Gateway (built dist, isolated state, WebChat operator over chat.send, local stub provider, a plugin with requester-command scheduled turns, tools.toolsBySender["*"] denying sessions_spawn / agents_wait), schedule created then the occurrence forced with cron.run:

    build runs occurrence command ran model requests
    main 5918b1d7bf4 2/2 error: Scheduled command requires current native subagent eligibility. no 0
    this branch (f758a1abbef) 2/2 ok yes, with native subagents 0
  • commands-plugin.scheduled-turns.test.ts (repo fixture: real plugin loader, cron service, channel ingress): on main the wildcard case and the account case fail at their assertions (the child loses read; a later deny for the requester's account is not applied), the direct-chat case passes; with the fix all three pass, together with the existing scheduled-turns, scheduled-turns-restart, plugin-command-scheduled-run and operator-authority tests (117/117 on the current head). The new cases take 2.3-2.5 s each; the whole file runs in 92 s alone (--maxWorkers=1, 31 tests), so they add about 8% to an existing fixture-heavy suite. The fixture now loads a minimal Discord channel that lists the configured accounts and resolves conversation tool policy like the Discord plugin; without a loaded channel, any configured-account check refuses every fixture occurrence.

  • tsgo:core, core test shards, oxlint, oxfmt, git diff --check, line-cap and max-lines ratchets: clean.

  • Test lines: the new tests add 125 net test lines (commands-plugin.scheduled-turns.test.ts +97, its test support +26, operator-authority.test-support.ts +2), recorded in config/test-lines-allocations/scheduled-command-tool-policy-186281.txt. Each of the three cases covers a policy source no existing test reaches (guest wildcard entry, requester account, direct-chat named account), and the fixture needs a loaded channel that lists the configured accounts.

  • Named account, real Gateway (built dist, isolated state, fake Telegram Bot API, named account team, supergroup requester whose sender is linked to an admin profile with users.linkChannelIdentity, local stub provider, the same plugin), occurrences forced with cron.run. Phase A: an allowed child reads a sentinel file. Phase B: two children with tools.swarm.maxConcurrent: 1, the first held at the provider so the second is queued, then the change. Phase C: the first occurrence after the change. Two runs per build and change:

    build change (config.patch on account team) runs A: allowed child B: queued child C: first occurrence after the change
    main 5918b1d7bf4 account removed 2/2 reads the file runs before the change applies, reads the file ok; its child has read and reads the file
    this branch account removed 2/2 reads the file same error: Scheduled account "team" is unavailable. Re-add it to the channel configuration, or recreate this automation from the intended account. No command ran, no child
    main 5918b1d7bf4 groups["*"].tools.deny: ["read"] 2/2 reads the file same ok; its child has read and reads the file
    this branch groups["*"].tools.deny: ["read"] 2/2 reads the file same ok; its child has no read

    Both changes need a Telegram channel reload, which waits for running work (deferring until ... complete), so the queued child runs under the old configuration on both builds; only phase C differs. This branch was measured at f758a1abbef.

  • Registry used by the account check: the occurrence's source check compares the Gateway's current plugin registry with the one it captured on entry, and the account check runs right after it with no await in between, so the process-root registry it reads is that captured registry. Instrumented builds of main and this branch on the named-account setup above (reload or config change while the occurrence waits for its parent session's turn) recorded the same object for the scheduled runner's scoped registry, the published registry and the process root at every point read: the account check, child tool policy, command runtime and execution admission. A registry published during the wait, including by a plugin that declares reload.turnHandover and is replaced mid-turn, makes the occurrence refuse at its next check with Scheduled plugin command source changed or expired. before any input, on main and on this branch alike; channel configuration changes wait for the running occurrence. On this setup the job carries no cron-level operator source, so its launch does not wait for the parent session; a wait at launch was not exercised.

…requester

Occurrences of requester-scheduled plugin commands built their native tool
surface like a live turn with no sender: the guest `toolsBySender["*"]` entry
applied, the requester's recorded channel account was not used for group and
channel tool policy, and a removed requester account was not refused.

Resolve the job's stored scheduled tool policy once, as capped automations do,
and pass it to admission and native tool preparation. Command schedules record
no creator origin, so the schedule's own channel (captured from the live
command and checked against the stored job on every occurrence) stands in for
it. In account mode, refuse an unavailable requester account by name before the
occurrence accepts any input.
@clawsweeper

clawsweeper Bot commented Oct 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 docs Improvements or additions to documentation gateway Gateway runtime plugin: file-transfer size: S labels Oct 27, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment 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. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Scheduled plugin command occurrences use the requester's recorded account policy for admission and native subagent preparation.

Example: Telegram account "team" is removed after its requester schedules a plugin command.

  • Before: The next occurrence runs and can spawn a child with read access.
  • After: The next occurrence refuses before command execution or child creation and names the unavailable account.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused contract repair with supplied product-path positive and negative evidence, distinct regression coverage, and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Supplied built-Gateway evidence at the reviewed head exercises chat.send and cron.run with isolated state, a local provider, and a Telegram Bot API fixture: allowed children read a sentinel, account-policy denial removes read, account removal prevents command and child execution, and registry replacement refuses before input; configuration reload waits for already-running work to settle.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Requester-scheduled commands can fail under guest wildcard restrictions or keep tools after their account policy changes.
Reason: Restores the documented requester-policy contract without adding configuration, public APIs, persistence formats, or another policy owner.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current policy gap with a focused change and supplied Gateway evidence; no actionable patch defects were found.

Priority: P2
Reviewed head: f758a1abbef88c08f66f03e2ec44a9cdb1fa496e

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Gateway restores requester-bound plugin schedules from cron jobs, validates their live authority, and dispatches commands whose native children receive the resolved tool ceiling.

flowchart TD
A[Requester command] --> B[Stored cron schedule]
B --> C[Gateway occurrence runner]
C --> D[Current requester and account policy]
D --> E[Command admission]
E --> F[Native subagent preparation]
Loading

Technical review

Best possible solution:

Use the existing scheduled-policy resolvers consistently across command admission and native child preparation, as this patch does.

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

Current-main source confirms the missing policy propagation, and the supplied built-Gateway comparisons reproduce wildcard failure and skipped account restrictions; this review executed no target code.

Is this the best way to solve the issue?

The patch is the smallest complete repair shown: it resolves policy through existing owners, checks the account before input, and supplies the same context to both consumers.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Scheduled command admission and native tool preparation keeps the original intent (ad40743: Requester commands gained bounded follow-up turns that restore their original requester and validate current authority.)
  • Scheduled fixture lifecycle and registry keeps the original intent (dfe0396: Restart continuity requires a real loaded plugin registry and retained scheduler state; subsequent fixture repairs added SDK binding and orderly child cleanup.)
  • Verified administrator ingress fixture keeps the original intent (c69b8b9: Verified channel identities inherit current administrator authority; the optional session key enables direct-chat coverage without replacing that authority producer.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Jason (Json): Raw commit ad40743 adds src/gateway/plugin-command-scheduled-run.ts:393 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ad407430c464; files: src/gateway/plugin-command-scheduled-run.ts)
  • Peter Steinberger: Raw commit c69b8b9 adds src/channels/message-access/operator-authority.test-support.ts:18 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: c69b8b986867; files: src/channels/message-access/operator-authority.test-support.ts)

PR surface

Source +27, Tests +125, Docs +4, Other +2. Total +158 across 6 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 28 1 +27
Tests 3 129 4 +125
Docs 1 5 1 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 6 164 6 +158

Review metrics

Metric Value Why it matters
Production versus test growth production +27 lines; tests +125 lines The production change reuses existing owners; the tests protect distinct wildcard, account-policy/removal, and direct-chat boundaries.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #186281
Summary: This PR is the focused fix candidate for the linked command-occurrence policy report; nearby scheduled-policy work affects distinct execution boundaries.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove merge-risk: 🚨 compatibility: Current PR review selected no merge-risk labels.

Label justifications:

  • P2: A bounded plugin scheduling workflow can fail or miss current requester-account restrictions; the repair is focused and no emergency impact is established.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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 (3 earlier review cycles)
  • reviewed 2026-10-27T20:50:08.853Z sha 840c8bf :: needs real behavior proof before merge. :: [P2] Resolve the account through the scheduled runtime registry
  • reviewed 2026-10-28T00:48:16.528Z sha 29acafb :: needs maintainer review before merge. :: none
  • reviewed 2026-10-28T00:54:49.145Z sha 29acafb :: needs maintainer review before merge. :: none

Reviewed November 3, 2026, 3:47 AM ET / 08:47 UTC (Revision 4).

@nxmxbbd

nxmxbbd commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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. labels Oct 28, 2026
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. clawsweeper:intake:bug Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 28, 2026
Resolve two conflicts with main 5918b1d:

- config/test-lines-baseline.txt: keep main's shared scalar (6320804).
  Main now budgets new test lines with per-change allocation records, so
  the test growth of this change (net +125 lines) moves to
  config/test-lines-allocations/scheduled-command-tool-policy-186281.txt.
- commands-plugin.scheduled-turns.test-support.ts: keep both sides. The
  fixture body stays a named function so it can pass the requester
  session key to withAdminIngress, and it now takes main's
  resolveGatewayContext and legacy SDK resource host.
@nxmxbbd

nxmxbbd commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. plugin: file-transfer proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S 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.

Plugin scheduled command turns ignore the requester's tool policy and apply the guest toolsBySender["*"] entry

1 participant