Skip to content

[Feature]: Isolated cron scheduled jobs per agent (per-agent jobs.json) in multi-user deployments #26370

Closed

Description

@mjzcng

Summary

Provide per-agent isolation for the cron scheduler by storing and managing scheduled jobs in an agent-scoped jobs.json instead of a global list.

Problem to solve

In a multi-user / multi-agent deployment, any agent that has permission to use the cron tool can currently create, edit, delete, and list scheduled tasks. The critical issue is that the job list appears to be global to the entire OpenClaw instance: if one agent maps to one user, then a user can see scheduled tasks created by other users’ agents, and may even be able to edit or delete them. This creates a serious isolation and security risk (information leakage + cross-tenant modification).

I’d like OpenClaw to introduce a new capability to isolate scheduled tasks per agent, for example by letting each agent use an independent jobs.json (agent-scoped storage and CRUD), so that agents can only view and manage their own scheduled jobs.

Proposed solution

Proposed solution
Introduce agent-scoped cron job storage and access control so scheduled tasks are isolated per agent (and therefore per user in multi-user deployments).

Storage isolation: Instead of a single global jobs.json, maintain a separate jobs.json per agent (e.g., under each agent’s state directory such as /cron/jobs.json), or another equivalent per-agent persistence mechanism.

Access control: The cron tool should only list / create / update / delete jobs within the caller agent’s own scope by default. Cross-agent visibility or modification should be impossible unless explicitly enabled by an administrator.

Migration / backward compatibility: If a global job file exists, provide a migration path (e.g., on startup: migrate existing jobs into the corresponding agent’s jobs.json when the owner can be determined; otherwise place them into an “unassigned” admin-only scope).

Optional admin mode: Optionally allow an admin/operator to query aggregated jobs across agents for operational purposes, but keep this separate from default agent behavior.

This would prevent information leakage and cross-tenant tampering in multi-user environments where each agent represents a different user.

Alternatives considered

No response

Impact

Affected users / systems / channels:
This primarily affects multi-user OpenClaw deployments where one agent maps to one end user (e.g., team or enterprise environments). It impacts any system using the cron tool in shared gateway setups, including chat channels (Feishu, Slack, etc.) and automated workflows that rely on scheduled jobs.

Severity:
High — this is a security and isolation issue, not just a usability concern. It can lead to cross-tenant visibility and potential unauthorized modification or deletion of scheduled jobs. In regulated or enterprise environments, this may violate basic multi-tenant isolation expectations.

Frequency:
Always reproducible in multi-agent environments where multiple agents have cron permissions. The risk increases as the number of users/agents grows.

Consequence:

Information leakage (users can see other users’ scheduled tasks)

Risk of accidental or malicious modification/deletion of other users’ jobs

Reduced trust in multi-user deployments

Additional manual operational overhead to monitor and remediate conflicts

Evidence/examples

No response

Additional information

No response

Activity

  1. added
    enhancement
    on Feb 25, 2026
  2. zard-wang commented on Mar 2, 2026

    @zard-wang

    Hi, I'm hitting this exact issue in production and want to share my experience and a possible lightweight fix.

    My Setup

    4 agents serving multiple users via WeChat Work (企业微信), each agent bound to a different WeChat app:

    • shaniu (general assistant) → wecom channel
    • yousuo (news analyst) → wecom-yousuo channel
    • niumo (finance) → wecom-niumo channel
    • huangmei (history) → wecom-huangmei channel

    Multiple users chat with the same agent. Sessions are properly isolated via session.dmScope: "per-channel-peer".

    The Problem (with evidence)

    When User A (cstarnight) asks yousuo "show my scheduled tasks", cron.list returns ALL 4 jobs — including 3 jobs created by User B (WangZiChun). The AI then displays all of them, leaking:

    • Other user's task names and content
    • Delivery targets (exposing user IDs like wecom-agent:WangZiChun)
    • Schedule details

    Worse: in one instance, the AI proactively modified User B's job (changed delivery.to) when User A asked about tasks. This is cross-user data tampering.

    What I Tried (soft constraints don't work)

    I spent significant time trying to solve this without code changes:

    1. SOUL.md instructions — told AI to filter by sessionKey/delivery.to → AI ignores it ~80% of the time
    2. Custom createdBy field in jobs.json → gets stripped by CronJob schema serialization
    3. SKILL.md with explicit matching rules → still unreliable
    4. Official sessionKey field on jobs + SOUL.md filtering → worked once, failed next time

    Conclusion: prompt-based filtering is fundamentally unreliable for privacy. This needs a hard constraint at the API level.

    Proposed Fix (minimal, backward-compatible)

    I've analyzed the source code and identified a ~30-line change across 4 files. Rather than per-agent storage (which is a bigger refactor), a simpler approach:

    Add optional sessionKey filter to cron.list:

    1. schema/cron.ts — add sessionKey: Type.Optional(Type.String()) to CronListParamsSchema
    2. cron/service/ops.ts — listPage() filters jobs by matching peer ID extracted from sessionKey
    3. gateway/server-methods/cron.ts — pass sessionKey param through to service
    4. agents/tools/cron-tool.ts — auto-pass opts.agentSessionKey when calling cron.list

    The key insight: CronJob already has a sessionKey field ("Origin session namespace"), and createCronTool already receives agentSessionKey. They just aren't connected for list operations.

    Backward compatible: omitting sessionKey returns all jobs (existing behavior). The tool-level change auto-passes it, so AI never sees other users' jobs.

    This also complements the per-agent storage proposal — even with per-agent jobs.json, you'd still need per-user filtering within a shared agent.

    Happy to Submit a PR

    I have the implementation ready and can submit a PR if maintainers agree this approach aligns with the project direction. Would love feedback on:

    1. Is filtering at the cron.list API level the right layer? Or should this be enforced elsewhere?
    2. Should the filter match on full sessionKey or just the peer ID portion?
    3. Any concerns about backward compatibility?

    Thanks for a great project — OpenClaw's architecture is solid, this is one of the few gaps I've found in a real multi-user deployment.

  3. padixa commented on Mar 11, 2026

    @padixa

    Our use case in multi-agent deployment:

    1. Agent execution unclear: cron jobs don not clearly specify which agent should execute, leading to random assignment

    2. Cross-app open_id issue: Different Feishu apps see different open_ids for the same user, causing delivery failures

    3. Tasks modified by other agents: Any agent can modify cron jobs created by other agents, causing configuration chaos

    Suggested:

    • Cron jobs should be explicitly bound to a specific agent
    • Only the creating agent should be able to modify its own tasks
    • Consider supporting user_id/union_id instead of open_id
  4. juanpablodlc commented on Mar 18, 2026

    @juanpablodlc
    Contributor

    +1 - let's please prioritize this. We need to enforce per-agent cron ownership in createCronTool
    Scope list, update, remove, run, and runs; leave status and add unchanged.

  5. steipete commented on Apr 26, 2026

    @steipete
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve.

    Keep open. Current main still has global cron management for the reported surfaces: jobs can carry agent/session metadata and cron.add stamps caller metadata, but cron.list, cron.update, cron.remove, cron.run, and cron.runs do not receive or enforce trusted caller scope. The issue discussion includes concrete production reports and a recent maintainer comment keeping the ownership model open for follow-up.

    Required change / next step:

    Keep this issue open for a maintainer-designed cron ownership model. The likely path is to thread trusted caller agent/session scope from createCronTool or the Gateway request context into cron.list, cron.update, cron.remove, cron.run, and cron.runs; enforce default job visibility/mutation by owner; preserve an explicit admin/operator all-jobs mode; handle existing global jobs safely; and update docs/tests alongside the protocol/service/UI surfaces. Related issue #35447 should be considered during consolidation, but this issue has the richer production context and should not be closed now.

    Best possible solution:

    Keep this issue open for a maintainer-designed cron ownership model. The likely path is to thread trusted caller agent/session scope from createCronTool or the Gateway request context into cron.list, cron.update, cron.remove, cron.run, and cron.runs; enforce default job visibility/mutation by owner; preserve an explicit admin/operator all-jobs mode; handle existing global jobs safely; and update docs/tests alongside the protocol/service/UI surfaces. Related issue #35447 should be considered during consolidation, but this issue has the richer production context and should not be closed now.

    Acceptance criteria:

    • pnpm test src/agents/tools/cron-tool.test.ts src/gateway/protocol/cron-validators.test.ts src/gateway/server-methods/cron.validation.test.ts src/gateway/server.cron.test.ts
    • pnpm test src/cron/service.list-page-sort-guards.test.ts src/cron/service.jobs.test.ts
    • pnpm check:changed in Testbox after code changes because this touches Gateway protocol, cron service/storage, docs, and agent tool behavior

    What I checked:

    • Issue discussion reports real cross-user leakage and maintainer follow-up: Provided comments include WeChat Work and Feishu production reports where cron.list exposed other users’ jobs and agents modified jobs from other users/apps. A maintainer comment on 2026-04-26 kept this open for scoped enforcement across list/update/remove/run/runs, admin mode, migration handling, docs, and tests.
    • Agent cron tool only stamps scope on add: createCronTool calls cron.list with only includeDisabled, stamps agentId/sessionKey only while adding jobs, and sends cron.update, cron.remove, cron.run, and cron.runs with bare job ids. (src/agents/tools/cron-tool.ts:656, 20e21173715e)
    • Gateway protocol lacks caller ownership scope for management calls: CronJob includes optional agentId/sessionKey metadata, but CronListParams exposes only paging/filter/sort fields; update/remove/run are id/jobId selectors, and cron.runs still supports all-scope history without caller ownership fields. (src/gateway/protocol/schema/cron.ts:282, 20e21173715e)
    • Gateway handlers operate globally or by bare id: cron.list forwards directly to context.cron.listPage without caller scope, cron.update/remove/run call service methods by requested id, and cron.runs scope=all reads all jobs and all run logs. (src/gateway/server-methods/cron.ts:135, 20e21173715e)
    • Cron service methods expose global store operations: CronServiceContract exposes list/listPage/update/remove/run/enqueueRun without caller-scope parameters; listPage filters over state.store.jobs globally, while update and remove find/filter by id only. (src/cron/service/ops.ts:274, 20e21173715e)
    • Docs still describe one cron store: The scheduled-job docs state that job definitions persist at ~/.openclaw/cron/jobs.json, and the configuration example uses one cron.store path rather than per-agent stores. Public docs: docs/automation/cron-jobs.md. (docs/automation/cron-jobs.md:42, 20e21173715e)

    Likely related people:

    • steipete: Peter Steinberger posted the recent maintainer comment keeping this issue open and has multiple recent commits on cron service, Gateway schema, delivery behavior, and docs, including shared list-page typing and startup scheduling behavior. (role: recent maintainer and adjacent cron owner; confidence: high; commits: 7877182b6f59, e3dd80f9d4f4, b6be42230672; files: src/cron/service/ops.ts, src/cron/service-contract.ts, src/gateway/protocol/schema/cron.ts)
    • Takhoffman: Commit 77c3b14 added full cron edit parity, all-jobs run history, and compact filters, touching the same Gateway handlers, protocol schema, validators, service ops, run-log, and UI cron surfaces involved in this issue. (role: historical Gateway/UI cron management contributor; confidence: high; commits: 77c3b142a966; files: src/cron/service/ops.ts, src/gateway/protocol/schema/cron.ts, src/gateway/server-methods/cron.ts)
    • vincentkoc: Recent cron work by Vincent Koc includes inferring session agentId when omitted and nearby cron startup/state fixes, which are directly adjacent to the agentId/sessionKey ownership metadata this issue would need to enforce. (role: recent agent/session cron metadata maintainer; confidence: medium; commits: ae63f76bbd51, 924271385ba9, 2896107153e5; files: src/agents/tools/cron-tool.ts, src/agents/tools/cron-tool.test.ts, src/cron/isolated-agent/delivery-target.ts)

    Remaining risk / open question:

    • This is security-sensitive multi-agent ownership work; a minimal sessionKey filter could leave update/remove/run/runs, run logs, admin all-jobs mode, legacy jobs, or cross-channel delivery semantics inconsistent.
    • Gateway protocol and client behavior would change, so CLI, Control UI, agent tool calls, validators, docs, and tests need to move together.
    • The current security docs do not promise hostile multi-tenant isolation on one shared Gateway, so maintainers need to decide the supported boundary and admin/operator escape hatch before implementation.

    Codex review notes: model gpt-5.5, reasoning high; reviewed against 20e21173715e.

  6. clawsweeper commented on May 1, 2026

    @clawsweeper
    Contributor

    Thanks for the context here. I did a careful shell check against current main, and this is already implemented.

    Current main now implements trusted caller-scoped cron access for agent-originated list/get/add/update/remove/run/runs, with regression coverage and merged PR/release provenance; the adjacent declarative agent cron configuration request remains separate.

    I found the merged PR that appears to have closed this: #96883: Scope agent cron operations to the calling agent.

    Root-cause cluster
    Relationship: canonical
    Canonical: #26370
    Summary: This issue is the canonical production-context report for agent cron ownership; the merged caller-scoped cron PR implements it, while related cron configuration and run-history items are duplicate, partial, or adjacent.

    Members:

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

    So I’m closing this as already implemented rather than keeping a duplicate issue open.

    Review details

    Best possible solution:

    Close this issue as implemented by the caller-scoped cron fix, and keep declarative agent-owned cron configuration tracked separately in #46590.

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

    Yes at source level: the earlier issue discussion and pre-fix review showed global cron management by bare id, and current tests now encode the same-agent and foreign-agent access cases that would have exposed the bug.

    Is this the best way to solve the issue?

    Yes: the landed fix enforces ownership at the trusted Gateway caller boundary while preserving unscoped operator behavior, which addresses the reported access-control problem without requiring per-agent storage as a separate persistence refactor.

    Security review:

    Security review cleared: The issue is security-sensitive, and current main now enforces trusted caller-scoped cron access for the reported boundary.

    AGENTS.md: found and applied where relevant.

    What I checked:

    • Issue discussion: The live issue reports production cross-user cron leakage and unauthorized scheduled-job modification in multi-agent WeChat Work/Feishu deployments, and commenters asked for hard API-level per-agent ownership enforcement across list, update, remove, run, and runs.
    • Trusted caller scope on current main: Current main derives cron caller scope from the Gateway client's internal agent runtime identity instead of model-supplied parameters. (src/gateway/server-methods/cron.ts:89, f27d494d00e7)
    • Scoped cron operations on current main: Gateway cron.list rejects foreign explicit agentId and scopes results; get, add, update, remove, run, and runs enforce the caller scope, with caller-scoped all-scope run history rejected. (src/gateway/server-methods/cron.ts:559, f27d494d00e7)
    • Agent tool forwards trusted identity: The agent cron tool resolves the caller agent from the session key and wraps Gateway calls with trusted caller identity; cron.list sends the caller agentId and rejects explicit foreign agent ids. (src/agents/tools/cron-tool.ts:948, f27d494d00e7)
    • Regression tests: Gateway and agent-tool tests cover same-agent access, foreign-agent denial for list/update/remove/run/runs, all-scope run-history rejection, spoofed caller-scope stripping, and update retarget rejection. (src/gateway/server-methods/cron.validation.test.ts:533, f27d494d00e7)
    • Fix provenance: Merged pull request Scope agent cron operations to the calling agent #96883 implemented caller-scoped cron operations, included built Gateway smoke proof for same-agent and cross-agent behavior, and merged as commit cee2aca. (cee2aca40912)

    Likely related people:

    • joshavant: Authored and merged the current-main fix that threads Gateway caller identity through agent cron operations and adds the main regression tests. (role: fix author; confidence: high; commits: cee2aca40912; files: src/gateway/server-methods/cron.ts, src/agents/tools/cron-tool.ts, src/gateway/server-methods/cron.validation.test.ts)
    • steipete: Posted the earlier keep-open review context and has recent cron Gateway/service validation and SQLite persistence work adjacent to this ownership boundary. (role: recent area contributor; confidence: medium; commits: 72bc9ae95231, d2f1c0eac80d, a825b5576b1c; files: src/gateway/server-methods/cron.ts, src/gateway/server-methods/cron.validation.test.ts, src/cron/service/store.ts)
    • Tak Hoffman: Commit 77c3b14 added full cron edit parity, all-jobs run history, compact filters, and touched the same Gateway, protocol, service, and UI cron management surfaces. (role: historical Gateway/UI cron management contributor; confidence: medium; commits: 77c3b142a966; files: src/gateway/server-methods/cron.ts, src/gateway/protocol/schema/cron.ts, src/cron/service/ops.ts)

    Codex review notes: model internal, reasoning high; reviewed against f27d494d00e7; fix evidence: merged PR #96883, release v2026.7.1-beta.1, commit cee2aca40912.

  7. added
    P1
    clawsweeper:source-repro
    clawsweeper:no-new-fix-pr
    clawsweeper:fix-shape-clear
    clawsweeper:needs-maintainer-review
    clawsweeper:needs-product-decision
    clawsweeper:needs-security-review
    impact:data-loss
    impact:security
    impact:message-loss
    issue-rating: 🦞 diamond lobster
    and removed
    clawsweeper:fix-shape-clear
    on May 16, 2026
  8. added
    clawsweeper:fix-shape-clear
    and removed
    clawsweeper:fix-shape-clear
    on Jun 12, 2026
  9. added
    clawsweeper:fix-shape-clear
    and removed
    clawsweeper:fix-shape-clear
    on Jul 4, 2026
  10. locked as resolved and limited conversation to collaborators on Jul 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1clawsweeper:fix-shape-clearclawsweeper:needs-maintainer-reviewclawsweeper:needs-product-decisionclawsweeper:needs-security-reviewclawsweeper:no-new-fix-prclawsweeper:source-reproenhancementimpact:data-lossimpact:message-lossimpact:securityissue-rating: 🦞 diamond lobster

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions